Skip to content

Commit

Permalink
Avoid holding references to ReactShadowNode after a tree is commited
Browse files Browse the repository at this point in the history
Reviewed By: achen1

Differential Revision: D7495721

fbshipit-source-id: 33d5bba5040729f891455a9c330234fe25130b02
  • Loading branch information
mdvacca authored and facebook-github-bot committed Apr 6, 2018
1 parent 9fd2b9a commit bf7601f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,9 @@ private void applyUpdatesRecursive(ReactShadowNode node, float absoluteX, float
boolean frameDidChange =
node.dispatchUpdates(absoluteX, absoluteY, mUIViewOperationQueue, null);
}
// Set the reference to the OriginalReactShadowNode to NULL, as the tree is already committed
// and we do not need to hold references to the previous tree anymore
node.setOriginalReactShadowNode(null);
node.markUpdateSeen();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,16 @@ protected ReactShadowNodeImpl(ReactShadowNodeImpl original) {
mViewClassName = original.mViewClassName;
mThemedContext = original.mThemedContext;
mShouldNotifyOnLayout = original.mShouldNotifyOnLayout;
mNodeUpdated = original.mNodeUpdated;
mIsLayoutOnly = original.mIsLayoutOnly;
mNativeParent = original.mNativeParent;
mScreenX = original.mScreenX;
mScreenY = original.mScreenY;
mScreenWidth = original.mScreenWidth;
mScreenHeight = original.mScreenHeight;
// Cloned nodes should be always updated.
mNodeUpdated = true;
// "cached" screen coordinates are not cloned because FabricJS not always clone the last
// ReactShadowNode that was rendered in the screen.
mScreenX = 0;
mScreenY = 0;
mScreenWidth = 0;
mScreenHeight = 0;
arraycopy(original.mPadding, 0, mPadding, 0, original.mPadding.length);
arraycopy(original.mPaddingIsPercent, 0, mPaddingIsPercent, 0, original.mPaddingIsPercent.length);
mNewProps = null;
Expand All @@ -148,6 +151,7 @@ protected ReactShadowNodeImpl(ReactShadowNodeImpl original) {
private void replaceChild(ReactShadowNodeImpl newNode, int childIndex) {
mChildren.remove(childIndex);
mChildren.add(childIndex, newNode);
newNode.mParent = this;
}

/**
Expand All @@ -164,14 +168,7 @@ public ReactShadowNodeImpl mutableCopy() {
copy.mNativeChildren = mNativeChildren == null ? null : new ArrayList<>(mNativeChildren);
copy.mTotalNativeChildren = mTotalNativeChildren;
copy.mChildren = mChildren == null ? null : new ArrayList<>(mChildren);
copy.mYogaNode.setData(this);
if (mChildren != null) {
for (ReactShadowNode child : mChildren) {
if (child.getOriginalReactShadowNode() == null) {
child.setOriginalReactShadowNode(child);
}
}
}
copy.mYogaNode.setData(copy);
return copy;
}

Expand All @@ -182,7 +179,7 @@ public ReactShadowNodeImpl mutableCopyWithNewChildren() {
copy.mNativeChildren = null;
copy.mChildren = null;
copy.mTotalNativeChildren = 0;
copy.mYogaNode.setData(this);
copy.mYogaNode.setData(copy);
return copy;
}

Expand Down Expand Up @@ -306,16 +303,6 @@ public void addChildAt(ReactShadowNodeImpl child, int i) {
+ toString()
+ "')");
}
// TODO: T26729293 This is a temporary code that will be replaced as part of T26729293.
YogaNode parent = childYogaNode.getOwner();
if (parent != null) {
for (int k = 0; k < parent.getChildCount(); k++) {
if (parent.getChildAt(k) == childYogaNode) {
parent.removeChildAt(k);
break;
}
}
}
mYogaNode.addChildAt(childYogaNode, i);
}
markUpdated();
Expand Down

0 comments on commit bf7601f

Please sign in to comment.