Skip to content

Commit

Permalink
Update ReactShadowNode to not add CSSNode children if parent has meas…
Browse files Browse the repository at this point in the history
…ure defined

Summary: See inline comment for rationale

Reviewed By: emilsjolander

Differential Revision: D4154168

fbshipit-source-id: 6d428d4e9f4a68c88bb994ded88c817bee744563
  • Loading branch information
astreet authored and Facebook Github Bot committed Nov 14, 2016
1 parent 07ef5a8 commit 10e0aec
Showing 1 changed file with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit 10e0aec

Please sign in to comment.