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
This commit is contained in:
parent
c3038d7210
commit
35cac3bf1b
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue