反应导航:有条件的主导航器

时间:2019-05-15 15:17:29

标签: react-native react-navigation

我正在开发一个移动应用程序,当用户打开该应用程序时,如果用户已登录,则他会登录到主页;如果用户未登录,则他将登录到登录页,并且用户已登录我们是否将其信息存储在本地存储中

所以我的问题是如何基于本地存储中的值如何有条件地切换应用程序根导航器

以下是我在导航器中使用的代码

const  BottomTabNavigator = createMaterialBottomTabNavigator({
   Home: { screen: HomePage },
   Library: { screen: LibrarePage },
}, 
{
  initialRouteName: 'Home',
  activeColor: '#f0edf6',
  inactiveColor: '#3e2465',
  barStyle: { backgroundColor: '#694fad' },
});

const loginNavigator = createSwitchNavigator({ SignInPage, BottomTabNavigator });

const AppContainer = createAppContainer((AsyncStorage.getItem("IsUserLoggedIn")) ? BottomTabNavigator : loginNavigator );

export default AppContainer;

上面的代码不起作用,因为AsyncStorage.getItem(“ IsUserLoggedIn”)是异步方法,所以我的问题是如何实现上述方案

0 个答案:

没有答案
相关问题