From 5840a9051d7a4e492e889d7162ae85d74b3c92d1 Mon Sep 17 00:00:00 2001 From: Mike Lambert Date: Thu, 8 Jun 2017 12:14:12 -0700 Subject: [PATCH] Fix deltatime calculation. Summary: This is necessary to fix an extraneous warning when a VirtualizedList is constructed on the first frame. On the first frame, the dt is huge (ie, time since epoch). On the second frame (which may legitimately be slow as a result of a lot to render), it will then assume there were two consecutive slow frames, and print a warning: "VirtualizedList: You have a large list that is slow to update..." Closes https://github.com/facebook/react-native/pull/14393 Differential Revision: D5210467 Pulled By: sahrens fbshipit-source-id: 2e79218c3d66a4a9df4884f328a125047ef264ed --- Libraries/Lists/VirtualizedList.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Libraries/Lists/VirtualizedList.js b/Libraries/Lists/VirtualizedList.js index bb4db8f53..211e57c57 100644 --- a/Libraries/Lists/VirtualizedList.js +++ b/Libraries/Lists/VirtualizedList.js @@ -734,7 +734,9 @@ class VirtualizedList extends React.PureComponent { const visibleLength = this._selectLength(e.nativeEvent.layoutMeasurement); const contentLength = this._selectLength(e.nativeEvent.contentSize); const offset = this._selectOffset(e.nativeEvent.contentOffset); - const dt = Math.max(1, timestamp - this._scrollMetrics.timestamp); + const dt = this._scrollMetrics.timestamp + ? Math.max(1, timestamp - this._scrollMetrics.timestamp) + : 1; if (dt > 500 && this._scrollMetrics.dt > 500 && (contentLength > (5 * visibleLength)) && !this._hasWarned.perf) { infoLog(