Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions packages/virtualized-lists/Lists/ViewabilityHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ export type ViewabilityConfig = $ReadOnly<{
* render.
*/
waitForInteraction?: boolean,

/**
* Offset from top of the screen
*/
absoluteTopOffset?: number,

/**
* Offset from bottom of the screen
*/
absoluteBottomOffset?: number,
}>;

/**
Expand Down Expand Up @@ -148,18 +158,21 @@ class ViewabilityHelper {
if (!metrics) {
continue;
}
const top = Math.floor(metrics.offset - scrollOffset);
const absoluteTopOffset = this._config.absoluteTopOffset ?? 0;
const absoluteBottomOffset = this._config.absoluteBottomOffset ?? 0;

const top = Math.floor(metrics.offset - scrollOffset - absoluteTopOffset);
const bottom = Math.floor(top + metrics.length);

if (top < viewportHeight && bottom > 0) {
if (top < viewportHeight - absoluteTopOffset && bottom > 0) {
firstVisible = idx;
if (
_isViewable(
viewAreaMode,
viewablePercentThreshold,
top,
bottom,
viewportHeight,
viewportHeight - absoluteTopOffset - absoluteBottomOffset,
metrics.length,
)
) {
Expand Down
10 changes: 10 additions & 0 deletions packages/virtualized-lists/Lists/VirtualizedList.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ export interface ViewabilityConfig {
* render.
*/
waitForInteraction?: boolean | undefined;

/**
* Offset from top of the screen
*/
absoluteTopOffset?: number | undefined;

/**
* Offset from bottom of the screen
*/
absoluteBottomOffset?: number | undefined;
}

export interface ViewabilityConfigCallbackPair {
Expand Down
Loading