@legendapp/list 1.0.0-beta.3 → 1.0.0-beta.31

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.
package/index.d.ts CHANGED
@@ -1,55 +1,141 @@
1
- import * as react from 'react';
2
- import { ComponentProps, ReactNode, ForwardedRef, ReactElement } from 'react';
3
- import { ScrollView, StyleProp, ViewStyle, ScrollViewProps, ScrollViewComponent, ScrollResponderMixin } from 'react-native';
1
+ import * as React$1 from 'react';
2
+ import { ComponentProps, ReactNode } from 'react';
3
+ import * as react_native from 'react-native';
4
+ import { ScrollView, StyleProp, ViewStyle, ScrollViewProps, NativeSyntheticEvent, NativeScrollEvent, ScrollViewComponent, ScrollResponderMixin } from 'react-native';
4
5
  import Animated from 'react-native-reanimated';
5
6
 
6
7
  declare class ScrollAdjustHandler {
7
8
  private ctx;
8
9
  private appliedAdjust;
9
- private pendingAdjust;
10
10
  private busy;
11
11
  private context;
12
- private firstAdjust;
12
+ private isPaused;
13
+ private isDisabled;
13
14
  constructor(ctx: any);
15
+ private doAjdust;
14
16
  requestAdjust(adjust: number, onAdjusted: (diff: number) => void): void;
15
17
  getAppliedAdjust(): number;
18
+ pauseAdjust(): void;
19
+ setDisableAdjust(disable: boolean): void;
20
+ unPauseAdjust(): boolean;
16
21
  }
17
22
 
