Skip to content

Commit

Permalink
Fix timestamps on android touch events to use milliseconds, to be
Browse files Browse the repository at this point in the history
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
  • Loading branch information
andreicoman11 authored and Facebook Github Bot 7 committed Sep 6, 2016
1 parent 4f004fa commit 79f3950
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ protected Event(int viewTag) {
*/
protected void init(int viewTag) {
mViewTag = viewTag;
mTimestampMs = SystemClock.nanoTime();
mTimestampMs = SystemClock.uptimeMillis();
mInitialized = true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -80,7 +80,7 @@ public Object answer(InvocationOnMock invocation) throws Throwable {
}
});
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;
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 79f3950

Please sign in to comment.