From e6d498b99b984187a56991c112c6d5df160ad538 Mon Sep 17 00:00:00 2001 From: Dave Miller Date: Tue, 15 Dec 2015 10:42:08 -0800 Subject: [PATCH] Fix case where measure is called with a view that is now off screen (and removed from clipping) Reviewed By: astreet Differential Revision: D2760119 fb-gh-sync-id: cf2723ddc94de64bba961e9390ce54f39ca4651f --- .../facebook/react/uimanager/NativeViewHierarchyManager.java | 5 +++++ .../main/java/com/facebook/react/uimanager/RootViewUtil.java | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) 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; }