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
This commit is contained in:
Andrei Coman 2016-09-06 04:57:47 -07:00 committed by Facebook Github Bot 7
parent 4f004fa3e5
commit 79f3950d62
2 changed files with 4 additions and 4 deletions

View File

@ -39,7 +39,7 @@ public abstract class Event<T extends Event> {
*/
protected void init(int viewTag) {
mViewTag = viewTag;
mTimestampMs = SystemClock.nanoTime();
mTimestampMs = SystemClock.uptimeMillis();
mInitialized = true;
}

View File

@ -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<Object>() {
@Override
@ -80,7 +80,7 @@ public class RootViewTest {
}
});
PowerMockito.mockStatic(SystemClock.class);
PowerMockito.when(SystemClock.nanoTime()).thenAnswer(new Answer<Object>() {
PowerMockito.when(SystemClock.uptimeMillis()).thenAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
return ts;
@ -116,7 +116,7 @@ public class RootViewTest {
rootView.startReactApplication(instanceManager, "");
rootView.simulateAttachForTesting();
long ts = SystemClock.nanoTime();
long ts = SystemClock.uptimeMillis();
// Test ACTION_DOWN event
rootView.onTouchEvent(