From d19d137cc18f10957b5ac64ac727d15fde57f018 Mon Sep 17 00:00:00 2001 From: Logan Daniels Date: Thu, 16 Nov 2017 20:03:07 -0800 Subject: [PATCH] Fix minimumViewTime in ViewabilityHelper Reviewed By: sahrens Differential Revision: D6350352 fbshipit-source-id: e909600875156127eb3144726981ab62e0015e6e --- Libraries/Lists/ViewabilityHelper.js | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/Libraries/Lists/ViewabilityHelper.js b/Libraries/Lists/ViewabilityHelper.js index 05f1a1bc79b435..858bb4d07e2d8a 100644 --- a/Libraries/Lists/ViewabilityHelper.js +++ b/Libraries/Lists/ViewabilityHelper.js @@ -74,7 +74,6 @@ export type ViewabilityConfig = {| class ViewabilityHelper { _config: ViewabilityConfig; _hasInteracted: boolean = false; - _lastUpdateTime: number = 0; _timers: Set = new Set(); _viewableIndices: Array = []; _viewableItems: Map = new Map(); @@ -170,15 +169,11 @@ class ViewabilityHelper { }) => void, renderRange?: {first: number, last: number}, // Optional optimization to reduce the scan size ): void { - const updateTime = Date.now(); - if (this._lastUpdateTime === 0 && itemCount > 0 && getFrameMetrics(0)) { - // Only count updates after the first item is rendered and has a frame. - this._lastUpdateTime = updateTime; - } - const updateElapsed = this._lastUpdateTime - ? updateTime - this._lastUpdateTime - : 0; - if (this._config.waitForInteraction && !this._hasInteracted) { + if ( + (this._config.waitForInteraction && !this._hasInteracted) || + itemCount === 0 || + !getFrameMetrics(0) + ) { return; } let viewableIndices = []; @@ -200,11 +195,7 @@ class ViewabilityHelper { return; } this._viewableIndices = viewableIndices; - this._lastUpdateTime = updateTime; - if ( - this._config.minimumViewTime && - updateElapsed < this._config.minimumViewTime - ) { + if (this._config.minimumViewTime) { const handle = setTimeout(() => { this._timers.delete(handle); this._onUpdateSync(