Add support for setChildren

Summary: This adds support for UIManager.setChildren on Android like D2757388 added for iOS.

Reviewed By: andreicoman11

Differential Revision: D3235369

fb-gh-sync-id: b538556ec4abdb606f9be26d1b74734046bca0cd
fbshipit-source-id: b538556ec4abdb606f9be26d1b74734046bca0cd
This commit is contained in:
Dave Miller
2016-04-29 04:03:24 -07:00
committed by Facebook Github Bot 1
parent 3f0207d7b5
commit 3a5457cd7c
6 changed files with 136 additions and 29 deletions
@@ -388,6 +388,51 @@ public class NativeViewHierarchyManager {
}
}
/**
* Simplified version of constructManageChildrenErrorMessage that only deals with adding children
* views
*/
private static String constructSetChildrenErrorMessage(
ViewGroup viewToManage,
ViewGroupManager viewManager,
ReadableArray childrenTags) {
ViewAtIndex[] viewsToAdd = new ViewAtIndex[childrenTags.size()];
for (int i = 0; i < childrenTags.size(); i++) {
viewsToAdd[i] = new ViewAtIndex(childrenTags.getInt(i), i);
}
return constructManageChildrenErrorMessage(
viewToManage,
viewManager,
null,
viewsToAdd,
null
);
}
/**
* Simplified version of manageChildren that only deals with adding children views
*/
public void setChildren(
int tag,
ReadableArray childrenTags) {
ViewGroup viewToManage = (ViewGroup) mTagsToViews.get(tag);
ViewGroupManager viewManager = (ViewGroupManager) resolveViewManager(tag);
for (int i = 0; i < childrenTags.size(); i++) {
View viewToAdd = mTagsToViews.get(childrenTags.getInt(i));
if (viewToAdd == null) {
throw new IllegalViewOperationException(
"Trying to add unknown view tag: "
+ childrenTags.getInt(i) + "\n detail: " +
constructSetChildrenErrorMessage(
viewToManage,
viewManager,
childrenTags));
}
viewManager.addView(viewToManage, viewToAdd, i);
}
}
/**
* See {@link UIManagerModule#addMeasuredRootView}.
*