Feature/toggle (#2492)

* add toggle functionality

* add documentation
This commit is contained in:
Gant Laborde 2017-08-29 21:55:33 -05:00 committed by Spencer Carli
parent aa92bcb0dd
commit 8fdfc6d7a6
3 changed files with 17 additions and 2 deletions

View File

@ -68,6 +68,12 @@ To open and close drawer, navigate to `'DrawerOpen'` and `'DrawerClose'` respect
this.props.navigation.navigate('DrawerOpen'); // open drawer
this.props.navigation.navigate('DrawerClose'); // close drawer
```
If you would like to toggle the drawer you can navigate to `'DrawerToggle'`, and this will choose which navigation is appropriate for you given the drawers current state.
```js
// fires 'DrawerOpen'/'DrawerClose' accordingly
this.props.navigation.navigate('DrawerToggle');
```
## API Definition
@ -181,7 +187,7 @@ The navigator component created by `DrawerNavigator(...)` takes the following pr
screenProps={/* this prop will get passed to the screen components and nav options as props.screenProps */}
/>
```
### Nesting `DrawerNavigation`
Please bear in mind that if you nest the DrawerNavigation, the drawer will show below the parent navigation.

View File

@ -63,6 +63,9 @@ const DrawerNavigator = (
DrawerOpen: {
screen: () => null,
},
DrawerToggle: {
screen: () => null,
},
},
{
initialRouteName: 'DrawerClose',

View File

@ -63,6 +63,12 @@ export default class DrawerView<T: *> extends PureComponent<void, Props, void> {
const { routes, index } = nextProps.navigation.state;
if (routes[index].routeName === 'DrawerOpen') {
this._drawer.openDrawer();
} else if (routes[index].routeName === 'DrawerToggle') {
if (this._drawer.state.drawerShown) {
this.props.navigation.navigate('DrawerClose');
} else {
this.props.navigation.navigate('DrawerOpen');
}
} else {
this._drawer.closeDrawer();
}