Log View hierarchy if removeViewAt crashes

Summary:
If removeViewAt crashes, log the children of the parent view, and all of the parent's ancestors.

Changelog: [Internal]

Reviewed By: shergin

Differential Revision: D24019515

fbshipit-source-id: c5b1ca0948ebc47f2648e161770affa8542ca5dd
This commit is contained in:
Joshua Gross
2020-09-30 22:40:26 -07:00
committed by Facebook GitHub Bot
parent 553fb8b28d
commit 8b7fd37b42
@@ -63,9 +63,9 @@ public class MountingManager {
mViewManagerRegistry = viewManagerRegistry;
}
private static void logViewHierarchy(ViewGroup parent) {
private static void logViewHierarchy(ViewGroup parent, boolean recurse) {
int parentTag = parent.getId();
FLog.e(TAG, " <ViewGroup tag=" + parentTag + ">");
FLog.e(TAG, " <ViewGroup tag=" + parentTag + " class=" + parent.getClass().toString() + ">");
for (int i = 0; i < parent.getChildCount(); i++) {
FLog.e(
TAG,
@@ -73,11 +73,24 @@ public class MountingManager {
+ i
+ " tag="
+ parent.getChildAt(i).getId()
+ " toString="
+ parent.getChildAt(i).toString()
+ " class="
+ parent.getChildAt(i).getClass().toString()
+ ">");
}
FLog.e(TAG, " </ViewGroup tag=" + parentTag + ">");
if (recurse) {
FLog.e(TAG, "Displaying Ancestors:");
ViewParent ancestor = parent.getParent();
while (ancestor != null) {
ViewGroup ancestorViewGroup = (ancestor instanceof ViewGroup ? (ViewGroup) ancestor : null);
int ancestorId = ancestorViewGroup == null ? View.NO_ID : ancestorViewGroup.getId();
FLog.e(
TAG,
"<ViewParent tag=" + ancestorId + " class=" + ancestor.getClass().toString() + ">");
ancestor = ancestor.getParent();
}
}
}
/**
@@ -218,7 +231,7 @@ public class MountingManager {
// Display children before inserting
if (SHOW_CHANGED_VIEW_HIERARCHIES) {
FLog.e(TAG, "addViewAt: [" + tag + "] -> [" + parentTag + "] idx: " + index + " BEFORE");
logViewHierarchy(parentView);
logViewHierarchy(parentView, false);
}
try {
@@ -243,7 +256,7 @@ public class MountingManager {
public void run() {
FLog.e(
TAG, "addViewAt: [" + tag + "] -> [" + parentTag + "] idx: " + index + " AFTER");
logViewHierarchy(parentView);
logViewHierarchy(parentView, false);
}
});
}
@@ -359,7 +372,7 @@ public class MountingManager {
if (SHOW_CHANGED_VIEW_HIERARCHIES) {
// Display children before deleting any
FLog.e(TAG, "removeViewAt: [" + tag + "] -> [" + parentTag + "] idx: " + index + " BEFORE");
logViewHierarchy(parentView);
logViewHierarchy(parentView, false);
}
ViewGroupManager<ViewGroup> viewGroupManager = getViewGroupManager(viewState);
@@ -398,6 +411,7 @@ public class MountingManager {
return;
}
logViewHierarchy(parentView, true);
throw new IllegalStateException(
"Tried to remove view ["
+ tag
@@ -431,6 +445,8 @@ public class MountingManager {
// enough that we shouldn't try to change this invariant, without a lot of thought.
int childCount = viewGroupManager.getChildCount(parentView);
logViewHierarchy(parentView, true);
throw new IllegalStateException(
"Cannot remove child at index "
+ index
@@ -451,7 +467,7 @@ public class MountingManager {
FLog.e(
TAG,
"removeViewAt: [" + tag + "] -> [" + parentTag + "] idx: " + index + " AFTER");
logViewHierarchy(parentView);
logViewHierarchy(parentView, false);
}
});
}