From 36c4e42d82498a37b023f6a162b871581254ff2b Mon Sep 17 00:00:00 2001 From: Xin Chen Date: Tue, 26 Apr 2022 14:18:17 -0700 Subject: [PATCH] Add null check for gesture ended notifier Summary: The `notifyNativeGestureEnded` API is added to notify user gesture ended, so that any optimization we had during handling the gesture can be restored. It's possible that when the gesture finishes, the RootView is already unmounted from the native side. This might happen when user starts a gesture that caused leave of the RN screen, or close the app. Changelog: [Android][Internal] - Avoid NPE for gesture notifier Reviewed By: javache Differential Revision: D35902523 fbshipit-source-id: 9bb5819a53dd053290031eebaae1b8f0318ae534 --- .../facebook/react/uimanager/events/NativeGestureUtil.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/NativeGestureUtil.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/NativeGestureUtil.java index 00d860593a7..d39a9511591 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/NativeGestureUtil.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/NativeGestureUtil.java @@ -9,6 +9,7 @@ package com.facebook.react.uimanager.events; import android.view.MotionEvent; import android.view.View; +import com.facebook.react.uimanager.RootView; import com.facebook.react.uimanager.RootViewUtil; /** Utilities for native Views that interpret native gestures (e.g. ScrollView, ViewPager, etc.). */ @@ -35,6 +36,9 @@ public class NativeGestureUtil { * @param event the MotionEvent that caused the gesture to be ended */ public static void notifyNativeGestureEnded(View view, MotionEvent event) { - RootViewUtil.getRootView(view).onChildEndedNativeGesture(view, event); + RootView rootView = RootViewUtil.getRootView(view); + if (rootView != null) { + rootView.onChildEndedNativeGesture(view, event); + } } }