Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

navigate('DrawerOpen') not working with createSwitchNavigator and createStackNavigator

Please check this expo snack.

I have a switch-navigator for logged-in and not-logged-in states.

When user is logged in, switcher loads a DrawerNavigator which loads Screen1 and loads the sidebar (SideBar.js) via contentComponent

Inside Screen1 I'm calling the this.props.navigation.navigate('DrawerOpen'); via the onPress event of the menu burger button. But it's not opening the drawer. What am I doing wroing

like image 251
Junaid Qadir Shekhanzai Avatar asked Nov 29 '22 13:11

Junaid Qadir Shekhanzai


1 Answers

You call in a screen which isn't contained in DrawerNavigation, so it can't navigate. To open drawer in anywhere just use

import { DrawerActions } from 'react-navigation';
...
openDrawer = () => {
  this.props.navigation.dispatch(DrawerActions.openDrawer());
}
...
like image 132
tuan.tran Avatar answered Dec 09 '22 17:12

tuan.tran