Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

react native drawer toggle is not working

The drawerNavigator is in the stackNavigator.

I set the header to none, and I want to make the header part work when I press the button.

I wrote the following code.

this.props.navigation.dispatch(DrawerActions.toggleDrawer());

No error occurs. But it does not do anything.

The navigator code looks like this:

navigator.js

const MainScene = createStackNavigator({
 MainTab: {screen: MainTab},
 OtherScene: {screen: OtherScene}
},{...})

const OtherScene: createStackNavigator({
 DrawerScene: {screen: DrawerScene}
},{...})

const DrawerScene = createDrawerNavigator({
 Page1: {screen: Page1},
 Page2: {screen: Page2},
},{...})

Header.js

_sideMenu() {
 this.props.navigation.dispatch(DrawerActions.toggleDrawer());
}

render() {
  return (
   ...
   <TouchableOpacity 
    onPress={() => this._sideMenu()}>
    <Image ... />
   </TouchableOpacity>
   ...
  )
 }

Both page1 and page2 contain directly written headers.

Page1.js

render() {
 return(
  <View>
   <Header navigation={this.props.navigation} />
   ...
  </View>
 )
}
like image 344
Backkom Avatar asked Sep 03 '18 02:09

Backkom


1 Answers

try this import { DrawerActions } from "react-navigation";

this.props.navigation.dispatch(DrawerActions.openDrawer());

this.props.navigation.dispatch(DrawerActions.closeDrawer());

like image 81
Barcode HJ Avatar answered Dec 03 '22 08:12

Barcode HJ