From 17c910fb5d69e02ef4015dfbf6a83d07019f4d03 Mon Sep 17 00:00:00 2001 From: Jeff Mendez Date: Thu, 21 Sep 2017 13:53:46 -0400 Subject: [PATCH] drawerLockMode (#1377) * added drawerLockMode with cabilities to update it on the fly * fixed incorrect name on markdown for usage * added handling if screenProps is not being used * Fix linting error * Use drawerLockMode instead of lockMode * Correct docs * Fix flow issues * Make drawerLockMode optional --- docs/api/navigators/DrawerNavigator.md | 5 ++++- src/TypeDefinition.js | 1 + src/navigators/DrawerNavigator.js | 2 ++ src/views/Drawer/DrawerView.js | 16 ++++++++++++++++ 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/docs/api/navigators/DrawerNavigator.md b/docs/api/navigators/DrawerNavigator.md index 868f9c55..ddc3a7fe 100644 --- a/docs/api/navigators/DrawerNavigator.md +++ b/docs/api/navigators/DrawerNavigator.md @@ -87,7 +87,6 @@ The route configs object is a mapping from route name to a route config, which t ### DrawerNavigatorConfig - - `drawerWidth` - Width of the drawer - `drawerPosition` - Options are `left` or `right`. Default is `left` position. - `contentComponent` - Component used to render the content of the drawer, for example, navigation items. Receives the `navigation` prop for the drawer. Defaults to `DrawerItems`. For more information, see below. @@ -172,6 +171,10 @@ String, React Element or a function that given `{ focused: boolean, tintColor: s React Element or a function, that given `{ focused: boolean, tintColor: string }` returns a React.Element, to display in drawer sidebar +#### `drawerLockMode` + +Specifies the [lock mode](https://facebook.github.io/react-native/docs/drawerlayoutandroid.html#drawerlockmode) of the drawer. This can also update dynamically by using screenProps.lockMode on your top level router. + ### Navigator Props The navigator component created by `DrawerNavigator(...)` takes the following props: diff --git a/src/TypeDefinition.js b/src/TypeDefinition.js index 85b7aebd..e40bec3e 100644 --- a/src/TypeDefinition.js +++ b/src/TypeDefinition.js @@ -359,6 +359,7 @@ export type NavigationDrawerScreenOptions = { | ((options: { tintColor: ?string, focused: boolean }) => ?React.Element< * >), + drawerLockMode?: 'unlocked' | 'locked-closed' | 'locked-open', }; /** diff --git a/src/navigators/DrawerNavigator.js b/src/navigators/DrawerNavigator.js index dcd718d2..a1d21b00 100644 --- a/src/navigators/DrawerNavigator.js +++ b/src/navigators/DrawerNavigator.js @@ -43,6 +43,7 @@ const DrawerNavigator = ( const { containerConfig, drawerWidth, + drawerLockMode, contentComponent, contentOptions, drawerPosition, @@ -82,6 +83,7 @@ const DrawerNavigator = ( )((props: *) => , @@ -138,11 +139,26 @@ export default class DrawerView extends PureComponent { const DrawerScreen = this.props.router.getComponentForRouteName( 'DrawerClose' ); + + const screenNavigation = addNavigationHelpers({ + state: this._screenNavigationProp.state, + dispatch: this._screenNavigationProp.dispatch, + }); + + const config = this.props.router.getScreenOptions( + screenNavigation, + this.props.screenProps + ); + return ( { this._drawer = c; }} + drawerLockMode={ + (this.props.screenProps && this.props.screenProps.drawerLockMode) || + (config && config.drawerLockMode) + } drawerWidth={this.props.drawerWidth} onDrawerOpen={this._handleDrawerOpen} onDrawerClose={this._handleDrawerClose}