Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
Help us understand the problem. What is going on with this article?

navigation v5 使い方メモ

概要

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>
  )
}



yutanoda
駆け出しエンジニアです。業務では主にRailsとLaravelを使用しています。 Reactなどモダンなフロントエンドもかじりたいこの頃
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away