Skip to content

Commit

Permalink
Fix panResponder nativeEvent.locationX and locationY values on touch …
Browse files Browse the repository at this point in the history
…move

Summary:
Fixes #12591

The Android JSTouchDispatcher was using `mTargetCoordinates` when creating the TouchEvent for a move. However, these are final values which are set when the touch down is received. When the user's finger moves, it's important to be able to track the coordinates of the touch as it moves. Thus, we need to update the x,y coordinates by calling `TouchTargetHelper` on each move event.
Closes #15123

Reviewed By: achen1

Differential Revision: D5476663

Pulled By: shergin

fbshipit-source-id: ce79e96490f3657a13f9114fcc93e80d5fdbebaf
  • Loading branch information
newyankeecodeshop authored and facebook-github-bot committed Aug 28, 2017
1 parent dc22bd6 commit 1a262a7
Showing 1 changed file with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

import android.view.MotionEvent;
import android.view.ViewGroup;

import com.facebook.common.logging.FLog;
import com.facebook.infer.annotation.Assertions;
import com.facebook.react.common.ReactConstants;
Expand Down Expand Up @@ -74,12 +73,7 @@ public void handleTouchEvent(MotionEvent ev, EventDispatcher eventDispatcher) {
// this gesture
mChildIsHandlingNativeGesture = false;
mGestureStartTime = ev.getEventTime();
mTargetTag = TouchTargetHelper.findTargetTagAndCoordinatesForTouch(
ev.getX(),
ev.getY(),
mRootViewGroup,
mTargetCoordinates,
null);
mTargetTag = findTargetTagAndSetCoordinates(ev);
eventDispatcher.dispatchEvent(
TouchEvent.obtain(
mTargetTag,
Expand All @@ -103,6 +97,7 @@ public void handleTouchEvent(MotionEvent ev, EventDispatcher eventDispatcher) {
} else if (action == MotionEvent.ACTION_UP) {
// End of the gesture. We reset target tag to -1 and expect no further event associated with
// this gesture.
findTargetTagAndSetCoordinates(ev);
eventDispatcher.dispatchEvent(
TouchEvent.obtain(
mTargetTag,
Expand All @@ -116,6 +111,7 @@ public void handleTouchEvent(MotionEvent ev, EventDispatcher eventDispatcher) {
mGestureStartTime = TouchEvent.UNSET;
} else if (action == MotionEvent.ACTION_MOVE) {
// Update pointer position for current gesture
findTargetTagAndSetCoordinates(ev);
eventDispatcher.dispatchEvent(
TouchEvent.obtain(
mTargetTag,
Expand Down Expand Up @@ -165,6 +161,12 @@ public void handleTouchEvent(MotionEvent ev, EventDispatcher eventDispatcher) {
}
}

private int findTargetTagAndSetCoordinates(MotionEvent ev) {
// This method updates `mTargetCoordinates` with coordinates for the motion event.
return TouchTargetHelper.findTargetTagAndCoordinatesForTouch(
ev.getX(), ev.getY(), mRootViewGroup, mTargetCoordinates, null);
}

private void dispatchCancelEvent(MotionEvent androidEvent, EventDispatcher eventDispatcher) {
// This means the gesture has already ended, via some other CANCEL or UP event. This is not
// expected to happen very often as it would mean some child View has decided to intercept the
Expand Down

0 comments on commit 1a262a7

Please sign in to comment.