From d344fb4e29a827d1e7d233672a3efe3b2b981a8a Mon Sep 17 00:00:00 2001 From: Joshua Gross Date: Thu, 27 Aug 2020 13:58:25 -0700 Subject: [PATCH] When logging errors with deleteView, try to find actual index of view Summary: If we try to delete a view and find the wrong one, when we crash, try to log the *actual* index of the view in question. Changelog: [Internal] Reviewed By: mdvacca Differential Revision: D23368229 fbshipit-source-id: 7f9835fd07cfe4924d05c7e37b42b9bcdffff4a9 --- .../react/fabric/mounting/MountingManager.java | 15 +++++++++++++-- 1 file changed, 13 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 aae78bf367b..a62cf858c2b 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 @@ -366,7 +366,16 @@ public class MountingManager { // Verify that the view we're about to remove has the same tag we expect View view = viewGroupManager.getChildAt(parentView, index); - if (view != null && view.getId() != tag) { + int actualTag = (view != null ? view.getId() : -1); + if (actualTag != tag) { + int tagActualIndex = -1; + for (int i = 0; i < parentView.getChildCount(); i++) { + if (parentView.getChildAt(i).getId() == tag) { + tagActualIndex = i; + break; + } + } + throw new IllegalStateException( "Tried to delete view [" + tag @@ -375,7 +384,9 @@ public class MountingManager { + "] at index " + index + ", but got view tag " - + view.getId()); + + actualTag + + " - actual index of view: " + + tagActualIndex); } try {