简体   繁体   English

React Native 嵌套导航以在登录/注册(StackNavigator)后实现带有选项卡(bottomTabNavigator)的登陆屏幕

[英]React Native nested navigation to achieve a landing screen with tabs (bottomTabNavigator) after Sign-In/Sign-Up(StackNavigator)

Here is an Expo Snack of my project : https://snack.expo.io/Sk3W8egTl这是我的项目的世博小吃: https : //snack.expo.io/Sk3W8egTl

I have a StackNavigator to implement a simple Sign Up and Login functionality.我有一个 StackNavigator 来实现一个简单的注册和登录功能。 It follows the structure provided in this article link它遵循本文链接中提供的结构

I also want to have a screen that uses a bottom Tab navigator with just two tabs for a Home Screen and a Settings Screen that I can land on after the login.我还想要一个使用底部选项卡导航器的屏幕,其中只有两个选项卡用于主屏幕和登录后可以登陆的设置屏幕。

My App.js looks like this :我的App.js看起来像这样:

import React, { useState } from 'react';
import { Platform, StatusBar, StyleSheet, View } from 'react-native';

import {createAppContainer} from 'react-navigation';
import { createBottomTabNavigator } from 'react-navigation-tabs';
import AppContainer from './navigation'

import Home from "./screens/HomeScreen";
import Settings from "./screens/SettingsScreen";

const BottomTabNavigator = createBottomTabNavigator({ //for the bottom two tabs after landing from the login screen
  Home: {screen: Home},
  Settings: {screen: Settings},

});

//const App = createAppContainer(BottomTabNavigator); 

//export default App;

export default function App() {
  return <AppContainer />
}

The navigation folder has three files, namely :导航文件夹有三个文件,分别是:

AppNavigation - for the main screens in the app AppNavigation - 用于应用程序的主屏幕

import { createStackNavigator } from 'react-navigation-stack'
import Home from '../screens/HomeScreen'

const AppNavigation = createStackNavigator(
  {
    Home: { screen: Home }
  },
  {
    initialRouteName: 'Home'
  }
)

export default AppNavigation

AuthNavigation - for the login and sign up screens AuthNavigation - 用于登录和注册屏幕

import { createStackNavigator } from 'react-navigation-stack'
import Login from '../screens/Login'
import SignUp from '../screens/SignUp'

const AuthNavigation = createStackNavigator(
  {
    Login: { screen: Login },
    SignUp: { screen: SignUp }
  },
  {
    initialRouteName: 'Login',
    headerMode: 'none',
  }
)

export default AuthNavigation

index.js - to integrate them index.js - 整合它们

import { createSwitchNavigator, createAppContainer } from 'react-navigation'
import AuthNavigation from './AuthNavigation'
import AppNavigation from './AppNavigation'


const SwitchNavigator = createSwitchNavigator(
  {
    Auth: AuthNavigation,
    App: AppNavigation
  },
  {
    initialRouteName: 'Auth'
  }
)
const AppContainer = createAppContainer(SwitchNavigator)

export default AppContainer

Right now I have the sign-in/sign-up pages and the bottom tabs separate but I want to be able to see the landing page with the two tabs after I sign in. I am really new to React Native and don't have an idea as to how to go about nesting the Navigators to achieve what I need.现在,我将登录/注册页面和底部选项卡分开,但我希望在登录后能够看到带有两个选项卡的登录页面。我真的是 React Native 的新手并且没有关于如何嵌套导航器以实现我需要的想法。 Please help me out here.请帮帮我。 Thank you!谢谢!

It's simple what you are trying to achieve.您想要实现的目标很简单。 In place of createStackNavigator... of your AppNavigation put your代替 createStackNavigator... 你的 AppNavigation 把你的

    createBottomTabNavigator({ //for the bottom two tabs after landing from the login screen
  Home: {screen: Home},
  Settings: {screen: Settings},

});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM