From 7781cf43e885c16d10e9fb08212a85e5511b51fd Mon Sep 17 00:00:00 2001 From: harukin-expo-dev-env Date: Tue, 20 Aug 2024 01:48:51 +0000 Subject: [PATCH 1/4] =?UTF-8?q?App.js=E3=81=AE=E5=88=86=E9=9B=A2=E3=80=81P?= =?UTF-8?q?roviderTree=E3=81=AE=E5=B0=8E=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App.js | 91 ++++++++----------------------------- Apps.js | 61 +++++++++++++++++++++++++ lib/providerTreeProvider.js | 25 ++++++++++ 3 files changed, 104 insertions(+), 73 deletions(-) create mode 100644 Apps.js create mode 100644 lib/providerTreeProvider.js diff --git a/App.js b/App.js index 38e843f..44d2de1 100644 --- a/App.js +++ b/App.js @@ -1,17 +1,12 @@ import React, { useEffect } from "react"; -import { NavigationContainer } from "@react-navigation/native"; -import { createBottomTabNavigator } from "@react-navigation/bottom-tabs"; import { Platform, UIManager } from "react-native"; import { GestureHandlerRootView } from "react-native-gesture-handler"; +import { AppContainer } from "./Apps.js"; import { UpdateAsync } from "./UpdateAsync.js"; -import TNDView from "./ndView"; import { LogBox } from "react-native"; -import { initIcon } from "./lib/initIcon"; import { FavoriteStationProvider } from "./stateBox/useFavoriteStation"; -import { Top } from "./Top.js"; -import { MenuPage } from "./MenuPage.js"; import { CurrentTrainProvider } from "./stateBox/useCurrentTrain.js"; -import { useAreaInfo, AreaInfoProvider } from "./stateBox/useAreaInfo.js"; +import { AreaInfoProvider } from "./stateBox/useAreaInfo.js"; import { BusAndTrainDataProvider } from "./stateBox/useBusAndTrainData.js"; import { AllTrainDiagramProvider } from "./stateBox/useAllTrainDiagram.js"; import { SheetProvider } from "react-native-actions-sheet"; @@ -20,11 +15,13 @@ import { TrainDelayDataProvider } from "./stateBox/useTrainDelayData.js"; import { SafeAreaProvider } from "react-native-safe-area-context"; import { DeviceOrientationChangeProvider } from "./stateBox/useDeviceOrientationChange.js"; import { TrainMenuProvider } from "./stateBox/useTrainMenu.js"; +import { buildProvidersTree } from "./lib/providerTreeProvider.js"; + LogBox.ignoreLogs([ "ViewPropTypes will be removed", "ColorPropType will be removed", ]); -const Tab = createBottomTabNavigator(); + if (Platform.OS === "android") { if (UIManager.setLayoutAnimationEnabledExperimental) { UIManager.setLayoutAnimationEnabledExperimental(true); @@ -33,77 +30,25 @@ if (Platform.OS === "android") { export default function App() { useEffect(() => UpdateAsync(), []); + + const ProviderTree = buildProvidersTree([ + FavoriteStationProvider, + TrainDelayDataProvider, + CurrentTrainProvider, + AreaInfoProvider, + AllTrainDiagramProvider, + BusAndTrainDataProvider, + TrainMenuProvider, + SheetProvider, + AppContainer, + ]); return ( - - - - - - - - - - - - - - - - - + ); } -export function AppContainer() { - const { areaInfo, areaIconBadgeText } = useAreaInfo(); - const navigationRef = React.useRef(); - return ( - - - - {(props) => } - - - - - {(props) => } - - - - ); -} diff --git a/Apps.js b/Apps.js new file mode 100644 index 0000000..d74c474 --- /dev/null +++ b/Apps.js @@ -0,0 +1,61 @@ +import React from "react"; +import { NavigationContainer } from "@react-navigation/native"; +import { createBottomTabNavigator } from "@react-navigation/bottom-tabs"; +import { Platform } from "react-native"; +import TNDView from "./ndView"; +import { initIcon } from "./lib/initIcon"; +import { Top } from "./Top.js"; +import { MenuPage } from "./MenuPage.js"; +import { useAreaInfo } from "./stateBox/useAreaInfo.js"; +import "./components/ActionSheetComponents/sheets.js"; + +const Tab = createBottomTabNavigator(); +export function AppContainer() { + const { areaInfo, areaIconBadgeText } = useAreaInfo(); + const navigationRef = React.useRef(); + return ( + + + + {(props) => } + + + + + {(props) => } + + + + ); + } + \ No newline at end of file diff --git a/lib/providerTreeProvider.js b/lib/providerTreeProvider.js new file mode 100644 index 0000000..e6fdd5f --- /dev/null +++ b/lib/providerTreeProvider.js @@ -0,0 +1,25 @@ +export const buildProvidersTree = (providers) => { + // 基本ケース:ContextProviderが1つしか残っていない場合、それを返して終了する + if (providers.length === 1) { + return providers[0]; + } + + // 配列から最初の2つのContextProviderを取り出す + const FirstProvider = providers.shift(); + const SecondProvider = providers.shift(); + + // 十分な数のContextProviderがあるかどうかを確認 + if (FirstProvider === undefined || SecondProvider === undefined) { + throw new Error("ContextProviderが不足しています"); + } + + // 最初の2つのContextProviderをネストした新しいContextProviderを作成し、再帰する + return buildProvidersTree([ + ({ children }) => ( + + {children} + + ), + ...providers, + ]); +}; From 85519cf857e832aed6a79003127460e47b42cff4 Mon Sep 17 00:00:00 2001 From: harukin-expo-dev-env Date: Tue, 20 Aug 2024 02:17:05 +0000 Subject: [PATCH 2/4] =?UTF-8?q?Apps=E3=81=AEprops=E6=A7=8B=E6=96=87?= =?UTF-8?q?=E6=95=B4=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Apps.js | 92 +++++++++++++++++++++++++++------------------------------ 1 file changed, 43 insertions(+), 49 deletions(-) diff --git a/Apps.js b/Apps.js index d74c474..9f4a261 100644 --- a/Apps.js +++ b/Apps.js @@ -9,53 +9,47 @@ import { MenuPage } from "./MenuPage.js"; import { useAreaInfo } from "./stateBox/useAreaInfo.js"; import "./components/ActionSheetComponents/sheets.js"; -const Tab = createBottomTabNavigator(); export function AppContainer() { - const { areaInfo, areaIconBadgeText } = useAreaInfo(); - const navigationRef = React.useRef(); - return ( - - - - {(props) => } - - - - - {(props) => } - - - - ); - } - \ No newline at end of file + const Tab = createBottomTabNavigator(); + const { areaInfo, areaIconBadgeText } = useAreaInfo(); + const navigationRef = React.useRef(); + const getTabProps = (name, label, icon, iconFamily, tabBarBadge) => ({ + name, + options: { + tabBarLabel: label, + headerTransparent: true, + gestureEnabled: true, + tabBarIcon: initIcon(icon, iconFamily), + tabBarBadge, + }, + }); + return ( + + + } + /> + + + } + /> + + + ); +} From 4085ee36754a46bc6832c042cd60b05b1f2077b1 Mon Sep 17 00:00:00 2001 From: harukin-expo-dev-env Date: Tue, 20 Aug 2024 03:15:13 +0000 Subject: [PATCH 3/4] =?UTF-8?q?Top.js=E3=81=AE=E9=83=A8=E5=88=86=E6=95=B4?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Top.js | 52 ++++++++++++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/Top.js b/Top.js index bb9aa87..6054b0e 100644 --- a/Top.js +++ b/Top.js @@ -18,8 +18,7 @@ import { useTrainMenu } from "./stateBox/useTrainMenu"; const Stack = createStackNavigator(); export const Top = ({ navigationRef }) => { const { webview } = useCurrentTrain(); - const navigation = useNavigation(); - const { navigate, addListener } = navigation; + const { navigate, addListener } = useNavigation(); //地図用 const { setMapsStationData, injectJavaScript, setInjectJavaScript } = @@ -38,33 +37,38 @@ export const Top = ({ navigationRef }) => { ASCore({ k: "mapSwitch", s: setMapSwitch, d: "false" }); }, []); + + const goToFavoriteList = () => navigate("favoriteList"); + useEffect(() => { - const unsubscribe = addListener("tabLongPress", () => - navigate("favoriteList") - ); + const unsubscribe = addListener("tabLongPress", goToFavoriteList); return unsubscribe; - }, [navigation]); - useEffect(() => { - const unsubscribe = navigation.addListener("tabPress", () => { - if (navigationRef.current?.getCurrentRoute().name == "Apps") { - if (mapSwitch == "true") { - navigation.navigate("trainMenu"); - setInjectJavaScript(""); - } else { - webview.current?.injectJavaScript(`AccordionClassEvent()`); - } + }, [{ navigate, addListener }]); + + + const goToTrainMenu = () => { + if (navigationRef.current?.getCurrentRoute().name == "Apps") { + if (mapSwitch == "true") { + navigate("trainMenu"); + setInjectJavaScript(""); } else { - if (mapSwitch == "true") { - if (injectJavaScript) { - webview.current?.injectJavaScript(injectJavaScript); - setInjectJavaScript(""); - } - } - navigation.navigate("Apps"); + webview.current?.injectJavaScript(`AccordionClassEvent()`); } - }); + } else { + if (mapSwitch == "true") { + if (injectJavaScript) { + webview.current?.injectJavaScript(injectJavaScript); + setInjectJavaScript(""); + } + } + navigate("Apps"); + } + }; + + useEffect(() => { + const unsubscribe = addListener("tabPress", goToTrainMenu); return unsubscribe; - }, [navigation, mapSwitch, injectJavaScript]); + }, [{ navigate, addListener }, mapSwitch, injectJavaScript]); return ( From 229a7ffe5e95c8ca73bd6a3c48cc917efda1e6b4 Mon Sep 17 00:00:00 2001 From: harukin-expo-dev-env Date: Tue, 20 Aug 2024 03:31:47 +0000 Subject: [PATCH 4/4] =?UTF-8?q?=E6=95=B4=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Top.js | 6 +----- components/Apps.js | 28 ++++++++++------------------ storageControl.js | 7 +++++++ 3 files changed, 18 insertions(+), 23 deletions(-) diff --git a/Top.js b/Top.js index 6054b0e..b2bd3bf 100644 --- a/Top.js +++ b/Top.js @@ -13,7 +13,7 @@ import FavoriteList from "./components/FavoriteList.js"; import { optionData } from "./lib/stackOption.js"; import { useNavigation } from "@react-navigation/native"; import { useCurrentTrain } from "./stateBox/useCurrentTrain.js"; -import { AS } from "./storageControl.js"; +import { ASCore } from "./storageControl.js"; import { useTrainMenu } from "./stateBox/useTrainMenu"; const Stack = createStackNavigator(); export const Top = ({ navigationRef }) => { @@ -28,10 +28,6 @@ export const Top = ({ navigationRef }) => { getStationList2().then(setMapsStationData); }, []); const [mapSwitch, setMapSwitch] = React.useState("false"); - const ASCore = ({ k, s, d }) => - AS.getItem(k) - .then((d) => (d ? s(d) : AS.setItem(k, d))) - .catch(() => AS.setItem(k, d)); useEffect(() => { //地図スイッチ ASCore({ k: "mapSwitch", s: setMapSwitch, d: "false" }); diff --git a/components/Apps.js b/components/Apps.js index 38a188b..1b33f12 100644 --- a/components/Apps.js +++ b/components/Apps.js @@ -11,7 +11,7 @@ import Constants from "expo-constants"; import { Ionicons } from "@expo/vector-icons"; import * as Updates from "expo-updates"; -import { AS } from "../storageControl"; +import { AS, ASCore } from "../storageControl"; import { news } from "../config/newsUpdate"; import { getStationList, lineList } from "../lib/getStationList"; import { injectJavascriptData } from "../lib/webViewInjectjavascript"; @@ -36,7 +36,7 @@ export default function Apps() { const { navigate } = useNavigation(); const { isLandscape } = useDeviceOrientationChange(); const handleLayout = () => {}; - const { setInjectJavaScript, mapsStationData: stationData } = useTrainMenu(); + const { setInjectJavaScript, mapsStationData } = useTrainMenu(); //画面表示関連 const [iconSetting, setIconSetting] = useState(undefined); @@ -63,10 +63,6 @@ export default function Apps() { stationMenu, trainMenu ); - const ASCore = ({ k, s, d }) => - AS.getItem(k) - .then((d) => (d ? s(d) : AS.setItem(k, d).then(Updates.reloadAsync))) - .catch(() => AS.setItem(k, d).then(Updates.reloadAsync)); useEffect(() => { //ニュース表示 @@ -79,13 +75,13 @@ export default function Apps() { useEffect(() => { //列車アイコンスイッチ - ASCore({ k: "iconSwitch", s: setIconSetting, d: "true" }); + ASCore({ k: "iconSwitch", s: setIconSetting, d: "true", u: true }); //地図スイッチ - ASCore({ k: "mapSwitch", s: setMapSwitch, d: "false" }); + ASCore({ k: "mapSwitch", s: setMapSwitch, d: "false", u: true }); //駅メニュースイッチ - ASCore({ k: "stationSwitch", s: setStationMenu, d: "true" }); + ASCore({ k: "stationSwitch", s: setStationMenu, d: "true", u: true }); //列車メニュースイッチ - ASCore({ k: "trainSwitch", s: setTrainMenu, d: "true" }); + ASCore({ k: "trainSwitch", s: setTrainMenu, d: "true", u: true }); }, []); const openStationACFromEachTrainInfo = async (stationName) => { @@ -127,7 +123,7 @@ export default function Apps() { {!trainInfo.trainNum && isLandscape ? ( ) : ( - + )} ); } -const NewMenu = ({ webview, LoadError }) => { +const NewMenu = ({ LoadError }) => { + const { webview } = useCurrentTrain(); const { width } = useWindowDimensions(); return ( storage.load({ key }), @@ -13,3 +14,9 @@ export const AS = { }), removeItem: (key) => storage.remove({ key }), }; +export const ASCore = ({ k, s, d, u }) => + AS.getItem(k) + .then((d) => + d ? s(d) : AS.setItem(k, d).then(() => u && Updates.reloadAsync()) + ) + .catch(() => AS.setItem(k, d).then(() => u && Updates.reloadAsync()));