メニュー表示機能追加

This commit is contained in:
harukin-expo-dev-env 2024-03-26 05:21:32 +00:00
parent aa0daeb791
commit 07345755c7
2 changed files with 30 additions and 8 deletions

8
App.js
View File

@ -57,10 +57,10 @@ export default function App() {
);
}
export function AppContainer() {
const { areaInfo, setAreaInfo } = useAreaInfo();
const { areaInfo } = useAreaInfo();
const navigationRef = React.useRef();
return (
<NavigationContainer name="Root" style={{ flex: 1 }}>
<NavigationContainer name="Root" style={{ flex: 1 }} ref={navigationRef}>
<Tab.Navigator
tabBarOptions={{ keyboardHidesTabBar: Platform.OS === "android" }}
>
@ -73,7 +73,7 @@ export function AppContainer() {
tabBarIcon: initIcon("barchart", "AntDesign"),
}}
>
{(props) => <Top {...props} />}
{(props) => <Top {...props} navigationRef={navigationRef} />}
</Tab.Screen>
<Tab.Screen
name="menuPage"

30
Top.js
View File

@ -13,9 +13,9 @@ import FavoriteList from "./components/FavoriteList.js";
import { useFavoriteStation } from "./stateBox/useFavoriteStation";
import { optionData } from "./lib/stackOption.js";
import { useCurrentTrain } from "./stateBox/useCurrentTrain.js";
import { AS } from "./storageControl.js";
const Stack = createStackNavigator();
export const Top = ({ navigation }) => {
const { favoriteStation, setFavoriteStation } = useFavoriteStation();
export const Top = ({ navigation, navigationRef }) => {
const { webview, getCurrentTrain } = useCurrentTrain();
//地図用
@ -24,14 +24,36 @@ export const Top = ({ navigation }) => {
useEffect(() => {
getStationList2().then(setMapsStationData);
}, []);
const [mapSwitch, setMapSwitch] = React.useState("false");
const ASCore = ({ k, s, d }) =>
AS.getItem(k)
.then((d) => (d ? s(d) : AS.setItem(k, d)))
.catch(() => AS.setItem(k, d));
useEffect(() => {
//地図スイッチ
ASCore({ k: "mapSwitch", s: setMapSwitch, d: "false" });
}, []);
useEffect(() => {
const unsubscribe = navigation.addListener("tabLongPress", (e) => {
const unsubscribe = navigation.addListener("tabLongPress", () => {
navigation.navigate("favoriteList");
});
return unsubscribe;
}, [navigation]);
useEffect(() => {
const unsubscribe = navigation.addListener("tabPress", () => {
if (navigationRef.current?.getCurrentRoute().name == "Apps") {
if (mapSwitch == "true") {
navigation.navigate("trainMenu");
} else {
webview.current?.injectJavaScript(`AccordionClassEvent()`);
}
} else {
navigation.navigate("Apps");
}
});
return unsubscribe;
}, [navigation, mapSwitch]);
return (
<Stack.Navigator>