266 lines
7.0 KiB
JavaScript
266 lines
7.0 KiB
JavaScript
import React from "react";
|
|
import {
|
|
View,
|
|
Platform,
|
|
Text,
|
|
TouchableOpacity,
|
|
useWindowDimensions,
|
|
LayoutAnimation,
|
|
} from "react-native";
|
|
import Constants from "expo-constants";
|
|
import { Ionicons } from "@expo/vector-icons";
|
|
import * as Updates from "expo-updates";
|
|
|
|
import { lineList } from "../lib/getStationList";
|
|
import { useCurrentTrain } from "../stateBox/useCurrentTrain";
|
|
import { useDeviceOrientationChange } from "../stateBox/useDeviceOrientationChange";
|
|
import { SheetManager } from "react-native-actions-sheet";
|
|
import TrainMenu from "../components/trainMenu";
|
|
import { EachTrainInfoCore } from "../components/ActionSheetComponents/EachTrainInfoCore";
|
|
|
|
import { useNavigation } from "@react-navigation/native";
|
|
import { useTrainMenu } from "../stateBox/useTrainMenu";
|
|
import { AppsWebView } from "./Apps/WebView";
|
|
import { NewMenu } from "./Apps/NewMenu";
|
|
/*
|
|
import StatusbarDetect from '../StatusbarDetect';
|
|
var Status = StatusbarDetect(); */
|
|
|
|
const top = Platform.OS == "ios" ? Constants.statusBarHeight : 0;
|
|
|
|
export default function Apps() {
|
|
const { webview } = useCurrentTrain();
|
|
const { height, width } = useWindowDimensions();
|
|
const { navigate } = useNavigation();
|
|
const { isLandscape } = useDeviceOrientationChange();
|
|
const handleLayout = () => {};
|
|
const { setInjectJavaScript, mapsStationData,
|
|
mapSwitch,
|
|
LoadError,
|
|
setLoadError,
|
|
trainInfo,
|
|
setTrainInfo,
|
|
originalStationList,
|
|
injectJavascript, } = useTrainMenu();
|
|
|
|
|
|
const openStationACFromEachTrainInfo = async (stationName) => {
|
|
await SheetManager.hide("EachTrainInfo");
|
|
const findStationEachLine = (selectLine) => {
|
|
let NearStation = selectLine.filter((d) => d.Station_JP == stationName);
|
|
return NearStation;
|
|
};
|
|
let returnDataBase = lineList
|
|
.map((d) => findStationEachLine(originalStationList[d]))
|
|
.filter((d) => d.length > 0)
|
|
.reduce((pre, current) => {
|
|
pre.push(...current);
|
|
return pre;
|
|
}, []);
|
|
if (returnDataBase.length) {
|
|
const payload = {
|
|
currentStation: returnDataBase,
|
|
originalStationList,
|
|
navigate,
|
|
goTo: "Apps",
|
|
useShow: () => SheetManager.show("StationDetailView", { payload }),
|
|
onExit: () => SheetManager.hide("StationDetailView"),
|
|
};
|
|
SheetManager.show("StationDetailView", { payload });
|
|
} else {
|
|
SheetManager.hide("StationDetailView");
|
|
}
|
|
};
|
|
return (
|
|
<View
|
|
style={{
|
|
height: "100%",
|
|
paddingTop: top,
|
|
flexDirection: isLandscape ? "row" : "column",
|
|
}}
|
|
onLayout={handleLayout}
|
|
>
|
|
{!trainInfo.trainNum && isLandscape ? (
|
|
<TrainMenu
|
|
webview={webview}
|
|
stationData={mapsStationData}
|
|
navigation={{ navigate: null }}
|
|
style={{
|
|
width: (width / 100) * 40,
|
|
height: "100%",
|
|
flexDirection: "column-reverse",
|
|
}}
|
|
/>
|
|
) : null}
|
|
{/* {Status} */}
|
|
<AppsWebView
|
|
{...{
|
|
originalStationList,
|
|
setLoadError,
|
|
setTrainInfo,
|
|
openStationACFromEachTrainInfo,
|
|
injectJavascript,
|
|
}}
|
|
/>
|
|
{isLandscape && trainInfo.trainNum && (
|
|
<View
|
|
style={{
|
|
width: (width / 100) * 40,
|
|
height: height,
|
|
flexDirection: "column",
|
|
}}
|
|
>
|
|
<EachTrainInfoCore
|
|
{...{
|
|
data: trainInfo.trainNum ? trainInfo : undefined,
|
|
originalStationList,
|
|
openStationACFromEachTrainInfo,
|
|
from: "Train",
|
|
setTrainInfo,
|
|
navigate,
|
|
}}
|
|
/>
|
|
</View>
|
|
)}
|
|
{isLandscape || (
|
|
<MapsButton
|
|
onPress={() => {
|
|
setInjectJavaScript("");
|
|
navigate("trainMenu", { webview });
|
|
}}
|
|
mapSwitch={mapSwitch == "true" ? "flex" : "none"}
|
|
/>
|
|
)}
|
|
{isLandscape && trainInfo.trainNum && (
|
|
<LandscapeBackButton
|
|
onPress={() => {
|
|
LayoutAnimation.easeInEaseOut();
|
|
setTrainInfo({
|
|
trainNum: undefined,
|
|
limited: undefined,
|
|
trainData: undefined,
|
|
});
|
|
}}
|
|
/>
|
|
)}
|
|
{mapSwitch == "true" ? (
|
|
<ReloadButton
|
|
onPress={() => Updates.reloadAsync()}
|
|
right={isLandscape && trainInfo.trainNum ? (width / 100) * 40 : 0}
|
|
LoadError={LoadError}
|
|
/>
|
|
) : (
|
|
<NewMenu LoadError={LoadError} />
|
|
)}
|
|
</View>
|
|
);
|
|
}
|
|
|
|
const MapsButton = ({ onPress, mapSwitch }) => {
|
|
const styles = {
|
|
touch: {
|
|
position: "absolute",
|
|
top,
|
|
left: 10,
|
|
width: 50,
|
|
height: 50,
|
|
backgroundColor: "#0099CC",
|
|
borderColor: "white",
|
|
borderStyle: "solid",
|
|
borderWidth: 1,
|
|
borderRadius: 50,
|
|
alignContent: "center",
|
|
alignSelf: "center",
|
|
alignItems: "center",
|
|
display: mapSwitch,
|
|
},
|
|
text: {
|
|
textAlign: "center",
|
|
width: "auto",
|
|
height: "auto",
|
|
textAlignVertical: "center",
|
|
fontWeight: "bold",
|
|
color: "white",
|
|
fontSize: 20,
|
|
},
|
|
};
|
|
return (
|
|
<TouchableOpacity onPress={onPress} style={styles.touch}>
|
|
<View style={{ flex: 1 }} />
|
|
<Text style={styles.text}>≡</Text>
|
|
<View style={{ flex: 1 }} />
|
|
</TouchableOpacity>
|
|
);
|
|
};
|
|
|
|
const LandscapeBackButton = ({ onPress }) => {
|
|
const styles = {
|
|
touch: {
|
|
position: "absolute",
|
|
left: 10,
|
|
width: 50,
|
|
height: 50,
|
|
backgroundColor: "#0099CC",
|
|
borderColor: "white",
|
|
borderStyle: "solid",
|
|
borderWidth: 1,
|
|
borderRadius: 50,
|
|
alignContent: "center",
|
|
alignSelf: "center",
|
|
alignItems: "center",
|
|
display: "flex",
|
|
},
|
|
text: {
|
|
textAlign: "center",
|
|
width: "auto",
|
|
height: "auto",
|
|
textAlignVertical: "center",
|
|
fontWeight: "bold",
|
|
color: "white",
|
|
},
|
|
};
|
|
return (
|
|
<TouchableOpacity onPress={onPress} style={styles.touch}>
|
|
<View style={{ flex: 1 }} />
|
|
<Ionicons name="arrow-back" color="white" size={30} />
|
|
<View style={{ flex: 1 }} />
|
|
</TouchableOpacity>
|
|
);
|
|
};
|
|
|
|
const ReloadButton = ({ onPress, mapSwitch, LoadError = false, right }) => {
|
|
const styles = {
|
|
touch: {
|
|
position: "absolute",
|
|
top,
|
|
right: 10 + right,
|
|
width: 50,
|
|
height: 50,
|
|
backgroundColor: LoadError ? "red" : "#0099CC",
|
|
borderColor: "white",
|
|
borderStyle: "solid",
|
|
borderWidth: 1,
|
|
borderRadius: 50,
|
|
alignContent: "center",
|
|
alignSelf: "center",
|
|
alignItems: "center",
|
|
display: mapSwitch,
|
|
},
|
|
text: {
|
|
textAlign: "center",
|
|
width: "auto",
|
|
height: "auto",
|
|
textAlignVertical: "center",
|
|
fontWeight: "bold",
|
|
color: "white",
|
|
},
|
|
};
|
|
return (
|
|
<TouchableOpacity onPress={onPress} style={styles.touch}>
|
|
<View style={{ flex: 1 }} />
|
|
<Ionicons name="reload" color="white" size={30} />
|
|
<View style={{ flex: 1 }} />
|
|
</TouchableOpacity>
|
|
);
|
|
};
|