@legendapp/list 1.0.0-beta.25 → 1.0.0-beta.27

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.mts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as React$1 from 'react';
2
2
  import { ComponentProps, ReactNode } from 'react';
3
3
  import * as react_native from 'react-native';
4
- import { ScrollView, StyleProp, ViewStyle, ScrollViewProps, ScrollViewComponent, ScrollResponderMixin } from 'react-native';
4
+ import { ScrollView, StyleProp, ViewStyle, ScrollViewProps, NativeSyntheticEvent, NativeScrollEvent, ScrollViewComponent, ScrollResponderMixin } from 'react-native';
5
5
  import Animated from 'react-native-reanimated';
6
6
 
7
7
  declare class ScrollAdjustHandler {
@@ -10,52 +10,132 @@ declare class ScrollAdjustHandler {
10
10
  private busy;
11
11
  private context;
12
12
  private isPaused;
13
+ private isDisabled;
13
14
  constructor(ctx: any);
14
15
  private doAjdust;
15
16
  requestAdjust(adjust: number, onAdjusted: (diff: number) => void): void;
16
17
  getAppliedAdjust(): number;
17
18
  pauseAdjust(): void;
19
+ setDisableAdjust(disable: boolean): void;
18
20
  unPauseAdjust(): boolean;
19
21
  }
20
22
 
21
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
+ */
22
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
+ */
23
69
  initialScrollOffset?: number;
70
+ /**
71
+ * Index to scroll to initially.
72
+ * @default 0
73
+ */
24
74
  initialScrollIndex?: number;
25
- drawDistance?: number;
26
- recycleItems?: boolean;
27
- onEndReachedThreshold?: number | null | undefined;
28
- 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
+ */
29
109
  maintainScrollAtEnd?: boolean;
110
+ /**
111
+ * Distance threshold in pixels to trigger maintainScrollAtEnd.
112
+ * @default 100
113
+ */
30
114
  maintainScrollAtEndThreshold?: number;
31
- alignItemsAtEnd?: boolean;
115
+ /**
116
+ * If true, maintains visibility of content during scroll (e.g., after insertions).
117
+ * @default false
118
+ */
32
119
  maintainVisibleContentPosition?: boolean;
120
+ /**
121
+ * Number of columns to render items in.
122
+ * @default 1
123
+ */
33
124
  numColumns?: number;
34
- columnWrapperStyle?: ColumnWrapperStyle;
35
- refScrollView?: React.Ref<ScrollView>;
36
- waitForInitialLayout?: boolean;
37
- initialContainerPoolRatio?: number | undefined;
38
- estimatedItemSize?: number;
39
- getEstimatedItemSize?: (index: number, item: ItemT) => number;
40
- onStartReached?: ((info: {
41
- distanceFromStart: number;
42
- }) => void) | null | undefined;
125
+ /**
126
+ * Called when scrolling reaches the end within onEndReachedThreshold.
127
+ */
43
128
  onEndReached?: ((info: {
44
129
  distanceFromEnd: number;
45
130
  }) => void) | null | undefined;
46
- keyExtractor?: (item: ItemT, index: number) => string;
47
- renderItem?: (props: LegendListRenderItemProps<ItemT>) => ReactNode;
48
- ListHeaderComponent?: React.ComponentType<any> | React.ReactElement | null | undefined;
49
- ListHeaderComponentStyle?: StyleProp<ViewStyle> | undefined;
50
- ListFooterComponent?: React.ComponentType<any> | React.ReactElement | null | undefined;
51
- ListFooterComponentStyle?: StyleProp<ViewStyle> | undefined;
52
- ListEmptyComponent?: React.ComponentType<any> | React.ReactElement | null | undefined;
53
- ItemSeparatorComponent?: React.ComponentType<{
54
- leadingItem: ItemT;
55
- }>;
56
- viewabilityConfigCallbackPairs?: ViewabilityConfigCallbackPairs | undefined;
57
- viewabilityConfig?: ViewabilityConfig;
58
- 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
+ */
59
139
  onItemSizeChanged?: (info: {
60
140
  size: number;
61
141
  previous: number;
@@ -63,15 +143,67 @@ type LegendListPropsBase<ItemT, TScrollView extends ComponentProps<typeof Scroll
63
143
  itemKey: string;
64
144
  itemData: ItemT;
65
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;
66
189
  /**
67
190
  * Render custom ScrollView component.
68
191
  * @default (props) => <ScrollView {...props} />
69
192
  */
70
193
  renderScrollComponent?: (props: ScrollViewProps) => React.ReactElement<ScrollViewProps>;
71
- extraData?: any;
72
- refreshing?: boolean;
73
- onRefresh?: () => void;
74
- progressViewOffset?: number;
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;
75
207
  };
76
208
  interface ColumnWrapperStyle {
77
209
  rowGap?: number;
@@ -139,6 +271,7 @@ interface InternalState {
139
271
  queuedCalculateItemsInView: number | undefined;
140
272
  lastBatchingAction: number;
141
273
  ignoreScrollFromCalcTotal?: boolean;
274
+ onScroll: ((event: NativeSyntheticEvent<NativeScrollEvent>) => void) | undefined;
142
275
  }
143
276
  interface ViewableRange<T> {
144
277
  startBuffered: number;
@@ -150,6 +283,7 @@ interface ViewableRange<T> {
150
283
  interface LegendListRenderItemProps<ItemT> {
151
284
  item: ItemT;
152
285
  index: number;
286
+ extraData: any;
153
287
  useViewability: (configId: string, callback: ViewabilityCallback) => void;
154
288
  useViewabilityAmount: (callback: ViewabilityAmountCallback) => void;
155
289
  useRecyclingEffect: (effect: (info: LegendListRecyclingState<ItemT>) => void | (() => void)) => void;
@@ -157,35 +291,63 @@ interface LegendListRenderItemProps<ItemT> {
157
291
  }
158
292
  type LegendListRef = {
159
293
  /**
160
- * Displays the scroll indicators momentarily.
161
- */
294
+ * Displays the scroll indicators momentarily.
295
+ */
162
296
  flashScrollIndicators(): void;
297
+ /**
298
+ * Returns the native ScrollView component reference.
299
+ */
163
300
  getNativeScrollRef(): React.ElementRef<typeof ScrollViewComponent>;
164
- getScrollResponder(): ScrollResponderMixin;
301
+ /**
302
+ * Returns the scroll responder instance for handling scroll events.
303
+ */
165
304
  getScrollableNode(): any;
166
305
  /**
167
- * A helper function that scrolls to the end of the scrollview;
168
- * If this is a vertical ScrollView, it scrolls to the bottom.
169
- * If this is a horizontal ScrollView scrolls to the right.
170
- *
171
- * The options object has an animated prop, that enables the scrolling animation or not.
172
- * The animated prop defaults to true
306
+ * Returns the ScrollResponderMixin for advanced scroll handling.
307
+ */
308
+ getScrollResponder(): ScrollResponderMixin;
309
+ /**
310
+ * Scrolls to the end of the list.
311
+ * @param options - Options for scrolling.
312
+ * @param options.animated - If true, animates the scroll. Default: true.
173
313
  */
174
314
  scrollToEnd(options?: {
175
315
  animated?: boolean | undefined;
176
316
  }): void;
317
+ /**
318
+ * Scrolls to a specific index in the list.
319
+ * @param params - Parameters for scrolling.
320
+ * @param params.animated - If true, animates the scroll. Default: true.
321
+ * @param params.index - The index to scroll to.
322
+ * @param params.viewOffset - Offset from the target position.
323
+ * @param params.viewPosition - Position of the item in the viewport (0 to 1).
324
+ */
177
325
  scrollToIndex(params: {
178
326
  animated?: boolean | undefined;
179
327
  index: number;
180
328
  viewOffset?: number | undefined;
181
329
  viewPosition?: number | undefined;
182
330
  }): void;
331
+ /**
332
+ * Scrolls to a specific item in the list.
333
+ * @param params - Parameters for scrolling.
334
+ * @param params.animated - If true, animates the scroll. Default: true.
335
+ * @param params.item - The item to scroll to.
336
+ * @param params.viewOffset - Offset from the target position.
337
+ * @param params.viewPosition - Position of the item in the viewport (0 to 1).
338
+ */
183
339
  scrollToItem(params: {
184
340
  animated?: boolean | undefined;
185
341
  item: any;
186
342
  viewOffset?: number | undefined;
187
343
  viewPosition?: number | undefined;
188
344
  }): void;
345
+ /**
346
+ * Scrolls to a specific offset in pixels.
347
+ * @param params - Parameters for scrolling.
348
+ * @param params.offset - The pixel offset to scroll to.
349
+ * @param params.animated - If true, animates the scroll. Default: true.
350
+ */
189
351
  scrollToOffset(params: {
190
352
  offset: number;
191
353
  animated?: boolean | undefined;
@@ -258,44 +420,34 @@ type TypedMemo = <T extends React.ComponentType<any>>(Component: T, propsAreEqua
258
420
  };
259
421
  declare const typedMemo: TypedMemo;
260
422
 
261
- declare const LegendList: <T>(props: Omit<react_native.ScrollViewProps, "contentOffset" | "contentInset" | "maintainVisibleContentPosition" | "stickyHeaderIndices"> & {
423
+ declare const LegendList: <T>(props: Omit<react_native.ScrollViewProps, "maintainVisibleContentPosition" | "stickyHeaderIndices" | "contentInset" | "contentOffset"> & {
424
+ alignItemsAtEnd?: boolean;
425
+ columnWrapperStyle?: ColumnWrapperStyle;
262
426
  data: readonly T[];
427
+ drawDistance?: number;
428
+ estimatedItemSize?: number;
429
+ extraData?: any;
430
+ getEstimatedItemSize?: ((index: number, item: T) => number) | undefined;
431
+ initialContainerPoolRatio?: number | undefined;
263
432
  initialScrollOffset?: number;
264
433
  initialScrollIndex?: number;
265
- drawDistance?: number;
266
- recycleItems?: boolean;
267
- onEndReachedThreshold?: number | null | undefined;
268
- onStartReachedThreshold?: number | null | undefined;
434
+ ItemSeparatorComponent?: React$1.ComponentType<{
435
+ leadingItem: T;
436
+ }> | undefined;
437
+ keyExtractor?: ((item: T, index: number) => string) | undefined;
438
+ ListEmptyComponent?: React$1.ComponentType<any> | React$1.ReactElement | null | undefined;
439
+ ListFooterComponent?: React$1.ComponentType<any> | React$1.ReactElement | null | undefined;
440
+ ListFooterComponentStyle?: react_native.StyleProp<react_native.ViewStyle> | undefined;
441
+ ListHeaderComponent?: React$1.ComponentType<any> | React$1.ReactElement | null | undefined;
442
+ ListHeaderComponentStyle?: react_native.StyleProp<react_native.ViewStyle> | undefined;
269
443
  maintainScrollAtEnd?: boolean;
270
444
  maintainScrollAtEndThreshold?: number;
271
- alignItemsAtEnd?: boolean;
272
445
  maintainVisibleContentPosition?: boolean;
273
446
  numColumns?: number;
274
- columnWrapperStyle?: ColumnWrapperStyle;
275
- refScrollView?: React$1.Ref<ScrollView>;
276
- waitForInitialLayout?: boolean;
277
- initialContainerPoolRatio?: number | undefined;
278
- estimatedItemSize?: number;
279
- getEstimatedItemSize?: ((index: number, item: T) => number) | undefined;
280
- onStartReached?: ((info: {
281
- distanceFromStart: number;
282
- }) => void) | null | undefined;
283
447
  onEndReached?: ((info: {
284
448
  distanceFromEnd: number;
285
449
  }) => void) | null | undefined;
286
- keyExtractor?: ((item: T, index: number) => string) | undefined;
287
- renderItem?: ((props: LegendListRenderItemProps<T>) => React$1.ReactNode) | undefined;
288
- ListHeaderComponent?: React$1.ComponentType<any> | React$1.ReactElement | null | undefined;
289
- ListHeaderComponentStyle?: react_native.StyleProp<react_native.ViewStyle> | undefined;
290
- ListFooterComponent?: React$1.ComponentType<any> | React$1.ReactElement | null | undefined;
291
- ListFooterComponentStyle?: react_native.StyleProp<react_native.ViewStyle> | undefined;
292
- ListEmptyComponent?: React$1.ComponentType<any> | React$1.ReactElement | null | undefined;
293
- ItemSeparatorComponent?: React$1.ComponentType<{
294
- leadingItem: T;
295
- }> | undefined;
296
- viewabilityConfigCallbackPairs?: ViewabilityConfigCallbackPairs | undefined;
297
- viewabilityConfig?: ViewabilityConfig;
298
- onViewableItemsChanged?: OnViewableItemsChanged | undefined;
450
+ onEndReachedThreshold?: number | null | undefined;
299
451
  onItemSizeChanged?: ((info: {
300
452
  size: number;
301
453
  previous: number;
@@ -303,11 +455,21 @@ declare const LegendList: <T>(props: Omit<react_native.ScrollViewProps, "content
303
455
  itemKey: string;
304
456
  itemData: T;
305
457
  }) => void) | undefined;
306
- renderScrollComponent?: (props: react_native.ScrollViewProps) => React$1.ReactElement<react_native.ScrollViewProps>;
307
- extraData?: any;
308
- refreshing?: boolean;
309
458
  onRefresh?: () => void;
459
+ onStartReached?: ((info: {
460
+ distanceFromStart: number;
461
+ }) => void) | null | undefined;
462
+ onStartReachedThreshold?: number | null | undefined;
463
+ onViewableItemsChanged?: OnViewableItemsChanged | undefined;
310
464
  progressViewOffset?: number;
465
+ recycleItems?: boolean;
466
+ refScrollView?: React$1.Ref<ScrollView>;
467
+ refreshing?: boolean;
468
+ renderItem?: ((props: LegendListRenderItemProps<T>) => React$1.ReactNode) | undefined;
469
+ renderScrollComponent?: (props: react_native.ScrollViewProps) => React$1.ReactElement<react_native.ScrollViewProps>;
470
+ viewabilityConfig?: ViewabilityConfig;
471
+ viewabilityConfigCallbackPairs?: ViewabilityConfigCallbackPairs | undefined;
472
+ waitForInitialLayout?: boolean;
311
473
  } & React$1.RefAttributes<LegendListRef>) => React$1.ReactNode;
312
474
 
313
475
  declare function useViewability(configId: string, callback: ViewabilityCallback): void;