React-native-router-flux: How to dynamically set initial scene via state

Created on 16 Dec 2016  路  2Comments  路  Source: aksonov/react-native-router-flux

Version

Tell us which versions you are using:

  • react-native-router-flux v3.35.0
  • react-native v0.36.0

Hey guys,
I'm trying to figure out how to dynamically set my initial scene on startup depending on my auth state. Ive tried the following but it does not work:

//render method
render () {
    let authenticated = this.props.isAuthenticated
    return (
      <Router>
        <Scene key='drawer' component={NavigationDrawer} open={false} unmountScenes>
          <Scene key='drawerChildrenWrapper' navigationBarStyle={Styles.navBar} titleStyle={Styles.title} leftButtonIconStyle={Styles.leftButton} rightButtonTextStyle={Styles.rightButton} >
             <Scene key='berries' initial={authenticated} component={BerriesTabs} hideNavBar />
             <Scene key='login' initial={!authenticated} direction="vertical" panHandlers={null} component={LoginScreen} title='Login' hideNavBar />
          </Scene>
        </Scene>
      </Router>
    )
}

//redux connect
const select = (state: Object) => {
  return {
    isAuthenticated: state.auth.isAuthenticated
  }
}

export default connect(select,null)(NavigationRouter)

Unfortunately, this does't seem to work. Before that, I tried to get Switch to work, which caused the error message can't find variable: Switch.

Best,
D

Most helpful comment

The way I've handled this is by always starting on a custom SplashScreen screen and have it trigger something on componentDidMount

All 2 comments

The way I've handled this is by always starting on a custom SplashScreen screen and have it trigger something on componentDidMount

can I render tabs or scene depending upon user type. i.e. if seller logs in I want to show different set of routes / tabs and if a customer logs in than different set of tabs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sreejithr picture sreejithr  路  3Comments

jgibbons picture jgibbons  路  3Comments

xnog picture xnog  路  3Comments

fgrs picture fgrs  路  3Comments

wootwoot1234 picture wootwoot1234  路  3Comments