/
VirtualizedList.d.ts
374 lines (318 loc) · 11.6 KB
/
VirtualizedList.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
import type * as React from 'react';
import type {LayoutChangeEvent} from '../../types';
import {StyleProp} from '../StyleSheet/StyleSheet';
import {ViewStyle} from '../StyleSheet/StyleSheetTypes';
import type {
ScrollResponderMixin,
ScrollView,
ScrollViewProps,
} from '../Components/ScrollView/ScrollView';
import type {View} from '../Components/View/View';
export interface ViewToken {
item: any;
key: string;
index: number | null;
isViewable: boolean;
section?: any;
}
export interface 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 | undefined;
/**
* Percent of viewport that must be covered for a partially occluded item to count as
* "viewable", 0-100. Fully visible items are always considered viewable. A value of 0 means
* that a single pixel in the viewport makes the item viewable, and a value of 100 means that
* an item must be either entirely visible or cover the entire viewport to count as viewable.
*/
viewAreaCoveragePercentThreshold?: number | undefined;
/**
* Similar to `viewAreaCoveragePercentThreshold`, but considers the percent of the item that is visible,
* rather than the fraction of the viewable area it covers.
*/
itemVisiblePercentThreshold?: number | undefined;
/**
* Nothing is considered viewable until the user scrolls or `recordInteraction` is called after
* render.
*/
waitForInteraction?: boolean | undefined;
}
export interface ViewabilityConfigCallbackPair {
viewabilityConfig: ViewabilityConfig;
onViewableItemsChanged:
| ((info: {
viewableItems: Array<ViewToken>;
changed: Array<ViewToken>;
}) => void)
| null;
}
export type ViewabilityConfigCallbackPairs = ViewabilityConfigCallbackPair[];
/**
* @see https://reactnative.dev/docs/flatlist#props
*/
export interface ListRenderItemInfo<ItemT> {
item: ItemT;
index: number;
separators: {
highlight: () => void;
unhighlight: () => void;
updateProps: (select: 'leading' | 'trailing', newProps: any) => void;
};
}
export type ListRenderItem<ItemT> = (
info: ListRenderItemInfo<ItemT>,
) => React.ReactElement | null;
/**
* @see https://reactnative.dev/docs/virtualizedlist
*/
export class VirtualizedList<ItemT> extends React.Component<
VirtualizedListProps<ItemT>
> {
scrollToEnd: (params?: {animated?: boolean | undefined}) => void;
scrollToIndex: (params: {
animated?: boolean | undefined;
index: number;
viewOffset?: number | undefined;
viewPosition?: number | undefined;
}) => void;
scrollToItem: (params: {
animated?: boolean | undefined;
item: ItemT;
viewOffset?: number | undefined;
viewPosition?: number | undefined;
}) => void;
/**
* Scroll to a specific content pixel offset in the list.
* Param `offset` expects the offset to scroll to. In case of horizontal is true, the
* offset is the x-value, in any other case the offset is the y-value.
* Param `animated` (true by default) defines whether the list should do an animation while scrolling.
*/
scrollToOffset: (params: {
animated?: boolean | undefined;
offset: number;
}) => void;
recordInteraction: () => void;
getScrollRef: () =>
| React.ElementRef<typeof ScrollView>
| React.ElementRef<typeof View>
| null;
getScrollResponder: () => ScrollResponderMixin | null;
}
/**
* @see https://reactnative.dev/docs/virtualizedlist#props
*/
export interface VirtualizedListProps<ItemT>
extends VirtualizedListWithoutRenderItemProps<ItemT> {
renderItem: ListRenderItem<ItemT> | null | undefined;
}
export interface VirtualizedListWithoutRenderItemProps<ItemT>
extends ScrollViewProps {
/**
* Rendered in between each item, but not at the top or bottom
*/
ItemSeparatorComponent?: React.ComponentType<any> | null | undefined;
/**
* Rendered when the list is empty. Can be a React Component Class, a render function, or
* a rendered element.
*/
ListEmptyComponent?:
| React.ComponentType<any>
| React.ReactElement
| null
| undefined;
/**
* Rendered at the bottom of all the items. Can be a React Component Class, a render function, or
* a rendered element.
*/
ListFooterComponent?:
| React.ComponentType<any>
| React.ReactElement
| null
| undefined;
/**
* Styling for internal View for ListFooterComponent
*/
ListFooterComponentStyle?: StyleProp<ViewStyle> | undefined;
/**
* Rendered at the top of all the items. Can be a React Component Class, a render function, or
* a rendered element.
*/
ListHeaderComponent?:
| React.ComponentType<any>
| React.ReactElement
| null
| undefined;
/**
* Styling for internal View for ListHeaderComponent
*/
ListHeaderComponentStyle?: StyleProp<ViewStyle> | undefined;
/**
* The default accessor functions assume this is an Array<{key: string}> but you can override
* getItem, getItemCount, and keyExtractor to handle any type of index-based data.
*/
data?: any;
/**
* `debug` will turn on extra logging and visual overlays to aid with debugging both usage and
* implementation, but with a significant perf hit.
*/
debug?: boolean | undefined;
/**
* DEPRECATED: Virtualization provides significant performance and memory optimizations, but fully
* unmounts react instances that are outside of the render window. You should only need to disable
* this for debugging purposes.
*/
disableVirtualization?: boolean | undefined;
/**
* A marker property for telling the list to re-render (since it implements `PureComponent`). If
* any of your `renderItem`, Header, Footer, etc. functions depend on anything outside of the
* `data` prop, stick it here and treat it immutably.
*/
extraData?: any;
/**
* A generic accessor for extracting an item from any sort of data blob.
*/
getItem?: ((data: any, index: number) => ItemT) | undefined;
/**
* Determines how many items are in the data blob.
*/
getItemCount?: ((data: any) => number) | undefined;
getItemLayout?:
| ((
data: any,
index: number,
) => {
length: number;
offset: number;
index: number;
})
| undefined;
horizontal?: boolean | null | undefined;
/**
* How many items to render in the initial batch. This should be enough to fill the screen but not
* much more. Note these items will never be unmounted as part of the windowed rendering in order
* to improve perceived performance of scroll-to-top actions.
*/
initialNumToRender?: number | undefined;
/**
* Instead of starting at the top with the first item, start at `initialScrollIndex`. This
* disables the "scroll to top" optimization that keeps the first `initialNumToRender` items
* always rendered and immediately renders the items starting at this initial index. Requires
* `getItemLayout` to be implemented.
*/
initialScrollIndex?: number | null | undefined;
/**
* Reverses the direction of scroll. Uses scale transforms of -1.
*/
inverted?: boolean | null | undefined;
keyExtractor?: ((item: ItemT, index: number) => string) | undefined;
/**
* The maximum number of items to render in each incremental render batch. The more rendered at
* once, the better the fill rate, but responsiveness my suffer because rendering content may
* interfere with responding to button taps or other interactions.
*/
maxToRenderPerBatch?: number | undefined;
/**
* Called once when the scroll position gets within within `onEndReachedThreshold`
* from the logical end of the list.
*/
onEndReached?: ((info: {distanceFromEnd: number}) => void) | null | undefined;
/**
* How far from the end (in units of visible length of the list) the trailing edge of the
* list must be from the end of the content to trigger the `onEndReached` callback.
* Thus, a value of 0.5 will trigger `onEndReached` when the end of the content is
* within half the visible length of the list.
*/
onEndReachedThreshold?: number | null | undefined;
onLayout?: ((event: LayoutChangeEvent) => void) | undefined;
/**
* If provided, a standard RefreshControl will be added for "Pull to Refresh" functionality. Make
* sure to also set the `refreshing` prop correctly.
*/
onRefresh?: (() => void) | null | undefined;
/**
* Used to handle failures when scrolling to an index that has not been measured yet.
* Recommended action is to either compute your own offset and `scrollTo` it, or scroll as far
* as possible and then try again after more items have been rendered.
*/
onScrollToIndexFailed?:
| ((info: {
index: number;
highestMeasuredFrameIndex: number;
averageItemLength: number;
}) => void)
| undefined;
/**
* Called once when the scroll position gets within within `onStartReachedThreshold`
* from the logical start of the list.
*/
onStartReached?:
| ((info: {distanceFromStart: number}) => void)
| null
| undefined;
/**
* How far from the start (in units of visible length of the list) the leading edge of the
* list must be from the start of the content to trigger the `onStartReached` callback.
* Thus, a value of 0.5 will trigger `onStartReached` when the start of the content is
* within half the visible length of the list.
*/
onStartReachedThreshold?: number | null | undefined;
/**
* Called when the viewability of rows changes, as defined by the
* `viewabilityConfig` prop.
*/
onViewableItemsChanged?:
| ((info: {
viewableItems: Array<ViewToken>;
changed: Array<ViewToken>;
}) => void)
| null
| undefined;
/**
* Set this when offset is needed for the loading indicator to show correctly.
* @platform android
*/
progressViewOffset?: number | undefined;
/**
* Set this true while waiting for new data from a refresh.
*/
refreshing?: boolean | null | undefined;
/**
* Note: may have bugs (missing content) in some circumstances - use at your own risk.
*
* This may improve scroll performance for large lists.
*/
removeClippedSubviews?: boolean | undefined;
/**
* Render a custom scroll component, e.g. with a differently styled `RefreshControl`.
*/
renderScrollComponent?:
| ((props: ScrollViewProps) => React.ReactElement<ScrollViewProps>)
| undefined;
/**
* Amount of time between low-pri item render batches, e.g. for rendering items quite a ways off
* screen. Similar fill rate/responsiveness tradeoff as `maxToRenderPerBatch`.
*/
updateCellsBatchingPeriod?: number | undefined;
viewabilityConfig?: ViewabilityConfig | undefined;
viewabilityConfigCallbackPairs?: ViewabilityConfigCallbackPairs | undefined;
/**
* Determines the maximum number of items rendered outside of the visible area, in units of
* visible lengths. So if your list fills the screen, then `windowSize={21}` (the default) will
* render the visible screen area plus up to 10 screens above and 10 below the viewport. Reducing
* this number will reduce memory consumption and may improve performance, but will increase the
* chance that fast scrolling may reveal momentary blank areas of unrendered content.
*/
windowSize?: number | undefined;
CellRendererComponent?: React.ComponentType<any> | undefined;
}