Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 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,
drawerGestureLock: true
};

var DRAWER_STATES = [
Expand All @@ -41,8 +42,9 @@ var DRAWER_STATES = [
* Drawer (typically used for navigation) is rendered with `renderNavigationView`
* and direct children are the main view (where your content goes). The navigation
* view is initially not visible on the screen, but can be pulled in from the
* side of the window specified by the `drawerPosition` prop and its width can
* be set by the `drawerWidth` prop.
* side of the window specified by the `drawerPosition` prop, its width can
* be set by the `drawerWidth` prop, and it's locking state can be set by the
* `drawerGestureLock` prop.
*
* Example:
*
Expand All @@ -57,6 +59,7 @@ var DRAWER_STATES = [
* <DrawerLayoutAndroid
* drawerWidth={300}

Choose a reason for hiding this comment

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

no-trailing-spaces: Trailing spaces not allowed.

* drawerPosition={DrawerLayoutAndroid.positions.Left}
* drawerGestureLock={DrawerLayoutAndroid.gestures.Unlocked}
* renderNavigationView={() => navigationView}>
* <View style={{flex: 1, alignItems: 'center'}}>
* <Text style={{margin: 10, fontSize: 15, textAlign: 'right'}}>Hello</Text>
Expand All @@ -70,6 +73,7 @@ var DRAWER_STATES = [
var DrawerLayoutAndroid = React.createClass({
statics: {
positions: DrawerConsts.DrawerPosition,
gestures: DrawerConsts.DrawerGestureLock
},

propTypes: {
Expand All @@ -90,6 +94,17 @@ var DrawerLayoutAndroid = React.createClass({
DrawerConsts.DrawerPosition.Left,
DrawerConsts.DrawerPosition.Right
]),
/**
* Specifies if the drawer gestures would be locked.
* - 'DrawerConsts.DrawerGestureLock.Unlocked' (the default), gestures will be enabled and the drawer will respond to both gestures and drawer commands.
* - 'DrawerConsts.DrawerGestureLock.LockedOpen', the drawer will be locked opened, gestures will be disabled and the drawer respond only to drawer commands.
* - 'DrawerConsts.DrawerGestureLock.LockedClosed', the drawer will be locked closed, gestures will be disabled and the drawer respond only to drawer commands.
*/
drawerGestureLock: ReactPropTypes.oneOf([
DrawerConsts.DrawerGestureLock.Unlocked,
DrawerConsts.DrawerGestureLock.LockedOpen,
DrawerConsts.DrawerGestureLock.LockedClosed
]),
/**
* Specifies the width of the drawer, more precisely the width of the view that be pulled in
* from the edge of the window.
Expand Down Expand Up @@ -142,6 +157,7 @@ var DrawerLayoutAndroid = React.createClass({
ref={RK_DRAWER_REF}
drawerWidth={this.props.drawerWidth}
drawerPosition={this.props.drawerPosition}
drawerGestureLock={this.props.drawerGestureLock}
style={styles.base}
onDrawerSlide={this._onDrawerSlide}
onDrawerOpen={this._onDrawerOpen}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
public static final int DEFAULT_DRAWER_WIDTH = LayoutParams.MATCH_PARENT;
private int mDrawerPosition = Gravity.START;
private int mDrawerWidth = DEFAULT_DRAWER_WIDTH;
private int mDrawerGestureLock = DrawerLayout.LOCK_MODE_UNLOCKED;

public ReactDrawerLayout(ReactContext reactContext) {
super(reactContext);
Expand Down Expand Up @@ -59,6 +60,10 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {
setDrawerProperties();
}

/* package */ void setDrawerGestureLock(int drawerGestureLock) {
mDrawerGestureLock = drawerGestureLock;
}

// Sets the properties of the drawer, after the navigationView has been set.
/* package */ void setDrawerProperties() {
if (this.getChildCount() == 2) {
Expand All @@ -68,6 +73,7 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {
layoutParams.width = mDrawerWidth;
drawerView.setLayoutParams(layoutParams);
drawerView.setClickable(true);
this.setDrawerLockMode(mDrawerGestureLock);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ public void getDrawerWidth(ReactDrawerLayout view, float width) {
view.setDrawerWidth(widthInPx);
}

@ReactProp(name = "drawerGestureLock", defaultInt = DrawerLayout.LOCK_MODE_UNLOCKED)
public void setDrawerGestureLock(ReactDrawerLayout view, int drawerGestureLock) {
view.setDrawerGestureLock(drawerGestureLock);
}

@Override
public boolean needsCustomLayoutForChildren() {
// Return true, since DrawerLayout will lay out it's own children.
Expand Down Expand Up @@ -105,8 +110,11 @@ public void receiveCommand(
@Override
public @Nullable Map getExportedViewConstants() {
return MapBuilder.of(
"DrawerPosition",
MapBuilder.of("Left", Gravity.START, "Right", Gravity.END));
"DrawerPosition",
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Please keep the original indentation of 4 spaces.

MapBuilder.of("Left", Gravity.START, "Right", Gravity.END),
"DrawerGestureLock",
MapBuilder.of("Unlocked", DrawerLayout.LOCK_MODE_UNLOCKED, "LockedOpen", DrawerLayout.LOCK_MODE_LOCKED_OPEN, "LockedClosed", DrawerLayout.LOCK_MODE_LOCKED_CLOSED)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Split this to multiple lines to keep under 100 characters.

);
}

@Override
Expand Down