Skip to content

Commit 17c910f

Browse files
j-mendezspencercarli
authored andcommitted
drawerLockMode (react-navigation#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
1 parent 2b40182 commit 17c910f

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

docs/api/navigators/DrawerNavigator.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ The route configs object is a mapping from route name to a route config, which t
8787

8888

8989
### DrawerNavigatorConfig
90-
9190
- `drawerWidth` - Width of the drawer
9291
- `drawerPosition` - Options are `left` or `right`. Default is `left` position.
9392
- `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
172171

173172
React Element or a function, that given `{ focused: boolean, tintColor: string }` returns a React.Element, to display in drawer sidebar
174173

174+
#### `drawerLockMode`
175+
176+
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.
177+
175178
### Navigator Props
176179

177180
The navigator component created by `DrawerNavigator(...)` takes the following props:

src/TypeDefinition.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ export type NavigationDrawerScreenOptions = {
359359
| ((options: { tintColor: ?string, focused: boolean }) => ?React.Element<
360360
*
361361
>),
362+
drawerLockMode?: 'unlocked' | 'locked-closed' | 'locked-open',
362363
};
363364

364365
/**

src/navigators/DrawerNavigator.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const DrawerNavigator = (
4343
const {
4444
containerConfig,
4545
drawerWidth,
46+
drawerLockMode,
4647
contentComponent,
4748
contentOptions,
4849
drawerPosition,
@@ -82,6 +83,7 @@ const DrawerNavigator = (
8283
)((props: *) =>
8384
<DrawerView
8485
{...props}
86+
drawerLockMode={drawerLockMode}
8587
useNativeAnimations={useNativeAnimations}
8688
drawerWidth={drawerWidth}
8789
contentComponent={contentComponent}

src/views/Drawer/DrawerView.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export type DrawerItem = {
2929
};
3030

3131
export type DrawerViewConfig = {
32+
drawerLockMode?: 'unlocked' | 'locked-closed' | 'locked-open',
3233
drawerWidth: number,
3334
drawerPosition: 'left' | 'right',
3435
contentComponent: ReactClass<*>,
@@ -138,11 +139,26 @@ export default class DrawerView<T: *> extends PureComponent<void, Props, void> {
138139
const DrawerScreen = this.props.router.getComponentForRouteName(
139140
'DrawerClose'
140141
);
142+
143+
const screenNavigation = addNavigationHelpers({
144+
state: this._screenNavigationProp.state,
145+
dispatch: this._screenNavigationProp.dispatch,
146+
});
147+
148+
const config = this.props.router.getScreenOptions(
149+
screenNavigation,
150+
this.props.screenProps
151+
);
152+
141153
return (
142154
<DrawerLayout
143155
ref={(c: *) => {
144156
this._drawer = c;
145157
}}
158+
drawerLockMode={
159+
(this.props.screenProps && this.props.screenProps.drawerLockMode) ||
160+
(config && config.drawerLockMode)
161+
}
146162
drawerWidth={this.props.drawerWidth}
147163
onDrawerOpen={this._handleDrawerOpen}
148164
onDrawerClose={this._handleDrawerClose}

0 commit comments

Comments
 (0)