React native 底部选项卡中的条件
我从React Native开始,这里有个小问题。我有一个bottomTabNavigator,如果用户有权限,他将导航到ImageScreen,否则,它将导航到主屏幕 我的函数global.hasPermission()检查权限并返回true或false,因此我希望能够根据函数返回的内容更改{screen:ImageScreen}。我怎么做?在哪里调用函数hasPermission() 这是我的标签导航器:React native 底部选项卡中的条件,react-native,react-navigation,react-navigation-stack,React Native,React Navigation,React Navigation Stack,我从React Native开始,这里有个小问题。我有一个bottomTabNavigator,如果用户有权限,他将导航到ImageScreen,否则,它将导航到主屏幕 我的函数global.hasPermission()检查权限并返回true或false,因此我希望能够根据函数返回的内容更改{screen:ImageScreen}。我怎么做?在哪里调用函数hasPermission() 这是我的标签导航器: const BottomTab = createBottomTabNavigator(
const BottomTab = createBottomTabNavigator({
Image: {
screen: ImageScreen,
navigationOptions: {
tabBarLabel: 'Image Screen',
tabBarIcon: ({ tintColor, focused }) => (
<Ionicons
name={'ios-camera'}
size={focused ? 30 : 26}
style={{ color: tintColor }}
/>
),
},
},
});
const BottomTab=createBottomTabNavigator({
图片:{
屏幕:图像屏幕,
导航选项:{
tabBarLabel:“图像屏幕”,
tabBarIcon:({tintColor,focused})=>(
),
},
},
});
在我的应用程序中,我通过React Context API处理身份验证
几天前,我回答了一个类似的问题,您可以在这里看到如何创建和使用上下文:
像我前面的回答一样,您可以将用户权限检查到ImageScreen的组件didmount(),如果他没有权限,您可以像这样将其重定向到主屏幕(假设主屏幕包含在堆栈导航器中):
//进入您的图像屏幕
组件安装(){
const hasPermission=YourFunctionWhichReturnsTrueOrFalse()
如果(!hasPermission)this.props.navigation.navigate('home')//此处显示主屏幕的标题
}