From 6404529b7611d24e1db25100501cd771c3e12a0f Mon Sep 17 00:00:00 2001 From: "Andrew Chen (Eng)" Date: Thu, 1 Mar 2018 16:51:48 -0800 Subject: [PATCH] Added an Assertion that addRoot is called before completeRoot Reviewed By: mdvacca Differential Revision: D7127321 fbshipit-source-id: a8215fda0d854471bed9aa5476141dfffc4dc11c --- .../react/fabric/FabricUIManagerModule.java | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManagerModule.java b/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManagerModule.java index 26eb5ad5bd3..28692254138 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManagerModule.java +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManagerModule.java @@ -180,7 +180,7 @@ public class FabricUIManagerModule implements UIManager { public void appendChild(ReactShadowNode parent, ReactShadowNode child) { try { parent.addChildAt(child, parent.getChildCount()); - setChildren(parent.getReactTag(), child.getReactTag()); + addChild(parent.getReactTag(), child.getReactTag()); } catch (Exception e) { handleException(parent.getThemedContext(), e); } @@ -203,25 +203,26 @@ public class FabricUIManagerModule implements UIManager { public void completeRoot(int rootTag, List childList) { try { - if (!childList.isEmpty()) { - ReactShadowNode rootNode = getRootNode(rootTag); - for (int i = 0; i < childList.size(); i++) { - ReactShadowNode child = childList.get(i); - rootNode.addChildAt(child, i); - setChildren(rootTag, child.getReactTag()); - } - - calculateRootLayout(rootNode); - applyUpdatesRecursive(rootNode, 0, 0); - mUIViewOperationQueue - .dispatchViewUpdates(1, System.currentTimeMillis(), System.currentTimeMillis()); + ReactShadowNode rootNode = getRootNode(rootTag); + Assertions.assertNotNull( + rootNode, + "Root view with tag " + rootTag + " must be added before completeRoot is called"); + for (int i = 0; i < childList.size(); i++) { + ReactShadowNode child = childList.get(i); + rootNode.addChildAt(child, i); + addChild(rootTag, child.getReactTag()); } + + calculateRootLayout(rootNode); + applyUpdatesRecursive(rootNode, 0, 0); + mUIViewOperationQueue + .dispatchViewUpdates(1, System.currentTimeMillis(), System.currentTimeMillis()); } catch (Exception e) { handleException(rootTag, e); } } - private void setChildren(int parent, int child) { + private void addChild(int parent, int child) { JavaOnlyArray childrenTags = new JavaOnlyArray(); childrenTags.pushInt(child); mUIViewOperationQueue.enqueueSetChildren(