Skip to content

Commit

Permalink
Fix minimumViewTime in ViewabilityHelper
Browse files Browse the repository at this point in the history
Reviewed By: sahrens

Differential Revision: D6350352

fbshipit-source-id: e909600875156127eb3144726981ab62e0015e6e
  • Loading branch information
logandaniels authored and facebook-github-bot committed Nov 17, 2017
1 parent bd9cb37 commit d19d137
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions Libraries/Lists/ViewabilityHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ export type ViewabilityConfig = {|
class ViewabilityHelper {
_config: ViewabilityConfig;
_hasInteracted: boolean = false;
_lastUpdateTime: number = 0;
_timers: Set<number> = new Set();
_viewableIndices: Array<number> = [];
_viewableItems: Map<string, ViewToken> = new Map();
Expand Down Expand Up @@ -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 = [];
Expand All @@ -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(
Expand Down

0 comments on commit d19d137

Please sign in to comment.