抽屉式导航反应原生纸张

问题描述 投票:0回答:1

我对 React 和 React Native 非常陌生。我需要一些有关在当前堆栈导航中嵌套抽屉导航器的帮助。

我有 Snack 的代码,如果有人可以帮助我,我将非常感激。

https://snack.expo.dev/@smith.james1982/github.com-callstack-react-native-paper-login-template

我想在主屏幕上使用react-native-paper放置带有汉堡包和后退箭头的抽屉导航。

提前非常感谢..

react-native react-native-paper
1个回答
2
投票

这就是我实现解决方案的方法,基本上是 2 个导航并使用状态共享库之间的使用。希望它对某人有帮助

import React, { memo, useState } from "react";

import { createStackNavigator } from "@react-navigation/stack";
import { createDrawerNavigator } from "@react-navigation/drawer";
import { NavigationContainer } from "@react-navigation/native";

import { HomeScreen, LoginScreen, RegisterScreen, ForgotPasswordScreen, Dashboard, Demo } from "./screens";

import { useLoginState } from "./core/state";
import { useBetween } from "use-between";

const Stack = createStackNavigator();
const Drawer = createDrawerNavigator();

//Login navigation
const LoginNav = () => {
  return (
    <NavigationContainer>
      <Stack.Navigator
        screenOptions={{
          headerShown: false,
        }}
        initialRouteName="HomeScreen"
      >
        <Stack.Screen name="HomeScreen" component={HomeScreen} />
        <Stack.Screen name="LoginScreen" component={LoginScreen} />
        <Stack.Screen name="RegisterScreen" component={RegisterScreen} />
        <Stack.Screen name="ForgotPasswordScreen" component={ForgotPasswordScreen} />
        <Stack.Screen name="Dashboard" component={Dashboard} />
      </Stack.Navigator>
    </NavigationContainer>
  );
};

//Logged in Navigation
const LoggedInNav = () => {
  return (
    <NavigationContainer>
      <Drawer.Navigator initialRouteName="Home">
        <Drawer.Screen name="Home" component={Demo} />
      </Drawer.Navigator>
    </NavigationContainer>
  );
};

export default function App() {
  const { loggedIn, setIsLoggedIn } = useBetween(useLoginState);
  return loggedIn ? <LoggedInNav /> : <LoginNav />;
}
© www.soinside.com 2019 - 2024. All rights reserved.