18
- type LegendListPropsBase<ItemT, TScrollView extends ComponentProps<typeof ScrollView> | ComponentProps<typeof Animated.ScrollView>> = Omit<TScrollView, 'contentOffset' | 'contentInset' | 'maintainVisibleContentPosition' | 'stickyHeaderIndices'> & {
19
- data: ArrayLike<any> & ItemT[];
23
+ type LegendListPropsBase<ItemT, TScrollView extends ComponentProps<typeof ScrollView> | ComponentProps<typeof Animated.ScrollView>> = Omit<TScrollView, "contentOffset" | "contentInset" | "maintainVisibleContentPosition" | "stickyHeaderIndices"> & {
24
+ /**
25
+ * If true, aligns items at the end of the list.
26
+ * @default false
27
+ */
28
+ alignItemsAtEnd?: boolean;
29
+ /**
30
+ * Style applied to each column's wrapper view.
31
+ */
32
+ columnWrapperStyle?: ColumnWrapperStyle;
33
+ /**
34
+ * Array of items to render in the list.
35
+ * @required
36
+ */
37
+ data: ReadonlyArray<ItemT>;
38
+ /**
39
+ * Distance in pixels to pre-render items ahead of the visible area.
40
+ * @default 250
41
+ */
42
+ drawDistance?: number;
43
+ /**
44
+ * Estimated size of each item in pixels; sufficient for most cases. If
45
+ * you leave this blank, a warning should appear and you will get
46
+ * a suggested size.
47
+ * @required
48
+ * @default undefined
49
+ */
50
+ estimatedItemSize?: number;
51
+ /**
52
+ * Extra data to trigger re-rendering when changed.
53
+ */
54
+ extraData?: any;
55
+ /**
56
+ * In case you have distinct item sizes, you can provide a function to get the size of an item.
57
+ * Use instead of FlatList's getItemLayout or FlashList overrideItemLayout if you want to have accurate initialScrollOffset, you should provide this function
58
+ */
59
+ getEstimatedItemSize?: (index: number, item: ItemT) => number;
60
+ /**
61
+ * Ratio of initial container pool size to data length (e.g., 0.5 for half).
62
+ * @default 1
63
+ */
64
+ initialContainerPoolRatio?: number | undefined;
65
+ /**
66
+ * Initial scroll position in pixels.
67
+ * @default 0
68
+ */
20
69
  initialScrollOffset?: number;
70
+ /**
71
+ * Index to scroll to initially.
72
+ * @default 0
73
+ */
21
74
  initialScrollIndex?: number;
22
- drawDistance?: number;
23
- recycleItems?: boolean;
24
- onEndReachedThreshold?: number | null | undefined;
25
- onStartReachedThreshold?: number | null | undefined;
75
+ /**
76
+ * Component to render between items, receiving the leading item as prop.
77
+ */
78
+ ItemSeparatorComponent?: React.ComponentType<{
79
+ leadingItem: ItemT;
80
+ }>;
81
+ /**
82
+ * Function to extract a unique key for each item.
83
+ */
84
+ keyExtractor?: (item: ItemT, index: number) => string;
85
+ /**
86
+ * Component or element to render when the list is empty.
87
+ */
88
+ ListEmptyComponent?: React.ComponentType<any> | React.ReactElement | null | undefined;
89
+ /**
90
+ * Component or element to render below the list.
91
+ */
92
+ ListFooterComponent?: React.ComponentType<any> | React.ReactElement | null | undefined;
93
+ /**
94
+ * Style for the footer component.
95
+ */
96
+ ListFooterComponentStyle?: StyleProp<ViewStyle> | undefined;
97
+ /**
98
+ * Component or element to render above the list.
99
+ */
100
+ ListHeaderComponent?: React.ComponentType<any> | React.ReactElement | null | undefined;
101
+ /**
102
+ * Style for the header component.
103
+ */
104
+ ListHeaderComponentStyle?: StyleProp<ViewStyle> | undefined;
105
+ /**
106
+ * If true, auto-scrolls to end when new items are added.
107
+ * @default false
108
+ */
26
109
  maintainScrollAtEnd?: boolean;
110
+ /**
111
+ * Distance threshold in pixels to trigger maintainScrollAtEnd.
112
+ * @default 100
113
+ */
27
114
  maintainScrollAtEndThreshold?: number;
28
- alignItemsAtEnd?: boolean;
115
+ /**
116
+ * If true, maintains visibility of content during scroll (e.g., after insertions).
117
+ * @default false
118
+ */
29
119
  maintainVisibleContentPosition?: boolean;
120
+ /**
121
+ * Number of columns to render items in.
122
+ * @default 1
123
+ */
30
124
  numColumns?: number;
31
- refScrollView?: React.Ref<ScrollView>;
32
- waitForInitialLayout?: boolean;
33
- estimatedItemSize?: number;
34
- getEstimatedItemSize?: (index: number, item: ItemT) => number;
35
- onStartReached?: ((info: {
36
- distanceFromStart: number;
37
- }) => void) | null | undefined;
125
+ /**
126
+ * Called when scrolling reaches the end within onEndReachedThreshold.
127
+ */
38
128
  onEndReached?: ((info: {
39
129
  distanceFromEnd: number;
40
130
  }) => void) | null | undefined;
41
- keyExtractor?: (item: ItemT, index: number) => string;
42
- renderItem?: (props: LegendListRenderItemProps<ItemT>) => ReactNode;
43
- ListHeaderComponent?: React.ComponentType<any> | React.ReactElement | null | undefined;
44
- ListHeaderComponentStyle?: StyleProp<ViewStyle> | undefined;
45
- ListFooterComponent?: React.ComponentType<any> | React.ReactElement | null | undefined;
46
- ListFooterComponentStyle?: StyleProp<ViewStyle> | undefined;
47
- ListEmptyComponent?: React.ComponentType<any> | React.ReactElement | null | undefined;
48
- ListEmptyComponentStyle?: StyleProp<ViewStyle> | undefined;
49
- ItemSeparatorComponent?: React.ComponentType<any>;
50
- viewabilityConfigCallbackPairs?: ViewabilityConfigCallbackPairs | undefined;
51
- viewabilityConfig?: ViewabilityConfig;
52
- onViewableItemsChanged?: OnViewableItemsChanged | undefined;
131
+ /**
132
+ * How close to the end (in fractional units of visible length) to trigger onEndReached.
133
+ * @default 0.5
134
+ */
135
+ onEndReachedThreshold?: number | null | undefined;
136
+ /**
137
+ * Called when an item's size changes.
138
+ */
53
139
  onItemSizeChanged?: (info: {
54
140
  size: number;
55
141
  previous: number;
@@ -57,15 +143,75 @@ type LegendListPropsBase<ItemT, TScrollView extends ComponentProps<typeof Scroll
57
143
  itemKey: string;
58
144
  itemData: ItemT;
59
145
  }) => void;
146
+ /**
147
+ * Function to call when the user pulls to refresh.
148
+ */
149
+ onRefresh?: () => void;
150
+ /**
151
+ * Called when scrolling reaches the start within onStartReachedThreshold.
152
+ */
153
+ onStartReached?: ((info: {
154
+ distanceFromStart: number;
155
+ }) => void) | null | undefined;
156
+ /**
157
+ * How close to the start (in fractional units of visible length) to trigger onStartReached.
158
+ * @default 0.5
159
+ */
160
+ onStartReachedThreshold?: number | null | undefined;
161
+ /**
162
+ * Called when the viewability of items changes.
163
+ */
164
+ onViewableItemsChanged?: OnViewableItemsChanged | undefined;
165
+ /**
166
+ * Offset in pixels for the refresh indicator.
167
+ * @default 0
168
+ */
169
+ progressViewOffset?: number;
170
+ /**
171
+ * If true, recycles item views for better performance.
172
+ * @default false
173
+ */
174
+ recycleItems?: boolean;
175
+ /**
176
+ * Ref to the underlying ScrollView component.
177
+ */
178
+ refScrollView?: React.Ref<ScrollView>;
179
+ /**
180
+ * If true, shows a refresh indicator.
181
+ * @default false
182
+ */
183
+ refreshing?: boolean;
184
+ /**
185
+ * Function to render each item in the list.
186
+ * @required
187
+ */
188
+ renderItem?: (props: LegendListRenderItemProps<ItemT>) => ReactNode;
60
189
  /**
61
190
  * Render custom ScrollView component.
62
191
  * @default (props) => <ScrollView {...props} />
63
192
  */
64
193
  renderScrollComponent?: (props: ScrollViewProps) => React.ReactElement<ScrollViewProps>;
65
- extraData?: any;
194
+ /**
195
+ * Configuration for determining item viewability.
196
+ */
197
+ viewabilityConfig?: ViewabilityConfig;
198
+ /**
199
+ * Pairs of viewability configs and their callbacks for tracking visibility.
200
+ */
201
+ viewabilityConfigCallbackPairs?: ViewabilityConfigCallbackPairs | undefined;
202
+ /**
203
+ * If true, delays rendering until initial layout is complete.
204
+ * @default false
205
+ */
206
+ waitForInitialLayout?: boolean;
66
207
  };
208
+ interface ColumnWrapperStyle {
209
+ rowGap?: number;
210
+ gap?: number;
211
+ columnGap?: number;
212
+ }
67
213
  type AnchoredPosition = {
68
- type: 'top' | 'bottom';
214
+ type: "top" | "bottom";
69
215
  relativeCoordinate: number;
70
216
  top: number;
71
217
  };
@@ -80,16 +226,14 @@ interface InternalState {
80
226
  positions: Map<string, number>;
81
227
  columns: Map<string, number>;
82
228
  sizes: Map<string, number>;
83
- sizesLaidOut: Map<string, number> | undefined;
229
+ sizesKnown: Map<string, number> | undefined;
84
230
  pendingAdjust: number;
85
- waitingForMicrotask: any;
86
231
  isStartReached: boolean;
87
232
  isEndReached: boolean;
88
233
  isAtBottom: boolean;
89
234
  isAtTop: boolean;
90
- data: any[];
91
- idsInFirstRender: Set<string>;
92
- hasScrolled: boolean;
235
+ data: readonly any[];
236
+ hasScrolled?: boolean;
93
237
  scrollLength: number;
94
238
  startBuffered: number;
95
239
  startBufferedId?: string;
@@ -116,11 +260,19 @@ interface InternalState {
116
260
  }>;
117
261
  scrollTimer: Timer | undefined;
118
262
  startReachedBlockedByTimer: boolean;
263
+ endReachedBlockedByTimer: boolean;
119
264
  scrollForNextCalculateItemsInView: {
120
265
  top: number;
121
266
  bottom: number;
122
267
  } | undefined;
123
268
  enableScrollForNextCalculateItemsInView: boolean;
269
+ minIndexSizeChanged: number | undefined;
270
+ numPendingInitialLayout: number;
271
+ queuedInitialLayout?: boolean | undefined;
272
+ queuedCalculateItemsInView: number | undefined;
273
+ lastBatchingAction: number;
274
+ ignoreScrollFromCalcTotal?: boolean;
275
+ onScroll: ((event: NativeSyntheticEvent<NativeScrollEvent>) => void) | undefined;
124
276
  }
125
277
  interface ViewableRange<T> {
126
278
  startBuffered: number;
@@ -132,44 +284,109 @@ interface ViewableRange<T> {
132
284
  interface LegendListRenderItemProps<ItemT> {
133
285
  item: ItemT;
134
286
  index: number;
287
+ extraData: any;
135
288
  useViewability: (configId: string, callback: ViewabilityCallback) => void;
136
289
  useViewabilityAmount: (callback: ViewabilityAmountCallback) => void;
137
290
  useRecyclingEffect: (effect: (info: LegendListRecyclingState<ItemT>) => void | (() => void)) => void;
138
291
  useRecyclingState: <T>(updateState: ((info: LegendListRecyclingState<ItemT>) => T) | T) => [T, React.Dispatch<T>];
139
292
  }
293
+ type ScrollState = {
294
+ contentLength: number;
295
+ end: number;
296
+ endBuffered: number;
297
+ isAtEnd: boolean;
298
+ isAtStart: boolean;
299
+ scroll: number;
300
+ scrollLength: number;
301
+ start: number;
302
+ startBuffered: number;
303
+ };
140
304
  type LegendListRef = {
141
305
  /**
142
306
  * Displays the scroll indicators momentarily.
143
307
  */
144
308
  flashScrollIndicators(): void;
309
+ /**
310
+ * Returns the native ScrollView component reference.
311
+ */
145
312
  getNativeScrollRef(): React.ElementRef<typeof ScrollViewComponent>;
146
- getScrollResponder(): ScrollResponderMixin;
313
+ /**
314
+ * Returns the scroll responder instance for handling scroll events.
315
+ */
147
316
  getScrollableNode(): any;
148
317
  /**
149
- * A helper function that scrolls to the end of the scrollview;
150
- * If this is a vertical ScrollView, it scrolls to the bottom.
151
- * If this is a horizontal ScrollView scrolls to the right.
152
- *
153
- * The options object has an animated prop, that enables the scrolling animation or not.
154
- * The animated prop defaults to true
318
+ * Returns the ScrollResponderMixin for advanced scroll handling.
319
+ */
320
+ getScrollResponder(): ScrollResponderMixin;
321
+ /**
322
+ * Returns the internal state of the scroll virtualization.
323
+ */
324
+ getState(): ScrollState;
325
+ /**
326
+ * Scrolls a specific index into view.
327
+ * @param params - Parameters for scrolling.
328
+ * @param params.animated - If true, animates the scroll. Default: true.
329
+ * @param params.index - The index to scroll to.
330
+ */
331
+ scrollIndexIntoView(params: {
332
+ animated?: boolean | undefined;
333
+ index: number;
334
+ }): void;
335
+ /**
336
+ * Scrolls a specific index into view.
337
+ * @param params - Parameters for scrolling.
338
+ * @param params.animated - If true, animates the scroll. Default: true.
339
+ * @param params.item - The item to scroll to.
340
+ */
341
+ scrollItemIntoView(params: {
342
+ animated?: boolean | undefined;
343
+ item: any;
344
+ }): void;
345
+ /**
346
+ * Scrolls to the end of the list.
347
+ * @param options - Options for scrolling.
348
+ * @param options.animated - If true, animates the scroll. Default: true.
155
349
  */
156
350
  scrollToEnd(options?: {
157
351
  animated?: boolean | undefined;
158
352
  }): void;
159
- scrollToIndex: (params: {
353
+ /**
354
+ * Scrolls to a specific index in the list.
355
+ * @param params - Parameters for scrolling.
356
+ * @param params.animated - If true, animates the scroll. Default: true.
357
+ * @param params.index - The index to scroll to.
358
+ * @param params.viewOffset - Offset from the target position.
359
+ * @param params.viewPosition - Position of the item in the viewport (0 to 1).
360
+ */
361
+ scrollToIndex(params: {
362
+ animated?: boolean | undefined;
160
363
  index: number;
161
- animated?: boolean;
162
- viewOffset?: number;
163
- viewPosition?: number;
164
- }) => void;
364
+ viewOffset?: number | undefined;
365
+ viewPosition?: number | undefined;
366
+ }): void;
367
+ /**
368
+ * Scrolls to a specific item in the list.
369
+ * @param params - Parameters for scrolling.
370
+ * @param params.animated - If true, animates the scroll. Default: true.
371
+ * @param params.item - The item to scroll to.
372
+ * @param params.viewOffset - Offset from the target position.
373
+ * @param params.viewPosition - Position of the item in the viewport (0 to 1).
374
+ */
165
375
  scrollToItem(params: {
166
- animated?: boolean;
376
+ animated?: boolean | undefined;
167
377
  item: any;
168
- viewPosition?: number;
378
+ viewOffset?: number | undefined;
379
+ viewPosition?: number | undefined;
169
380
  }): void;
381
+ /**
382
+ * Scrolls to a specific offset in pixels.
383
+ * @param params - Parameters for scrolling.
384
+ * @param params.offset - The pixel offset to scroll to.
385
+ * @param params.animated - If true, animates the scroll. Default: true.
386
+ */
170
387
  scrollToOffset(params: {
171
388
  offset: number;
172
- animated?: boolean;
389
+ animated?: boolean | undefined;
173
390
  }): void;
174
391
  };
175
392
  interface ViewToken<ItemT = any> {
@@ -232,14 +449,68 @@ interface LegendListRecyclingState<T> {
232
449
  index: number;
233
450
  prevIndex: number | undefined;
234
451
  }
452
+ type TypedForwardRef = <T, P = {}>(render: (props: P, ref: React.Ref<T>) => React.ReactNode) => (props: P & React.RefAttributes<T>) => React.ReactNode;
453
+ declare const typedForwardRef: TypedForwardRef;
454
+ type TypedMemo = <T extends React.ComponentType<any>>(Component: T, propsAreEqual?: (prevProps: Readonly<ComponentProps<T>>, nextProps: Readonly<ComponentProps<T>>) => boolean) => T & {
455
+ displayName?: string;
456
+ };
457
+ declare const typedMemo: TypedMemo;
235
458
 
236
- declare const LegendList: <T>(props: LegendListProps<T> & {
237
- ref?: ForwardedRef<LegendListRef>;
238
- }) => ReactElement;
459
+ declare const LegendList: <T>(props: Omit<react_native.ScrollViewProps, "contentOffset" | "contentInset" | "maintainVisibleContentPosition" | "stickyHeaderIndices"> & {
460
+ alignItemsAtEnd?: boolean;
461
+ columnWrapperStyle?: ColumnWrapperStyle;
462
+ data: readonly T[];
463
+ drawDistance?: number;
464
+ estimatedItemSize?: number;
465
+ extraData?: any;
466
+ getEstimatedItemSize?: ((index: number, item: T) => number) | undefined;
467
+ initialContainerPoolRatio?: number | undefined;
468
+ initialScrollOffset?: number;
469
+ initialScrollIndex?: number;
470
+ ItemSeparatorComponent?: React$1.ComponentType<{
471
+ leadingItem: T;
472
+ }> | undefined;
473
+ keyExtractor?: ((item: T, index: number) => string) | undefined;
474
+ ListEmptyComponent?: React$1.ComponentType<any> | React$1.ReactElement | null | undefined;
475
+ ListFooterComponent?: React$1.ComponentType<any> | React$1.ReactElement | null | undefined;
476
+ ListFooterComponentStyle?: react_native.StyleProp<react_native.ViewStyle> | undefined;
477
+ ListHeaderComponent?: React$1.ComponentType<any> | React$1.ReactElement | null | undefined;
478
+ ListHeaderComponentStyle?: react_native.StyleProp<react_native.ViewStyle> | undefined;
479
+ maintainScrollAtEnd?: boolean;
480
+ maintainScrollAtEndThreshold?: number;
481
+ maintainVisibleContentPosition?: boolean;
482
+ numColumns?: number;
483
+ onEndReached?: ((info: {
484
+ distanceFromEnd: number;
485
+ }) => void) | null | undefined;
486
+ onEndReachedThreshold?: number | null | undefined;
487
+ onItemSizeChanged?: ((info: {
488
+ size: number;
489
+ previous: number;
490
+ index: number;
491
+ itemKey: string;
492
+ itemData: T;
493
+ }) => void) | undefined;
494
+ onRefresh?: () => void;
495
+ onStartReached?: ((info: {
496
+ distanceFromStart: number;
497
+ }) => void) | null | undefined;
498
+ onStartReachedThreshold?: number | null | undefined;
499
+ onViewableItemsChanged?: OnViewableItemsChanged | undefined;
500
+ progressViewOffset?: number;
501
+ recycleItems?: boolean;
502
+ refScrollView?: React$1.Ref<ScrollView>;
503
+ refreshing?: boolean;
504
+ renderItem?: ((props: LegendListRenderItemProps<T>) => React$1.ReactNode) | undefined;
505
+ renderScrollComponent?: (props: react_native.ScrollViewProps) => React$1.ReactElement<react_native.ScrollViewProps>;
506
+ viewabilityConfig?: ViewabilityConfig;
507
+ viewabilityConfigCallbackPairs?: ViewabilityConfigCallbackPairs | undefined;
508
+ waitForInitialLayout?: boolean;
509
+ } & React$1.RefAttributes<LegendListRef>) => React$1.ReactNode;
239
510
 
240
511
  declare function useViewability(configId: string, callback: ViewabilityCallback): void;
241
512
  declare function useViewabilityAmount(callback: ViewabilityAmountCallback): void;
242
513
  declare function useRecyclingEffect(effect: (info: LegendListRecyclingState<unknown>) => void | (() => void)): void;
243
- declare function useRecyclingState(valueOrFun: ((info: LegendListRecyclingState<unknown>) => any) | any): [any, react.Dispatch<any>];
514
+ declare function useRecyclingState(valueOrFun: ((info: LegendListRecyclingState<unknown>) => any) | any): [any, React$1.Dispatch<any>];
244
515
 
245
- export { type AnchoredPosition, type InternalState, LegendList, type LegendListProps, type LegendListPropsBase, type LegendListRecyclingState, type LegendListRef, type LegendListRenderItemProps, type OnViewableItemsChanged, type ViewAmountToken, type ViewToken, type ViewabilityAmountCallback, type ViewabilityCallback, type ViewabilityConfig, type ViewabilityConfigCallbackPair, type ViewabilityConfigCallbackPairs, type ViewableRange, useRecyclingEffect, useRecyclingState, useViewability, useViewabilityAmount };
516
+ export { type AnchoredPosition, type ColumnWrapperStyle, type InternalState, LegendList, type LegendListProps, type LegendListPropsBase, type LegendListRecyclingState, type LegendListRef, type LegendListRenderItemProps, type OnViewableItemsChanged, type ScrollState, type TypedForwardRef, type TypedMemo, type ViewAmountToken, type ViewToken, type ViewabilityAmountCallback, type ViewabilityCallback, type ViewabilityConfig, type ViewabilityConfigCallbackPair, type ViewabilityConfigCallbackPairs, type ViewableRange, typedForwardRef, typedMemo, useRecyclingEffect, useRecyclingState, useViewability, useViewabilityAmount };