Permalink
Browse files

Update ReactShadowNode to not add CSSNode children if parent has meas…

…ure defined

Summary: See inline comment for rationale

Reviewed By: emilsjolander

Differential Revision: D4154168

fbshipit-source-id: 6d428d4e9f4a68c88bb994ded88c817bee744563
  • Loading branch information...
1 parent 07ef5a8 commit 10e0aec62fbdac7287aae74afd07ec54274dd6be @astreet astreet committed with Facebook Github Bot Nov 14, 2016
Showing with 17 additions and 3 deletions.
  1. +17 −3 ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactShadowNode.java
@@ -142,7 +142,11 @@ public void addChildAt(ReactShadowNode child, int i) {
mChildren.add(i, child);
child.mParent = this;
- mCSSNode.addChildAt(child.mCSSNode, i);
+ // 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 (!mCSSNode.isMeasureDefined()) {
+ mCSSNode.addChildAt(child.mCSSNode, i);
+ }
markUpdated();
int increase = child.mIsLayoutOnly ? child.mTotalNativeChildren : 1;
@@ -159,7 +163,9 @@ public ReactShadowNode removeChildAt(int i) {
ReactShadowNode removed = mChildren.remove(i);
removed.mParent = null;
- mCSSNode.removeChildAt(i);
+ if (!mCSSNode.isMeasureDefined()) {
+ mCSSNode.removeChildAt(i);
+ }
markUpdated();
int decrease = removed.mIsLayoutOnly ? removed.mTotalNativeChildren : 1;
@@ -191,7 +197,9 @@ public void removeAllChildren() {
int decrease = 0;
for (int i = getChildCount() - 1; i >= 0; i--) {
- mCSSNode.removeChildAt(i);
+ if (!mCSSNode.isMeasureDefined()) {
+ mCSSNode.removeChildAt(i);
+ }
ReactShadowNode toRemove = getChildAt(i);
toRemove.mParent = null;
decrease += toRemove.mIsLayoutOnly ? toRemove.mTotalNativeChildren : 1;
@@ -633,6 +641,12 @@ public void setShouldNotifyOnLayout(boolean shouldNotifyOnLayout) {
}
public void setMeasureFunction(CSSNodeAPI.MeasureFunction measureFunction) {
+ if ((measureFunction == null ^ mCSSNode.isMeasureDefined()) &&
+ getChildCount() != 0) {
+ throw new RuntimeException(
+ "Since a node with a measure function does not add any native CSSLayout children, it's " +
+ "not safe to transition to/from having a measure function unless a node has no children");
+ }
mCSSNode.setMeasureFunction(measureFunction);
}

0 comments on commit 10e0aec

Please sign in to comment.