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 dd40b7a16..2193fa3d4 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/NativeViewHierarchyManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/NativeViewHierarchyManager.java @@ -467,6 +467,11 @@ public class NativeViewHierarchyManager { } View rootView = (View) RootViewUtil.getRootView(v); + // It is possible that the RootView can't be found because this view is no longer on the screen + // and has been removed by clipping + if (rootView == null) { + throw new NoSuchNativeViewException("Native view " + tag + " is no longer on screen"); + } rootView.getLocationInWindow(outputBuffer); int rootX = outputBuffer[0]; int rootY = outputBuffer[1]; diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/RootViewUtil.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/RootViewUtil.java index e12a76488..f9076cbe4 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/RootViewUtil.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/RootViewUtil.java @@ -26,7 +26,9 @@ public class RootViewUtil { return (RootView) current; } ViewParent next = current.getParent(); - Assertions.assertNotNull(next); + if (next == null) { + return null; + } Assertions.assertCondition(next instanceof View); current = (View) next; }