diff --git a/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java b/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java index 0f51cd86d..3450f883a 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java +++ b/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java @@ -61,8 +61,6 @@ public class ReactRootView extends SizeMonitoringFrameLayout implements RootView private @Nullable String mJSModuleName; private @Nullable Bundle mLaunchOptions; private int mTargetTag = -1; - // Note mTargetCoordinates are Y,X - // TODO: t9136625 tracks moving to X,Y private final float[] mTargetCoordinates = new float[2]; private boolean mChildIsHandlingNativeGesture = false; private boolean mWasMeasured = false; @@ -147,8 +145,8 @@ public class ReactRootView extends SizeMonitoringFrameLayout implements RootView // this gesture mChildIsHandlingNativeGesture = false; mTargetTag = TouchTargetHelper.findTargetTagAndCoordinatesForTouch( - ev.getY(), ev.getX(), + ev.getY(), this, mTargetCoordinates); eventDispatcher.dispatchEvent( @@ -157,8 +155,8 @@ public class ReactRootView extends SizeMonitoringFrameLayout implements RootView SystemClock.uptimeMillis(), TouchEventType.START, ev, - mTargetCoordinates[1], - mTargetCoordinates[0])); + mTargetCoordinates[0], + mTargetCoordinates[1])); } else if (mChildIsHandlingNativeGesture) { // If the touch was intercepted by a child, we've already sent a cancel event to JS for this // gesture, so we shouldn't send any more touches related to it. @@ -179,8 +177,8 @@ public class ReactRootView extends SizeMonitoringFrameLayout implements RootView SystemClock.uptimeMillis(), TouchEventType.END, ev, - mTargetCoordinates[1], - mTargetCoordinates[0])); + mTargetCoordinates[0], + mTargetCoordinates[1])); mTargetTag = -1; } else if (action == MotionEvent.ACTION_MOVE) { // Update pointer position for current gesture @@ -190,8 +188,8 @@ public class ReactRootView extends SizeMonitoringFrameLayout implements RootView SystemClock.uptimeMillis(), TouchEventType.MOVE, ev, - mTargetCoordinates[1], - mTargetCoordinates[0])); + mTargetCoordinates[0], + mTargetCoordinates[1])); } else if (action == MotionEvent.ACTION_POINTER_DOWN) { // New pointer goes down, this can only happen after ACTION_DOWN is sent for the first pointer eventDispatcher.dispatchEvent( @@ -200,8 +198,8 @@ public class ReactRootView extends SizeMonitoringFrameLayout implements RootView SystemClock.uptimeMillis(), TouchEventType.START, ev, - mTargetCoordinates[1], - mTargetCoordinates[0])); + mTargetCoordinates[0], + mTargetCoordinates[1])); } else if (action == MotionEvent.ACTION_POINTER_UP) { // Exactly onw of the pointers goes up eventDispatcher.dispatchEvent( @@ -210,8 +208,8 @@ public class ReactRootView extends SizeMonitoringFrameLayout implements RootView SystemClock.uptimeMillis(), TouchEventType.END, ev, - mTargetCoordinates[1], - mTargetCoordinates[0])); + mTargetCoordinates[0], + mTargetCoordinates[1])); } else if (action == MotionEvent.ACTION_CANCEL) { dispatchCancelEvent(ev); mTargetTag = -1; @@ -261,8 +259,8 @@ public class ReactRootView extends SizeMonitoringFrameLayout implements RootView SystemClock.uptimeMillis(), TouchEventType.CANCEL, androidEvent, - mTargetCoordinates[1], - mTargetCoordinates[0])); + mTargetCoordinates[0], + mTargetCoordinates[1])); } @Override diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/NativeViewHierarchyManager.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/NativeViewHierarchyManager.java index 28b95139c..ac6ae4e46 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/NativeViewHierarchyManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/NativeViewHierarchyManager.java @@ -437,7 +437,7 @@ public class NativeViewHierarchyManager { if (view == null) { throw new JSApplicationIllegalArgumentException("Could not find view with tag " + reactTag); } - return TouchTargetHelper.findTargetTagForTouch(touchY, touchX, (ViewGroup) view); + return TouchTargetHelper.findTargetTagForTouch(touchX, touchY, (ViewGroup) view); } public void setJSResponder(int reactTag, int initialReactTag, boolean blockNativeResponder) { diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/TouchTargetHelper.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/TouchTargetHelper.java index 24a4d2869..8564258ba 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/TouchTargetHelper.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/TouchTargetHelper.java @@ -35,38 +35,38 @@ public class TouchTargetHelper { * Find touch event target view within the provided container given the coordinates provided * via {@link MotionEvent}. * - * @param eventY the Y screen coordinate of the touch location * @param eventX the X screen coordinate of the touch location + * @param eventY the Y screen coordinate of the touch location * @param viewGroup the container view to traverse * @return the react tag ID of the child view that should handle the event */ public static int findTargetTagForTouch( - float eventY, float eventX, + float eventY, ViewGroup viewGroup) { - return findTargetTagAndCoordinatesForTouch(eventY, eventX, viewGroup, mEventCoords); + return findTargetTagAndCoordinatesForTouch(eventX, eventY, viewGroup, mEventCoords); } /** * Find touch event target view within the provided container given the coordinates provided * via {@link MotionEvent}. * - * @param eventY the Y screen coordinate of the touch location * @param eventX the X screen coordinate of the touch location + * @param eventY the Y screen coordinate of the touch location * @param viewGroup the container view to traverse - * @param viewCoords an out parameter that will return the Y,X value in the target view + * @param viewCoords an out parameter that will return the X,Y value in the target view * @return the react tag ID of the child view that should handle the event */ public static int findTargetTagAndCoordinatesForTouch( - float eventY, float eventX, + float eventY, ViewGroup viewGroup, float[] viewCoords) { UiThreadUtil.assertOnUiThread(); int targetTag = viewGroup.getId(); // Store eventCoords in array so that they are modified to be relative to the targetView found. - viewCoords[0] = eventY; - viewCoords[1] = eventX; + viewCoords[0] = eventX; + viewCoords[1] = eventY; View nativeTargetView = findTouchTargetView(viewCoords, viewGroup); if (nativeTargetView != null) { View reactTargetView = findClosestReactAncestor(nativeTargetView); @@ -105,16 +105,16 @@ public class TouchTargetHelper { // coordinates relative to the child // We need to store the existing X,Y for the viewGroup away as it is possible this child // will not actually be the target and so we restore them if not - float restoreY = eventCoords[0]; - float restoreX = eventCoords[1]; - eventCoords[0] = childPoint.y; - eventCoords[1] = childPoint.x; + float restoreX = eventCoords[0]; + float restoreY = eventCoords[1]; + eventCoords[0] = childPoint.x; + eventCoords[1] = childPoint.y; View targetView = findTouchTargetViewWithPointerEvents(eventCoords, child); if (targetView != null) { return targetView; } - eventCoords[0] = restoreY; - eventCoords[1] = restoreX; + eventCoords[0] = restoreX; + eventCoords[1] = restoreY; } } return viewGroup; @@ -126,8 +126,8 @@ public class TouchTargetHelper { * This code is taken from {@link ViewGroup#isTransformedTouchPointInView()} */ private static boolean isTransformedTouchPointInView( - float y, float x, + float y, ViewGroup parent, View child, PointF outLocalPoint) { @@ -190,7 +190,7 @@ public class TouchTargetHelper { } } - private static int getTouchTargetForView(View targetView, float eventY, float eventX) { + private static int getTouchTargetForView(View targetView, float eventX, float eventY) { if (targetView instanceof ReactCompoundView) { // Use coordinates relative to the view, which have been already computed by // {@link #findTouchTargetView()}.