我正在博览会上使用反应导航(“ ^ 3.0.9”)。
这是我的逻辑流程:
TabView(BottomTabNavigator) with StackNavigatior:
HomeStack
--HomeScreen
...
LinksStack
--LinkScreen
...
SettingsStack
-- Aboutscreen
...
一切正常,但现在我想添加一个抽屉式导航(汉堡菜单),如下所示:
DrawerNavigation View
--HomeScreen(which will show HomeScreen with 3 tabs)
--Screen2 (no tabs)
--Screen3 (no tabs)
我尝试执行以下操作:
export const Tab = createBottomTabNavigator({
HomeStack,
LinksStack,
SettingsStack,
}
);
export const Drawer = DrawerNavigator({
HomeScreen: { screen: HomeScreen },
Screen2: { screen: Screen2 },
Screen3: { screen: Screen3 },
});
他们返回未定义错误的不是函数
原始代码仅用于导出默认的底部标签导航器,
//export default createBottomTabNavigator({
// HomeStack,
// LinksStack,
// SettingsStack,
// }
// );
如何同时实现BottomTabNavigator和DrawerNavigator?
-代码如下
调用AppNavigator的我的App.js
render() {
if (!this.state.isLoadingComplete && !this.props.skipLoadingScreen) {
return (
<AppLoading
startAsync={this._loadResourcesAsync}
onError={this._handleLoadingError}
onFinish={this._handleFinishLoading}
/>
);
} else {
return (
<View style={styles.container}>
{Platform.OS === 'ios' && <StatusBar barStyle="default" />}
<AppNavigator />
</View>
);
}
}
AppNavigator称为MainTabNavigator
import { createAppContainer, createSwitchNavigator } from 'react-navigation';
import MainTabNavigator from './MainTabNavigator';
export default createAppContainer(createSwitchNavigator({
Main: MainTabNavigator,
}
));
带有Tab的stackNavigator的示例
const HomeStack = createStackNavigator({
Home: HomeScreen,
HomeDetail: HomeDetailScreen
});
HomeStack.navigationOptions = {
tabBarLabel: 'Home',
tabBarIcon: ({ focused }) => (
<TabBarIcon
focused={focused}
name={
Platform.OS === 'ios'
? `ios-home`
: 'md-home'
}
/>
),
};
更新: 我已经完成了正确的工作snack example,任何人都可以参考。
答案 0 :(得分:2)
您需要在DrawerNavigator中添加tabNavigator。
const ProfileNavigator = createDrawerNavigator({
Drawer: DashboardTabNav
}, {
initialRouteName: 'Drawer',
contentComponent: ExampleScreen,
drawerWidth: 300
});
// Manifest of possible screens
const PrimaryNav = createStackNavigator({
DashboardScreen: { screen: ProfileNavigator },
LoginScreen: { screen: LoginScreen },
LaunchScreen: { screen: LaunchScreen },
UpdateUserScreen: { screen: UpdateUserScreen }
}, {
// Default config for all screens
headerMode: 'none',
initialRouteName: 'LoginScreen',
navigationOptions: {
headerStyle: styles.header
}
});
export default createAppContainer(PrimaryNav);
看看how to open drawer without navigating to the screen from one of the tabs of tabnavigator? 要么 https://readybytes.in/blog/how-to-integrate-tabs-navigation-drawer-navigation-and-stack-navigation-together-in-react-navigation-v2 另外,以完整示例为例,请查看https://gitlab.com/readybytes/ReactNavigationExampleVersion2