From 79f3950d62dcd34011851813fba07d02f730cda0 Mon Sep 17 00:00:00 2001 From: Andrei Coman Date: Tue, 6 Sep 2016 04:57:47 -0700 Subject: [PATCH] Fix timestamps on android touch events to use milliseconds, to be Summary: Landing D3528215 again, now that D3593884 has landed and makes that easier. Copy-paste summary from previous diff: So PanReponder.onPanResponderRelease/onPanResponderTerminate receive a gestureState object containing a onPanResponderTerminate.vx/vy property. On Android and iOS, they appear to be orders of magnitude different, which appear to be due to the different scale of timestamps that are used when generating touch events. This pull request fixes the timestamps to be milliseconds on both platforms (since I assume iOS is the more authoritative one, and is the one that react-native-viewpager's vx thresholds written written to compare against.) As far as I can tell, the RN code doesn't use the vx/vy properties, so they should be okay. And looks like the RN code only cares about relative values of startTimestamp/currentTimestamp/previousTimestamp though, so should be fine too. it's quite possible there will be downstream android breakage with this change, particularly for those who are already compensating for the RN discrepancy. Reviewed By: foghina Differential Revision: D3819761 fbshipit-source-id: fd2d85748ae6a9cde6af715aabb620f340c2220c --- .../java/com/facebook/react/uimanager/events/Event.java | 2 +- .../src/test/java/com/facebook/react/RootViewTest.java | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) 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 d54e6ab6a780e5..4da9ed777d3758 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 @@ -39,7 +39,7 @@ protected Event(int viewTag) { */ protected void init(int viewTag) { mViewTag = viewTag; - mTimestampMs = SystemClock.nanoTime(); + mTimestampMs = SystemClock.uptimeMillis(); mInitialized = true; } diff --git a/ReactAndroid/src/test/java/com/facebook/react/RootViewTest.java b/ReactAndroid/src/test/java/com/facebook/react/RootViewTest.java index 2eb7f5ed87d8ae..05d679a205d886 100644 --- a/ReactAndroid/src/test/java/com/facebook/react/RootViewTest.java +++ b/ReactAndroid/src/test/java/com/facebook/react/RootViewTest.java @@ -65,7 +65,7 @@ public class RootViewTest { @Before public void setUp() { - final long ts = SystemClock.nanoTime(); + final long ts = SystemClock.uptimeMillis(); PowerMockito.mockStatic(Arguments.class); PowerMockito.when(Arguments.createArray()).thenAnswer(new Answer() { @Override @@ -80,7 +80,7 @@ public Object answer(InvocationOnMock invocation) throws Throwable { } }); PowerMockito.mockStatic(SystemClock.class); - PowerMockito.when(SystemClock.nanoTime()).thenAnswer(new Answer() { + PowerMockito.when(SystemClock.uptimeMillis()).thenAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { return ts; @@ -116,7 +116,7 @@ public void testTouchEmitter() { rootView.startReactApplication(instanceManager, ""); rootView.simulateAttachForTesting(); - long ts = SystemClock.nanoTime(); + long ts = SystemClock.uptimeMillis(); // Test ACTION_DOWN event rootView.onTouchEvent(