File tree 2 files changed +26
-3
lines changed
packages/virtualized-lists/Lists
2 files changed +26
-3
lines changed Original file line number Diff line number Diff line change @@ -65,6 +65,16 @@ export type ViewabilityConfig = $ReadOnly<{
65
65
* render.
66
66
*/
67
67
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 ,
68
78
} > ;
69
79
70
80
/**
@@ -148,18 +158,21 @@ class ViewabilityHelper {
148
158
if ( ! metrics ) {
149
159
continue ;
150
160
}
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 ) ;
152
165
const bottom = Math . floor ( top + metrics . length ) ;
153
166
154
- if ( top < viewportHeight && bottom > 0 ) {
167
+ if ( top < viewportHeight - absoluteTopOffset && bottom > 0 ) {
155
168
firstVisible = idx ;
156
169
if (
157
170
_isViewable (
158
171
viewAreaMode ,
159
172
viewablePercentThreshold,
160
173
top,
161
174
bottom,
162
- viewportHeight,
175
+ viewportHeight - absoluteTopOffset - absoluteBottomOffset ,
163
176
metrics. length ,
164
177
)
165
178
) {
Original file line number Diff line number Diff line change @@ -53,6 +53,16 @@ export interface ViewabilityConfig {
53
53
* render.
54
54
*/
55
55
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 ;
56
66
}
57
67
58
68
export interface ViewabilityConfigCallbackPair {
You can’t perform that action at this time.
0 commit comments