Fix XY coords to be XY instead of YX

Summary: public

This fixes the ordering of methods in touch handling to take their arguments as X,Y instead of Y,X.

This is really just internal cleanup of native touch handling.

Reviewed By: andreicoman11

Differential Revision: D2703003

fb-gh-sync-id: d169436d21fd11c1a9cb251e7e0b57b2094699e4
This commit is contained in:
Dave Miller 2015-12-01 04:41:04 -08:00 committed by facebook-github-bot-2
parent d08727d99f
commit 7377fdcc70
3 changed files with 30 additions and 32 deletions

View File

@ -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

View File

@ -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) {

View File

@ -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()}.