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

[TIMOB-23974] Android: Add property to release space when hiding an object #8458

Merged
merged 3 commits into from
Oct 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ public class UIModule extends KrollModule implements Handler.Callback
@Kroll.constant public static final int INPUT_TYPE_CLASS_NUMBER = InputType.TYPE_CLASS_NUMBER;
@Kroll.constant public static final int INPUT_TYPE_CLASS_TEXT = InputType.TYPE_CLASS_TEXT;

@Kroll.constant public static final int HIDDEN_BEHAVIOR_GONE = View.GONE;
@Kroll.constant public static final int HIDDEN_BEHAVIOR_INVISIBLE = View.INVISIBLE;

protected static final int MSG_SET_BACKGROUND_COLOR = KrollProxy.MSG_LAST_ID + 100;
protected static final int MSG_SET_BACKGROUND_IMAGE = KrollProxy.MSG_LAST_ID + 101;
protected static final int MSG_LAST_ID = MSG_SET_BACKGROUND_IMAGE;
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 @@ -1444,6 +1444,11 @@ public class TiC
*/
public static final String PROPERTY_FRAGMENT_ONLY = "fragmentOnly";

/**
* @module.api
*/
public static final String PROPERTY_HIDDEN_BEHAVIOR = "hiddenBehavior";

/**
* @module.api
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@
"softKeyboardOnFocus", "transform", "elevation", "touchTestId",
"translationX", "translationY", "translationZ", "rotation", "rotationX", "rotationY", "scaleX", "scaleY",

TiC.PROPERTY_TOUCH_FEEDBACK, TiC.PROPERTY_TOUCH_FEEDBACK_COLOR, TiC.PROPERTY_TRANSITION_NAME
TiC.PROPERTY_TOUCH_FEEDBACK, TiC.PROPERTY_TOUCH_FEEDBACK_COLOR, TiC.PROPERTY_TRANSITION_NAME,
TiC.PROPERTY_HIDDEN_BEHAVIOR
})
public abstract class TiViewProxy extends KrollProxy implements Handler.Callback
{
Expand Down Expand Up @@ -118,6 +119,7 @@ public TiViewProxy()
defaultValues.put(TiC.PROPERTY_BACKGROUND_REPEAT, false);
defaultValues.put(TiC.PROPERTY_VISIBLE, true);
defaultValues.put(TiC.PROPERTY_ENABLED, true);
defaultValues.put(TiC.PROPERTY_HIDDEN_BEHAVIOR, View.INVISIBLE);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ public abstract class TiUIView

//to maintain sync visibility between borderview and view. Default is visible
private int visibility = View.VISIBLE;
private int hiddenBehavior = View.INVISIBLE;

protected GestureDetector detector = null;

Expand Down Expand Up @@ -941,6 +942,8 @@ public void propertyChanged(String key, Object oldValue, Object newValue, KrollP
if (getOuterView() != null) {
ViewCompat.setRotationY(getOuterView(), TiConvert.toFloat(newValue));
}
} else if (key.equals(TiC.PROPERTY_HIDDEN_BEHAVIOR)) {
hiddenBehavior = TiConvert.toInt(newValue, View.INVISIBLE);
} else if (Log.isDebugModeEnabled()) {
Log.d(TAG, "Unhandled property key: " + key, Log.DEBUG_MODE);
}
Expand Down Expand Up @@ -997,6 +1000,14 @@ public void processProperties(KrollDict d)
}
}

if (d.containsKey(TiC.PROPERTY_HIDDEN_BEHAVIOR) && !nativeViewNull) {
Object hidden = d.get(TiC.PROPERTY_HIDDEN_BEHAVIOR);
if (hidden != null){
hiddenBehavior = TiConvert.toInt(hidden, View.INVISIBLE);
} else {
hiddenBehavior = View.INVISIBLE;
}
}
if (d.containsKey(TiC.PROPERTY_VISIBLE) && !nativeViewNull) {
Object visible = d.get(TiC.PROPERTY_VISIBLE);
if (visible != null) {
Expand Down Expand Up @@ -1229,6 +1240,9 @@ public void release()

private void setVisibility(int visibility)
{
if (visibility == View.INVISIBLE) {
visibility = hiddenBehavior;
}
this.visibility = visibility;
if (borderView != null) {
borderView.setVisibility(this.visibility);
Expand Down
14 changes: 14 additions & 0 deletions apidoc/Titanium/UI/UI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1428,6 +1428,20 @@ properties:
permission: read-only
since: "2.0.0"

- name: HIDDEN_BEHAVIOR_GONE
summary: Release free space when hiding an object.
type: Number
platforms: [android]
since: "6.1.0"
permission: read-only

- name: HIDDEN_BEHAVIOR_INVISIBLE
summary: Keeps free space when hiding an object.
type: Number
platforms: [android]
since: "6.1.0"
permission: read-only

- name: INHERIT
summary: INHERIT behavior for UI layout.
description: |
Expand Down
15 changes: 15 additions & 0 deletions apidoc/Titanium/UI/View.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1317,6 +1317,21 @@ properties:
constants: [Titanium.UI.FILL, Titanium.UI.SIZE]
type: [Number,String]

- name: hiddenBahavior
summary: Sets the behavior when hiding an object to release or keep the free space
description: |
If setting `hiddenBahavior` to <Titanium.UI.HIDDEN_BEHAVIOR_GONE> it will automatically release the space the view occupied.
For example: in a vertical layout the views below the object will move up when you hide
an object with `hiddenBahavior:Titanium.UI.HIDDEN_BEHAVIOR_GONE`.

* <Titanium.UI.HIDDEN_BEHAVIOR_INVISIBLE>. Keeps the space and just hides the object (default).
* <Titanium.UI.HIDDEN_BEHAVIOR_GONE>. Releases the space and hides the object.
type: Number
constants: [Titanium.UI.HIDDEN_BEHAVIOR_INVISIBLE, Titanium.UI.HIDDEN_BEHAVIOR_GONE]
default: Titanium.UI.HIDDEN_BEHAVIOR_INVISIBLE
platforms: [android]
since: 6.1.0

- name: left
summary: View's left position, in platform-specific units.
description: |
Expand Down