我是React Native 的新手。我尝试在App.js中嵌套多个导航。我已经成功地在我的BottomTabNavigation中嵌套了StackNavigator,但没有问题。我通过将这些导航器的初始路径组件设置为等于前一个导航器来链接它们。我尝试在其中添加DrawerNavigation,但一直收到错误。我的所有代码都在1个文件中(App.js)。我该如何处理这个问题?
堆栈导航器
const navigator = createStackNavigator(
{
Home: {
screen: HomeScreen,
navigationOptions: {
headerShown: false,
},
},
Favs: {
screen: CrossingScreen,
navigationOptions: {
title: 'News',
headerTitleStyle: {
color: 'white',
},
headerStyle: {
backgroundColor: 'red',
},
headerBackTitle: null,
headerTintColor: 'white',
},
},
},
{
initialRouteName: 'Home',
headerMode: 'screen',
})
底部选项卡导航器
const TabNavigator = createMaterialBottomTabNavigator(
{
Home: {
screen: navigator,
navigationOptions: {
tabBarLabel: 'Home',
tabBarIcon: ({ tintColor }) => (
<View>
<Icon
style={[{ color: tintColor }]}
size={25}
name={'train'}
/>
</View>
),
},
},
FavScreen: {
screen: FavScreen,
navigationOptions: {
tabBarLabel: 'Favorites',
tabBarIcon: ({ tintColor }) => (
<View>
<Icon
style={[{ color: tintColor }]}
size={28}
name={'star'}
/>
</View>
),
activeColor: '#f60c0d',
inactiveColor: '#f65a22',
barStyle: { backgroundColor: '#f69b31' },
},
},
MapScreen: {
screen: MapScreen,
navigationOptions: {
tabBarLabel: 'Map',
tabBarIcon: ({ tintColor }) => (
<View>
<Icon
style={[{ color: tintColor }]}
size={25}
name={'map'}
/>
</View>
),
activeColor: '#615af6',
inactiveColor: '#46f6d7',
barStyle: { backgroundColor: '#67baf6' },
},
},
Cart: {
screen: CartScreen,
navigationOptions: {
tabBarLabel: 'Feedback',
tabBarIcon: ({ tintColor }) => (
<View>
<Icon
style={[{ color: tintColor }]}
size={25}
name={'mail'}
/>
</View>
),
},
},
Cart2: {
screen: CartScreen,
navigationOptions: {
tabBarLabel: 'Add',
tabBarIcon: ({ tintColor }) => (
<View>
<Icon
style={[{ color: tintColor }]}
size={25}
name={'add'}
/>
</View>
),
},
},
},
{
initialRouteName: 'Home',
activeColor: '#f0edf6',
inactiveColor: '#226557',
barStyle: { backgroundColor: '#3BAD87' },
})
抽屉导航器
const DrawerNav = createDrawerNavigator(
{
Page1: {
screen: TabNavigator,
},
Page2: {
screen: FavScreen,
},
Page3: {
screen: MapScreen,
},
},
{
contentComponent: SideMenu,
drawerWidth: 300,
})
将其导出到App.js的应用容器中
export default createAppContainer(DrawerNav)
错误:
1条答案
按热度按时间bvjxkvbb1#
我通过仔细阅读[https://reactnavigation.org/docs/upgrading-from-4.x][1]解决了我的问题
导航API在v4.0和v5.0之间发生了重大变化
这是在抽屉导航器中嵌套StackNavigator和MaterialBottomTabNavigatior的方法
如果使用常规BottomTabNavigatior,则实现相同