Skip to content

Instantly share code, notes, and snippets.

View sueLan's full-sized avatar
🎯
Focusing

RY Zheng sueLan

🎯
Focusing
View GitHub Profile
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) {
type State = {
// The range of the rendered items,
// used for the optimization to reduce the scan size
first: number,
last: number,
...
};
// 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,
}
}
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