列車の現在地情報から列車位置情報にジャンプできるように変更
This commit is contained in:
parent
4a44ab5628
commit
c0e0039bfb
3
Top.js
3
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);
|
||||
|
@ -7,6 +7,7 @@ export const LongHeader = ({
|
||||
currentPosition,
|
||||
nearTrainIDList,
|
||||
openTrainInfo,
|
||||
navigate,
|
||||
}) => {
|
||||
return (
|
||||
<ScrollView
|
||||
@ -27,6 +28,7 @@ export const LongHeader = ({
|
||||
currentPosition={currentPosition}
|
||||
nearTrainIDList={nearTrainIDList}
|
||||
openTrainInfo={openTrainInfo}
|
||||
navigate={navigate}
|
||||
/>
|
||||
</ScrollView>
|
||||
);
|
||||
|
@ -7,6 +7,7 @@ export const ShortHeader = ({
|
||||
currentPosition,
|
||||
nearTrainIDList,
|
||||
openTrainInfo,
|
||||
navigate,
|
||||
}) => {
|
||||
return (
|
||||
<ScrollView
|
||||
@ -29,6 +30,7 @@ export const ShortHeader = ({
|
||||
currentPosition={currentPosition}
|
||||
nearTrainIDList={nearTrainIDList}
|
||||
openTrainInfo={openTrainInfo}
|
||||
navigate={navigate}
|
||||
/>
|
||||
</ScrollView>
|
||||
);
|
||||
|
@ -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 (
|
||||
<View
|
||||
style={{
|
||||
@ -22,10 +31,29 @@ export const TrainDataView = ({
|
||||
width: isLandscape ? (width / 100) * 40 : width,
|
||||
flex: 1,
|
||||
}}
|
||||
>
|
||||
<TouchableOpacity
|
||||
style={{ flex: 1, flexDirection: "row" }}
|
||||
disabled={!onLine}
|
||||
onPress={() => {
|
||||
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");
|
||||
}}
|
||||
>
|
||||
<StateBox
|
||||
mode={mode}
|
||||
title={`現在地 ${currentPosition.toString()}`}
|
||||
title={`現在地 ${currentPosition?.toString()}${onLine ? "▶️" : ""}`}
|
||||
text={
|
||||
currentTrainData?.Pos.match("~")
|
||||
? `${
|
||||
@ -39,7 +67,14 @@ export const TrainDataView = ({
|
||||
}`
|
||||
: currentTrainData?.Pos
|
||||
}
|
||||
style={
|
||||
onLine
|
||||
? { borderWidth: 1, borderColor: "red", borderStyle: "solid" }
|
||||
: {}
|
||||
}
|
||||
/>
|
||||
</TouchableOpacity>
|
||||
|
||||
<View style={{ flex: 1, flexDirection: mode == 2 ? "row" : "column" }}>
|
||||
<View style={{ flex: 1, flexDirection: "row" }}>
|
||||
<StateBox
|
||||
|
@ -323,6 +323,7 @@ export const EachTrainInfoCore = ({
|
||||
currentPosition={currentPosition}
|
||||
nearTrainIDList={nearTrainIDList}
|
||||
openTrainInfo={openTrainInfo}
|
||||
navigate={navigate}
|
||||
/>
|
||||
)
|
||||
}
|
||||
@ -335,6 +336,7 @@ export const EachTrainInfoCore = ({
|
||||
currentPosition={currentPosition}
|
||||
nearTrainIDList={nearTrainIDList}
|
||||
openTrainInfo={openTrainInfo}
|
||||
navigate={navigate}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
@ -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 (
|
||||
<CurrentTrainContext.Provider
|
||||
value={{
|
||||
webview,
|
||||
currentTrain,
|
||||
setCurrentTrain,
|
||||
currentTrainLoading,
|
||||
|
Loading…
Reference in New Issue
Block a user