Skip to content

Commit

Permalink
RN] Add public API to ReactRootView to control if JS touch events are…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
ryancat authored and facebook-github-bot committed Mar 24, 2022
1 parent 12ad1ff commit 0a517ae
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java
Original file line number Diff line number Diff line change
Expand Up @@ -234,15 +234,25 @@ private boolean isDispatcherReady() {
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
Expand Down

0 comments on commit 0a517ae

Please sign in to comment.