Skip to content

Commit b48e595

Browse files
committed
Fix timestamps on android touch events to use milliseconds, to be consistent with iOS
Summary: 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. Closes facebook/react-native#8199 Differential Revision: D3528215 Pulled By: dmmiller fbshipit-source-id: cbd25bb7e7bb87fa77b661a057643a6ea97bc3f1
1 parent b70dcea commit b48e595

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

ReactViewPager.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,14 @@ private class PageChangeListener implements OnPageChangeListener {
9191
@Override
9292
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
9393
mEventDispatcher.dispatchEvent(
94-
new PageScrollEvent(getId(), SystemClock.nanoTime(), position, positionOffset));
94+
new PageScrollEvent(getId(), SystemClock.elapsedRealtime(), position, positionOffset));
9595
}
9696

9797
@Override
9898
public void onPageSelected(int position) {
9999
if (!mIsCurrentItemFromJs) {
100100
mEventDispatcher.dispatchEvent(
101-
new PageSelectedEvent(getId(), SystemClock.nanoTime(), position));
101+
new PageSelectedEvent(getId(), SystemClock.elapsedRealtime(), position));
102102
}
103103
}
104104

@@ -119,7 +119,7 @@ public void onPageScrollStateChanged(int state) {
119119
throw new IllegalStateException("Unsupported pageScrollState");
120120
}
121121
mEventDispatcher.dispatchEvent(
122-
new PageScrollStateChangedEvent(getId(), SystemClock.nanoTime(), pageScrollState));
122+
new PageScrollStateChangedEvent(getId(), SystemClock.elapsedRealtime(), pageScrollState));
123123
}
124124
}
125125

0 commit comments

Comments
 (0)