From 36b199ef98e7b4e64f84fe1176b6ee9542bf098c Mon Sep 17 00:00:00 2001 From: harukin-OneMix4 Date: Mon, 25 Dec 2023 03:37:15 +0900 Subject: [PATCH] =?UTF-8?q?=E3=82=A2=E3=82=AF=E3=82=B7=E3=83=A7=E3=83=B3?= =?UTF-8?q?=E3=82=B7=E3=83=BC=E3=83=88=E3=81=AE=E4=BE=9D=E5=AD=98=E6=9B=B4?= =?UTF-8?q?=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App.js | 26 ++-- Apps.js | 112 +++++++++++------- .../ActionSheetComponents/EachTrainInfo.js | 27 ++--- .../ActionSheetComponents/JRSTraInfo.js | 20 ++-- .../StationDeteilView.js | 41 ++++--- components/ActionSheetComponents/sheets.js | 10 ++ components/発車時刻表/LED_vidion.js | 42 ++++--- howto.js | 11 +- menu.js | 101 ++++++++-------- package.json | 2 +- yarn.lock | 8 +- 11 files changed, 227 insertions(+), 173 deletions(-) create mode 100644 components/ActionSheetComponents/sheets.js diff --git a/App.js b/App.js index 97a3f19..9c3f952 100644 --- a/App.js +++ b/App.js @@ -25,7 +25,9 @@ import { useBusAndTrainData, BusAndTrainDataProvider, } from "./stateBox/useBusAndTrainData.js"; - +import { AllTrainDiagramProvider } from "./stateBox/useAllTrainDiagram.js"; +import { SheetProvider } from "react-native-actions-sheet"; +import "./components/ActionSheetComponents/sheets.js"; LogBox.ignoreLogs([ "ViewPropTypes will be removed", "ColorPropType will be removed", @@ -40,15 +42,19 @@ if (Platform.OS === "android") { export default function App() { useEffect(() => UpdateAsync(), []); return ( - - - - - - - - - + + + + + + + + + + + + + ); } export function AppContainer() { diff --git a/Apps.js b/Apps.js index cc53cde..2f6128a 100644 --- a/Apps.js +++ b/Apps.js @@ -12,6 +12,7 @@ import { EachTrainInfo } from "./components/ActionSheetComponents/EachTrainInfo" import { checkDuplicateTrainData } from "./lib/checkDuplicateTrainData"; import { useFavoriteStation } from "./stateBox/useFavoriteStation"; import { useCurrentTrain } from "./stateBox/useCurrentTrain"; +import { SheetManager } from "react-native-actions-sheet"; /* import StatusbarDetect from './StatusbarDetect'; var Status = StatusbarDetect(); */ @@ -29,7 +30,6 @@ export default function Apps({ navigation, webview, stationData }) { const [LoadError, setLoadError] = useState(false); //列車情報表示関連 - const EachTrainInfoAsSR = useRef(null); const [trainInfo, setTrainInfo] = useState({ trainNum: undefined, limited: undefined, @@ -37,10 +37,7 @@ export default function Apps({ navigation, webview, stationData }) { }); //駅情報画面用 - const StationBoardAcSR = useRef(null); - const [stationBoardData, setStationBoardData] = useState(undefined); const [originalStationList, setOriginalStationList] = useState(); - const [selectedStation, setSelectedStation] = useState(undefined); const [trainMenu, setTrainMenu] = useState("true"); let once = false; useEffect(() => { @@ -132,31 +129,43 @@ export default function Apps({ navigation, webview, stationData }) { setLoadError(true); return; } - case "PopUpMenu": { - const selectedStationPDFAddress = dataSet.pdf; - const findStationEachLine = (selectLine) => { - let NearStation = selectLine.filter( - (d) => d.StationTimeTable == selectedStationPDFAddress - ); - return NearStation; - }; - let returnDataBase = lineList - .map((d) => findStationEachLine(originalStationList[d])) - .filter((d) => d.length > 0) - .reduce((pre, current) => { - pre.push(...current); - return pre; - }, []); + case "PopUpMenu": + { + const selectedStationPDFAddress = dataSet.pdf; + const findStationEachLine = (selectLine) => { + let NearStation = selectLine.filter( + (d) => d.StationTimeTable == selectedStationPDFAddress + ); + 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) { - setStationBoardData(returnDataBase); - StationBoardAcSR.current?.show(); - } else { - setStationBoardData(undefined); - StationBoardAcSR.current?.hide(); + if (returnDataBase.length) { + const payload = { + currentStation: returnDataBase, + originalStationList: originalStationList, + navigate: navigate, + goTo: "Apps", + useShow: () => + SheetManager.show("StationDetailView", { + payload, + }), + onExit: () => { + SheetManager.hide("StationDetailView"); + }, + }; + SheetManager.show("StationDetailView", { + payload, + }); + } } return; - } case "ShowTrainTimeInfo": { const { trainNum, limited } = dataSet; //alert(trainNum, limited); @@ -167,7 +176,21 @@ export default function Apps({ navigation, webview, stationData }) { currentTrain.filter((a) => a.num == trainNum) ), }); //遅延情報は未実装 - EachTrainInfoAsSR.current?.show(); + const payload = { + data: { + trainNum, + limited, + trainData: checkDuplicateTrainData( + currentTrain.filter((a) => a.num == trainNum) + ), + }, + navigate, + originalStationList, + openStationACFromEachTrainInfo, + }; + SheetManager.show("EachTrainInfo", { + payload, + }); return; } default: { @@ -215,7 +238,7 @@ export default function Apps({ navigation, webview, stationData }) { } const openStationACFromEachTrainInfo = (stationName) => { - EachTrainInfoAsSR.current?.hide(); + SheetManager.hide("EachTrainInfo"); const findStationEachLine = (selectLine) => { let NearStation = selectLine.filter((d) => d.Station_JP == stationName); return NearStation; @@ -228,13 +251,26 @@ export default function Apps({ navigation, webview, stationData }) { return pre; }, []); if (returnDataBase.length) { - setStationBoardData(returnDataBase); sleep(25, function () { - StationBoardAcSR.current?.show(); + const payload = { + currentStation: returnDataBase, + originalStationList: originalStationList, + navigate: navigate, + goTo: "Apps", + useShow: () => + SheetManager.show("StationDetailView", { + payload, + }), + onExit: () => { + SheetManager.hide("StationDetailView"); + }, + }; + SheetManager.show("StationDetailView", { + payload, + }); }); } else { - setStationBoardData(undefined); - StationBoardAcSR.current?.hide(); + SheetManager.hide("StationDetailView"); } }; return ( @@ -260,7 +296,6 @@ export default function Apps({ navigation, webview, stationData }) { onNavigationStateChange={onNavigationStateChange} onMessage={onMessage} injectedJavaScript={injectJavascript} - onTouchMove={() => StationBoardAcSR.current?.hide()} onLoadEnd={() => { if (once) return () => {}; if (!stationData) return () => {}; @@ -293,18 +328,7 @@ export default function Apps({ navigation, webview, stationData }) { LoadError={LoadError} /> - { - StationBoardAcSR.current?.setModalVisible(); - navigate("Apps"); - }} - /> { +export const EachTrainInfo = (props) => { + if (!props.payload) return <>; + const { + data, + navigate, + originalStationList, + openStationACFromEachTrainInfo, + from, + } = props.payload; const [trainData, setTrainData] = useState([]); const [isTop, setIsTop] = useState(true); const [currentPosition, setCurrentPosition] = useState([]); @@ -240,11 +241,7 @@ export const EachTrainInfo = ({ }; return ( - } - > + }> )} diff --git a/components/ActionSheetComponents/JRSTraInfo.js b/components/ActionSheetComponents/JRSTraInfo.js index 7b7d6d7..eaf0e37 100644 --- a/components/ActionSheetComponents/JRSTraInfo.js +++ b/components/ActionSheetComponents/JRSTraInfo.js @@ -11,19 +11,11 @@ import { Ionicons, MaterialCommunityIcons } from "@expo/vector-icons"; import ActionSheet from "react-native-actions-sheet"; import LottieView from "lottie-react-native"; export const JRSTraInfo = (props) => { - const { - JRSTraInfoEXAcSR, - getTime, - loadingDelayData, - setLoadingDelayData, - delayData, - } = props; + if (!props.payload) return <>; + const { getTime, loadingDelayData, setLoadingDelayData, delayData } = + props.payload; return ( - } - > + }> { borderRadius: 5, alignItems: "center", }} - onPress={() => Linking.openURL("https://mstdn.y-zu.org/@JRSTraInfoEX")} + onPress={() => + Linking.openURL("https://mstdn.y-zu.org/@JRSTraInfoEX") + } > diff --git a/components/ActionSheetComponents/StationDeteilView.js b/components/ActionSheetComponents/StationDeteilView.js index 77764cd..9d33582 100644 --- a/components/ActionSheetComponents/StationDeteilView.js +++ b/components/ActionSheetComponents/StationDeteilView.js @@ -13,13 +13,15 @@ import { useBusAndTrainData } from "../../stateBox/useBusAndTrainData"; import { AS } from "../../storageControl"; export const StationDeteilView = (props) => { + if (!props.payload) return <>; const { - StationBoardAcSR, currentStation, originalStationList, navigate, onExit, - } = props; + goTo, + useShow, + } = props.payload; const { busAndTrainData } = useBusAndTrainData(); const [trainBus, setTrainBus] = useState(); useEffect(() => { @@ -43,11 +45,7 @@ export const StationDeteilView = (props) => { ? getPDFViewURL(currentStation[0].StationTimeTable) : currentStation[0].StationTimeTable); return ( - } - > + }> { ? Linking.openURL(currentStation[0].StationTimeTable) : navigate("howto", { info, - onExit, + goTo, + useShow, }); - StationBoardAcSR.current?.hide(); + onExit(); }} oLP={() => Linking.openURL(currentStation[0].StationTimeTable)} /> @@ -109,9 +108,11 @@ export const StationDeteilView = (props) => { info: currentStation[0].JrHpUrl.replace("/index.html", "/") + "/kounai_map.html", - onExit, + + goTo, + useShow, }); - StationBoardAcSR.current?.hide(); + onExit(); }} oLP={() => { Linking.openURL( @@ -132,9 +133,11 @@ export const StationDeteilView = (props) => { onPressButton={() => { navigate("howto", { info: currentStation[0].JrHpUrl, - onExit, + + goTo, + useShow, }); - StationBoardAcSR.current?.hide(); + onExit(); }} onLongPressButton={() => Linking.openURL(currentStation[0].JrHpUrl) @@ -153,9 +156,11 @@ export const StationDeteilView = (props) => { ? Linking.openURL(currentStation[0].StationTimeTable) : navigate("howto", { info, - onExit, + + goTo, + useShow, }); - StationBoardAcSR.current?.hide(); + onExit(); }} onLongPressButton={() => Linking.openURL(currentStation[0].StationTimeTable) @@ -184,9 +189,11 @@ export const StationDeteilView = (props) => { onPressButton={() => { navigate("howto", { info: trainBus.address, - onExit, + + goTo, + useShow, }); - StationBoardAcSR.current?.hide(); + onExit(); }} onLongPressButton={() => Linking.openURL(trainBus.address)} > diff --git a/components/ActionSheetComponents/sheets.js b/components/ActionSheetComponents/sheets.js new file mode 100644 index 0000000..da95b04 --- /dev/null +++ b/components/ActionSheetComponents/sheets.js @@ -0,0 +1,10 @@ +import { registerSheet } from "react-native-actions-sheet"; +import { EachTrainInfo } from "./EachTrainInfo"; +import { JRSTraInfo } from "./JRSTraInfo"; +import { StationDeteilView } from "./StationDeteilView"; + +registerSheet("EachTrainInfo", EachTrainInfo); +registerSheet("JRSTraInfo", JRSTraInfo); +registerSheet("StationDetailView", StationDeteilView); + +export {}; diff --git a/components/発車時刻表/LED_vidion.js b/components/発車時刻表/LED_vidion.js index 140dc8c..33f078c 100644 --- a/components/発車時刻表/LED_vidion.js +++ b/components/発車時刻表/LED_vidion.js @@ -12,6 +12,7 @@ import { getTrainDelayStatus } from "../../lib/getTrainDelayStatus"; import { checkDuplicateTrainData } from "../../lib/checkDuplicateTrainData"; import { useCurrentTrain } from "../../stateBox/useCurrentTrain"; import { useAreaInfo } from "../../stateBox/useAreaInfo"; +import { SheetManager } from "react-native-actions-sheet"; /** * @@ -45,10 +46,11 @@ import { useAreaInfo } from "../../stateBox/useAreaInfo"; export default function LED_vision(props) { const { station, - setTrainInfo, - EachTrainInfoAsSR, trainDiagram, getCurrentTrain, + navigate, + originalStationList, + openStationACFromEachTrainInfo, } = props; const { currentTrain } = useCurrentTrain(); const [stationDiagram, setStationDiagram] = useState({}); //当該駅の全時刻表 @@ -191,8 +193,9 @@ export default function LED_vision(props) { trainDescriptionSwitch={trainDescriptionSwitch} station={station} customTrainDataDetector={customTrainDataDetector} - setTrainInfo={setTrainInfo} - EachTrainInfoAsSR={EachTrainInfoAsSR} + navigate={navigate} + originalStationList={originalStationList} + openStationACFromEachTrainInfo={openStationACFromEachTrainInfo} /> ))} {areaString != "" && ( @@ -299,8 +302,9 @@ const EachData = ({ trainDescriptionSwitch, station, customTrainDataDetector, - setTrainInfo, - EachTrainInfoAsSR, + navigate, + originalStationList, + openStationACFromEachTrainInfo, }) => { const { currentTrain } = useCurrentTrain(); const openTrainInfo = (d) => { @@ -311,16 +315,24 @@ const EachData = ({ train.trainNumDistance; TrainNumber = timeInfo + "号"; } - setTrainInfo({ - trainNum: d.train, - limited: `${getTrainType(train.type).data}:${ - train.trainName - }${TrainNumber}`, - trainData: checkDuplicateTrainData( - currentTrain.filter((a) => a.num == d.train) - ), + const payload = { + data: { + trainNum: d.train, + limited: `${getTrainType(train.type).data}:${ + train.trainName + }${TrainNumber}`, + trainData: checkDuplicateTrainData( + currentTrain.filter((a) => a.num == d.train) + ), + }, + navigate, + originalStationList, + openStationACFromEachTrainInfo, + from: "LED", + }; + SheetManager.show("EachTrainInfo", { + payload, }); - EachTrainInfoAsSR.current?.show(); }; const [train, setTrain] = useState(customTrainDataDetector(d.train)); useEffect(() => { diff --git a/howto.js b/howto.js index 60209a1..228cb64 100644 --- a/howto.js +++ b/howto.js @@ -3,10 +3,17 @@ import React, { Component } from "react"; import { StatusBar, View, TouchableOpacity, Text } from "react-native"; import { WebView } from "react-native-webview"; export default ({ navigation: { navigate }, route }) => { - const { info, onExit = () => navigate("Apps") } = route.params; + const { info, goTo, useShow } = route.params; + const onExit = () => { + navigate(goTo); + useShow(); + }; return ( - + diff --git a/menu.js b/menu.js index 3d68a4c..b45ab74 100644 --- a/menu.js +++ b/menu.js @@ -38,14 +38,13 @@ import { EachTrainInfo } from "./components/ActionSheetComponents/EachTrainInfo" import useInterval from "./lib/useInterval"; import { HeaderConfig } from "./lib/HeaderConfig"; import { useFavoriteStation } from "./stateBox/useFavoriteStation"; +import { SheetManager } from "react-native-actions-sheet"; export default function Menu(props) { const { navigation: { navigate }, getCurrentTrain, } = props; - const JRSTraInfoEXAcSR = useRef(null); - const StationBoardAcSR = useRef(null); const { favoriteStation } = useFavoriteStation(); //位置情報 @@ -56,14 +55,6 @@ export default function Menu(props) { }); }, []); - //列車情報表示関連 - const EachTrainInfoAsSR = useRef(null); - const [trainInfo, setTrainInfo] = useState({ - trainNum: undefined, - limited: undefined, - trainData: undefined, - }); - const getCurrentPosition = () => { if (locationStatus !== "granted") return () => {}; Location.getCurrentPositionAsync({}).then((location) => @@ -227,7 +218,27 @@ export default function Menu(props) { { + const payload = { + currentStation: + originalStationList && + allStationData.length != 0 && + allStationData[selectedCurrentStation], + originalStationList: originalStationList, + navigate: navigate, + goTo: "menu", + useShow: () => + SheetManager.show("StationDetailView", { + payload, + }), + onExit: () => { + SheetManager.hide("StationDetailView"); + }, + }; + SheetManager.show("StationDetailView", { + payload, + }); + }} /> ); @@ -241,14 +252,14 @@ export default function Menu(props) { station={ originalStationList && allStationData[selectedCurrentStation][0] } - setTrainInfo={setTrainInfo} - EachTrainInfoAsSR={EachTrainInfoAsSR} trainDiagram={trainDiagram} getCurrentTrain={getCurrentTrain} + navigate={navigate} + originalStationList={originalStationList} + openStationACFromEachTrainInfo={openStationACFromEachTrainInfo} /> )} - - { - StationBoardAcSR.current?.setModalVisible(); - navigate("menu"); - }} - /> - - ); } @@ -349,13 +330,7 @@ const TopMenuButton = () => { }; const JRSTraInfoBox = (props) => { - const { - JRSTraInfoEXAcSR, - getTime, - setLoadingDelayData, - loadingDelayData, - delayData, - } = props; + const { getTime, setLoadingDelayData, loadingDelayData, delayData } = props; const styles = { touch: { backgroundColor: "#0099CC", @@ -387,7 +362,17 @@ const JRSTraInfoBox = (props) => { }; return ( { + const payload = { + getTime, + setLoadingDelayData, + loadingDelayData, + delayData, + }; + SheetManager.show("JRSTraInfo", { + payload, + }); + }} style={styles.touch} > @@ -570,6 +555,18 @@ const FixedContentBottom = (props) => { JR四国グループの施設をご案内 + {/* props.navigate("AllTrainIDList")} + > + + JR四国のお店・サービス + + + JR四国グループの施設をご案内 + + */}