From c0e0039bfb271f3cf6aa125fb5ea05ec203abf2d Mon Sep 17 00:00:00 2001 From: harukin-expo-dev-env Date: Sun, 17 Mar 2024 18:41:51 +0000 Subject: [PATCH] =?UTF-8?q?=E5=88=97=E8=BB=8A=E3=81=AE=E7=8F=BE=E5=9C=A8?= =?UTF-8?q?=E5=9C=B0=E6=83=85=E5=A0=B1=E3=81=8B=E3=82=89=E5=88=97=E8=BB=8A?= =?UTF-8?q?=E4=BD=8D=E7=BD=AE=E6=83=85=E5=A0=B1=E3=81=AB=E3=82=B8=E3=83=A3?= =?UTF-8?q?=E3=83=B3=E3=83=97=E3=81=A7=E3=81=8D=E3=82=8B=E3=82=88=E3=81=86?= =?UTF-8?q?=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Top.js | 3 +- .../EachTrainInfo/LongHeader.js | 2 + .../EachTrainInfo/ShortHeader.js | 2 + .../EachTrainInfo/TrainDataView.js | 73 ++++++++++++++----- .../EachTrainInfoCore.js | 2 + stateBox/useCurrentTrain.js | 12 ++- 6 files changed, 72 insertions(+), 22 deletions(-) diff --git a/Top.js b/Top.js index b320f59..1d36df5 100644 --- a/Top.js +++ b/Top.js @@ -15,9 +15,8 @@ import { optionData } from "./lib/stackOption.js"; import { useCurrentTrain } from "./stateBox/useCurrentTrain.js"; const Stack = createStackNavigator(); export const Top = ({ navigation }) => { - const webview = useRef(); const { favoriteStation, setFavoriteStation } = useFavoriteStation(); - const { getCurrentTrain } = useCurrentTrain(); + const { webview, getCurrentTrain } = useCurrentTrain(); //地図用 const [mapsStationData, setMapsStationData] = useState(undefined); diff --git a/components/ActionSheetComponents/EachTrainInfo/LongHeader.js b/components/ActionSheetComponents/EachTrainInfo/LongHeader.js index 95f23f9..0410b53 100644 --- a/components/ActionSheetComponents/EachTrainInfo/LongHeader.js +++ b/components/ActionSheetComponents/EachTrainInfo/LongHeader.js @@ -7,6 +7,7 @@ export const LongHeader = ({ currentPosition, nearTrainIDList, openTrainInfo, + navigate, }) => { return ( ); diff --git a/components/ActionSheetComponents/EachTrainInfo/ShortHeader.js b/components/ActionSheetComponents/EachTrainInfo/ShortHeader.js index a289e24..1f68b85 100644 --- a/components/ActionSheetComponents/EachTrainInfo/ShortHeader.js +++ b/components/ActionSheetComponents/EachTrainInfo/ShortHeader.js @@ -7,6 +7,7 @@ export const ShortHeader = ({ currentPosition, nearTrainIDList, openTrainInfo, + navigate, }) => { return ( ); diff --git a/components/ActionSheetComponents/EachTrainInfo/TrainDataView.js b/components/ActionSheetComponents/EachTrainInfo/TrainDataView.js index fdb5426..978bd78 100644 --- a/components/ActionSheetComponents/EachTrainInfo/TrainDataView.js +++ b/components/ActionSheetComponents/EachTrainInfo/TrainDataView.js @@ -1,7 +1,10 @@ -import React from "react"; +import React, { useState, useEffect } from "react"; import { View, TouchableOpacity, useWindowDimensions } from "react-native"; import { StateBox } from "./StateBox"; import { useDeviceOrientationChange } from "../../../stateBox/useDeviceOrientationChange"; +import { getStationList2 } from "../../../lib/getStationList2"; +import { useCurrentTrain } from "../../../stateBox/useCurrentTrain"; +import { SheetManager } from "react-native-actions-sheet"; export const TrainDataView = ({ currentTrainData, @@ -9,10 +12,16 @@ export const TrainDataView = ({ nearTrainIDList, openTrainInfo, mode = 0, + navigate, }) => { const { width, height } = useWindowDimensions(); const { isLandscape } = useDeviceOrientationChange(); - + const { webview, getCurrentTrain } = useCurrentTrain(); + const [mapsStationData, setMapsStationData] = useState(undefined); + useEffect(() => { + getStationList2().then(setMapsStationData); + }, []); + const onLine = !!currentPosition?.toString().length; return ( - + { + const test = []; + Object.keys(mapsStationData).forEach((d) => { + mapsStationData[d].forEach((x) => { + if (x.StationNumber == currentPosition[0]) + test.push({ line: d, station: x }); + }); + }); + if (!test.length) return; + webview.current?.injectJavaScript( + `MoveDisplayStation('${test[0].line}_${test[0].station.MyStation}_${test[0].station.Station_JP}')` + ); + navigate("Apps"); + SheetManager.hide("EachTrainInfo"); + }} + > + + + ) } @@ -335,6 +336,7 @@ export const EachTrainInfoCore = ({ currentPosition={currentPosition} nearTrainIDList={nearTrainIDList} openTrainInfo={openTrainInfo} + navigate={navigate} /> ) } diff --git a/stateBox/useCurrentTrain.js b/stateBox/useCurrentTrain.js index 944b37c..9e181d8 100644 --- a/stateBox/useCurrentTrain.js +++ b/stateBox/useCurrentTrain.js @@ -1,8 +1,15 @@ -import React, { createContext, useContext, useState, useEffect } from "react"; +import React, { + createContext, + useContext, + useState, + useEffect, + useRef, +} from "react"; import { HeaderConfig } from "../lib/HeaderConfig"; import useInterval from "../lib/useInterval"; const initialState = { + webview: {}, currentTrain: [], setCurrentTrain: () => {}, currentTrainLoading: "loading", @@ -40,9 +47,12 @@ export const CurrentTrainProvider = ({ children }) => { useEffect(getCurrentTrain, []); //初回だけ現在の全在線列車取得 useInterval(getCurrentTrain, 15000); //15秒毎に全在線列車取得 + + const webview = useRef(); return (