This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export type ViewabilityConfig = { | |
/** | |
* Minimum amount of time (in milliseconds) that an item must be physically viewable before the | |
* viewability callback will be fired. A high number means that scrolling through content without | |
* stopping will not mark the content as viewable. | |
*/ | |
minimumViewTime?: number, | |
/** | |
* Percent of viewport that must be covered for a partially occluded item to count as |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The map storing the cell layout info | |
{ [cellKey]: { | |
// offset of the item cell | |
offset: number, | |
// length of the item cell. width or height determined by the direction of the VirtualizedList | |
length: number, | |
index: number, | |
inLayout: boolean, | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type State = { | |
// The range of the rendered items, | |
// used for the optimization to reduce the scan size | |
first: number, | |
last: number, | |
... | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for (let idx = first; idx <= last; idx++) { | |
const metrics = getFrameMetrics(idx); | |
if (!metrics) { | |
continue; | |
} | |
// The top of current item cell, relative to the screen | |
const top = metrics.offset - scrollOffset; | |
// The bottom of current item cell | |
const bottom = top + metrics.length; | |
if (top < viewportHeight && bottom > 0) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function _isViewable( | |
viewAreaMode: boolean, | |
viewablePercentThreshold: number, | |
top: number, | |
bottom: number, | |
viewportHeight: number, | |
itemLength: number, | |
): boolean { | |
if (_isEntirelyVisible(top, bottom, viewportHeight)) { | |
// Entirely visible |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
this._viewableIndices = viewableIndices; | |
if (this._config.minimumViewTime) { | |
const handle = setTimeout(() => { | |
this._timers.delete(handle); | |
this._onUpdateSync( | |
viewableIndices, | |
onViewableItemsChanged, | |
createViewToken, | |
); | |
}, this._config.minimumViewTime); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Filter out indices that have gone out of view since this call was scheduled. | |
viewableIndicesToCheck = viewableIndicesToCheck.filter(ii => | |
this._viewableIndices.includes(ii), | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_onUpdateSync( | |
viewableIndicesToCheck, | |
onViewableItemsChanged, | |
createViewToken, | |
) { | |
// Filter out indices that have gone out of view since this call was scheduled. | |
viewableIndicesToCheck = viewableIndicesToCheck.filter(ii => | |
this._viewableIndices.includes(ii), | |
); | |
const prevItems = this._viewableItems; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export type ViewabilityConfig = { | |
/** | |
* Minimum amount of time (in milliseconds) that an item must be physically viewable before the | |
* viewability callback will be fired. A high number means that scrolling through content without | |
* stopping will not mark the content as viewable. | |
*/ | |
minimumViewTime?: number, | |
/** | |
* Percent of viewport that must be covered for a partially occluded item to count as |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
viewabilityConfig = { | |
waitForInteraction: true, | |
viewAreaCoveragePercentThreshold: 95, | |
itemVisiblePercentThreshold: 75 | |
} | |
onViewableItemsChanged = ({viewableItems, changed}) => { | |
console.log("Visible items are", viewableItems); | |
console.log("Changed in this iteration", changed); | |
}; |
OlderNewer