Cleanup native view hierarchy when view is dropped.

Differential Revision: D2659738

fb-gh-sync-id: 1c14b8c3c6fabbd0e580777bb94221df6dd98f71
This commit is contained in:
Krzysztof Magiera
2015-11-16 14:27:57 -08:00
committed by facebook-github-bot-7
parent 0f590d1233
commit bd1885b5d4
6 changed files with 47 additions and 14 deletions

View File

@@ -122,16 +122,7 @@ public class ReactShadowNode extends CSSNode {
int increase = node.mIsLayoutOnly ? node.mTotalNativeChildren : 1;
mTotalNativeChildren += increase;
if (mIsLayoutOnly) {
ReactShadowNode parent = getParent();
while (parent != null) {
parent.mTotalNativeChildren += increase;
if (!parent.mIsLayoutOnly) {
break;
}
parent = parent.getParent();
}
}
updateNativeChildrenCountInParent(increase);
}
@Override
@@ -141,17 +132,31 @@ public class ReactShadowNode extends CSSNode {
int decrease = removed.mIsLayoutOnly ? removed.mTotalNativeChildren : 1;
mTotalNativeChildren -= decrease;
updateNativeChildrenCountInParent(-decrease);
return removed;
}
public void removeAllChildren() {
for (int i = getChildCount() - 1; i >= 0; i--) {
super.removeChildAt(i);
}
markUpdated();
updateNativeChildrenCountInParent(-mTotalNativeChildren);
mTotalNativeChildren = 0;
}
private void updateNativeChildrenCountInParent(int delta) {
if (mIsLayoutOnly) {
ReactShadowNode parent = getParent();
while (parent != null) {
parent.mTotalNativeChildren -= decrease;
parent.mTotalNativeChildren -= delta;
if (!parent.mIsLayoutOnly) {
break;
}
parent = parent.getParent();
}
}
return removed;
}
/**