Fix minimumViewTime in ViewabilityHelper
Reviewed By: sahrens Differential Revision: D6350352 fbshipit-source-id: e909600875156127eb3144726981ab62e0015e6e
This commit is contained in:
parent
bd9cb37ccf
commit
d19d137cc1
|
@ -74,7 +74,6 @@ export type ViewabilityConfig = {|
|
||||||
class ViewabilityHelper {
|
class ViewabilityHelper {
|
||||||
_config: ViewabilityConfig;
|
_config: ViewabilityConfig;
|
||||||
_hasInteracted: boolean = false;
|
_hasInteracted: boolean = false;
|
||||||
_lastUpdateTime: number = 0;
|
|
||||||
_timers: Set<number> = new Set();
|
_timers: Set<number> = new Set();
|
||||||
_viewableIndices: Array<number> = [];
|
_viewableIndices: Array<number> = [];
|
||||||
_viewableItems: Map<string, ViewToken> = new Map();
|
_viewableItems: Map<string, ViewToken> = new Map();
|
||||||
|
@ -170,15 +169,11 @@ class ViewabilityHelper {
|
||||||
}) => void,
|
}) => void,
|
||||||
renderRange?: {first: number, last: number}, // Optional optimization to reduce the scan size
|
renderRange?: {first: number, last: number}, // Optional optimization to reduce the scan size
|
||||||
): void {
|
): void {
|
||||||
const updateTime = Date.now();
|
if (
|
||||||
if (this._lastUpdateTime === 0 && itemCount > 0 && getFrameMetrics(0)) {
|
(this._config.waitForInteraction && !this._hasInteracted) ||
|
||||||
// Only count updates after the first item is rendered and has a frame.
|
itemCount === 0 ||
|
||||||
this._lastUpdateTime = updateTime;
|
!getFrameMetrics(0)
|
||||||
}
|
) {
|
||||||
const updateElapsed = this._lastUpdateTime
|
|
||||||
? updateTime - this._lastUpdateTime
|
|
||||||
: 0;
|
|
||||||
if (this._config.waitForInteraction && !this._hasInteracted) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let viewableIndices = [];
|
let viewableIndices = [];
|
||||||
|
@ -200,11 +195,7 @@ class ViewabilityHelper {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this._viewableIndices = viewableIndices;
|
this._viewableIndices = viewableIndices;
|
||||||
this._lastUpdateTime = updateTime;
|
if (this._config.minimumViewTime) {
|
||||||
if (
|
|
||||||
this._config.minimumViewTime &&
|
|
||||||
updateElapsed < this._config.minimumViewTime
|
|
||||||
) {
|
|
||||||
const handle = setTimeout(() => {
|
const handle = setTimeout(() => {
|
||||||
this._timers.delete(handle);
|
this._timers.delete(handle);
|
||||||
this._onUpdateSync(
|
this._onUpdateSync(
|
||||||
|
|
Loading…
Reference in New Issue