Files

117 lines
3.7 KiB
TypeScript
Raw Permalink Normal View History

import React, { useCallback, useEffect, useRef } from "react";
2025-01-22 11:34:05 +00:00
import { createStackNavigator } from "@react-navigation/stack";
import { useNavigation } from "@react-navigation/native";
import { useColorScheme } from "react-native";
2024-06-07 06:24:15 +00:00
import Apps from "./components/Apps";
import TrainBase from "./components/trainbaseview";
import HowTo from "./howto";
2024-08-20 07:34:59 +00:00
import News from "./components/news";
import TrainMenu from "./components/trainMenu";
2025-03-21 13:22:11 +00:00
import { FavoriteList } from "./components/FavoriteList";
2024-08-20 07:34:59 +00:00
import { optionData } from "./lib/stackOption";
import { useCurrentTrain } from "./stateBox/useCurrentTrain";
import { useTrainMenu } from "./stateBox/useTrainMenu";
import { AS } from "./storageControl";
import { news } from "./config/newsUpdate";
2025-03-04 10:38:04 +00:00
import { Linking, Platform } from "react-native";
2025-06-15 05:20:11 +00:00
import GeneralWebView from "./GeneralWebView";
2025-08-25 15:54:40 +00:00
import { StationDiagramView } from "@/components/StationDiagram/StationDiagramView";
import { positionsStackNavRef } from "./lib/rootNavigation";
const Stack = createStackNavigator();
2025-01-22 11:34:05 +00:00
export const Top = () => {
const { webview } = useCurrentTrain();
2026-03-25 01:43:33 +09:00
const { navigate, addListener, isFocused } = useNavigation<any>();
const isDark = useColorScheme() === "dark";
const bgColor = isDark ? "#1c1c1e" : "#ffffff";
//地図用
const { mapSwitch } = useTrainMenu();
const mapSwitchRef = useRef(mapSwitch);
useEffect(() => {
mapSwitchRef.current = mapSwitch;
}, [mapSwitch]);
2025-01-22 11:34:05 +00:00
const goToFavoriteList = () =>
navigate("positions", { screen: "favoriteList" });
2024-08-20 03:15:13 +00:00
useEffect(() => {
2024-08-20 03:15:13 +00:00
const unsubscribe = addListener("tabLongPress", goToFavoriteList);
return unsubscribe;
2025-01-22 11:34:05 +00:00
}, []);
2024-08-20 03:15:13 +00:00
const stackNavRef = positionsStackNavRef;
const goToTrainMenu = useCallback((e: any) => {
2025-03-04 10:38:04 +00:00
if (Platform.OS === "web") {
Linking.openURL("https://train.jr-shikoku.co.jp/");
setTimeout(() => navigate("topMenu", { screen: "menu" }), 100);
2025-03-04 10:38:04 +00:00
return;
}
if (!isFocused()) return;
const stackNav = stackNavRef.current;
if (stackNav && stackNav.getState()?.index > 0) {
e.preventDefault();
stackNav.goBack();
return;
}
if (mapSwitchRef.current == "true")
2025-08-25 15:54:40 +00:00
navigate("positions", { screen: "trainMenu" });
else webview.current?.injectJavaScript(`AccordionClassEvent()`);
2025-01-22 11:34:05 +00:00
return;
}, [isFocused, navigate, webview]);
2025-01-22 11:34:05 +00:00
2024-08-20 03:15:13 +00:00
useEffect(() => {
const unsubscribe = addListener("tabPress", goToTrainMenu);
2024-03-26 05:21:32 +00:00
return unsubscribe;
}, [addListener, goToTrainMenu]);
return (
<Stack.Navigator
id={null}
2026-03-25 01:43:33 +09:00
screenOptions={{ cardStyle: { backgroundColor: bgColor } }}
screenListeners={({ navigation: stackNav }) => {
stackNavRef.current = stackNav;
return {};
}}
>
<Stack.Screen
name="Apps"
options={{
headerShown: false,
gestureEnabled: true,
headerTransparent: true,
2025-01-22 11:34:05 +00:00
detachPreviousScreen: false,
}}
2024-05-31 07:31:32 +00:00
component={Apps}
2024-03-19 09:38:20 +00:00
/>
<Stack.Screen
name="trainbase"
2025-01-22 11:34:05 +00:00
options={{ ...optionData }}
2024-03-19 09:38:20 +00:00
component={TrainBase}
/>
2025-08-25 15:54:40 +00:00
<Stack.Screen
name="stDiagram"
2025-09-11 15:05:32 +00:00
options={{ ...optionData, gestureEnabled: false }}
2025-08-25 15:54:40 +00:00
component={StationDiagramView}
/>
2024-03-19 09:38:20 +00:00
<Stack.Screen name="howto" options={optionData} component={HowTo} />
2025-08-25 15:54:40 +00:00
<Stack.Screen
name="generalWebView"
options={optionData}
component={GeneralWebView}
/>
2024-03-19 09:38:20 +00:00
<Stack.Screen name="news" options={optionData} component={News} />
<Stack.Screen
2024-03-19 09:38:20 +00:00
name="trainMenu"
options={optionData}
2024-05-31 07:31:32 +00:00
component={TrainMenu}
2024-03-19 09:38:20 +00:00
/>
<Stack.Screen
name="favoriteList"
options={{ ...optionData, gestureEnabled: false }}
2024-05-31 07:31:32 +00:00
component={FavoriteList}
2024-03-19 09:38:20 +00:00
/>
</Stack.Navigator>
);
};