You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Make SurfaceMountingManager errors more actionable (#57318)
Summary:
Pull Request resolved: #57318
Make it clearer when parent view is null vs not a view group and log what class it is if so.
Changelog: [Internal]
Reviewed By: cortinico
Differential Revision: D109539811
fbshipit-source-id: 89808be7b8051047e7f6dbc306ba95576deb166f
Copy file name to clipboardExpand all lines: packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/SurfaceMountingManager.kt
+19-15Lines changed: 19 additions & 15 deletions
Original file line number
Diff line number
Diff line change
@@ -308,13 +308,16 @@ internal constructor(
308
308
)
309
309
return
310
310
}
311
-
if (parentViewState.view !isViewGroup) {
311
+
312
+
val parentView = parentViewState.view
313
+
checkNotNull(parentView) { "Unable to find parentView for tag $parentTag" }
314
+
if (parentView !isViewGroup) {
312
315
val message =
313
-
"Unable to add a view into a view that is not a ViewGroup. ParentTag: $parentTag - Tag: $tag - Index: $index"
316
+
"Unable to add a view into a non-ViewGroup${parentView.javaClass.simpleName} when inserting [$tag] into parent [$parentTag]"
314
317
FLog.e(TAG, message)
315
318
throwIllegalStateException(message)
316
319
}
317
-
val parentView = parentViewState.view asViewGroup
320
+
318
321
val viewState = getNullableViewState(tag)
319
322
if (viewState ==null) {
320
323
ReactSoftExceptionLogger.logSoftException(
@@ -332,13 +335,13 @@ internal constructor(
332
335
logViewHierarchy(parentView, false)
333
336
}
334
337
335
-
valviewParent= view.parent
336
-
if (viewParent!=null) {
337
-
val actualParentId =if (viewParentisViewGroup) viewParent.id elseView.NO_ID
338
+
valcurrParentView= view.parent
339
+
if (currParentView!=null) {
340
+
val actualParentId =if (currParentViewisViewGroup) currParentView.id elseView.NO_ID
338
341
ReactSoftExceptionLogger.logSoftException(
339
342
TAG,
340
343
IllegalStateException(
341
-
"addViewAt: cannot insert view [$tag] into parent [$parentTag]: View already has a parent: [$actualParentId] Parent: ${viewParent.javaClass.simpleName} View: ${view.javaClass.simpleName}"
344
+
"addViewAt: cannot insert view [$tag] into parent [$parentTag]: View already has a parent: [$actualParentId] Parent: ${currParentView.javaClass.simpleName} View: ${view.javaClass.simpleName}"
342
345
),
343
346
)
344
347
@@ -356,8 +359,8 @@ internal constructor(
356
359
// should be impossible - we mark this as a "readded" View and
357
360
// thus prevent the RemoveDeleteTree worker from deleting this
358
361
// View in the future.
359
-
if (viewParentisViewGroup) {
360
-
viewParent.removeView(view)
362
+
if (currParentViewisViewGroup) {
363
+
currParentView.removeView(view)
361
364
}
362
365
erroneouslyReaddedReactTags.add(tag)
363
366
}
@@ -394,6 +397,7 @@ internal constructor(
394
397
395
398
@UiThread
396
399
publicfunremoveViewAt(tag:Int, parentTag:Int, index:Int): Unit {
400
+
UiThreadUtil.assertOnUiThread()
397
401
if (isStopped) {
398
402
return
399
403
}
@@ -409,22 +413,22 @@ internal constructor(
409
413
return
410
414
}
411
415
412
-
UiThreadUtil.assertOnUiThread()
413
416
val parentViewState = getNullableViewState(parentTag)
0 commit comments