From 47910f0cadda30099bc6f5dfda03a69babd663a7 Mon Sep 17 00:00:00 2001 From: "Andrew Chen (Eng)" Date: Wed, 21 Mar 2018 17:43:11 -0700 Subject: [PATCH] Set measure function after YogaNode has been copied Reviewed By: mdvacca Differential Revision: D7338948 fbshipit-source-id: e805169e162a47d0c7c775a3decbe9013c27c0e4 --- .../react/uimanager/ReactShadowNodeImpl.java | 5 ----- .../react/views/text/ReactTextShadowNode.java | 16 +++++++++++++++- 2 files changed, 15 insertions(+), 6 deletions(-) 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 8d906c4bc..5f4ad868f 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactShadowNodeImpl.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactShadowNodeImpl.java @@ -1024,11 +1024,6 @@ public class ReactShadowNodeImpl implements ReactShadowNode @Override public void setMeasureFunction(YogaMeasureFunction measureFunction) { - if ((measureFunction == null ^ mYogaNode.isMeasureDefined()) && getChildCount() != 0) { - throw new RuntimeException( - "Since a node with a measure function does not add any native yoga children, it's " - + "not safe to transition to/from having a measure function unless a node has no children"); - } mYogaNode.setMeasureFunction(measureFunction); } diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextShadowNode.java b/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextShadowNode.java index 37b13700f..1cec7c690 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextShadowNode.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextShadowNode.java @@ -18,6 +18,7 @@ import android.view.Gravity; import android.widget.TextView; import com.facebook.infer.annotation.Assertions; import com.facebook.react.uimanager.LayoutShadowNode; +import com.facebook.react.uimanager.ReactShadowNodeImpl; import com.facebook.react.uimanager.Spacing; import com.facebook.react.uimanager.UIViewOperationQueue; import com.facebook.yoga.YogaConstants; @@ -144,7 +145,6 @@ public class ReactTextShadowNode extends ReactBaseTextShadowNode { private ReactTextShadowNode(ReactTextShadowNode node) { super(node); this.mPreparedSpannableText = node.mPreparedSpannableText; - initMeasureFunction(); } private void initMeasureFunction() { @@ -158,6 +158,20 @@ public class ReactTextShadowNode extends ReactBaseTextShadowNode { return new ReactTextShadowNode(this); } + @Override + public ReactShadowNodeImpl mutableCopy() { + ReactTextShadowNode copy = (ReactTextShadowNode) super.mutableCopy(); + copy.initMeasureFunction(); + return copy; + } + + @Override + public ReactShadowNodeImpl mutableCopyWithNewChildren() { + ReactTextShadowNode copy = (ReactTextShadowNode) super.mutableCopyWithNewChildren(); + copy.initMeasureFunction(); + return copy; + } + // Return text alignment according to LTR or RTL style private int getTextAlign() { int textAlign = mTextAlign;