From 35cac3bf1ba90eb785a0aba6f2ca2ef7db55e767 Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Wed, 6 Sep 2017 17:08:30 -0700 Subject: [PATCH] Introducing `ReactShadowNode.isYogaLeafNode()` Summary: We have to have a way to explicitly enforce the fact that some nodes cannot have Yoga child nodes. Previously we relied on `isMeasureDefined()`, which is actually special case (so it does not cover all possible cases). Reviewed By: AaaChiuuu Differential Revision: D5647855 fbshipit-source-id: 59591be61ef62c61eb98748d44bb28b878f713fc --- .../react/uimanager/ReactShadowNode.java | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) 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();