1

My router is this. Is there a way where a variable will tell what screen should display?

export const HomeNavigator = TabNavigator({
    ...
    Search:{
        screen: usertype == 1? Customer : Handyman,
    },
    ...
});

export const RootStack = StackNavigator({
    Login: {screen: Login}
    Home:{screen: HomeNavigator},
    ...
},{
    headerMode: 'none'
});

export default RootStack;

After the user logged in his account, the application will check his account type. Then his account type will tell what screen should display in the Search tab:

if the user's account type is 1 the screen that should display is customer.js

if the user's account type is 2 the screen that should display is Handyman.js

Community
  • 1
  • 1
PJ Concepcion
  • 108
  • 1
  • 13

1 Answers1

0

I will show you workflow of my package, and feel free to ask if you still confusing,

in router.js (handling screen):

const Tab =  TabNavigator({
  Customer : {
    screen: Customer,
  }
});

const TabLogged =  TabNavigator({
  Handyman: {
    screen: Handyman,
  }
});
// here's the key to handle which account is logged
export const Check = SwitchNavigator({
  Auth: Auth,
  Account1: Tab,
  Account2: TabLogged
})

create Auth.js to check which account is logged:

..import

class foo extends React.component{
  componentWillMount(){
    this.props.navigation.navigate(usertype == 1 ? 'Account1' : 'Account2');
  }

  render(){
    <View>
      <ActivityIndicator size="large" color="#0000ff" />
      <StatusBar barStyle="default" />
    </View>
  }
}

and in your app.js or index.js :

..import check variable from router.js

class app extends Component{
  render() {
    return <check/>;
  }
}
flix
  • 1,688
  • 3
  • 34
  • 64