Update Android Touch events

Summary: public

This moves Android touch events to parity with iOS.  The locationX,Y value passed to js now is view relative to the view that is handling the touch.
The pageX,Y is now relative to the root view.

Reviewed By: andreicoman11

Differential Revision: D2670028

fb-gh-sync-id: 5438640d6c78633629b9a308a59cc306bb07815e
This commit is contained in:
Dave Miller
2015-11-23 08:00:46 -08:00
committed by facebook-github-bot-3
parent e0d53e1c48
commit 0c2ee5d480
4 changed files with 125 additions and 35 deletions

View File

@@ -61,6 +61,9 @@ 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;
private boolean mAttachScheduled = false;
@@ -143,9 +146,19 @@ public class ReactRootView extends SizeMonitoringFrameLayout implements RootView
// {@link #findTargetTagForTouch} to find react view ID that will be responsible for handling
// this gesture
mChildIsHandlingNativeGesture = false;
mTargetTag = TouchTargetHelper.findTargetTagForTouch(ev.getY(), ev.getX(), this);
mTargetTag = TouchTargetHelper.findTargetTagAndCoordinatesForTouch(
ev.getY(),
ev.getX(),
this,
mTargetCoordinates);
eventDispatcher.dispatchEvent(
TouchEvent.obtain(mTargetTag, SystemClock.uptimeMillis(), TouchEventType.START, ev));
TouchEvent.obtain(
mTargetTag,
SystemClock.uptimeMillis(),
TouchEventType.START,
ev,
mTargetCoordinates[1],
mTargetCoordinates[0]));
} 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.
@@ -161,20 +174,44 @@ public class ReactRootView extends SizeMonitoringFrameLayout implements RootView
// End of the gesture. We reset target tag to -1 and expect no further event associated with
// this gesture.
eventDispatcher.dispatchEvent(
TouchEvent.obtain(mTargetTag, SystemClock.uptimeMillis(), TouchEventType.END, ev));
TouchEvent.obtain(
mTargetTag,
SystemClock.uptimeMillis(),
TouchEventType.END,
ev,
mTargetCoordinates[1],
mTargetCoordinates[0]));
mTargetTag = -1;
} else if (action == MotionEvent.ACTION_MOVE) {
// Update pointer position for current gesture
eventDispatcher.dispatchEvent(
TouchEvent.obtain(mTargetTag, SystemClock.uptimeMillis(), TouchEventType.MOVE, ev));
TouchEvent.obtain(
mTargetTag,
SystemClock.uptimeMillis(),
TouchEventType.MOVE,
ev,
mTargetCoordinates[1],
mTargetCoordinates[0]));
} 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(
TouchEvent.obtain(mTargetTag, SystemClock.uptimeMillis(), TouchEventType.START, ev));
TouchEvent.obtain(
mTargetTag,
SystemClock.uptimeMillis(),
TouchEventType.START,
ev,
mTargetCoordinates[1],
mTargetCoordinates[0]));
} else if (action == MotionEvent.ACTION_POINTER_UP) {
// Exactly onw of the pointers goes up
eventDispatcher.dispatchEvent(
TouchEvent.obtain(mTargetTag, SystemClock.uptimeMillis(), TouchEventType.END, ev));
TouchEvent.obtain(
mTargetTag,
SystemClock.uptimeMillis(),
TouchEventType.END,
ev,
mTargetCoordinates[1],
mTargetCoordinates[0]));
} else if (action == MotionEvent.ACTION_CANCEL) {
dispatchCancelEvent(ev);
mTargetTag = -1;
@@ -223,7 +260,9 @@ public class ReactRootView extends SizeMonitoringFrameLayout implements RootView
mTargetTag,
SystemClock.uptimeMillis(),
TouchEventType.CANCEL,
androidEvent));
androidEvent,
mTargetCoordinates[1],
mTargetCoordinates[0]));
}
@Override