0

I built my navigation based on Ex-navigation's example

Everything is working as expected, but I don't know how to Sign out

I have a <Main/> component which renders a <DrawerNavigationMenu/> as in the example .This is my <DrawerNavigationMenu/>

render() {
return (
  <DrawerNavigation
    renderHeader={this._renderHeader}
    drawerWidth={300}
    initialItem="home">
    <DrawerNavigationItem
      id="home"
      selectedStyle={styles.selectedItemStyle}
      renderTitle={isSelected => this._renderTitle('Home', isSelected)}
      renderIcon={isSelected => this._renderIcon('md-home', isSelected)}>
      <StackNavigation
        id="home"
        defaultRouteConfig={{
          navigationBar: {
            backgroundColor: '#2497b7',
            tintColor: '#fff',
            height: 60,
          },
        }}
        initialRoute={Router.getRoute('home')}/>
    </DrawerNavigationItem>

    <DrawerNavigationItem
      id="logout"
      selectedStyle={styles.selectedItemStyle}
      renderTitle={isSelected => this._renderTitle('Logout', isSelected)}
      renderIcon={isSelected => this._renderIcon('md-exit', isSelected)}>
      <StackNavigation
        id="root"
        initialRoute={Router.getRoute('root')}/>
    </DrawerNavigationItem>
  </DrawerNavigation>
);
}

In the "logout" item I need to reset the navigation stack and render my Root scene without the chance of going back

I tried using initialStack= instead of initialRoute=, like this

<StackNavigation
 id="root"
 initialStack={[Router.getRoute('root')]}/>

But when I hit (Android)back, it still going back to Home scene. I'm not using Redux explicitly here. Is this the right way to implement a sign out navigation? Any ideas? Please!

1 Answers1

1

Give DrawernavigationItem props onPress and call a function that switches between Authentication and Landing pages.

<DrawerNavigationItem
     id="Sign out"
     selectedStyle={styles.selectedItemStyle}
     onPress={()=>{this.signOut()}}
     renderTitle={isSelected => this._renderTitle('Sign out', isSelected)}
   />
A-J-A
  • 2,344
  • 1
  • 17
  • 26