[英]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.