Skip to content

Commit

Permalink
NativeGestureUtil.notifyNativeGestureEnded is called
Browse files Browse the repository at this point in the history
Summary:
Changelog: [Internal] - Make sure `onChildEndedNativeGesture` is called for view managers that call `onChildStartedNativeGesture`

This affects `JSTouchDispatcher`, `JSPointerDispatcher` as they track what view is reporting native gesturing handling.

This is a bug that view managers never shared the fact that they've stopped managing a native gesture. Both `JSTouchDispatcher`, `JSPointerDispatcher` get around this by manually resetting their internal flag on ACTION_DOWN event (we will get rid of this in a later diff)

Reviewed By: javache

Differential Revision: D38850609

fbshipit-source-id: ef4afb591249bb621f42667608dc1ef20424b65c
  • Loading branch information
Luna Wei authored and facebook-github-bot committed Aug 31, 2022
1 parent 4352459 commit 823f6b7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,6 @@ public void handleMotionEvent(MotionEvent motionEvent, EventDispatcher eventDisp

// First down pointer
if (action == MotionEvent.ACTION_DOWN) {

// Reset mChildHandlingNativeGesture like JSTouchDispatcher does
mChildHandlingNativeGesture = -1;
mPrimaryPointerId = motionEvent.getPointerId(actionIndex);

// Start a "down" coalescing key
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
public static final int DEFAULT_DRAWER_WIDTH = LayoutParams.MATCH_PARENT;
private int mDrawerPosition = Gravity.START;
private int mDrawerWidth = DEFAULT_DRAWER_WIDTH;
private boolean mDragging = false;

public ReactDrawerLayout(ReactContext reactContext) {
super(reactContext);
Expand All @@ -35,6 +36,7 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {
try {
if (super.onInterceptTouchEvent(ev)) {
NativeGestureUtil.notifyNativeGestureStarted(this, ev);
mDragging = true;
return true;
}
} catch (IllegalArgumentException e) {
Expand All @@ -47,6 +49,16 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {
return false;
}

@Override
public boolean onTouchEvent(MotionEvent ev) {
int action = ev.getActionMasked();
if (action == MotionEvent.ACTION_UP && mDragging) {
NativeGestureUtil.notifyNativeGestureEnded(this, ev);
mDragging = false;
}
return super.onTouchEvent(ev);
}

/* package */ void openDrawer() {
openDrawer(mDrawerPosition);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class ReactSwipeRefreshLayout extends SwipeRefreshLayout {
private int mTouchSlop;
private float mPrevTouchX;
private boolean mIntercepted;
private boolean mNativeGestureStarted = false;

public ReactSwipeRefreshLayout(ReactContext reactContext) {
super(reactContext);
Expand Down Expand Up @@ -86,6 +87,7 @@ public void requestDisallowInterceptTouchEvent(boolean disallowIntercept) {
public boolean onInterceptTouchEvent(MotionEvent ev) {
if (shouldInterceptTouchEvent(ev) && super.onInterceptTouchEvent(ev)) {
NativeGestureUtil.notifyNativeGestureStarted(this, ev);
mNativeGestureStarted = true;

// If the pull-to-refresh gesture is interrupted by a parent with its own
// onInterceptTouchEvent then the refresh indicator gets stuck on-screen
Expand All @@ -99,6 +101,16 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {
return false;
}

@Override
public boolean onTouchEvent(MotionEvent ev) {
int action = ev.getActionMasked();
if (action == MotionEvent.ACTION_UP && mNativeGestureStarted) {
NativeGestureUtil.notifyNativeGestureEnded(this, ev);
mNativeGestureStarted = false;
}
return super.onTouchEvent(ev);
}

/**
* {@link SwipeRefreshLayout} completely bypasses ViewGroup's "disallowIntercept" by overriding
* {@link ViewGroup#onInterceptTouchEvent} and never calling super.onInterceptTouchEvent(). This
Expand Down

0 comments on commit 823f6b7

Please sign in to comment.