From 45abbf36d67fb50ddf5f74f8d7912a35bf7c1dad Mon Sep 17 00:00:00 2001 From: David Vacca Date: Tue, 27 Mar 2018 10:44:15 -0700 Subject: [PATCH] Support multiple Fabric ReactRootView running at the same time Reviewed By: achen1 Differential Revision: D7409472 fbshipit-source-id: 9525e610f3bce49cae8d3c5e4427f99a48c32091 --- .../react/fabric/FabricUIManager.java | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java b/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java index 81a604350..47359b44f 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java @@ -50,7 +50,6 @@ public class FabricUIManager implements UIManager { private final ViewManagerRegistry mViewManagerRegistry; private final UIViewOperationQueue mUIViewOperationQueue; private volatile int mCurrentBatch = 0; - private ReactShadowNode mCurrentRootShadowNode; private FabricReconciler mFabricReconciler; public FabricUIManager( @@ -246,32 +245,32 @@ public class FabricUIManager implements UIManager { Log.d(TAG, "completeRoot rootTag: " + rootTag + ", childList: " + childList); } try { - ReactShadowNode rootNode = getRootNode(rootTag); + ReactShadowNode currentRootShadowNode = getRootNode(rootTag); Assertions.assertNotNull( - rootNode, + currentRootShadowNode, "Root view with tag " + rootTag + " must be added before completeRoot is called"); - rootNode = calculateDiffingAndCreateNewRootNode(rootNode, childList); + currentRootShadowNode = calculateDiffingAndCreateNewRootNode(currentRootShadowNode, childList); if (DEBUG) { - Log.d(TAG, "ReactShadowNodeHierarchy after diffing: " + rootNode.getHierarchyInfo()); + Log.d(TAG, "ReactShadowNodeHierarchy after diffing: " + currentRootShadowNode.getHierarchyInfo()); } - notifyOnBeforeLayoutRecursive(rootNode); - rootNode.calculateLayout(); + notifyOnBeforeLayoutRecursive(currentRootShadowNode); + currentRootShadowNode.calculateLayout(); if (DEBUG) { Log.d( TAG, - "ReactShadowNodeHierarchy after calculate Layout: " + rootNode.getHierarchyInfo()); + "ReactShadowNodeHierarchy after calculate Layout: " + currentRootShadowNode.getHierarchyInfo()); } - applyUpdatesRecursive(rootNode, 0, 0); + applyUpdatesRecursive(currentRootShadowNode, 0, 0); mUIViewOperationQueue.dispatchViewUpdates( mCurrentBatch++, System.currentTimeMillis(), System.currentTimeMillis()); - mCurrentRootShadowNode = rootNode; + mRootShadowNodeRegistry.addNode(currentRootShadowNode); } catch (Exception e) { handleException(getRootNode(rootTag), e); } @@ -294,7 +293,7 @@ public class FabricUIManager implements UIManager { appendChild(newRootShadowNode, child); } - mFabricReconciler.manageChildren(mCurrentRootShadowNode, newRootShadowNode); + mFabricReconciler.manageChildren(currentRootShadowNode, newRootShadowNode); return newRootShadowNode; } @@ -321,7 +320,7 @@ public class FabricUIManager implements UIManager { } @Override - public int addRootView( + public synchronized int addRootView( final T rootView) { int rootTag = ReactRootViewTagGenerator.getNextRootViewTag(); ThemedReactContext themedRootContext =