3

I'm using a tab navigator and drawer navigator in a react native app. I need to have the drawer navigator open when one of the tabs is pressed. For example, the last tab named 'account' should open up the drawer.

// drawer navigation
const AppDrawerNavigator = createDrawerNavigator({
  Account: AccountScreen,
});

// tab navigation
const AppTabNavigator = createBottomTabNavigator({
  Home: {
    screen: HomeScreen,
  },
  Account: {
    screen: AppDrawerNavigator,
  }
});

With my code right now, the app is simply navigating to the account screen when the account tab is pressed, instead of opening up the drawer. Is there a way to do this?

awebdev
  • 997
  • 2
  • 10
  • 27

1 Answers1

0

I found my answer on this question > React Native - Accessing drawer navigation outside of AppNavigator

I created a NavigationService and added the following to the service.

function openDrawer(routeName, params) {
  _navigator.dispatch(DrawerActions.openDrawer());
}
awebdev
  • 997
  • 2
  • 10
  • 27
  • 1
    Hey. Do you have a full code example of that? Because I am struggling with this as well, and not sure where to call this method in the navigator. – RadioLog Mar 17 '20 at 10:35
  • I down voted because I'm also trying to do this, but the answer doesn't provide any further guidance on where or how to use the service – Paulo Madroñero Jul 19 '20 at 23:44
  • @PauloMadroñero This should help https://reactnavigation.org/docs/navigating-without-navigation-prop/ – awebdev Jul 21 '20 at 16:07