Skip to content

Commit d19d137

Browse files
logandanielsfacebook-github-bot
authored andcommitted
Fix minimumViewTime in ViewabilityHelper
Reviewed By: sahrens Differential Revision: D6350352 fbshipit-source-id: e909600875156127eb3144726981ab62e0015e6e
1 parent bd9cb37 commit d19d137

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed

Libraries/Lists/ViewabilityHelper.js

+6-15
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ export type ViewabilityConfig = {|
7474
class ViewabilityHelper {
7575
_config: ViewabilityConfig;
7676
_hasInteracted: boolean = false;
77-
_lastUpdateTime: number = 0;
7877
_timers: Set<number> = new Set();
7978
_viewableIndices: Array<number> = [];
8079
_viewableItems: Map<string, ViewToken> = new Map();
@@ -170,15 +169,11 @@ class ViewabilityHelper {
170169
}) => void,
171170
renderRange?: {first: number, last: number}, // Optional optimization to reduce the scan size
172171
): void {
173-
const updateTime = Date.now();
174-
if (this._lastUpdateTime === 0 && itemCount > 0 && getFrameMetrics(0)) {
175-
// Only count updates after the first item is rendered and has a frame.
176-
this._lastUpdateTime = updateTime;
177-
}
178-
const updateElapsed = this._lastUpdateTime
179-
? updateTime - this._lastUpdateTime
180-
: 0;
181-
if (this._config.waitForInteraction && !this._hasInteracted) {
172+
if (
173+
(this._config.waitForInteraction && !this._hasInteracted) ||
174+
itemCount === 0 ||
175+
!getFrameMetrics(0)
176+
) {
182177
return;
183178
}
184179
let viewableIndices = [];
@@ -200,11 +195,7 @@ class ViewabilityHelper {
200195
return;
201196
}
202197
this._viewableIndices = viewableIndices;
203-
this._lastUpdateTime = updateTime;
204-
if (
205-
this._config.minimumViewTime &&
206-
updateElapsed < this._config.minimumViewTime
207-
) {
198+
if (this._config.minimumViewTime) {
208199
const handle = setTimeout(() => {
209200
this._timers.delete(handle);
210201
this._onUpdateSync(

0 commit comments

Comments
 (0)