diff --git a/components/ActionSheetComponents/EachTrainInfo.js b/components/ActionSheetComponents/EachTrainInfo.js index 6331cca..d2830ac 100644 --- a/components/ActionSheetComponents/EachTrainInfo.js +++ b/components/ActionSheetComponents/EachTrainInfo.js @@ -2,8 +2,8 @@ import React, { useRef } from "react"; import { Platform } from "react-native"; import ActionSheet from "react-native-actions-sheet"; import { EachTrainInfoCore } from "./EachTrainInfoCore"; -export const EachTrainInfo = (props) => { - if (!props.payload) return <>; +export const EachTrainInfo = ({payload}) => { + if (!payload) return <>; const actionSheetRef = useRef(null); return ( @@ -17,7 +17,7 @@ export const EachTrainInfo = (props) => { //useBottomSafeAreaPadding={Platform.OS == "android"} > - + ); }; diff --git a/components/ActionSheetComponents/EachTrainInfoCore.js b/components/ActionSheetComponents/EachTrainInfoCore.js index 9e13d58..a163c6e 100644 --- a/components/ActionSheetComponents/EachTrainInfoCore.js +++ b/components/ActionSheetComponents/EachTrainInfoCore.js @@ -8,7 +8,6 @@ import { useWindowDimensions, BackHandler, Linking, - Image, } from "react-native"; import { Ionicons } from "@expo/vector-icons"; import { SheetManager } from "react-native-actions-sheet"; @@ -34,22 +33,22 @@ import { getType } from "../../lib/eachTrainInfoCoreLib/getType"; import { searchSpecialTrain } from "../../lib/eachTrainInfoCoreLib/searchSpecialTrain"; import { openBackTrainInfo } from "../../lib/eachTrainInfoCoreLib/openBackTrainInfo"; import { ShowSpecialTrain } from "./EachTrainInfo/ShowSpecialTrain"; -import { useNavigation } from "@react-navigation/native"; -import { useInterval } from "../../lib/useInterval"; -import dayjs from "dayjs"; import { TrainIconStatus } from "./EachTrainInfo/trainIconStatus"; +import { useTrainMenu } from "../../stateBox/useTrainMenu"; export const EachTrainInfoCore = ({ actionSheetRef, data, - originalStationList, openStationACFromEachTrainInfo, from, - setTrainInfo, navigate, }) => { // const [actionSheetHorizonalScroll, setActionSheetHorizonalScroll] = useState(false); const { currentTrain } = useCurrentTrain(); + const { + setTrainInfo, + originalStationList, + } = useTrainMenu(); const [currentTrainData, setCurrentTrainData] = useState(); // const [actionSheetHorizonalScroll, setActionSheetHorizonalScroll] = useState(false); @@ -96,7 +95,7 @@ export const EachTrainInfoCore = ({ ); // 使用例 - const stopStationIDList = trainData.map((i, index) => { + const stopStationIDList = trainData.map((i) => { const [station, se, time] = i.split(","); const Stations = stationList.map((a) => a.filter((d) => d.StationName == station) @@ -137,7 +136,7 @@ export const EachTrainInfoCore = ({ } }, [data.limited, trainData]); - const { height, width } = useWindowDimensions(); + const { height } = useWindowDimensions(); const { isLandscape } = useDeviceOrientationChange(); const [trueTrainID, setTrueTrainID] = useState(); @@ -222,7 +221,7 @@ export const EachTrainInfoCore = ({ .then((d) => { if (d) setTrainPositionSwitch(d); }) - .catch((d) => AS.setItem("trainPositionSwitch", "false")); + .catch(() => AS.setItem("trainPositionSwitch", "false")); }, []); const openTrainInfo = (d) => { diff --git a/components/Apps.js b/components/Apps.js index 2df3147..5d487be 100644 --- a/components/Apps.js +++ b/components/Apps.js @@ -22,6 +22,9 @@ import { useNavigation } from "@react-navigation/native"; import { useTrainMenu } from "../stateBox/useTrainMenu"; import { AppsWebView } from "./Apps/WebView"; import { NewMenu } from "./Apps/NewMenu"; +import { MapsButton } from "./Apps/MapsButton"; +import { ReloadButton } from "./Apps/ReloadButton"; +import { LandscapeBackButton } from "./Apps/LandscapeBackButton"; /* import StatusbarDetect from '../StatusbarDetect'; var Status = StatusbarDetect(); */ @@ -34,15 +37,13 @@ export default function Apps() { const { navigate } = useNavigation(); const { isLandscape } = useDeviceOrientationChange(); const handleLayout = () => {}; - const { setInjectJavaScript, mapsStationData, + const { + setInjectJavaScript, mapSwitch, - LoadError, - setLoadError, trainInfo, setTrainInfo, originalStationList, - injectJavascript, } = useTrainMenu(); - + } = useTrainMenu(); const openStationACFromEachTrainInfo = async (stationName) => { await SheetManager.hide("EachTrainInfo"); @@ -82,9 +83,6 @@ export default function Apps() { > {!trainInfo.trainNum && isLandscape ? ( {isLandscape && trainInfo.trainNum && ( @@ -113,10 +107,8 @@ export default function Apps() { @@ -128,7 +120,6 @@ export default function Apps() { setInjectJavaScript(""); navigate("trainMenu", { webview }); }} - mapSwitch={mapSwitch == "true" ? "flex" : "none"} /> )} {isLandscape && trainInfo.trainNum && ( @@ -147,119 +138,13 @@ export default function Apps() { Updates.reloadAsync()} right={isLandscape && trainInfo.trainNum ? (width / 100) * 40 : 0} - LoadError={LoadError} /> ) : ( - + )} ); } -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 ( - - - - - - ); -}; -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 ( - - - - - - ); -}; -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 ( - - - - - - ); -}; diff --git a/components/Apps/LandscapeBackButton.tsx b/components/Apps/LandscapeBackButton.tsx new file mode 100644 index 0000000..c7fc3e0 --- /dev/null +++ b/components/Apps/LandscapeBackButton.tsx @@ -0,0 +1,50 @@ +import React, { FC } from "react"; +import { + View, + TouchableOpacity, + TouchableOpacityProps, + TextStyle, +} from "react-native"; +import { Ionicons } from "@expo/vector-icons"; +import Constants from "expo-constants"; +import { useTrainMenu } from "../../stateBox/useTrainMenu"; +export const LandscapeBackButton: FC<{ + onPress: () => void; +}> = ({ onPress }) => { + type stylesType = { + touch: TouchableOpacityProps["style"]; + text: TextStyle; + }; + const styles: stylesType = { + 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 ( + + + + + + ); +}; diff --git a/components/Apps/MapsButton.tsx b/components/Apps/MapsButton.tsx new file mode 100644 index 0000000..66e7501 --- /dev/null +++ b/components/Apps/MapsButton.tsx @@ -0,0 +1,58 @@ +import React, { FC } from "react"; +import { + View, + Text, + TouchableOpacity, + Platform, + TouchableOpacityProps, + TextStyle, +} from "react-native"; +import Constants from "expo-constants"; +import { useTrainMenu } from "../../stateBox/useTrainMenu"; + +const top = Platform.OS == "ios" ? Constants.statusBarHeight : 0; +type MapsButtonProps = { + onPress: () => void; +}; +type stylesType = { + touch: TouchableOpacityProps["style"]; + text: TextStyle; +}; + +export const MapsButton: FC = ({ onPress }) => { + const { mapSwitch } = useTrainMenu(); + const styles: stylesType = { + 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 == "true" ? "flex" : "none", + }, + text: { + textAlign: "center", + width: "auto", + height: "auto", + textAlignVertical: "center", + fontWeight: "bold", + color: "white", + fontSize: 20, + }, + }; + return ( + + + + + + ); +}; diff --git a/components/Apps/NewMenu.tsx b/components/Apps/NewMenu.tsx index d2e4a8f..ae8693e 100644 --- a/components/Apps/NewMenu.tsx +++ b/components/Apps/NewMenu.tsx @@ -4,11 +4,13 @@ import { Ionicons } from "@expo/vector-icons"; import * as Updates from "expo-updates"; import Constants from "expo-constants"; import { useCurrentTrain } from "../../stateBox/useCurrentTrain"; +import { useTrainMenu } from "../../stateBox/useTrainMenu"; const top = Platform.OS == "ios" ? Constants.statusBarHeight : 0; -export const NewMenu = ({ LoadError }) => { +export const NewMenu = () => { const { webview } = useCurrentTrain(); const { width } = useWindowDimensions(); + const { LoadError } = useTrainMenu(); return ( void; + right: number; + +} +export const ReloadButton:FC = ({ onPress, right }) => { + const { mapSwitch, LoadError = false } = useTrainMenu(); + const styles: stylesType = { + 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 ( + + + + + + ); +}; diff --git a/components/Apps/WebView.jsx b/components/Apps/WebView.jsx index 1a5469f..8f90d96 100644 --- a/components/Apps/WebView.jsx +++ b/components/Apps/WebView.jsx @@ -12,18 +12,19 @@ import { SheetManager } from "react-native-actions-sheet"; import { useNavigation } from "@react-navigation/native"; import { useTrainMenu } from "../../stateBox/useTrainMenu"; import { stationNamePair } from "../../lib/getStationList2"; -export const AppsWebView = ({ - originalStationList, - setLoadError, - setTrainInfo, - openStationACFromEachTrainInfo, - injectJavascript, -}) => { +export const AppsWebView = ({ openStationACFromEachTrainInfo }) => { const { webview, currentTrain } = useCurrentTrain(); const { navigate } = useNavigation(); const { favoriteStation } = useFavoriteStation(); const { isLandscape } = useDeviceOrientationChange(); - const { setSelectedLine, mapsStationData: stationData } = useTrainMenu(); + const { + setSelectedLine, + mapsStationData: stationData, + setLoadError, + setTrainInfo, + originalStationList, + injectJavascript, + } = useTrainMenu(); var urlcache = ""; let once = false;