navigationの制御方式多少変更

This commit is contained in:
harukin-DeskMini 2023-01-30 00:04:18 +09:00
parent fae18a6a47
commit f5e4947c3b
3 changed files with 70 additions and 52 deletions

62
App.js
View File

@ -10,12 +10,12 @@ import { Platform, UIManager } from "react-native";
import { UpdateAsync } from "./UpdateAsync.js"; import { UpdateAsync } from "./UpdateAsync.js";
import Apps from "./Apps"; import Apps from "./Apps";
import tndView from "./ndView"; import tndView from "./ndView";
import trainbase from "./trainbaseview"; import TrainBase from "./trainbaseview";
import howto from "./howto"; import HowTo from "./howto";
import menu from "./menu"; import menu from "./menu";
import News from "./components/news.js"; import News from "./components/news.js";
import Setting from "./components/settings.js"; import Setting from "./components/settings.js";
import trainMenu from "./components/trainMenu.js"; import TrainMenu from "./components/trainMenu.js";
import FavoriteList from "./components/FavoriteList.js"; import FavoriteList from "./components/FavoriteList.js";
const Stack = createStackNavigator(); const Stack = createStackNavigator();
const Tab = createBottomTabNavigator(); const Tab = createBottomTabNavigator();
@ -25,14 +25,14 @@ if (Platform.OS === "android") {
} }
} }
export default function App() { export default function App() {
const navigationRef = useRef();
useEffect(() => { useEffect(() => {
UpdateAsync(); UpdateAsync();
}, []); }, []);
return ( return (
<NavigationContainer name="Root" ref={navigationRef} style={{ flex: 1 }}> <NavigationContainer name="Root" style={{ flex: 1 }}>
<Tab.Navigator> <Tab.Navigator>
<Stack.Screen <Tab.Screen
name="login" name="login"
component={top} component={top}
options={{ options={{
@ -42,7 +42,7 @@ export default function App() {
tabBarIcon: () => <AntDesign name="barchart" size={32} />, tabBarIcon: () => <AntDesign name="barchart" size={32} />,
}} }}
/> />
<Stack.Screen <Tab.Screen
name="menuPage" name="menuPage"
component={menuPage} component={menuPage}
options={{ options={{
@ -52,7 +52,7 @@ export default function App() {
tabBarIcon: () => <Ionicons name="ios-radio" size={32} />, tabBarIcon: () => <Ionicons name="ios-radio" size={32} />,
}} }}
/> />
<Stack.Screen <Tab.Screen
name="home" name="home"
component={tndView} component={tndView}
options={{ options={{
@ -66,43 +66,63 @@ export default function App() {
</NavigationContainer> </NavigationContainer>
); );
} }
const top = () => ( const top = ({ navigation }) => {
useEffect(() => {
const unsubscribe = navigation.addListener("tabLongPress", (e) => {
alert("longPress!");
navigation.navigate("favoriteList", { webview, stationData });
});
return unsubscribe;
}, [navigation]);
const webview = useRef();
return (
<Stack.Navigator> <Stack.Navigator>
<Stack.Screen <Stack.Screen
name="Apps" name="Apps"
component={Apps}
options={{ options={{
headerShown: false, headerShown: false,
gestureEnabled: true, gestureEnabled: true,
headerTransparent: true, headerTransparent: true,
}} }}
/> >
{(props) => <Apps {...props} webview={webview} />}
</Stack.Screen>
<Stack.Screen <Stack.Screen
name="trainbase" name="trainbase"
component={trainbase}
options={{ options={{
title: "トレインビジョン", title: "トレインビジョン",
gestureEnabled: true, gestureEnabled: true,
...TransitionPresets.SlideFromRightIOS, ...TransitionPresets.SlideFromRightIOS,
}} }}
/> >
{(props) => <TrainBase {...props} webview={webview} />}
</Stack.Screen>
<Stack.Screen <Stack.Screen
name="howto" name="howto"
component={howto}
options={{ options={{
title: "使い方", title: "使い方",
...optionData, ...optionData,
}} }}
/> >
<Stack.Screen name="news" component={News} options={optionData} /> {(props) => <HowTo {...props} />}
<Stack.Screen name="trainMenu" component={trainMenu} options={optionData} /> </Stack.Screen>
<Stack.Screen name="news" options={optionData}>
{(props) => <News {...props} />}
</Stack.Screen>
<Stack.Screen name="trainMenu" options={optionData}>
{(props) => <TrainMenu {...props} webview={webview} />}
</Stack.Screen>
<Stack.Screen <Stack.Screen
name="favoriteList" name="favoriteList"
component={FavoriteList}
options={{ ...optionData, gestureEnabled: false }} options={{ ...optionData, gestureEnabled: false }}
/> >
{(props) => <FavoriteList {...props} webview={webview} />}
</Stack.Screen>
</Stack.Navigator> </Stack.Navigator>
); );
};
function menuPage() { function menuPage() {
return ( return (
<Stack.Navigator> <Stack.Navigator>
@ -118,7 +138,7 @@ function menuPage() {
<Stack.Screen name="setting" component={Setting} options={optionData} /> <Stack.Screen name="setting" component={Setting} options={optionData} />
<Stack.Screen <Stack.Screen
name="trainbase" name="trainbase"
component={trainbase} component={TrainBase}
options={{ options={{
...TransitionPresets.ModalPresentationIOS, ...TransitionPresets.ModalPresentationIOS,
cardOverlayEnabled: true, cardOverlayEnabled: true,

View File

@ -19,12 +19,10 @@ import { getStationList2 } from "./lib/getStationList2";
import StatusbarDetect from './StatusbarDetect'; import StatusbarDetect from './StatusbarDetect';
var Status = StatusbarDetect(); */ var Status = StatusbarDetect(); */
export default function Apps(props) { export default function Apps({ navigation, webview }) {
const { const { navigate } = navigation;
navigation: { navigate },
} = props;
var urlcache = ""; var urlcache = "";
const webview = useRef();
//画面表示関連 //画面表示関連
const [iconSetting, setIconSetting] = useState(undefined); const [iconSetting, setIconSetting] = useState(undefined);
const [mapSwitch, setMapSwitch] = useState(undefined); const [mapSwitch, setMapSwitch] = useState(undefined);

View File

@ -2,7 +2,7 @@ import React, { useRef } from "react";
import { View, Text, TouchableOpacity, Linking } from "react-native"; import { View, Text, TouchableOpacity, Linking } from "react-native";
import MapView, { Marker } from "react-native-maps"; import MapView, { Marker } from "react-native-maps";
import { MaterialCommunityIcons } from "@expo/vector-icons"; import { MaterialCommunityIcons } from "@expo/vector-icons";
export default function trainMenu({ export default function TrainMenu({
route: { route: {
params: { webview, stationData }, params: { webview, stationData },
}, },