From 0a517ae43892fb764d829f8bae56c1ac58356b1b Mon Sep 17 00:00:00 2001 From: Xin Chen Date: Wed, 23 Mar 2022 22:21:29 -0700 Subject: [PATCH] RN] Add public API to ReactRootView to control if JS touch events are dispatched Summary: This diff adds flag to `ReactRootView` to control if the touch event is to be dispatched to the JS side. This is needed for subclass of `ReactRootView` to control if the dispatch is needed. Reviewed By: javache Differential Revision: D35033684 fbshipit-source-id: febab6988cc3e4259e726d03d797dd0ffc978d24 --- .../java/com/facebook/react/ReactRootView.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java b/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java index 3d5ee968202..89fff09bd7b 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java +++ b/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java @@ -234,15 +234,25 @@ public class ReactRootView extends FrameLayout implements RootView, ReactRoot { return true; } + // By default the JS touch events are dispatched at the root view. This can be overridden in + // subclasses as needed. + public boolean shouldDispatchJSTouchEvent(MotionEvent ev) { + return true; + } + @Override public boolean onInterceptTouchEvent(MotionEvent ev) { - dispatchJSTouchEvent(ev); + if (shouldDispatchJSTouchEvent(ev)) { + dispatchJSTouchEvent(ev); + } return super.onInterceptTouchEvent(ev); } @Override public boolean onTouchEvent(MotionEvent ev) { - dispatchJSTouchEvent(ev); + if (shouldDispatchJSTouchEvent(ev)) { + dispatchJSTouchEvent(ev); + } super.onTouchEvent(ev); // In case when there is no children interested in handling touch event, we return true from // the root view in order to receive subsequent events related to that gesture