From de3711e1fc550bdacab989e11c6c489350806070 Mon Sep 17 00:00:00 2001 From: "Andrew Chen (Eng)" Date: Wed, 14 Nov 2018 10:46:18 -0800 Subject: [PATCH] Fix crash when releasing RN views Summary: There are cases where we're trying to drop a view that is not associated with a ViewManager. This is likely caused by race conditions that can occur if we're dropping a view from JS (when it's no longer used) but at the same time dropping it from native (when layout animation ends, when the rootview gets unmounted). In either of those cases, it should be safe to ignore the drop operation because the view was likely dropped already. Reviewed By: mdvacca Differential Revision: D13036643 fbshipit-source-id: 260ffb56d32a0d670ad08f449b8df165b2533195 --- .../facebook/react/uimanager/NativeViewHierarchyManager.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/NativeViewHierarchyManager.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/NativeViewHierarchyManager.java index 1e079af1926162..6ff94ffa96ecf3 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/NativeViewHierarchyManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/NativeViewHierarchyManager.java @@ -563,6 +563,11 @@ protected synchronized final void addRootViewGroup( */ protected synchronized void dropView(View view) { UiThreadUtil.assertOnUiThread(); + if (mTagsToViewManagers.get(view.getId()) == null) { + // This view has already been dropped (likely due to a threading issue caused by async js + // execution). Ignore this drop operation. + return; + } if (!mRootTags.get(view.getId())) { // For non-root views we notify viewmanager with {@link ViewManager#onDropInstance} resolveViewManager(view.getId()).onDropViewInstance(view);