React Navigation - How to switch Tab Navigation to handle Login Screen?

此生再无相见时 提交于 2019-12-20 04:56:05

问题


I want to know if it's possible to handle login screen after the button login pressed,

I have a router.js:

export const TabLoged= TabNavigator({
  Home: {
    screen: HomeStack,
  },
  MyPatient:{
    screen: MyPatientStack
  },
  MyAccount: {
    screen: MyAccount,
  }
});

export const Tab =  TabNavigator({
  Home: {
    screen: HomeStack,
  },
  Login: {
    screen: LoginStack,
  }
});

export const Root = StackNavigator({
  Tab: {
    screen: Tab,
  }
},{headerMode:'none'})

In export const Root I want to change the code looks like :

export const Root = StackNavigator({
  Tab: {
    // here i want to set the `alredyLogin` to be boolean, but i dont know how to do that
    screen: alreadyLogin ? TabLoged : Tab,
  }
},{headerMode:'none'})

Refer to this question I dont get it how to handle this issue, so I want to know there's another way to archive my goal?


回答1:


To achieve desired behavior you can use SwitchNavigator. There is a really good example for it in the doc. You can check it here.

SwitchNavigator reference

SwitchNavigator(RouteConfigs, SwitchNavigatorConfig)

Example from docs

const AppStack = StackNavigator({ Home: HomeScreen, Other: OtherScreen });
const AuthStack = StackNavigator({ SignIn: SignInScreen });

export default SwitchNavigator(
  {
    AuthLoading: AuthLoadingScreen,
    App: AppStack,
    Auth: AuthStack,
  },
  {
    initialRouteName: 'AuthLoading',
  }
);


来源:https://stackoverflow.com/questions/49747162/react-navigation-how-to-switch-tab-navigation-to-handle-login-screen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!