React Native项目二级页面设置tabBarVisible: false无法隐藏tabBar问题

问题描述:
我的项目结构是这样的:tabNavigater上有两个stackNavigator,每个stackNavigator上都有对应的首页和详情页面,在进入详情页后,我想隐藏tabBar,做如下设置(未生效):

static navigationOptions = {
	tabBarVisible: true,
}

解决办法:
在创建stackNavigator时,做如下配置:

const HomeNav = createStackNavigator({
	Home: {
		screen: Home
	}
}, {
	defaultNavigationOptions: {
		headerTitle: '首页',
		headerBackTitle: null,
		headerTintColor: '#333333',
		showIcon: true,
		headerTitleStyle: {
			alignSelf: 'center'
		},
	},
	// 设置二级页面隐藏tabBar
	navigationOptions: ({
		navigation
	}) => ({
		tabBarVisible: navigation.state.index > 0 ? false : true,
	})
});

参考地址:
https://reactnavigation.org/docs/zh-Hans/navigation-options-resolution.html

https://github.com/react-navigation/react-navigation-tabs/issues/19

https://snack.expo.io/Sk7Go1WRM

你可能感兴趣的:(React,Native)