Don't use MotionEvent timestamp for touch events
Differential Revision: D2554905 fb-gh-sync-id: 7f83e94948cc9ac1024e249764d445fb056f400e
This commit is contained in:
parent
e3f33ea261
commit
716f7e8ef2
|
@ -14,6 +14,7 @@ import javax.annotation.Nullable;
|
|||
import android.content.Context;
|
||||
import android.graphics.Rect;
|
||||
import android.os.Bundle;
|
||||
import android.os.SystemClock;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
|
@ -143,7 +144,8 @@ public class ReactRootView extends SizeMonitoringFrameLayout implements RootView
|
|||
// this gesture
|
||||
mChildIsHandlingNativeGesture = false;
|
||||
mTargetTag = TouchTargetHelper.findTargetTagForTouch(ev.getY(), ev.getX(), this);
|
||||
eventDispatcher.dispatchEvent(new TouchEvent(mTargetTag, TouchEventType.START, ev));
|
||||
eventDispatcher.dispatchEvent(
|
||||
new TouchEvent(mTargetTag, SystemClock.uptimeMillis(),TouchEventType.START, ev));
|
||||
} 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.
|
||||
|
@ -158,17 +160,21 @@ public class ReactRootView extends SizeMonitoringFrameLayout implements RootView
|
|||
} 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.
|
||||
eventDispatcher.dispatchEvent(new TouchEvent(mTargetTag, TouchEventType.END, ev));
|
||||
eventDispatcher.dispatchEvent(
|
||||
new TouchEvent(mTargetTag, SystemClock.uptimeMillis(), TouchEventType.END, ev));
|
||||
mTargetTag = -1;
|
||||
} else if (action == MotionEvent.ACTION_MOVE) {
|
||||
// Update pointer position for current gesture
|
||||
eventDispatcher.dispatchEvent(new TouchEvent(mTargetTag, TouchEventType.MOVE, ev));
|
||||
eventDispatcher.dispatchEvent(
|
||||
new TouchEvent(mTargetTag, SystemClock.uptimeMillis(), TouchEventType.MOVE, ev));
|
||||
} 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(new TouchEvent(mTargetTag, TouchEventType.START, ev));
|
||||
eventDispatcher.dispatchEvent(
|
||||
new TouchEvent(mTargetTag, SystemClock.uptimeMillis(), TouchEventType.START, ev));
|
||||
} else if (action == MotionEvent.ACTION_POINTER_UP) {
|
||||
// Exactly onw of the pointers goes up
|
||||
eventDispatcher.dispatchEvent(new TouchEvent(mTargetTag, TouchEventType.END, ev));
|
||||
eventDispatcher.dispatchEvent(
|
||||
new TouchEvent(mTargetTag, SystemClock.uptimeMillis(), TouchEventType.END, ev));
|
||||
} else if (action == MotionEvent.ACTION_CANCEL) {
|
||||
dispatchCancelEvent(ev);
|
||||
mTargetTag = -1;
|
||||
|
@ -213,7 +219,11 @@ public class ReactRootView extends SizeMonitoringFrameLayout implements RootView
|
|||
!mChildIsHandlingNativeGesture,
|
||||
"Expected to not have already sent a cancel for this gesture");
|
||||
Assertions.assertNotNull(eventDispatcher).dispatchEvent(
|
||||
new TouchEvent(mTargetTag, TouchEventType.CANCEL, androidEvent));
|
||||
new TouchEvent(
|
||||
mTargetTag,
|
||||
SystemClock.uptimeMillis(),
|
||||
TouchEventType.CANCEL,
|
||||
androidEvent));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -25,8 +25,12 @@ public class TouchEvent extends Event<TouchEvent> {
|
|||
private final TouchEventType mTouchEventType;
|
||||
private final short mCoalescingKey;
|
||||
|
||||
public TouchEvent(int viewTag, TouchEventType touchEventType, MotionEvent motionEventToCopy) {
|
||||
super(viewTag, motionEventToCopy.getEventTime());
|
||||
public TouchEvent(
|
||||
int viewTag,
|
||||
long timestampMs,
|
||||
TouchEventType touchEventType,
|
||||
MotionEvent motionEventToCopy) {
|
||||
super(viewTag, timestampMs);
|
||||
mTouchEventType = touchEventType;
|
||||
mMotionEvent = MotionEvent.obtain(motionEventToCopy);
|
||||
|
||||
|
|
Loading…
Reference in New Issue