Cleanup mNativeChildren on react node cleanup.

Differential Revision: D2663443

fb-gh-sync-id: 7e6e7212103b738f6b6f535e54cc8b86e5def685
This commit is contained in:
Krzysztof Magiera
2015-11-17 05:42:12 -08:00
committed by facebook-github-bot-8
parent 0b46a0c13b
commit 337dc7e093
3 changed files with 29 additions and 11 deletions

View File

@@ -137,20 +137,22 @@ public class ReactShadowNode extends CSSNode {
}
public void removeAllChildren() {
int decrease = 0;
for (int i = getChildCount() - 1; i >= 0; i--) {
super.removeChildAt(i);
ReactShadowNode removed = (ReactShadowNode) super.removeChildAt(i);
decrease += removed.mIsLayoutOnly ? removed.mTotalNativeChildren : 1;
}
markUpdated();
updateNativeChildrenCountInParent(-mTotalNativeChildren);
mTotalNativeChildren = 0;
mTotalNativeChildren -= decrease;
updateNativeChildrenCountInParent(-decrease);
}
private void updateNativeChildrenCountInParent(int delta) {
if (mIsLayoutOnly) {
ReactShadowNode parent = getParent();
while (parent != null) {
parent.mTotalNativeChildren -= delta;
parent.mTotalNativeChildren += delta;
if (!parent.mIsLayoutOnly) {
break;
}
@@ -289,6 +291,15 @@ public class ReactShadowNode extends CSSNode {
return removed;
}
public void removeAllNativeChildren() {
if (mNativeChildren != null) {
for (int i = mNativeChildren.size() - 1; i >= 0; i--) {
mNativeChildren.get(i).mNativeParent = null;
}
mNativeChildren.clear();
}
}
public int getNativeChildCount() {
return mNativeChildren == null ? 0 : mNativeChildren.size();
}