From c883d4e72772d124324855148b48f0111fbb9c1e Mon Sep 17 00:00:00 2001 From: David Vacca Date: Fri, 9 Mar 2018 09:39:42 -0800 Subject: [PATCH] Add "newProps" map into ReactShadowNode Reviewed By: achen1 Differential Revision: D7205127 fbshipit-source-id: 6c27070806de36cab7adf9c392a10c815aee90d4 --- .../react/fabric/FabricUIManager.java | 6 ++-- .../react/uimanager/ReactShadowNode.java | 6 ++++ .../react/uimanager/ReactShadowNodeImpl.java | 32 ++++++++++++++++++- 3 files changed, 39 insertions(+), 5 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 2fa9557f5..6fd4c1ae2 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java @@ -140,8 +140,7 @@ public class FabricUIManager implements UIManager { ReactShadowNode node, @Nullable ReadableNativeMap newProps) { try { - ReactShadowNode clone = node.mutableCopy(); - updateProps(clone, newProps); + ReactShadowNode clone = node.mutableCopyWithNewProps(newProps == null ? null : new ReactStylesDiffMap(newProps)); assertReactShadowNodeCopy(node, clone); return clone; } catch (Throwable t) { @@ -161,8 +160,7 @@ public class FabricUIManager implements UIManager { ReactShadowNode node, ReadableNativeMap newProps) { try { - ReactShadowNode clone = node.mutableCopyWithNewChildren(); - updateProps(clone, newProps); + ReactShadowNode clone = node.mutableCopyWithNewChildrenAndProps(newProps == null ? null : new ReactStylesDiffMap(newProps)); assertReactShadowNodeCopy(node, clone); return clone; } catch (Throwable t) { diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactShadowNode.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactShadowNode.java index 71f8d0936..ab8e26925 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactShadowNode.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactShadowNode.java @@ -72,8 +72,12 @@ public interface ReactShadowNode { */ T mutableCopy(); + T mutableCopyWithNewProps(@Nullable ReactStylesDiffMap newProps); + T mutableCopyWithNewChildren(); + T mutableCopyWithNewChildrenAndProps(@Nullable ReactStylesDiffMap newProps); + String getViewClass(); boolean hasUpdates(); @@ -100,6 +104,8 @@ public interface ReactShadowNode { void removeAndDisposeAllChildren(); + @Nullable ReactStylesDiffMap getNewProps(); + /** * This method will be called by {@link UIManagerModule} once per batch, before calculating * layout. Will be only called for nodes that are marked as updated with {@link #markUpdated()} or diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactShadowNodeImpl.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactShadowNodeImpl.java index 2390f5681..664dd0972 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactShadowNodeImpl.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactShadowNodeImpl.java @@ -98,6 +98,8 @@ public class ReactShadowNodeImpl implements ReactShadowNode private final boolean[] mPaddingIsPercent = new boolean[Spacing.ALL + 1]; private final YogaNode mYogaNode; + private @Nullable ReactStylesDiffMap mNewProps; + public ReactShadowNodeImpl() { if (!isVirtual()) { YogaNode node = YogaNodePool.get().acquire(); @@ -119,7 +121,6 @@ public class ReactShadowNodeImpl implements ReactShadowNode mShouldNotifyOnLayout = original.mShouldNotifyOnLayout; mNodeUpdated = original.mNodeUpdated; mChildren = original.mChildren == null ? null : new ArrayList<>(original.mChildren); - mParent = null; mIsLayoutOnly = original.mIsLayoutOnly; mTotalNativeChildren = original.mTotalNativeChildren; mNativeParent = original.mNativeParent; @@ -133,6 +134,8 @@ public class ReactShadowNodeImpl implements ReactShadowNode arraycopy(original.mPaddingIsPercent, 0, mPaddingIsPercent, 0, original.mPaddingIsPercent.length); mYogaNode = original.mYogaNode.clone(); mYogaNode.setData(this); + mParent = null; + mNewProps = null; } catch (CloneNotSupportedException e) { // it should never happen throw new IllegalArgumentException(); @@ -152,6 +155,27 @@ public class ReactShadowNodeImpl implements ReactShadowNode return copy; } + @Override + public ReactShadowNodeImpl mutableCopyWithNewProps(@Nullable ReactStylesDiffMap newProps) { + ReactShadowNodeImpl copy = mutableCopy(); + if (newProps != null) { + copy.updateProperties(newProps); + copy.mNewProps = newProps; + } + return copy; + } + + @Override + public ReactShadowNodeImpl mutableCopyWithNewChildrenAndProps(@Nullable ReactStylesDiffMap newProps) { + ReactShadowNodeImpl copy = mutableCopyWithNewChildren(); + if (newProps != null) { + copy.updateProperties(newProps); + copy.mNewProps = newProps; + } + return copy; + } + + /** * Nodes that return {@code true} will be treated as "virtual" nodes. That is, nodes that are not * mapped into native views (e.g. nested text node). By default this method returns {@code false}. @@ -360,6 +384,12 @@ public class ReactShadowNodeImpl implements ReactShadowNode // no-op } + @Override + @Nullable + public ReactStylesDiffMap getNewProps() { + return mNewProps; + } + /** * Called after layout step at the end of the UI batch from {@link UIManagerModule}. May be used * to enqueue additional ui operations for the native view. Will only be called on nodes marked as