简体   繁体   English

如何使用 React 导航 5.X 将堆栈导航与底部选项卡导航器一起使用

[英]How to use stack navigation with bottom tab navigator using React navigation 5.X

I am updating my code to use the react-navigation 5.x, but I don't know how to implement the stack navigation with a bottom tab navigator in this version.我正在更新我的代码以使用 react-navigation 5.x,但我不知道如何在此版本中使用底部选项卡导航器实现堆栈导航。 I use the bottom tab navigator only on the screens that appear after the user logs in. On the initial screen, there is only navigation with custom buttons.我只在用户登录后出现的屏幕上使用底部标签导航器。在初始屏幕上,只有带有自定义按钮的导航。 My problem is I don't know how to create the route to that necessity I have.我的问题是我不知道如何创建通往我所拥有的必要性的路线。 I've been looking for a code example, but I only found codes that use the bottom tab navigator alone.我一直在寻找一个代码示例,但我只找到了单独使用底部选项卡导航器的代码。 Could you please give me an example of code I can use?你能给我一个我可以使用的代码示例吗? I would appreciate it我会很感激

I have this piece of code that is what I have working right now我有这段代码,这就是我现在正在使用的代码

import React from 'react'
import { createStackNavigator } from '@react-navigation/stack';
import { NavigationContainer } from '@react-navigation/native';

import Login from '../screens/Login'
import Register from '../screens/Register'
import Main from '../screens/Main'
import Ex1 from '../screens/Ex1'
import Ex2 from '../screens/Ex2'

const AuthStack = createStackNavigator();

const AuthStackScreen = () => (
    <NavigationContainer>
        <AuthStack.Navigator 
        initialRouteName="Login" 
        screenOptions={{
            headerShown: false
        }}>
            <AuthStack.Screen
            name="Login"
            component={Login}
            />
            <AuthStack.Screen
            name="Register"
            component={Register}
            />
        </AuthStack.Navigator>
    </NavigationContainer>
);

export default AuthStackScreen

you can do somethin like this:你可以这样做:

export default function ComponentC() {
    return(
        <View>
            <Text>It Works!</Text>
        </View>
    )
}

export default function ComponentB() {
  return (
    <Stack.Navigator initialRouteName={'Main'}>
        <Stack.Screen name={'Main'} component={ComponentC} />
    </Stack.Navigator>   
  );
} 

export default function ComponentA () {
    return (
      <NavigationContainer>
        <Tab.Navigator
          initialRouteName={'ComponentB'}
        >
          <Tab.Screen name={'ComponentB'} component={ComponentB} options={{ tabBarIcon: ({color}) => (
              <FontAwesome5 color={color}  name={'check-square'} size={20}/>
          )}} />
        </Tab.Navigator>
      </NavigationContainer>    
    );
  } 

The Component B going to be called in the Bottom Tab Navigator and the initial route is gonna be the Component C.组件 B 将在底部选项卡导航器中调用,初始路径将是组件 C。

暂无
暂无

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

相关问题 如何在反应导航 5.x 中从选项卡导航(底部选项卡)中隐藏 header? - How to hide the header from Tab navigation (bottom-tabs) in react navigation 5.x? 在 react-navigation 5.x 选项卡中预加载嵌套堆栈 - Preload nested stack in react-navigation 5.x tab 我如何在 React Navigation 5.x 中从一个堆栈到另一个包含选项卡堆栈的 go? - How do i go from one stack to another containing a tab stack in React Navigation 5.x? 如何使用嵌套的底部选项卡导航器将导航按钮添加到 React 导航堆栈 header? - How do I add a navigation button to a React Navigation Stack header with nested Bottom Tab Navigator? 如何使用React本机导航创建嵌套导航? (示例:选项卡导航器中的堆栈导航器) - How to use react native navigation to create a nested navigation? (Example: Stack navigator inside a Tab navigator) React Navigation V5 在 Stack Navigator 中隐藏底部标签栏 - React Navigation V5 hide Bottom tab bar in Stack Navigator 如何隐藏特定屏幕上的底部标签栏(反应导航 5.x) - How can I hide the bottom tab bar on a specific screen (react navigation 5.x) React 导航:带有选项卡导航器的堆栈导航器不起作用 - React navigation: stack navigator with tab navigator is not working 如何将底部选项卡导航器添加到堆栈导航中的一个屏幕? - How to add bottom tab navigator to one screen inside stack navigation? 有没有办法检查屏幕是否在底部标签导航中 - 反应导航 5.X - Is there any way to check if screen is in bottom tab navigation - react navigation 5.X
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM