89 lines
2.6 KiB
JavaScript
89 lines
2.6 KiB
JavaScript
import React, { useEffect } from "react";
|
|
import { createStackNavigator } from "@react-navigation/stack";
|
|
import { useNavigation } from "@react-navigation/native";
|
|
import Apps from "./components/Apps";
|
|
import TrainBase from "./components/trainbaseview";
|
|
import HowTo from "./howto";
|
|
import News from "./components/news";
|
|
import TrainMenu from "./components/trainMenu";
|
|
import FavoriteList from "./components/FavoriteList";
|
|
import { optionData } from "./lib/stackOption";
|
|
import { useCurrentTrain } from "./stateBox/useCurrentTrain";
|
|
import { useTrainMenu } from "./stateBox/useTrainMenu";
|
|
import { AS } from "./storageControl";
|
|
import { news } from "./config/newsUpdate";
|
|
import { Linking, Platform } from "react-native";
|
|
const Stack = createStackNavigator();
|
|
export const Top = () => {
|
|
const { webview } = useCurrentTrain();
|
|
const { navigate, addListener, isFocused } = useNavigation();
|
|
|
|
//地図用
|
|
const { injectJavaScript, mapSwitch } = useTrainMenu();
|
|
|
|
const goToFavoriteList = () =>
|
|
navigate("positions", { screen: "favoriteList" });
|
|
|
|
useEffect(() => {
|
|
const unsubscribe = addListener("tabLongPress", goToFavoriteList);
|
|
return unsubscribe;
|
|
}, []);
|
|
|
|
const goToTrainMenu = () => {
|
|
if (Platform.OS === "web") {
|
|
Linking.openURL("https://train.jr-shikoku.co.jp/");
|
|
setTimeout(() => {
|
|
navigate("topMenu", { screen: "menu" });
|
|
}, 100);
|
|
|
|
return;
|
|
}
|
|
if (!isFocused()) {
|
|
navigate("positions", { screen: "Apps" });
|
|
}
|
|
if (mapSwitch == "true") {
|
|
navigate("positions", { screen: "trainMenu" });
|
|
} else {
|
|
webview.current?.injectJavaScript(`AccordionClassEvent()`);
|
|
}
|
|
return;
|
|
};
|
|
|
|
useEffect(() => {
|
|
const unsubscribe = addListener("tabPress", goToTrainMenu);
|
|
return unsubscribe;
|
|
}, [addListener, mapSwitch, injectJavaScript]);
|
|
|
|
return (
|
|
<Stack.Navigator detachInactiveScreens={false}>
|
|
<Stack.Screen
|
|
name="Apps"
|
|
options={{
|
|
headerShown: false,
|
|
gestureEnabled: true,
|
|
headerTransparent: true,
|
|
detachPreviousScreen: false,
|
|
}}
|
|
component={Apps}
|
|
/>
|
|
<Stack.Screen
|
|
name="trainbase"
|
|
options={{ ...optionData }}
|
|
component={TrainBase}
|
|
/>
|
|
<Stack.Screen name="howto" options={optionData} component={HowTo} />
|
|
<Stack.Screen name="news" options={optionData} component={News} />
|
|
<Stack.Screen
|
|
name="trainMenu"
|
|
options={optionData}
|
|
component={TrainMenu}
|
|
/>
|
|
<Stack.Screen
|
|
name="favoriteList"
|
|
options={{ ...optionData, gestureEnabled: false }}
|
|
component={FavoriteList}
|
|
/>
|
|
</Stack.Navigator>
|
|
);
|
|
};
|