@legendapp/list 3.0.0-beta.44 → 3.0.0-beta.45

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/animated.d.ts CHANGED
@@ -2,16 +2,28 @@ import * as React from 'react';
2
2
  import { Key } from 'react';
3
3
  import { ScrollViewProps, NativeSyntheticEvent as NativeSyntheticEvent$1, NativeScrollEvent as NativeScrollEvent$1, ScrollView, StyleProp as StyleProp$1, ViewStyle as ViewStyle$1, ScrollViewComponent, ScrollResponderMixin, Insets as Insets$1, Animated } from 'react-native';
4
4
 
5
- type ListenerType = "activeStickyIndex" | "debugComputedScroll" | "debugRawScroll" | "extraData" | "footerSize" | "headerSize" | "lastItemKeys" | "lastPositionUpdate" | "maintainVisibleContentPosition" | "numColumns" | "numContainers" | "numContainersPooled" | "otherAxisSize" | "readyToRender" | "scrollAdjust" | "scrollAdjustPending" | "scrollAdjustUserOffset" | "scrollSize" | "snapToOffsets" | "stylePaddingTop" | "totalSize" | `containerColumn${number}` | `containerSpan${number}` | `containerItemData${number}` | `containerItemKey${number}` | `containerPosition${number}` | `containerSticky${number}`;
6
- type LegendListListenerType = Extract<ListenerType, "activeStickyIndex" | "footerSize" | "headerSize" | "lastItemKeys" | "lastPositionUpdate" | "numContainers" | "numContainersPooled" | "otherAxisSize" | "readyToRender" | "snapToOffsets" | "totalSize">;
5
+ interface MaintainVisibleContentPositionNormalized<ItemT = any> {
6
+ data: boolean;
7
+ size: boolean;
8
+ shouldRestorePosition?: (item: ItemT, index: number, data: readonly ItemT[]) => boolean;
9
+ }
10
+
11
+ type ListenerType = "activeStickyIndex" | "anchoredEndSpaceSize" | "debugComputedScroll" | "debugRawScroll" | "extraData" | "footerSize" | "headerSize" | "lastItemKeys" | "lastPositionUpdate" | "maintainVisibleContentPosition" | "numColumns" | "numContainers" | "numContainersPooled" | "otherAxisSize" | "readyToRender" | "scrollAdjust" | "scrollAdjustPending" | "scrollAdjustUserOffset" | "scrollSize" | "snapToOffsets" | "stylePaddingTop" | "totalSize" | "isAtEnd" | "isAtStart" | "isNearEnd" | "isNearStart" | "isWithinMaintainScrollAtEndThreshold" | `containerColumn${number}` | `containerSpan${number}` | `containerItemData${number}` | `containerItemKey${number}` | `containerPosition${number}` | `containerSticky${number}`;
12
+ type LegendListListenerType = Extract<ListenerType, "activeStickyIndex" | "anchoredEndSpaceSize" | "footerSize" | "headerSize" | "isAtEnd" | "isAtStart" | "isNearEnd" | "isNearStart" | "isWithinMaintainScrollAtEndThreshold" | "lastItemKeys" | "lastPositionUpdate" | "numContainers" | "numContainersPooled" | "otherAxisSize" | "readyToRender" | "snapToOffsets" | "totalSize">;
7
13
  type ListenerTypeValueMap = {
8
14
  activeStickyIndex: number;
15
+ anchoredEndSpaceSize: number;
9
16
  animatedScrollY: any;
10
17
  debugComputedScroll: number;
11
18
  debugRawScroll: number;
12
19
  extraData: any;
13
20
  footerSize: number;
14
21
  headerSize: number;
22
+ isAtEnd: boolean;
23
+ isAtStart: boolean;
24
+ isNearEnd: boolean;
25
+ isNearStart: boolean;
26
+ isWithinMaintainScrollAtEndThreshold: boolean;
15
27
  lastItemKeys: string[];
16
28
  lastPositionUpdate: number;
17
29
  maintainVisibleContentPosition: MaintainVisibleContentPositionNormalized;
@@ -113,6 +125,11 @@ interface LegendListSpecificProps<ItemT, TItemType extends string | undefined> {
113
125
  * Style applied to each column's wrapper view.
114
126
  */
115
127
  columnWrapperStyle?: ColumnWrapperStyle;
128
+ /**
129
+ * Version token that forces the list to treat data as updated even when the array reference is stable.
130
+ * Increment or change this when mutating the data array in place.
131
+ */
132
+ dataVersion?: Key;
116
133
  /**
117
134
  * Distance in pixels to pre-render items ahead of the visible area.
118
135
  * @default 250
@@ -136,33 +153,35 @@ interface LegendListSpecificProps<ItemT, TItemType extends string | undefined> {
136
153
  * Extra data to trigger re-rendering when changed.
137
154
  */
138
155
  extraData?: any;
139
- /**
140
- * Version token that forces the list to treat data as updated even when the array reference is stable.
141
- * Increment or change this when mutating the data array in place.
142
- */
143
- dataVersion?: Key;
144
156
  /**
145
157
  * In case you have distinct item sizes, you can provide a function to get the size of an item.
146
- * Use instead of FlatList's getItemLayout or FlashList overrideItemLayout if you want to have accurate initialScrollOffset, you should provide this function
147
158
  */
148
159
  getEstimatedItemSize?: (item: ItemT, index: number, type: TItemType) => number;
149
160
  /**
150
- * Customize layout for multi-column lists, such as allowing items to span multiple columns.
151
- * Similar to FlashList's overrideItemLayout.
161
+ * In case items always have a fixed size, you can provide a function to return it.
152
162
  */
153
- overrideItemLayout?: (layout: {
154
- span?: number;
155
- }, item: ItemT, index: number, maxColumns: number, extraData?: any) => void;
163
+ getFixedItemSize?: (item: ItemT, index: number, type: TItemType) => number | undefined;
164
+ /**
165
+ * Returns a stable item type used for pooling and size estimation.
166
+ */
167
+ getItemType?: (item: ItemT, index: number) => TItemType;
168
+ /**
169
+ * Component to render between items, receiving the leading item as prop.
170
+ */
171
+ ItemSeparatorComponent?: React.ComponentType<{
172
+ leadingItem: ItemT;
173
+ }>;
156
174
  /**
157
175
  * Ratio of initial container pool size to data length (e.g., 0.5 for half).
158
176
  * @default 2
159
177
  */
160
178
  initialContainerPoolRatio?: number | undefined;
161
179
  /**
162
- * Initial scroll position in pixels.
163
- * @default 0
180
+ * When true, the list initializes scrolled to the last item.
181
+ * Overrides `initialScrollIndex` and `initialScrollOffset` when data is available.
182
+ * @default false
164
183
  */
165
- initialScrollOffset?: number;
184
+ initialScrollAtEnd?: boolean;
166
185
  /**
167
186
  * Index to scroll to initially.
168
187
  * @default 0
@@ -173,17 +192,14 @@ interface LegendListSpecificProps<ItemT, TItemType extends string | undefined> {
173
192
  viewPosition?: number | undefined;
174
193
  };
175
194
  /**
176
- * When true, the list initializes scrolled to the last item.
177
- * Overrides `initialScrollIndex` and `initialScrollOffset` when data is available.
178
- * @default false
195
+ * Initial scroll position in pixels.
196
+ * @default 0
179
197
  */
180
- initialScrollAtEnd?: boolean;
198
+ initialScrollOffset?: number;
181
199
  /**
182
- * Component to render between items, receiving the leading item as prop.
200
+ * Custom equality function to detect semantically unchanged items.
183
201
  */
184
- ItemSeparatorComponent?: React.ComponentType<{
185
- leadingItem: ItemT;
186
- }>;
202
+ itemsAreEqual?: (itemPrevious: ItemT, item: ItemT, index: number, data: readonly ItemT[]) => boolean;
187
203
  /**
188
204
  * Function to extract a unique key for each item.
189
205
  */
@@ -229,10 +245,9 @@ interface LegendListSpecificProps<ItemT, TItemType extends string | undefined> {
229
245
  */
230
246
  maintainVisibleContentPosition?: boolean | MaintainVisibleContentPositionConfig<ItemT>;
231
247
  /**
232
- * Web only: when true, listens to window/body scrolling instead of rendering a scrollable list container.
233
- * @default false
248
+ * Keeps an item visually anchored to the start by adding trailing space when the content below it underflows.
234
249
  */
235
- useWindowScroll?: boolean;
250
+ anchoredEndSpace?: AnchoredEndSpaceConfig;
236
251
  /**
237
252
  * Number of columns to render items in.
238
253
  * @default 1
@@ -259,6 +274,12 @@ interface LegendListSpecificProps<ItemT, TItemType extends string | undefined> {
259
274
  itemKey: string;
260
275
  itemData: ItemT;
261
276
  }) => void;
277
+ /**
278
+ * Called after the initial render work completes.
279
+ */
280
+ onLoad?: (info: {
281
+ elapsedTimeInMs: number;
282
+ }) => void;
262
283
  /**
263
284
  * Called when list layout metrics change.
264
285
  */
@@ -267,6 +288,9 @@ interface LegendListSpecificProps<ItemT, TItemType extends string | undefined> {
267
288
  * Function to call when the user pulls to refresh.
268
289
  */
269
290
  onRefresh?: () => void;
291
+ /**
292
+ * Called when the list scrolls.
293
+ */
270
294
  onScroll?: (event: NativeSyntheticEvent<NativeScrollEvent>) => void;
271
295
  /**
272
296
  * Called when scrolling reaches the start within onStartReachedThreshold.
@@ -290,6 +314,12 @@ interface LegendListSpecificProps<ItemT, TItemType extends string | undefined> {
290
314
  * Called when the viewability of items changes.
291
315
  */
292
316
  onViewableItemsChanged?: OnViewableItemsChanged<ItemT> | undefined;
317
+ /**
318
+ * Customize layout for multi-column lists, such as allowing items to span multiple columns.
319
+ */
320
+ overrideItemLayout?: (layout: {
321
+ span?: number;
322
+ }, item: ItemT, index: number, maxColumns: number, extraData?: any) => void;
293
323
  /**
294
324
  * Offset in pixels for the refresh indicator.
295
325
  * @default 0
@@ -315,6 +345,10 @@ interface LegendListSpecificProps<ItemT, TItemType extends string | undefined> {
315
345
  * @default (props) => <ScrollView {...props} />
316
346
  */
317
347
  renderScrollComponent?: (props: any) => React.ReactElement | null;
348
+ /**
349
+ * Array of item indices to use as snap points.
350
+ */
351
+ snapToIndices?: number[];
318
352
  /**
319
353
  * This will log a suggested estimatedItemSize.
320
354
  * @required
@@ -329,10 +363,6 @@ interface LegendListSpecificProps<ItemT, TItemType extends string | undefined> {
329
363
  * Pairs of viewability configs and their callbacks for tracking visibility.
330
364
  */
331
365
  viewabilityConfigCallbackPairs?: ViewabilityConfigCallbackPairs<ItemT> | undefined;
332
- onLoad?: (info: {
333
- elapsedTimeInMs: number;
334
- }) => void;
335
- snapToIndices?: number[];
336
366
  /**
337
367
  * Array of child indices determining which children get docked to the top of the screen when scrolling.
338
368
  * For example, passing stickyHeaderIndices={[0]} will cause the first child to be fixed to the top of the scroll view.
@@ -349,9 +379,11 @@ interface LegendListSpecificProps<ItemT, TItemType extends string | undefined> {
349
379
  * @default undefined
350
380
  */
351
381
  stickyHeaderConfig?: StickyHeaderConfig;
352
- getItemType?: (item: ItemT, index: number) => TItemType;
353
- getFixedItemSize?: (item: ItemT, index: number, type: TItemType) => number | undefined;
354
- itemsAreEqual?: (itemPrevious: ItemT, item: ItemT, index: number, data: readonly ItemT[]) => boolean;
382
+ /**
383
+ * Web only: when true, listens to window/body scrolling instead of rendering a scrollable list container.
384
+ * @default false
385
+ */
386
+ useWindowScroll?: boolean;
355
387
  }
356
388
  type LegendListPropsBase<ItemT, TScrollViewProps = Record<string, any>, TItemType extends string | undefined = string | undefined> = BaseScrollViewProps<TScrollViewProps> & LegendListSpecificProps<ItemT, TItemType> & (DataModeProps<ItemT, TItemType> | ChildrenModeProps);
357
389
  interface MaintainVisibleContentPositionConfig<ItemT = any> {
@@ -359,10 +391,12 @@ interface MaintainVisibleContentPositionConfig<ItemT = any> {
359
391
  size?: boolean;
360
392
  shouldRestorePosition?: (item: ItemT, index: number, data: readonly ItemT[]) => boolean;
361
393
  }
362
- interface MaintainVisibleContentPositionNormalized<ItemT = any> {
363
- data: boolean;
364
- size: boolean;
365
- shouldRestorePosition?: (item: ItemT, index: number, data: readonly ItemT[]) => boolean;
394
+ interface AnchoredEndSpaceConfig {
395
+ anchorIndex: number;
396
+ anchorOffset?: number;
397
+ anchorMaxSize?: number;
398
+ includeInEndInset?: boolean;
399
+ onSizeChanged?: (size: number) => void;
366
400
  }
367
401
  interface StickyHeaderConfig {
368
402
  /**
@@ -425,8 +459,11 @@ type LegendListState = {
425
459
  endBuffered: number;
426
460
  isAtEnd: boolean;
427
461
  isAtStart: boolean;
462
+ isNearEnd: boolean;
463
+ isNearStart: boolean;
428
464
  isEndReached: boolean;
429
465
  isStartReached: boolean;
466
+ isWithinMaintainScrollAtEndThreshold: boolean;
430
467
  listen: <T extends LegendListListenerType>(listenerType: T, callback: (value: ListenerTypeValueMap[T]) => void) => () => void;
431
468
  listenToPosition: (key: string, callback: (value: number) => void) => () => void;
432
469
  positionAtIndex: (index: number) => number;
@@ -565,10 +602,15 @@ interface ViewabilityConfigCallbackPair<ItemT = any> {
565
602
  viewabilityConfig: ViewabilityConfig;
566
603
  }
567
604
  type ViewabilityConfigCallbackPairs<ItemT> = ViewabilityConfigCallbackPair<ItemT>[];
568
- type OnViewableItemsChanged<ItemT> = ((info: {
569
- viewableItems: Array<ViewToken<ItemT>>;
605
+ interface OnViewableItemsChangedInfo<ItemT> {
570
606
  changed: Array<ViewToken<ItemT>>;
571
- }) => void) | null;
607
+ end: number;
608
+ endBuffered: number;
609
+ start: number;
610
+ startBuffered: number;
611
+ viewableItems: Array<ViewToken<ItemT>>;
612
+ }
613
+ type OnViewableItemsChanged<ItemT> = ((info: OnViewableItemsChangedInfo<ItemT>) => void) | null;
572
614
  interface ViewabilityConfig {
573
615
  /**
574
616
  * A unique ID to identify this viewability config
@@ -599,7 +641,7 @@ interface ViewabilityConfig {
599
641
  waitForInteraction?: boolean | undefined;
600
642
  }
601
643
 
602
- type LegendListPropsOverrides<ItemT, TItemType extends string | undefined> = Omit<LegendListPropsBase<ItemT, ScrollViewProps, TItemType>, "onScroll" | "refScrollView" | "renderScrollComponent" | "ListHeaderComponentStyle" | "ListFooterComponentStyle"> & {
644
+ type LegendListPropsOverrides<ItemT, TItemType extends string | undefined> = Omit<LegendListPropsBase<ItemT, ScrollViewProps, TItemType>, "anchoredEndSpace" | "onScroll" | "refScrollView" | "renderScrollComponent" | "ListHeaderComponentStyle" | "ListFooterComponentStyle"> & {
603
645
  onScroll?: (event: NativeSyntheticEvent$1<NativeScrollEvent$1>) => void;
604
646
  refScrollView?: React.Ref<ScrollView>;
605
647
  renderScrollComponent?: (props: ScrollViewProps) => React.ReactElement<ScrollViewProps>;