EsiS
EsiS

Reputation: 23

Can't toggle drawer in stack navigator from custom header

I have StackNavigator component with a custom header for DrawerNavigator. The custom header has a button that should toggle Drawer on press. I have added the action as provided in React Navigation docs but doesn't work.

A snack with issue can be found here

What am I doing wrong? Thank you.

Upvotes: 2

Views: 1189

Answers (1)

igorves
igorves

Reputation: 591

You can import: import { DrawerActions } from 'react-navigation';

And then just use it inside Header:

const Header = (props) => {
 return (
    <View style={{marginTop: 25}}>
      <Button
        onPress={() => props.navigation.dispatch(DrawerActions.toggleDrawer())}
        title="Toggle"
        color="#841584" />
    </View>)
}

Upvotes: 5

Related Questions