Avoid holding references to ReactShadowNode after a tree is commited

Reviewed By: achen1

Differential Revision: D7495721

fbshipit-source-id: 33d5bba5040729f891455a9c330234fe25130b02
This commit is contained in:
David Vacca 2018-04-06 15:01:19 -07:00 committed by Facebook Github Bot
parent 9fd2b9a75f
commit bf7601fde1
2 changed files with 14 additions and 24 deletions

View File

@ -329,6 +329,9 @@ public class FabricUIManager implements UIManager {
boolean frameDidChange = boolean frameDidChange =
node.dispatchUpdates(absoluteX, absoluteY, mUIViewOperationQueue, null); 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(); node.markUpdateSeen();
} }

View File

@ -131,13 +131,16 @@ public class ReactShadowNodeImpl implements ReactShadowNode<ReactShadowNodeImpl>
mViewClassName = original.mViewClassName; mViewClassName = original.mViewClassName;
mThemedContext = original.mThemedContext; mThemedContext = original.mThemedContext;
mShouldNotifyOnLayout = original.mShouldNotifyOnLayout; mShouldNotifyOnLayout = original.mShouldNotifyOnLayout;
mNodeUpdated = original.mNodeUpdated;
mIsLayoutOnly = original.mIsLayoutOnly; mIsLayoutOnly = original.mIsLayoutOnly;
mNativeParent = original.mNativeParent; mNativeParent = original.mNativeParent;
mScreenX = original.mScreenX; // Cloned nodes should be always updated.
mScreenY = original.mScreenY; mNodeUpdated = true;
mScreenWidth = original.mScreenWidth; // "cached" screen coordinates are not cloned because FabricJS not always clone the last
mScreenHeight = original.mScreenHeight; // 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.mPadding, 0, mPadding, 0, original.mPadding.length);
arraycopy(original.mPaddingIsPercent, 0, mPaddingIsPercent, 0, original.mPaddingIsPercent.length); arraycopy(original.mPaddingIsPercent, 0, mPaddingIsPercent, 0, original.mPaddingIsPercent.length);
mNewProps = null; mNewProps = null;
@ -148,6 +151,7 @@ public class ReactShadowNodeImpl implements ReactShadowNode<ReactShadowNodeImpl>
private void replaceChild(ReactShadowNodeImpl newNode, int childIndex) { private void replaceChild(ReactShadowNodeImpl newNode, int childIndex) {
mChildren.remove(childIndex); mChildren.remove(childIndex);
mChildren.add(childIndex, newNode); mChildren.add(childIndex, newNode);
newNode.mParent = this;
} }
/** /**
@ -164,14 +168,7 @@ public class ReactShadowNodeImpl implements ReactShadowNode<ReactShadowNodeImpl>
copy.mNativeChildren = mNativeChildren == null ? null : new ArrayList<>(mNativeChildren); copy.mNativeChildren = mNativeChildren == null ? null : new ArrayList<>(mNativeChildren);
copy.mTotalNativeChildren = mTotalNativeChildren; copy.mTotalNativeChildren = mTotalNativeChildren;
copy.mChildren = mChildren == null ? null : new ArrayList<>(mChildren); copy.mChildren = mChildren == null ? null : new ArrayList<>(mChildren);
copy.mYogaNode.setData(this); copy.mYogaNode.setData(copy);
if (mChildren != null) {
for (ReactShadowNode child : mChildren) {
if (child.getOriginalReactShadowNode() == null) {
child.setOriginalReactShadowNode(child);
}
}
}
return copy; return copy;
} }
@ -182,7 +179,7 @@ public class ReactShadowNodeImpl implements ReactShadowNode<ReactShadowNodeImpl>
copy.mNativeChildren = null; copy.mNativeChildren = null;
copy.mChildren = null; copy.mChildren = null;
copy.mTotalNativeChildren = 0; copy.mTotalNativeChildren = 0;
copy.mYogaNode.setData(this); copy.mYogaNode.setData(copy);
return copy; return copy;
} }
@ -306,16 +303,6 @@ public class ReactShadowNodeImpl implements ReactShadowNode<ReactShadowNodeImpl>
+ toString() + 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); mYogaNode.addChildAt(childYogaNode, i);
} }
markUpdated(); markUpdated();