Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(android): allow ability to set drawer gravity #10970

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@
import ti.modules.titanium.ui.widget.TiUIDrawerLayout;

import org.appcelerator.kroll.annotations.Kroll;
import org.appcelerator.kroll.common.Log;
import org.appcelerator.kroll.KrollProxy;
import org.appcelerator.titanium.proxy.TiViewProxy;
import org.appcelerator.titanium.TiC;
import org.appcelerator.titanium.util.TiConvert;
import org.appcelerator.titanium.view.TiUIView;

import android.app.Activity;
import android.support.v4.widget.DrawerLayout;
import android.view.Gravity;

@Kroll.proxy(creatableInModule = AndroidModule.class)
public class DrawerLayoutProxy extends TiViewProxy
Expand All @@ -30,6 +28,12 @@ public class DrawerLayoutProxy extends TiViewProxy
public static final int LOCK_MODE_UNLOCKED = DrawerLayout.LOCK_MODE_UNLOCKED;
@Kroll.constant
public static final int LOCK_MODE_UNDEFINED = DrawerLayout.LOCK_MODE_UNDEFINED;
@Kroll.constant
public static final int GRAVITY_NONE = Gravity.NO_GRAVITY;
@Kroll.constant
public static final int GRAVITY_LEFT = Gravity.LEFT;
@Kroll.constant
public static final int GRAVITY_RIGHT = Gravity.RIGHT;

private static final String TAG = "DrawerLayoutProxy";

Expand Down Expand Up @@ -220,6 +224,27 @@ public void setDrawerLockMode(Object arg)
setPropertyAndFire(TiC.PROPERTY_DRAWER_LOCK_MODE, arg);
}

// clang-format off
@Kroll.method
@Kroll.getProperty
public int getDrawerGravity()
// clang-format on
{
if (hasProperty(TiC.PROPERTY_DRAWER_GRAVITY)) {
return (Integer) getProperty(TiC.PROPERTY_DRAWER_GRAVITY);
}
return Gravity.NO_GRAVITY;
}

// clang-format off
@Kroll.method
@Kroll.setProperty
public void setDrawerGravity(Object arg)
// clang-format on
{
setPropertyAndFire(TiC.PROPERTY_DRAWER_GRAVITY, arg);
}

@Kroll.method
public void interceptTouchEvent(TiViewProxy view, Boolean disallowIntercept)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,16 @@ public void processProperties(KrollDict d)
rightFrame.getLayoutParams().width = LayoutParams.MATCH_PARENT;
}
}
if (d.containsKey(TiC.PROPERTY_DRAWER_LOCK_MODE)) {
layout.setDrawerLockMode(TiConvert.toInt(d.get(TiC.PROPERTY_DRAWER_LOCK_MODE)));
if (d.containsKey(TiC.PROPERTY_DRAWER_LOCK_MODE) || d.containsKey(TiC.PROPERTY_DRAWER_GRAVITY)) {
int lockMode = TiConvert.toInt(d.get(TiC.PROPERTY_DRAWER_LOCK_MODE),
((DrawerLayoutProxy) getProxy()).getDrawerLockMode());
int gravity = TiConvert.toInt(d.get(TiC.PROPERTY_DRAWER_GRAVITY),
((DrawerLayoutProxy) getProxy()).getDrawerGravity());
if (gravity != Gravity.NO_GRAVITY) {
layout.setDrawerLockMode(lockMode, gravity);
} else {
layout.setDrawerLockMode(lockMode);
}
}
// If theme has default ActionBar ignore `toolbarEnabled` and `toolbar` properties
if (!this.themeHasActionBar) {
Expand Down Expand Up @@ -536,7 +544,15 @@ public void propertyChanged(String key, Object oldValue, Object newValue, KrollP
this.rightFrame.setLayoutParams(rightFrameLayout);

} else if (key.equals(TiC.PROPERTY_DRAWER_LOCK_MODE)) {
layout.setDrawerLockMode(TiConvert.toInt(newValue));
int gravity = ((DrawerLayoutProxy) getProxy()).getDrawerGravity();
if (gravity != Gravity.NO_GRAVITY) {
layout.setDrawerLockMode(TiConvert.toInt(newValue), gravity);
} else {
layout.setDrawerLockMode(TiConvert.toInt(newValue));
}

} else if (key.equals(TiC.PROPERTY_DRAWER_GRAVITY)) {
layout.setDrawerLockMode(((DrawerLayoutProxy) getProxy()).getDrawerLockMode(), TiConvert.toInt(newValue));

} else if (key.equals(TiC.PROPERTY_DRAWER_INDICATOR_ENABLED)) {
if (drawerToggle != null) {
Expand Down
5 changes: 5 additions & 0 deletions android/titanium/src/java/org/appcelerator/titanium/TiC.java
Original file line number Diff line number Diff line change
Expand Up @@ -1548,6 +1548,11 @@ public class TiC
*/
public static final String PROPERTY_DRAG_MARGIN = "dragMargin";

/**
* @module.api
*/
public static final String PROPERTY_DRAWER_GRAVITY = "drawerGravity";

/**
* @module.api
*/
Expand Down
28 changes: 28 additions & 0 deletions apidoc/Titanium/UI/Android/DrawerLayout.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,27 @@ since: "6.2.0"
platforms: [android]

properties:
- name: GRAVITY_NONE
summary: |
Use with [DrawerLayout.drawerLockMode](Titanium.UI.Android.DrawerLayout.drawerGravity) to specify the gravity.
type: Number
permission: read-only
since: "8.3.0"

- name: GRAVITY_LEFT
summary: |
Use with [DrawerLayout.drawerLockMode](Titanium.UI.Android.DrawerLayout.drawerGravity) to specify the gravity.
type: Number
permission: read-only
since: "8.3.0"

- name: GRAVITY_RIGHT
summary: |
Use with [DrawerLayout.drawerLockMode](Titanium.UI.Android.DrawerLayout.drawerGravity) to specify the gravity.
type: Number
permission: read-only
since: "8.3.0"

- name: LOCK_MODE_LOCKED_CLOSED
summary: |
Use with [DrawerLayout.drawerLockMode](Titanium.UI.Android.DrawerLayout.drawerLockMode) to specify the drawer is locked closed.
Expand Down Expand Up @@ -91,6 +112,13 @@ properties:
constants: Titanium.UI.Android.DrawerLayout.LOCK_MODE_*
default: <Titanium.UI.Android.DrawerLayout.LOCK_MODE_UNDEFINED>

- name: drawerGravity
summary: Get or set the drawerGravity
type: Number
constants: Titanium.UI.Android.DrawerLayout.GRAVITY_*
default: <Titanium.UI.Android.DrawerLayout.GRAVITY_BOTH>
since: "8.3.0"

- name: toolbarEnabled
summary: Determine whether to enable the toolbar.
description: |
Expand Down