From 7e559465bdbfb8d21399cb43c32b3b553320d503 Mon Sep 17 00:00:00 2001 From: Joshua Gross Date: Wed, 27 May 2020 16:00:35 -0700 Subject: [PATCH] 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 --- .../com/facebook/react/fabric/mounting/MountingManager.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/MountingManager.java b/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/MountingManager.java index 05438adaf07..7d89e34ebf7 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/MountingManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/MountingManager.java @@ -242,7 +242,9 @@ public class MountingManager { throw new IllegalStateException("Unable to find view for tag " + parentTag); } - if (parentView.getChildCount() <= index) { + ViewGroupManager 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