Add invariant to SurfaceMountingManager: when removing a view, the parent View must be a ViewGroup

Summary:
In addViewAt, we have this check. Add this same check to removeViewAt.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D26381475

fbshipit-source-id: 1050377aa4e528668446fd561ff09c61f27c700f
This commit is contained in:
Joshua Gross
2021-02-10 16:00:18 -08:00
committed by Facebook GitHub Bot
parent 5ca832b4aa
commit 81810f4c62
@@ -318,10 +318,10 @@ public class SurfaceMountingManager {
}
UiThreadUtil.assertOnUiThread();
ViewState viewState = getNullableViewState(parentTag);
ViewState parentViewState = getNullableViewState(parentTag);
// TODO: throw exception here?
if (viewState == null) {
if (parentViewState == null) {
ReactSoftException.logSoftException(
MountingManager.TAG,
new IllegalStateException(
@@ -329,7 +329,19 @@ public class SurfaceMountingManager {
return;
}
final ViewGroup parentView = (ViewGroup) viewState.mView;
if (!(parentViewState.mView instanceof ViewGroup)) {
String message =
"Unable to remove a view from a view that is not a ViewGroup. ParentTag: "
+ parentTag
+ " - Tag: "
+ tag
+ " - Index: "
+ index;
FLog.e(TAG, message);
throw new IllegalStateException(message);
}
final ViewGroup parentView = (ViewGroup) parentViewState.mView;
if (parentView == null) {
throw new IllegalStateException("Unable to find view for tag [" + parentTag + "]");
@@ -341,7 +353,7 @@ public class SurfaceMountingManager {
logViewHierarchy(parentView, false);
}
ViewGroupManager<ViewGroup> viewGroupManager = getViewGroupManager(viewState);
ViewGroupManager<ViewGroup> viewGroupManager = getViewGroupManager(parentViewState);
// Verify that the view we're about to remove has the same tag we expect
View view = viewGroupManager.getChildAt(parentView, index);