javascript - 无法使用堆栈导航设置底部选项卡导航
问题描述
我同时使用堆栈导航和底部选项卡导航在我的应用程序中导航
Stack Navigation基本上是这样设置的:
WelcomeScreen --> SignInScreen <--> SignUpScreen --> HomeScreen
现在,我想使用底部选项卡导航在我的 HomeScreen 和 MyGamesScreen 之间导航
主屏幕 <--> 我的游戏屏幕
我想显示底部选项卡导航器的唯一屏幕是 HomeScreen 和 MyGamesScreen。
我尝试了几个教程,最后一次尝试是查看Nesting Navigator上的文档页面,但它对我不起作用。我要么让我的底部选项卡导航器显示在所有页面中,要么不显示在任何页面中。
这是我的App.js,它目前没有在 HomeScreen 中显示我的底部选项卡导航器。我尝试将我的函数名称切换为“HomeScreen”作为解决它的一种方法,就像文档显示的那样,但它给了我一个错误,说“HomesScreen”已经被声明。
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
import LoadingScreen from '/Users/toxnd/Documents/MaisJogo/MaisJogoApp/screens/LoadingScreen'
import WelcomeScreen from '/Users/toxnd/Documents/MaisJogo/MaisJogoApp/screens/WelcomeScreen'
import SignInScreen from '/Users/toxnd/Documents/MaisJogo/MaisJogoApp/screens/SignInScreen'
import SignUpScreen from '/Users/toxnd/Documents/MaisJogo/MaisJogoApp/screens/SignUpScreen'
import HomeScreen from '/Users/toxnd/Documents/MaisJogo/MaisJogoApp/screens/HomeScreen'
import MyGamesScreen from '/Users/toxnd/Documents/MaisJogo/MaisJogoApp/screens/WelcomeScreen'
const Stack = createStackNavigator();
const Tab = createBottomTabNavigator();
export function Home() {
return (
<Tab.Navigator>
<Tab.Screen name="Home" component={HomeScreen} />
<Tab.Screen name='Meus Jogos' component={MyGamesScreen} />
</Tab.Navigator>
);
}
export default function App() {
return (
<NavigationContainer>
<Stack.Navigator
initialRouteName="Loading"
screenOptions={{
headerStyle: {
backgroundColor: '#BB2CD9',
},
headerTintColor: '#fff',
headerTitleStyle: {
fontWeight: 'bold',
},
}}>
<Stack.Screen
options={{headerShown: false}}
name='Loading' component={LoadingScreen} />
<Stack.Screen
options={{ headerShown: false }}
name='Welcome' component={WelcomeScreen} />
<Stack.Screen
options={{headerShown: false}}
name="Sign In" component={SignInScreen} />
<Stack.Screen
options={{ headerShown: false }}
name='Sign Up' component={SignUpScreen} />
<Stack.Screen name="Home" component={HomeScreen} />
</Stack.Navigator>
</NavigationContainer>
);
}
解决方案
快速看一下,您似乎使用了HomeScreen
两次,这与 的导入冲突HomeScreen
,请考虑为选项卡导航器变量使用不同的名称。
推荐阅读
- swift - 如何快速访问firebase字段?
- python - Python 在 RStudio 中找不到 TensorFlow 或 Keras
- node.js - 如何在猫鼬中存储关联的对象数组
- kubernetes - Kubernetes Pod Horizontal Autoscaler pod 和对象选择器字段是字符串吗?
- python - 使用 try 和 except 创建复杂形式的字典
- angular - 为什么我在 Angular 中的登录表单未经过验证且未显示错误消息?
- docker - 使用无服务器和 DynamoDB 对 Flask REST API 进行 Dockerize
- yarnpkg - 如何判断项目是否使用 Yarn
- python - 基于两列Python对List的数字字符串值进行排序
- c++ - 为什么我的代码没有读入我的输入值?