diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/Event.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/Event.java index b045cd8984f..909a5644337 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/Event.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/Event.java @@ -56,8 +56,16 @@ public abstract class Event { init(-1, viewTag); } - /** This method needs to be called before event is sent to event dispatcher. */ protected void init(int surfaceId, int viewTag) { + init(surfaceId, viewTag, SystemClock.uptimeMillis()); + } + + /** + * This method needs to be called before event is sent to event dispatcher. Event timestamps can + * optionally be dated/backdated to a custom time: for example, touch events should be dated with + * the system event time. + */ + protected void init(int surfaceId, int viewTag, long timestampMs) { mSurfaceId = surfaceId; mViewTag = viewTag; @@ -73,7 +81,7 @@ public abstract class Event { // At some point it would be great to pass the SurfaceContext here instead. mUIManagerType = (surfaceId == -1 ? UIManagerType.DEFAULT : UIManagerType.FABRIC); - mTimestampMs = SystemClock.uptimeMillis(); + mTimestampMs = timestampMs; mInitialized = true; } diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/TouchEvent.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/TouchEvent.java index 554456ccccc..de64e8c8f90 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/TouchEvent.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/TouchEvent.java @@ -96,7 +96,7 @@ public class TouchEvent extends Event { float viewX, float viewY, TouchEventCoalescingKeyHelper touchEventCoalescingKeyHelper) { - super.init(surfaceId, viewTag); + super.init(surfaceId, viewTag, motionEventToCopy.getEventTime()); SoftAssertions.assertCondition( gestureStartTime != UNSET, "Gesture start time must be initialized");