Fix panResponder nativeEvent.locationX and locationY values on touch 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 https://github.com/facebook/react-native/pull/15123

Reviewed By: achen1

Differential Revision: D5476663

Pulled By: shergin

fbshipit-source-id: ce79e96490f3657a13f9114fcc93e80d5fdbebaf
This commit is contained in:
Andrew Goodale 2017-08-27 22:03:40 -07:00 committed by Facebook Github Bot
parent dc22bd638f
commit 1a262a7c7d
1 changed files with 9 additions and 7 deletions

View File

@ -11,7 +11,6 @@ package com.facebook.react.uimanager;
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;
@ -74,12 +73,7 @@ public class JSTouchDispatcher {
// 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,
@ -103,6 +97,7 @@ public class JSTouchDispatcher {
} 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,
@ -116,6 +111,7 @@ public class JSTouchDispatcher {
mGestureStartTime = TouchEvent.UNSET;
} else if (action == MotionEvent.ACTION_MOVE) {
// Update pointer position for current gesture
findTargetTagAndSetCoordinates(ev);
eventDispatcher.dispatchEvent(
TouchEvent.obtain(
mTargetTag,
@ -165,6 +161,12 @@ public class JSTouchDispatcher {
}
}
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