@react-native-tvos/virtualized-lists 0.73.4-0

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