Skip to content

Commit

Permalink
Add drawerLockMode prop to DrawerLayoutAndroid
Browse files Browse the repository at this point in the history
Summary:Closes #5270.
Closes #5534

Differential Revision: D2970771

fb-gh-sync-id: 36a814032283df7d4c469964f803b8d20d1b0c93
shipit-source-id: 36a814032283df7d4c469964f803b8d20d1b0c93
  • Loading branch information
andreasdri authored and facebook-github-bot-7 committed Feb 24, 2016
1 parent 9ae3714 commit ec173b1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Libraries/Components/DrawerAndroid/DrawerLayoutAndroid.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var INNERVIEW_REF = 'innerView';
var DrawerLayoutValidAttributes = {
drawerWidth: true,
drawerPosition: true,
drawerLockMode: true
};

var DRAWER_STATES = [
Expand Down Expand Up @@ -95,6 +96,18 @@ var DrawerLayoutAndroid = React.createClass({
* from the edge of the window.
*/
drawerWidth: ReactPropTypes.number,
/**
* Specifies the lock mode of the drawer. The drawer can be locked in 3 states:
* - unlocked (default), meaning that the drawer will respond (open/close) to touch gestures.
* - locked closed, meaning that the drawer will stay closed and not respond to gestures.
* - locked open, meaning that the drawer will stay opened and not respond to gestures.
* The drawer may still be opened and closed programmatically (`openDrawer`/`closeDrawer`).
*/
drawerLockMode: ReactPropTypes.oneOf([
'unlocked',
'locked-closed',
'locked-open'
]),
/**
* Function called whenever there is an interaction with the navigation view.
*/
Expand Down Expand Up @@ -142,6 +155,7 @@ var DrawerLayoutAndroid = React.createClass({
ref={RK_DRAWER_REF}
drawerWidth={this.props.drawerWidth}
drawerPosition={this.props.drawerPosition}
drawerLockMode={this.props.drawerLockMode}
style={styles.base}
onDrawerSlide={this._onDrawerSlide}
onDrawerOpen={this._onDrawerOpen}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,19 @@ public void getDrawerWidth(ReactDrawerLayout view, float width) {
view.setDrawerWidth(widthInPx);
}

@ReactProp(name = "drawerLockMode")
public void setDrawerLockMode(ReactDrawerLayout view, @Nullable String drawerLockMode) {
if (drawerLockMode == null || "unlocked".equals(drawerLockMode)) {
view.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
} else if ("locked-closed".equals(drawerLockMode)) {
view.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
} else if ("locked-open".equals(drawerLockMode)) {
view.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_OPEN);
} else {
throw new JSApplicationIllegalArgumentException("Unknown drawerLockMode " + drawerLockMode);
}
}

@Override
public boolean needsCustomLayoutForChildren() {
// Return true, since DrawerLayout will lay out it's own children.
Expand Down

3 comments on commit ec173b1

@sachinbiradar9
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andybb this doesn't work in react-native@0.22.0. Did some one check it? i tried it in following manner. Am i missing something?

< DrawerLayoutAndroid
drawerLockMode = {'locked-closed'}
drawerWidth={R.constants.drawerMenu.width}
drawerPosition={DrawerLayoutAndroid.positions.Left}
ref={'drawer'}
renderNavigationView={() => navigationView}>
{this.props.children}
</ DrawerLayoutAndroid >

@djalmajr
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

drawerLockMode="locked-closed" Doesn't work for me too. :/

@andreasdri
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@009dollar @djalmajr I'll take a look at it tonight.

Please sign in to comment.