From 7af33311717af3f76abd29c083c4812743da4702 Mon Sep 17 00:00:00 2001 From: Ahmed El-Helw Date: Wed, 26 Oct 2016 13:01:08 -0700 Subject: [PATCH] Don't crash on dropping a dropped view in Nodes Summary: In Nodes, we sometimes get crashes when we drop an already dropped view. For now, this catches the exception to allow things to be handled gracefully (until we can identify the actual root cause). #accept2ship Reviewed By: sriramramani Differential Revision: D4059333 --- .../flat/FlatNativeViewHierarchyManager.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/flat/FlatNativeViewHierarchyManager.java b/ReactAndroid/src/main/java/com/facebook/react/flat/FlatNativeViewHierarchyManager.java index 7ebd399cc..d7d74eb2e 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/flat/FlatNativeViewHierarchyManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/flat/FlatNativeViewHierarchyManager.java @@ -191,8 +191,12 @@ import com.facebook.react.uimanager.ViewManagerRegistry; int viewToDrop = viewsToDrop.keyAt(i); View view = null; if (viewToDrop > 0) { - view = resolveView(viewToDrop); - dropView(view); + try { + view = resolveView(viewToDrop); + dropView(view); + } catch (Exception e) { + // the view is already dropped, nothing we can do + } } else { // Root views are noted with a negative tag from StateBuilder. removeRootView(-viewToDrop); @@ -229,7 +233,13 @@ import com.facebook.react.uimanager.ViewManagerRegistry; SparseArray detachedViews = flatViewGroup.getDetachedViews(); for (int i = 0, size = detachedViews.size(); i < size; i++) { View detachedChild = detachedViews.valueAt(i); - dropView(detachedChild); + try { + dropView(detachedChild); + } catch (Exception e) { + // if the view is already dropped, ignore any exceptions + // in reality, we should find out the edge cases that cause + // this to happen and properly fix them. + } // trigger onDetachedFromWindow and clean up this detached/clipped view flatViewGroup.removeDetachedView(detachedChild); }