Skip to content

Commit

Permalink
Add null check for gesture ended notifier
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ryancat authored and facebook-github-bot committed Apr 26, 2022
1 parent 1a3eaa5 commit 36c4e42
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

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.). */
Expand All @@ -35,6 +36,9 @@ public static void notifyNativeGestureStarted(View view, MotionEvent event) {
* @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);
}
}
}

0 comments on commit 36c4e42

Please sign in to comment.