Set measure function after YogaNode has been copied

Reviewed By: mdvacca

Differential Revision: D7338948

fbshipit-source-id: e805169e162a47d0c7c775a3decbe9013c27c0e4
This commit is contained in:
Andrew Chen (Eng) 2018-03-21 17:43:11 -07:00 коммит произвёл Facebook Github Bot
Родитель 96daf677b7
Коммит 47910f0cad
2 изменённых файлов: 15 добавлений и 6 удалений

Просмотреть файл

@ -1024,11 +1024,6 @@ public class ReactShadowNodeImpl implements ReactShadowNode<ReactShadowNodeImpl>
@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);
}

Просмотреть файл

@ -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;