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.content.Context;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.SystemClock;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
@ -143,7 +144,8 @@ public class ReactRootView extends SizeMonitoringFrameLayout implements RootView
|
||||||
// this gesture
|
// this gesture
|
||||||
mChildIsHandlingNativeGesture = false;
|
mChildIsHandlingNativeGesture = false;
|
||||||
mTargetTag = TouchTargetHelper.findTargetTagForTouch(ev.getY(), ev.getX(), this);
|
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) {
|
} else if (mChildIsHandlingNativeGesture) {
|
||||||
// If the touch was intercepted by a child, we've already sent a cancel event to JS for this
|
// 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.
|
// 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) {
|
} else if (action == MotionEvent.ACTION_UP) {
|
||||||
// End of the gesture. We reset target tag to -1 and expect no further event associated with
|
// End of the gesture. We reset target tag to -1 and expect no further event associated with
|
||||||
// this gesture.
|
// this gesture.
|
||||||
eventDispatcher.dispatchEvent(new TouchEvent(mTargetTag, TouchEventType.END, ev));
|
eventDispatcher.dispatchEvent(
|
||||||
|
new TouchEvent(mTargetTag, SystemClock.uptimeMillis(), TouchEventType.END, ev));
|
||||||
mTargetTag = -1;
|
mTargetTag = -1;
|
||||||
} else if (action == MotionEvent.ACTION_MOVE) {
|
} else if (action == MotionEvent.ACTION_MOVE) {
|
||||||
// Update pointer position for current gesture
|
// 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) {
|
} else if (action == MotionEvent.ACTION_POINTER_DOWN) {
|
||||||
// New pointer goes down, this can only happen after ACTION_DOWN is sent for the first pointer
|
// 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) {
|
} else if (action == MotionEvent.ACTION_POINTER_UP) {
|
||||||
// Exactly onw of the pointers goes 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) {
|
} else if (action == MotionEvent.ACTION_CANCEL) {
|
||||||
dispatchCancelEvent(ev);
|
dispatchCancelEvent(ev);
|
||||||
mTargetTag = -1;
|
mTargetTag = -1;
|
||||||
|
@ -213,7 +219,11 @@ public class ReactRootView extends SizeMonitoringFrameLayout implements RootView
|
||||||
!mChildIsHandlingNativeGesture,
|
!mChildIsHandlingNativeGesture,
|
||||||
"Expected to not have already sent a cancel for this gesture");
|
"Expected to not have already sent a cancel for this gesture");
|
||||||
Assertions.assertNotNull(eventDispatcher).dispatchEvent(
|
Assertions.assertNotNull(eventDispatcher).dispatchEvent(
|
||||||
new TouchEvent(mTargetTag, TouchEventType.CANCEL, androidEvent));
|
new TouchEvent(
|
||||||
|
mTargetTag,
|
||||||
|
SystemClock.uptimeMillis(),
|
||||||
|
TouchEventType.CANCEL,
|
||||||
|
androidEvent));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -25,8 +25,12 @@ public class TouchEvent extends Event<TouchEvent> {
|
||||||
private final TouchEventType mTouchEventType;
|
private final TouchEventType mTouchEventType;
|
||||||
private final short mCoalescingKey;
|
private final short mCoalescingKey;
|
||||||
|
|
||||||
public TouchEvent(int viewTag, TouchEventType touchEventType, MotionEvent motionEventToCopy) {
|
public TouchEvent(
|
||||||
super(viewTag, motionEventToCopy.getEventTime());
|
int viewTag,
|
||||||
|
long timestampMs,
|
||||||
|
TouchEventType touchEventType,
|
||||||
|
MotionEvent motionEventToCopy) {
|
||||||
|
super(viewTag, timestampMs);
|
||||||
mTouchEventType = touchEventType;
|
mTouchEventType = touchEventType;
|
||||||
mMotionEvent = MotionEvent.obtain(motionEventToCopy);
|
mMotionEvent = MotionEvent.obtain(motionEventToCopy);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue