2026-03-20 07:14:58 +00:00
|
|
|
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";
|
2026-03-24 04:37:46 +00:00
|
|
|
import { useColorScheme } from "react-native";
|
2024-06-07 06:24:15 +00:00
|
|
|
import Apps from "./components/Apps";
|
|
|
|
|
import TrainBase from "./components/trainbaseview";
|
2023-12-15 00:32:58 +09:00
|
|
|
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";
|
2024-05-27 16:39:15 +00:00
|
|
|
import { useTrainMenu } from "./stateBox/useTrainMenu";
|
2024-09-16 16:31:14 +00:00
|
|
|
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";
|
2026-04-08 02:54:14 +00:00
|
|
|
import { positionsStackNavRef } from "./lib/rootNavigation";
|
2023-12-15 00:32:58 +09:00
|
|
|
const Stack = createStackNavigator();
|
2025-01-22 11:34:05 +00:00
|
|
|
export const Top = () => {
|
2024-05-30 13:09:08 +00:00
|
|
|
const { webview } = useCurrentTrain();
|
2026-03-25 01:43:33 +09:00
|
|
|
const { navigate, addListener, isFocused } = useNavigation<any>();
|
2026-03-24 04:37:46 +00:00
|
|
|
const isDark = useColorScheme() === "dark";
|
|
|
|
|
const bgColor = isDark ? "#1c1c1e" : "#ffffff";
|
2024-09-16 16:31:14 +00:00
|
|
|
|
2023-12-15 00:32:58 +09:00
|
|
|
//地図用
|
2025-05-01 14:29:20 +00:00
|
|
|
const { mapSwitch } = useTrainMenu();
|
2026-03-20 07:14:58 +00:00
|
|
|
const mapSwitchRef = useRef(mapSwitch);
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
mapSwitchRef.current = mapSwitch;
|
|
|
|
|
}, [mapSwitch]);
|
2023-12-15 00:32:58 +09:00
|
|
|
|
2025-01-22 11:34:05 +00:00
|
|
|
const goToFavoriteList = () =>
|
|
|
|
|
navigate("positions", { screen: "favoriteList" });
|
2024-08-20 03:15:13 +00:00
|
|
|
|
2023-12-15 00:32:58 +09:00
|
|
|
useEffect(() => {
|
2024-08-20 03:15:13 +00:00
|
|
|
const unsubscribe = addListener("tabLongPress", goToFavoriteList);
|
2023-12-15 00:32:58 +09:00
|
|
|
return unsubscribe;
|
2025-01-22 11:34:05 +00:00
|
|
|
}, []);
|
2024-08-20 03:15:13 +00:00
|
|
|
|
2026-04-08 02:54:14 +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/");
|
2025-03-30 02:47:02 +00:00
|
|
|
setTimeout(() => navigate("topMenu", { screen: "menu" }), 100);
|
2025-03-04 10:38:04 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2026-04-08 02:54:14 +00:00
|
|
|
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" });
|
2025-03-30 02:47:02 +00:00
|
|
|
else webview.current?.injectJavaScript(`AccordionClassEvent()`);
|
2025-01-22 11:34:05 +00:00
|
|
|
return;
|
2026-03-20 07:14:58 +00:00
|
|
|
}, [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;
|
2026-03-20 07:14:58 +00:00
|
|
|
}, [addListener, goToTrainMenu]);
|
2023-12-15 00:32:58 +09:00
|
|
|
|
|
|
|
|
return (
|
2026-03-24 04:37:46 +00:00
|
|
|
<Stack.Navigator
|
|
|
|
|
id={null}
|
2026-03-25 01:43:33 +09:00
|
|
|
screenOptions={{ cardStyle: { backgroundColor: bgColor } }}
|
2026-04-08 02:54:14 +00:00
|
|
|
screenListeners={({ navigation: stackNav }) => {
|
|
|
|
|
stackNavRef.current = stackNav;
|
|
|
|
|
return {};
|
|
|
|
|
}}
|
2026-03-24 04:37:46 +00:00
|
|
|
>
|
2023-12-15 00:32:58 +09:00
|
|
|
<Stack.Screen
|
|
|
|
|
name="Apps"
|
|
|
|
|
options={{
|
|
|
|
|
headerShown: false,
|
|
|
|
|
gestureEnabled: true,
|
|
|
|
|
headerTransparent: true,
|
2025-01-22 11:34:05 +00:00
|
|
|
detachPreviousScreen: false,
|
2023-12-15 00:32:58 +09:00
|
|
|
}}
|
2024-05-31 07:31:32 +00:00
|
|
|
component={Apps}
|
2024-03-19 09:38:20 +00:00
|
|
|
/>
|
2023-12-15 00:32:58 +09: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} />
|
2023-12-15 00:32:58 +09:00
|
|
|
<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
|
|
|
/>
|
2023-12-15 00:32:58 +09: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
|
|
|
/>
|
2023-12-15 00:32:58 +09:00
|
|
|
</Stack.Navigator>
|
|
|
|
|
);
|
|
|
|
|
};
|