Skip to content

Commit

Permalink
Fix (Pointer|Touch)Events not firing after drag and scroll for Scroll…
Browse files Browse the repository at this point in the history
…View and HorizontalScrollView

Summary:
Changelog: [Android][Fixed] - Fix such that when the scrollviews call `onChildStartedNativeGesture`, they appropriately call `onChildEndedNativeGesture` to unlock the native gesture such that `JSTouchDispatcher` or `JSPointerDispatcher` will continue to emit events.

### How did we find this issue?
As React Native is adding pointer event support for different input types, we noticed after pressing and dragging on a ScrollView, hover events would not fire.

### Why was this not an issue before?
This was always an issue -- it was just that `JSTouchDispatcher` worked its way around it by explicitly setting `mChildIsHandlingNativeGesture = false` on a `ACTION_DOWN` event, [code pointer](https://github.com/facebook/react-native/blob/main/ReactAndroid/src/main/java/com/facebook/react/uimanager/JSTouchDispatcher.java#L76). Similarly, `JSPointerDispatcher` [copied this logic](https://github.com/facebook/react-native/blob/main/ReactAndroid/src/main/java/com/facebook/react/uimanager/JSPointerDispatcher.java#L106).

With new hover support in `JSPointerDispatcher` no similar workaround was put in (or even a good place to insert).

### What's next?
* As a follow-up, we should look at removing this workaround (at least for `JSPointerDispatcher`)
* By searching for usages of where we `notifyNativeGestureStarted`, it looks like `ReactDrawerLayout` and `ReactSwipeRefreshLayout` both do and don't call the symmetric `notifyNativeGestureEnded`. This will likely be an issue in the future (or maybe if we remove the workaround)

Reviewed By: mdvacca

Differential Revision: D37977982

fbshipit-source-id: 0d18767f4debbf24cfb24b54df1310f6f96a0d03
  • Loading branch information
Luna Wei authored and facebook-github-bot committed Jul 21, 2022
1 parent 27fe6f1 commit 143a0f7
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,7 @@ public boolean onTouchEvent(MotionEvent ev) {
float velocityX = mVelocityHelper.getXVelocity();
float velocityY = mVelocityHelper.getYVelocity();
ReactScrollViewHelper.emitScrollEndDragEvent(this, velocityX, velocityY);
NativeGestureUtil.notifyNativeGestureEnded(this, ev);
mDragging = false;
// After the touch finishes, we may need to do some scrolling afterwards either as a result
// of a fling or because we need to page align the content
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ public boolean onTouchEvent(MotionEvent ev) {
float velocityX = mVelocityHelper.getXVelocity();
float velocityY = mVelocityHelper.getYVelocity();
ReactScrollViewHelper.emitScrollEndDragEvent(this, velocityX, velocityY);
NativeGestureUtil.notifyNativeGestureEnded(this, ev);
mDragging = false;
// After the touch finishes, we may need to do some scrolling afterwards either as a result
// of a fling or because we need to page align the content
Expand Down

0 comments on commit 143a0f7

Please sign in to comment.