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-19482] Support arrays passed to Ti.UI.View.add() #8452

Merged
merged 2 commits into from
Sep 29, 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 @@ -99,12 +99,12 @@ public void handleCreationDict(KrollDict dict) {
}

@Override
public void add(TiViewProxy o)
public void add(Object args)
{
if (TiApplication.isUIThread()) {
handleAddRow(o);
handleAddRow((TiViewProxy) args);
} else {
TiMessenger.sendBlockingMainMessage(getMainHandler().obtainMessage(MSG_ADD), o);
TiMessenger.sendBlockingMainMessage(getMainHandler().obtainMessage(MSG_ADD), args);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,14 +221,6 @@ private void handleRemoveColumn(TiViewProxy child)
}

@Override
public void add(TiViewProxy child)
{
this.add((Object)child);
}

// We need a special add() method above and beyond the TiViewProxy add() because
// because we can also accept array of PickerRowProxys
@Kroll.method
public void add(Object child)
{
if (!isPlainPicker()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void setRowListener(PickerRowListener listener)
}

@Override
public void add(TiViewProxy child)
public void add(Object args)
{
Log.w(TAG, "PickerRow does not support child controls");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -551,34 +551,43 @@ public void releaseViews()

/**
* Adds a child to this view proxy.
* @param child The child view proxy to add.
* @param args The child view proxy/proxies to add.
* @module.api
*/
@Kroll.method
public void add(TiViewProxy child)
public void add(Object args)
{
if (child == null) {
if (args == null) {
Log.e(TAG, "Add called with a null child");
return;
}

if (children == null) {
children = new ArrayList<TiViewProxy>();
}

if (peekView() != null) {
if (TiApplication.isUIThread()) {
handleAdd(child);
return;
if (args instanceof Object[]) {
for (Object arg : (Object[]) args) {
if (arg instanceof TiViewProxy) {
add((TiViewProxy) arg);
} else {
Log.w(TAG, "add() unsupported array object: " + arg.getClass().getSimpleName());
}
}

TiMessenger.sendBlockingMainMessage(getMainHandler().obtainMessage(MSG_ADD_CHILD), child);

} else if (args instanceof TiViewProxy) {
TiViewProxy child = (TiViewProxy) args;
if (peekView() != null) {
if (TiApplication.isUIThread()) {
handleAdd(child);
return;
}
TiMessenger.sendBlockingMainMessage(getMainHandler().obtainMessage(MSG_ADD_CHILD), child);
} else {
children.add(child);
child.parent = new WeakReference<TiViewProxy>(this);
}
//TODO zOrder
} else {
children.add(child);
child.parent = new WeakReference<TiViewProxy>(this);
Log.w(TAG, "add() unsupported argument type: " + args.getClass().getSimpleName());
}
//TODO zOrder
}

@Kroll.method
Expand Down
2 changes: 1 addition & 1 deletion apidoc/Titanium/UI/View.yml
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ methods:
summary: |
View to add to this view's hierarchy.

On the iOS and Windows platforms, you may pass an array of views.
You may pass an array of views, e.g. `view.add([subview1, subview2]`.
type: [Titanium.UI.View, Array<Titanium.UI.View>]

- name: animate
Expand Down