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
if (this.props.viewabilityConfigCallbackPairs) { | |
this._viewabilityTuples = this.props.viewabilityConfigCallbackPairs.map( | |
pair => ({ | |
viewabilityHelper: new ViewabilityHelper(pair.viewabilityConfig), | |
onViewableItemsChanged: pair.onViewableItemsChanged, | |
}), | |
); | |
} else if (this.props.onViewableItemsChanged) { | |
this._viewabilityTuples.push({ | |
viewabilityHelper: new ViewabilityHelper(this.props.viewabilityConfig), |
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
/** | |
* Called when the viewability of rows changes, as defined by the | |
* `viewabilityConfig` prop. | |
*/ | |
onViewableItemsChanged?: ?(info: { | |
viewableItems: Array<ViewToken>, | |
changed: Array<ViewToken>, | |
... | |
}) => void, | |
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
_viewabilityTuples: Array<ViewabilityHelperCallbackTuple> = []; |
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
const timestamp = e.timeStamp; | |
let visibleLength = this._selectLength(e.nativeEvent.layoutMeasurement); | |
let contentLength = this._selectLength(e.nativeEvent.contentSize); | |
let offset = this._selectOffset(e.nativeEvent.contentOffset); | |
let dOffset = offset - this._scrollMetrics.offset; | |
// ... | |
this._scrollMetrics = { | |
contentLength, | |
dt, |
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); | |
}; |
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
_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
// 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
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
function _isViewable( | |
viewAreaMode: boolean, | |
viewablePercentThreshold: number, | |
top: number, | |
bottom: number, | |
viewportHeight: number, | |
itemLength: number, | |
): boolean { | |
if (_isEntirelyVisible(top, bottom, viewportHeight)) { | |
// Entirely visible |