use performanceNow instead of Date.now() in ScrollResponder

Reviewed By: shergin

Differential Revision: D4833701

fbshipit-source-id: cb127cb6c40ecb188100eeb204412401c7772c9e
This commit is contained in:
Spencer Ahrens 2017-04-05 18:42:46 -07:00 committed by Facebook Github Bot
parent 4f243f1ecd
commit 6dbcb47e4c

View File

@ -25,6 +25,7 @@ var { getInstanceFromNode } = require('ReactNativeComponentTree');
var { ScrollViewManager } = require('NativeModules');
var invariant = require('fbjs/lib/invariant');
var performanceNow = require('fbjs/lib/performanceNow');
/**
* Mixin that can be integrated in order to handle scrolling that plays well
@ -321,7 +322,7 @@ var ScrollResponderMixin = {
* Invoke this from an `onMomentumScrollBegin` event.
*/
scrollResponderHandleMomentumScrollBegin: function(e: Event) {
this.state.lastMomentumScrollBeginTime = Date.now();
this.state.lastMomentumScrollBeginTime = performanceNow();
this.props.onMomentumScrollBegin && this.props.onMomentumScrollBegin(e);
},
@ -330,7 +331,7 @@ var ScrollResponderMixin = {
*/
scrollResponderHandleMomentumScrollEnd: function(e: Event) {
FrameRateLogger.endScroll();
this.state.lastMomentumScrollEndTime = Date.now();
this.state.lastMomentumScrollEndTime = performanceNow();
this.props.onMomentumScrollEnd && this.props.onMomentumScrollEnd(e);
},
@ -371,7 +372,7 @@ var ScrollResponderMixin = {
* a touch has just started or ended.
*/
scrollResponderIsAnimating: function(): boolean {
var now = Date.now();
var now = performanceNow();
var timeSinceLastMomentumScrollEnd = now - this.state.lastMomentumScrollEndTime;
var isAnimating = timeSinceLastMomentumScrollEnd < IS_ANIMATING_TOUCH_START_THRESHOLD_MS ||
this.state.lastMomentumScrollEndTime < this.state.lastMomentumScrollBeginTime;