From a7558d58a08f7d1bb650574842b24e181b1bd68b Mon Sep 17 00:00:00 2001 From: David Vacca Date: Fri, 9 Mar 2018 09:39:38 -0800 Subject: [PATCH] Clone ReactShadowNode when Yoga clones a YogaNode during layout Reviewed By: achen1 Differential Revision: D7195840 fbshipit-source-id: d596e3ada8fe48577b91295721d41c0afd33087f --- .../react/uimanager/ReactShadowNodeImpl.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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 5624324c0..51846af18 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactShadowNodeImpl.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactShadowNodeImpl.java @@ -21,6 +21,7 @@ import com.facebook.yoga.YogaFlexDirection; import com.facebook.yoga.YogaJustify; import com.facebook.yoga.YogaMeasureFunction; import com.facebook.yoga.YogaNode; +import com.facebook.yoga.YogaNodeClonedFunction; import com.facebook.yoga.YogaOverflow; import com.facebook.yoga.YogaPositionType; import com.facebook.yoga.YogaValue; @@ -58,6 +59,19 @@ public class ReactShadowNodeImpl implements ReactShadowNode private static final YogaConfig sYogaConfig; static { sYogaConfig = ReactYogaConfigProvider.get(); + sYogaConfig.setOnNodeCloned(new YogaNodeClonedFunction() { + @Override + public void onNodeCloned(YogaNode oldYogaNode, + YogaNode newYogaNode, + YogaNode parent, + int childIndex) { + ReactShadowNode parentReactShadowNode = (ReactShadowNode) parent.getData(); + Assertions.assertNotNull(parentReactShadowNode); + + ReactShadowNode newReactShadowNode = (ReactShadowNode) newYogaNode.getData(); + Assertions.assertNotNull(newReactShadowNode); + } + }); } private int mReactTag; @@ -88,6 +102,7 @@ public class ReactShadowNodeImpl implements ReactShadowNode if (!isVirtual()) { YogaNode node = YogaNodePool.get().acquire(); mYogaNode = node == null ? new YogaNode(sYogaConfig) : node; + mYogaNode.setData(this); Arrays.fill(mPadding, YogaConstants.UNDEFINED); } else { mYogaNode = null; @@ -117,6 +132,7 @@ public class ReactShadowNodeImpl implements ReactShadowNode arraycopy(original.mPadding, 0, mPadding, 0, original.mPadding.length); arraycopy(original.mPaddingIsPercent, 0, mPaddingIsPercent, 0, original.mPaddingIsPercent.length); mYogaNode = original.mYogaNode.clone(); + mYogaNode.setData(this); } catch (CloneNotSupportedException e) { // it should never happen throw new IllegalArgumentException();