This file contains 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 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 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 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 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 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 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 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
_updateViewableItems(data: any) { | |
const {getItemCount} = this.props; | |
this._viewabilityTuples.forEach(tuple => { | |
tuple.viewabilityHelper.onUpdate( | |
getItemCount(data), | |
// contentOffset of the list | |
this._scrollMetrics.offset, | |
// 🌟 viewportHeight | |
this._scrollMetrics.visibleLength, |
This file contains 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
class ViewabilityHelper { | |
_config: ViewabilityConfig; | |
_hasInteracted: boolean = false; | |
/* A set of `timeoutID`, used for memory management */ | |
_timers: Set<number> = new Set(); | |
// Indexs of the viewable items | |
_viewableIndices: Array<number> = []; | |
// A map for viewable items | |
_viewableItems: Map<string, ViewToken> = new Map(); | |
} |
This file contains 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 ViewabilityHelperCallbackTuple = { | |
viewabilityHelper: ViewabilityHelper, | |
onViewableItemsChanged: (info: { | |
viewableItems: Array<ViewToken>, | |
changed: Array<ViewToken>, | |
... | |
}) => void, | |
... | |
}; |
NewerOlder