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 2 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 VIEW_GONE = View.GONE;
@Kroll.constant public static final int VIEW_INVISIBLE = View.INVISIBLE;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Thinking about it, we might want to rename them to Ti.UI.HIDDEN_BEHAVIOR_GONE and Ti.UI.HIDDEN_BEHAVIOR_INVISIBLE. What do you think? And please add + validate the docs for the constants, they are not documented, yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, changed the property and updated the constants inside the doc! HIDDEN_BEHAVIOR_INVISIBLE is fine, too. So its more connected to the property name


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_BEHAVIOUR = "hiddenBehaviour";

/**
* @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_BEHAVIOUR
})
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_BEHAVIOUR, 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_BEHAVIOUR)) {
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_BEHAVIOUR) && !nativeViewNull) {
Object hidden = d.get(TiC.PROPERTY_HIDDEN_BEHAVIOUR);
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
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.VIEW_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.VIEW_GONE`.

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

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