列車の現在地情報から列車位置情報にジャンプできるように変更
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";
|
import { useCurrentTrain } from "./stateBox/useCurrentTrain.js";
|
||||||
const Stack = createStackNavigator();
|
const Stack = createStackNavigator();
|
||||||
export const Top = ({ navigation }) => {
|
export const Top = ({ navigation }) => {
|
||||||
const webview = useRef();
|
|
||||||
const { favoriteStation, setFavoriteStation } = useFavoriteStation();
|
const { favoriteStation, setFavoriteStation } = useFavoriteStation();
|
||||||
const { getCurrentTrain } = useCurrentTrain();
|
const { webview, getCurrentTrain } = useCurrentTrain();
|
||||||
|
|
||||||
//地図用
|
//地図用
|
||||||
const [mapsStationData, setMapsStationData] = useState(undefined);
|
const [mapsStationData, setMapsStationData] = useState(undefined);
|
||||||
|
@ -7,6 +7,7 @@ export const LongHeader = ({
|
|||||||
currentPosition,
|
currentPosition,
|
||||||
nearTrainIDList,
|
nearTrainIDList,
|
||||||
openTrainInfo,
|
openTrainInfo,
|
||||||
|
navigate,
|
||||||
}) => {
|
}) => {
|
||||||
return (
|
return (
|
||||||
<ScrollView
|
<ScrollView
|
||||||
@ -27,6 +28,7 @@ export const LongHeader = ({
|
|||||||
currentPosition={currentPosition}
|
currentPosition={currentPosition}
|
||||||
nearTrainIDList={nearTrainIDList}
|
nearTrainIDList={nearTrainIDList}
|
||||||
openTrainInfo={openTrainInfo}
|
openTrainInfo={openTrainInfo}
|
||||||
|
navigate={navigate}
|
||||||
/>
|
/>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
);
|
);
|
||||||
|
@ -7,6 +7,7 @@ export const ShortHeader = ({
|
|||||||
currentPosition,
|
currentPosition,
|
||||||
nearTrainIDList,
|
nearTrainIDList,
|
||||||
openTrainInfo,
|
openTrainInfo,
|
||||||
|
navigate,
|
||||||
}) => {
|
}) => {
|
||||||
return (
|
return (
|
||||||
<ScrollView
|
<ScrollView
|
||||||
@ -29,6 +30,7 @@ export const ShortHeader = ({
|
|||||||
currentPosition={currentPosition}
|
currentPosition={currentPosition}
|
||||||
nearTrainIDList={nearTrainIDList}
|
nearTrainIDList={nearTrainIDList}
|
||||||
openTrainInfo={openTrainInfo}
|
openTrainInfo={openTrainInfo}
|
||||||
|
navigate={navigate}
|
||||||
/>
|
/>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
);
|
);
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
import React from "react";
|
import React, { useState, useEffect } from "react";
|
||||||
import { View, TouchableOpacity, useWindowDimensions } from "react-native";
|
import { View, TouchableOpacity, useWindowDimensions } from "react-native";
|
||||||
import { StateBox } from "./StateBox";
|
import { StateBox } from "./StateBox";
|
||||||
import { useDeviceOrientationChange } from "../../../stateBox/useDeviceOrientationChange";
|
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 = ({
|
export const TrainDataView = ({
|
||||||
currentTrainData,
|
currentTrainData,
|
||||||
@ -9,10 +12,16 @@ export const TrainDataView = ({
|
|||||||
nearTrainIDList,
|
nearTrainIDList,
|
||||||
openTrainInfo,
|
openTrainInfo,
|
||||||
mode = 0,
|
mode = 0,
|
||||||
|
navigate,
|
||||||
}) => {
|
}) => {
|
||||||
const { width, height } = useWindowDimensions();
|
const { width, height } = useWindowDimensions();
|
||||||
const { isLandscape } = useDeviceOrientationChange();
|
const { isLandscape } = useDeviceOrientationChange();
|
||||||
|
const { webview, getCurrentTrain } = useCurrentTrain();
|
||||||
|
const [mapsStationData, setMapsStationData] = useState(undefined);
|
||||||
|
useEffect(() => {
|
||||||
|
getStationList2().then(setMapsStationData);
|
||||||
|
}, []);
|
||||||
|
const onLine = !!currentPosition?.toString().length;
|
||||||
return (
|
return (
|
||||||
<View
|
<View
|
||||||
style={{
|
style={{
|
||||||
@ -22,10 +31,29 @@ export const TrainDataView = ({
|
|||||||
width: isLandscape ? (width / 100) * 40 : width,
|
width: isLandscape ? (width / 100) * 40 : width,
|
||||||
flex: 1,
|
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
|
<StateBox
|
||||||
mode={mode}
|
mode={mode}
|
||||||
title={`現在地 ${currentPosition.toString()}`}
|
title={`現在地 ${currentPosition?.toString()}${onLine ? "▶️" : ""}`}
|
||||||
text={
|
text={
|
||||||
currentTrainData?.Pos.match("~")
|
currentTrainData?.Pos.match("~")
|
||||||
? `${
|
? `${
|
||||||
@ -39,7 +67,14 @@ export const TrainDataView = ({
|
|||||||
}`
|
}`
|
||||||
: currentTrainData?.Pos
|
: 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: mode == 2 ? "row" : "column" }}>
|
||||||
<View style={{ flex: 1, flexDirection: "row" }}>
|
<View style={{ flex: 1, flexDirection: "row" }}>
|
||||||
<StateBox
|
<StateBox
|
||||||
|
@ -323,6 +323,7 @@ export const EachTrainInfoCore = ({
|
|||||||
currentPosition={currentPosition}
|
currentPosition={currentPosition}
|
||||||
nearTrainIDList={nearTrainIDList}
|
nearTrainIDList={nearTrainIDList}
|
||||||
openTrainInfo={openTrainInfo}
|
openTrainInfo={openTrainInfo}
|
||||||
|
navigate={navigate}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -335,6 +336,7 @@ export const EachTrainInfoCore = ({
|
|||||||
currentPosition={currentPosition}
|
currentPosition={currentPosition}
|
||||||
nearTrainIDList={nearTrainIDList}
|
nearTrainIDList={nearTrainIDList}
|
||||||
openTrainInfo={openTrainInfo}
|
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 { HeaderConfig } from "../lib/HeaderConfig";
|
||||||
|
|
||||||
import useInterval from "../lib/useInterval";
|
import useInterval from "../lib/useInterval";
|
||||||
const initialState = {
|
const initialState = {
|
||||||
|
webview: {},
|
||||||
currentTrain: [],
|
currentTrain: [],
|
||||||
setCurrentTrain: () => {},
|
setCurrentTrain: () => {},
|
||||||
currentTrainLoading: "loading",
|
currentTrainLoading: "loading",
|
||||||
@ -40,9 +47,12 @@ export const CurrentTrainProvider = ({ children }) => {
|
|||||||
useEffect(getCurrentTrain, []); //初回だけ現在の全在線列車取得
|
useEffect(getCurrentTrain, []); //初回だけ現在の全在線列車取得
|
||||||
|
|
||||||
useInterval(getCurrentTrain, 15000); //15秒毎に全在線列車取得
|
useInterval(getCurrentTrain, 15000); //15秒毎に全在線列車取得
|
||||||
|
|
||||||
|
const webview = useRef();
|
||||||
return (
|
return (
|
||||||
<CurrentTrainContext.Provider
|
<CurrentTrainContext.Provider
|
||||||
value={{
|
value={{
|
||||||
|
webview,
|
||||||
currentTrain,
|
currentTrain,
|
||||||
setCurrentTrain,
|
setCurrentTrain,
|
||||||
currentTrainLoading,
|
currentTrainLoading,
|
||||||
|
Loading…
Reference in New Issue
Block a user