0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

navigation v5 使い方メモ

Last updated at Posted at 2020-11-16

##概要
NavigationContainerでAppStack.NavigatorとAppStack.Screenをwrapする。

import React from "react";
import {StyleSheet, Text, View } from "react-native";
import { NavigationContainer } from "@react-navigation/native";
import { createStackNavigator } from '@react-navigation/stack';

// リストの型指定
export type RootStackParamList = {
  LoginScreen: undefined;
  SignageHomeScreen: undefined
  DisplayDataListScreen: undefined
  FirstScreen: undefined;
  SecondScreen: undefined;
  ThirdScreen: undefined;
  InputTitleScreen:undefined;
};

const AppStack = createStackNavigator<RootStackParamList>();

const App = () => {
  return (
    <NavigationContainer>
      <AppStack.Navigator initialRouteName="LoginScreen">
        <AppStack.Screen name="LoginScreen" component={LoginScreen} />
        <AppStack.Screen name="SignageHomeScreen" component={SignageHomeScreen} />
        <AppStack.Screen name="DisplayDataListScreen" component={DisplayDataListScreen} />
               ・
         ・
         ・
    </AppStack.Navigator>
    </NavigationContainer>
  );
}

##createDrawerNavigatorと組み合わせる場合

import React from "react";
import {StyleSheet, Text, View } from "react-native";
import { DrawerActions, NavigationContainer } from "@react-navigation/native"; // New!!
import { createStackNavigator } from '@react-navigation/stack';
import { createDrawerNavigator } from '@react-navigation/drawer'; // New!!

// リストの型指定
export type RootStackParamList = {
  LoginScreen: undefined;
  SignageHomeScreen: undefined
  DisplayDataListScreen: undefined
  FirstScreen: undefined;
  SecondScreen: undefined;
  ThirdScreen: undefined;
  InputTitleScreen:undefined;
};

const AppStack = createStackNavigator<RootStackParamList>();
const DrawerMenu = createDrawerNavigator();  //New!!

const App = () => {
  return (
    <NavigationContainer>
      <AppStack.Navigator initialRouteName="LoginScreen">
        <AppStack.Screen name="LoginScreen" component={LoginScreen} />
        <AppStack.Screen name="SignageHomeScreen" component={SignageHomeScreen} />
        <AppStack.Screen name="DisplayDataListScreen" component={DisplayDataListScreen} />
        <AppStack.Screen           // New!!
          name="ConnectScreen"
          component={MakeDrawerMenu}
          options={({ navigation }) => ({
            headerLeft: () => (
              <View> 
              <Button
                  onPress={() => {
                    navigation.dispatch(DrawerActions.toggleDrawer());
                  }}
                />
              </View>
            ),
          })}
        />
               ・
         ・
         ・
    </AppStack.Navigator>
    </NavigationContainer>
  );
}

const MakeDrawerMenu = () => {             //New!!
  return (
    <DrawerMenu.Navigator initialRouteName="DevicesList">
      <DrawerMenu.Screen
        name="DevicesList"
        component={ConnectScreen}
        options={{title:"サイネージ一覧"}}/>
      <DrawerMenu.Screen
        name="Notification"
        component={NotificationScreen}
        options={{ title: "お知らせ" }}/>
      <DrawerMenu.Screen
        name="Help"
        component={HelpScreen}
        options={{ title:"ヘルプ" }}/>
      
    </DrawerMenu.Navigator>
  )
}



0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?