Skip to content

Commit a5f71cd

Browse files
committed
Add list viewability offset parameters
1 parent d32ea66 commit a5f71cd

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

packages/virtualized-lists/Lists/ViewabilityHelper.js

+16-3
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,16 @@ export type ViewabilityConfig = $ReadOnly<{
6565
* render.
6666
*/
6767
waitForInteraction?: boolean,
68+
69+
/**
70+
* Offset from top of the screen
71+
*/
72+
absoluteTopOffset?: number | undefined,
73+
74+
/**
75+
* Offset from bottom of the screen
76+
*/
77+
absoluteBottomOffset?: number | undefined,
6878
}>;
6979

7080
/**
@@ -148,18 +158,21 @@ class ViewabilityHelper {
148158
if (!metrics) {
149159
continue;
150160
}
151-
const top = Math.floor(metrics.offset - scrollOffset);
161+
const absoluteTopOffset = this._config.absoluteTopOffset ?? 0;
162+
const absoluteBottomOffset = this._config.absoluteBottomOffset ?? 0;
163+
164+
const top = Math.floor(metrics.offset - scrollOffset - absoluteTopOffset);
152165
const bottom = Math.floor(top + metrics.length);
153166

154-
if (top < viewportHeight && bottom > 0) {
167+
if (top < viewportHeight - absoluteTopOffset && bottom > 0) {
155168
firstVisible = idx;
156169
if (
157170
_isViewable(
158171
viewAreaMode,
159172
viewablePercentThreshold,
160173
top,
161174
bottom,
162-
viewportHeight,
175+
viewportHeight - absoluteTopOffset - absoluteBottomOffset,
163176
metrics.length,
164177
)
165178
) {

packages/virtualized-lists/Lists/VirtualizedList.d.ts

+10
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,16 @@ export interface ViewabilityConfig {
5353
* render.
5454
*/
5555
waitForInteraction?: boolean | undefined;
56+
57+
/**
58+
* Offset from top of the screen
59+
*/
60+
absoluteTopOffset?: number | undefined;
61+
62+
/**
63+
* Offset from bottom of the screen
64+
*/
65+
absoluteBottomOffset?: number | undefined;
5666
}
5767

5868
export interface ViewabilityConfigCallbackPair {

0 commit comments

Comments
 (0)