Fix crash introduced by D21735940 in T67525923

Summary:
We cannot call `parentView.getChildCount()` directly, we must get the child count through the ViewManager:

A simple `Log.e` call shows:

```
MountingManager: parentView.getChildCount(): 0 // viewGroupManager.getChildCount(parentView): 7
```

This difference does not occur for ALL views, but it occurs for... enough that this will crash on basically ~every screen, at least on navigation when all views are removed.

Theory about why this is happening: some ViewGroup types compute childCount differently, especially if we do some sort of custom child management for some view type? By coercing to `T` which the ViewManager does, we call getChildCount on the correct class type. This is just a hypothesis, though. But the failing views are all `View`s and it does look like `ReactClippingViewManager` has custom `getChildCount` logic, so that's likely the answer.

There's no such thing as an easy diff!

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D21750097

fbshipit-source-id: 3d87d8f629a0c12101658050e57e09242dfc2a8c
This commit is contained in:
Joshua Gross
2020-05-27 16:03:56 -07:00
committed by Facebook GitHub Bot
parent 97d3abf982
commit 7e559465bd
@@ -242,7 +242,9 @@ public class MountingManager {
throw new IllegalStateException("Unable to find view for tag " + parentTag);
}
if (parentView.getChildCount() <= index) {
ViewGroupManager<ViewGroup> viewGroupManager = getViewGroupManager(viewState);
if (viewGroupManager.getChildCount(parentView) <= index) {
throw new IllegalStateException(
"Cannot remove child at index "
+ index
@@ -253,7 +255,7 @@ public class MountingManager {
+ " children in parent");
}
getViewGroupManager(viewState).removeViewAt(parentView, index);
viewGroupManager.removeViewAt(parentView, index);
}
@UiThread