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 4357e9157..9a33f8a4c 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactShadowNode.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactShadowNode.java @@ -119,6 +119,16 @@ public class ReactShadowNode { return false; } + /** + * Nodes that return {@code true} will not manage (and and remove) child Yoga nodes. + * For example {@link ReactTextInputShadowNode} or {@link ReactTextShadowNode} have child nodes, + * which do not want Yoga to lay out, so in the eyes of Yoga it is a leaf node. + * Override this method in subclass to enforce this requirement. + */ + public boolean isYogaLeafNode() { + return isMeasureDefined(); + } + public final String getViewClass() { return Assertions.assertNotNull(mViewClassName); } @@ -172,7 +182,7 @@ public class ReactShadowNode { // If a CSS node has measure defined, the layout algorithm will not visit its children. Even // more, it asserts that you don't add children to nodes with measure functions. - if (mYogaNode != null && !mYogaNode.isMeasureDefined()) { + if (mYogaNode != null && !isYogaLeafNode()) { YogaNode childYogaNode = child.mYogaNode; if (childYogaNode == null) { throw new RuntimeException( @@ -198,7 +208,7 @@ public class ReactShadowNode { ReactShadowNode removed = mChildren.remove(i); removed.mParent = null; - if (mYogaNode != null && !mYogaNode.isMeasureDefined()) { + if (mYogaNode != null && !isYogaLeafNode()) { mYogaNode.removeChildAt(i); } markUpdated(); @@ -232,7 +242,7 @@ public class ReactShadowNode { int decrease = 0; for (int i = getChildCount() - 1; i >= 0; i--) { - if (mYogaNode != null && !mYogaNode.isMeasureDefined()) { + if (mYogaNode != null && !isYogaLeafNode()) { mYogaNode.removeChildAt(i); } ReactShadowNode toRemove = getChildAt(i); @@ -797,6 +807,10 @@ public class ReactShadowNode { mYogaNode.setMeasureFunction(measureFunction); } + public boolean isMeasureDefined() { + return mYogaNode.isMeasureDefined(); + } + @Override public String toString() { StringBuilder sb = new StringBuilder();