Skip to content

Commit 0a517ae

Browse files
ryancatfacebook-github-bot
authored andcommitted
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
1 parent 12ad1ff commit 0a517ae

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java

+12-2
Original file line numberDiff line numberDiff line change
@@ -234,15 +234,25 @@ private boolean isDispatcherReady() {
234234
return true;
235235
}
236236

237+
// By default the JS touch events are dispatched at the root view. This can be overridden in
238+
// subclasses as needed.
239+
public boolean shouldDispatchJSTouchEvent(MotionEvent ev) {
240+
return true;
241+
}
242+
237243
@Override
238244
public boolean onInterceptTouchEvent(MotionEvent ev) {
239-
dispatchJSTouchEvent(ev);
245+
if (shouldDispatchJSTouchEvent(ev)) {
246+
dispatchJSTouchEvent(ev);
247+
}
240248
return super.onInterceptTouchEvent(ev);
241249
}
242250

243251
@Override
244252
public boolean onTouchEvent(MotionEvent ev) {
245-
dispatchJSTouchEvent(ev);
253+
if (shouldDispatchJSTouchEvent(ev)) {
254+
dispatchJSTouchEvent(ev);
255+
}
246256
super.onTouchEvent(ev);
247257
// In case when there is no children interested in handling touch event, we return true from
248258
// the root view in order to receive subsequent events related to that gesture

0 commit comments

Comments
 (0)