m00n
m00n

Reputation: 2047

Hide drawer in custom drawer component in React Native

SideMenu is my custom drawer component and it has X button in it.

When I press the X button, I want the drawer to be closed.

How can I do this?

Upvotes: 0

Views: 443

Answers (2)

Taohidul Islam
Taohidul Islam

Reputation: 5414

You can use this.props.navigation.closeDrawer() or this.props.navigation.toggleDrawer() for this.

<Button onPress={()=>this.props.navigation.closeDrawer()} />

or

<Button onPress={()=>this.props.navigation.toggleDrawer()} />

Read this doc

Upvotes: 2

vm909
vm909

Reputation: 581

You want to use toggleDrawer(). Very basic example:

render() {
  const { navigator } = this.props

  return (
    <Button
      onPress={() => navigator.toggleDrawer({ side: 'right', animated: true })} />
  )
}

Upvotes: 0

Related Questions