diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/JSTouchDispatcher.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/JSTouchDispatcher.java index ba8d56be8ad2fe..86abf04fdd3f19 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/JSTouchDispatcher.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/JSTouchDispatcher.java @@ -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; @@ -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, @@ -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, @@ -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, @@ -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