mirror of
https://github.com/status-im/react-native.git
synced 2025-02-10 16:36:25 +00:00
Fix minimumViewTime
Reviewed By: blairvanderhoof Differential Revision: D4723575 fbshipit-source-id: a120eef4079a808bd3dead08df93989e1db3d96a
This commit is contained in:
parent
63fa621df1
commit
b1a63f0088
@ -49,7 +49,7 @@ export type ViewabilityConfig = {|
|
|||||||
* layout.
|
* layout.
|
||||||
*
|
*
|
||||||
* An item is said to be in a "viewable" state when any of the following
|
* An item is said to be in a "viewable" state when any of the following
|
||||||
* is true for longer than `minViewTime` milliseconds (after an interaction if `waitForInteraction`
|
* is true for longer than `minimumViewTime` milliseconds (after an interaction if `waitForInteraction`
|
||||||
* is true):
|
* is true):
|
||||||
*
|
*
|
||||||
* - Occupying >= `viewAreaCoveragePercentThreshold` of the view area XOR fraction of the item
|
* - Occupying >= `viewAreaCoveragePercentThreshold` of the view area XOR fraction of the item
|
||||||
@ -145,7 +145,7 @@ class ViewabilityHelper {
|
|||||||
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();
|
const updateTime = Date.now();
|
||||||
if (this._lastUpdateTime === 0 && getFrameMetrics(0)) {
|
if (this._lastUpdateTime === 0 && itemCount > 0 && getFrameMetrics(0)) {
|
||||||
// Only count updates after the first item is rendered and has a frame.
|
// Only count updates after the first item is rendered and has a frame.
|
||||||
this._lastUpdateTime = updateTime;
|
this._lastUpdateTime = updateTime;
|
||||||
}
|
}
|
||||||
@ -171,13 +171,13 @@ class ViewabilityHelper {
|
|||||||
}
|
}
|
||||||
this._viewableIndices = viewableIndices;
|
this._viewableIndices = viewableIndices;
|
||||||
this._lastUpdateTime = updateTime;
|
this._lastUpdateTime = updateTime;
|
||||||
if (this._config.minViewTime && updateElapsed < this._config.minViewTime) {
|
if (this._config.minimumViewTime && updateElapsed < this._config.minimumViewTime) {
|
||||||
const handle = setTimeout(
|
const handle = setTimeout(
|
||||||
() => {
|
() => {
|
||||||
this._timers.delete(handle);
|
this._timers.delete(handle);
|
||||||
this._onUpdateSync(viewableIndices, onViewableItemsChanged, createViewToken);
|
this._onUpdateSync(viewableIndices, onViewableItemsChanged, createViewToken);
|
||||||
},
|
},
|
||||||
this._config.minViewTime,
|
this._config.minimumViewTime,
|
||||||
);
|
);
|
||||||
this._timers.add(handle);
|
this._timers.add(handle);
|
||||||
} else {
|
} else {
|
||||||
|
@ -249,9 +249,9 @@ describe('onUpdate', function() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
it(
|
it(
|
||||||
'minViewTime delays callback',
|
'minimumViewTime delays callback',
|
||||||
function() {
|
function() {
|
||||||
const helper = new ViewabilityHelper({minViewTime: 350, viewAreaCoveragePercentThreshold: 0});
|
const helper = new ViewabilityHelper({minimumViewTime: 350, viewAreaCoveragePercentThreshold: 0});
|
||||||
rowFrames = {
|
rowFrames = {
|
||||||
a: {y: 0, height: 200},
|
a: {y: 0, height: 200},
|
||||||
b: {y: 200, height: 200},
|
b: {y: 200, height: 200},
|
||||||
@ -279,9 +279,9 @@ describe('onUpdate', function() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
it(
|
it(
|
||||||
'minViewTime skips briefly visible items',
|
'minimumViewTime skips briefly visible items',
|
||||||
function() {
|
function() {
|
||||||
const helper = new ViewabilityHelper({minViewTime: 350, viewAreaCoveragePercentThreshold: 0});
|
const helper = new ViewabilityHelper({minimumViewTime: 350, viewAreaCoveragePercentThreshold: 0});
|
||||||
rowFrames = {
|
rowFrames = {
|
||||||
a: {y: 0, height: 250},
|
a: {y: 0, height: 250},
|
||||||
b: {y: 250, height: 200},
|
b: {y: 250, height: 200},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user