From ace1b4d78e337cccc95539afa8cd50f19ef18cf6 Mon Sep 17 00:00:00 2001 From: Andy Street Date: Thu, 30 Jun 2016 04:12:52 -0700 Subject: [PATCH] Start creating views before end of batch for nodes Summary: Depends on D3120798 Depends on D3120631 Enables D3120631 for nodes. This implementation seems to work but let me know if I'm doing something really stupid. Reviewed By: ahmedre Differential Revision: D3120814 --- .../react/flat/FlatUIImplementation.java | 1 - .../com/facebook/react/flat/StateBuilder.java | 53 ++++++------------- 2 files changed, 15 insertions(+), 39 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/flat/FlatUIImplementation.java b/ReactAndroid/src/main/java/com/facebook/react/flat/FlatUIImplementation.java index 7b7fb54f2..de277b74b 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/flat/FlatUIImplementation.java +++ b/ReactAndroid/src/main/java/com/facebook/react/flat/FlatUIImplementation.java @@ -464,7 +464,6 @@ public class FlatUIImplementation extends UIImplementation { @Override protected void updateViewHierarchy(EventDispatcher eventDispatcher) { - mStateBuilder.beforeUpdateViewHierarchy(); super.updateViewHierarchy(eventDispatcher); mStateBuilder.afterUpdateViewHierarchy(eventDispatcher); } diff --git a/ReactAndroid/src/main/java/com/facebook/react/flat/StateBuilder.java b/ReactAndroid/src/main/java/com/facebook/react/flat/StateBuilder.java index f5972247a..492b565d0 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/flat/StateBuilder.java +++ b/ReactAndroid/src/main/java/com/facebook/react/flat/StateBuilder.java @@ -45,8 +45,6 @@ import com.facebook.react.uimanager.events.EventDispatcher; private final ArrayList mViewsToDetachAllChildrenFrom = new ArrayList<>(); private final ArrayList mViewsToDetach = new ArrayList<>(); private final ArrayList mViewsToDrop = new ArrayList<>(); - private final ArrayList mViewsToUpdate = new ArrayList<>(); - private final ArrayList mStylesToUpdate = new ArrayList<>(); private final ArrayList mOnLayoutEvents = new ArrayList<>(); private final ArrayList mUpdateViewBoundsOperations = new ArrayList<>(); @@ -61,10 +59,6 @@ import com.facebook.react.uimanager.events.EventDispatcher; return mOperationsQueue; } - void beforeUpdateViewHierarchy() { - commitViewUpdates(); - } - /** * Given a root of the laid-out shadow node hierarchy, walks the tree and generates an array of * DrawCommands that will then mount in UI thread to a root FlatViewGroup so that it can draw. @@ -143,8 +137,21 @@ import com.facebook.react.uimanager.events.EventDispatcher; /* package */ void enqueueCreateOrUpdateView( FlatShadowNode node, @Nullable ReactStylesDiffMap styles) { - mViewsToUpdate.add(node); - mStylesToUpdate.add(styles); + if (node.isBackingViewCreated()) { + // if the View is already created, make sure propagate new styles. + mOperationsQueue.enqueueUpdateProperties( + node.getReactTag(), + node.getViewClass(), + styles); + } else { + mOperationsQueue.enqueueCreateView( + node.getThemedContext(), + node.getReactTag(), + node.getViewClass(), + styles); + + node.signalBackingViewIsCreated(); + } } /* package */ boolean ensureBackingViewIsCreated(FlatShadowNode node) { @@ -163,36 +170,6 @@ import com.facebook.react.uimanager.events.EventDispatcher; mViewsToDrop.add(node); } - private void commitViewUpdates() { - for (int i = 0, numViewsToUpdate = mViewsToUpdate.size(); i != numViewsToUpdate; ++i) { - FlatShadowNode node = mViewsToUpdate.get(i); - if (node.getParent() == null) { - // Shadow node is not attached to the hierarchy, which means it is being discarded. - // No need to create or update view in this case, as the View is already gone as well. - continue; - } - - if (node.isBackingViewCreated()) { - // if the View is already created, make sure propagate new styles. - mOperationsQueue.enqueueUpdateProperties( - node.getReactTag(), - node.getViewClass(), - mStylesToUpdate.get(i)); - } else { - mOperationsQueue.enqueueCreateView( - node.getThemedContext(), - node.getReactTag(), - node.getViewClass(), - mStylesToUpdate.get(i)); - - node.signalBackingViewIsCreated(); - } - } - - mViewsToUpdate.clear(); - mStylesToUpdate.clear(); - } - private void addNodeRegion( FlatShadowNode node, float left,