@legendapp/list 3.5.0 → 3.7.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.
package/react-native.d.ts CHANGED
@@ -8,8 +8,8 @@ interface MaintainVisibleContentPositionNormalized<ItemT = any> {
8
8
  shouldRestorePosition?: (item: ItemT, index: number, data: readonly ItemT[]) => boolean;
9
9
  }
10
10
 
11
- type ListenerType = "activeStickyIndex" | "alignItemsAtEndPadding" | "anchoredEndSpaceSize" | "containerLayoutEpoch" | "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" | "adaptiveRender" | `containerColumn${number}` | `containerSpan${number}` | `containerItemData${number}` | `containerItemIndex${number}` | `containerItemKey${number}` | `containerLayoutReady${number}` | `containerPosition${number}` | `containerSticky${number}`;
12
- type LegendListListenerType = Extract<ListenerType, "activeStickyIndex" | "anchoredEndSpaceSize" | "footerSize" | "headerSize" | "isAtEnd" | "isAtStart" | "isNearEnd" | "isNearStart" | "isWithinMaintainScrollAtEndThreshold" | "adaptiveRender" | "lastItemKeys" | "lastPositionUpdate" | "numContainers" | "numContainersPooled" | "otherAxisSize" | "readyToRender" | "snapToOffsets" | "totalSize">;
11
+ type ListenerType = "activeStickyIndex" | "alignItemsAtEndPadding" | "anchoredEndSpaceSize" | "containerLayoutEpoch" | "debugComputedScroll" | "debugRawScroll" | "extraData" | "footerSize" | "headerSize" | "lastItemKeys" | "lastPositionUpdate" | "maintainVisibleContentPosition" | "numColumns" | "numContainers" | "numContainersPooled" | "otherAxisSize" | "readyToRender" | "isScrollActive" | "scrollAdjust" | "scrollAdjustPending" | "scrollAdjustUserOffset" | "scrollSize" | "snapToOffsets" | "stylePaddingTop" | "totalSize" | "isFollowingEnd" | "isAtEnd" | "isAtStart" | "isNearEnd" | "isNearStart" | "isWithinMaintainScrollAtEndThreshold" | "adaptiveRender" | `containerColumn${number}` | `containerSpan${number}` | `containerItemData${number}` | `containerItemIndex${number}` | `containerItemKey${number}` | `containerLayoutReady${number}` | `containerPosition${number}` | `containerSticky${number}`;
12
+ type LegendListListenerType = Extract<ListenerType, "activeStickyIndex" | "anchoredEndSpaceSize" | "footerSize" | "headerSize" | "isFollowingEnd" | "isAtEnd" | "isAtStart" | "isNearEnd" | "isNearStart" | "isWithinMaintainScrollAtEndThreshold" | "adaptiveRender" | "lastItemKeys" | "lastPositionUpdate" | "numContainers" | "numContainersPooled" | "otherAxisSize" | "readyToRender" | "snapToOffsets" | "totalSize">;
13
13
  type ListenerTypeValueMap = {
14
14
  activeStickyIndex: number;
15
15
  alignItemsAtEndPadding: number;
@@ -21,6 +21,7 @@ type ListenerTypeValueMap = {
21
21
  extraData: any;
22
22
  footerSize: number;
23
23
  headerSize: number;
24
+ isFollowingEnd: boolean;
24
25
  isAtEnd: boolean;
25
26
  isAtStart: boolean;
26
27
  isNearEnd: boolean;
@@ -34,6 +35,7 @@ type ListenerTypeValueMap = {
34
35
  numContainersPooled: number;
35
36
  otherAxisSize: number;
36
37
  readyToRender: boolean;
38
+ isScrollActive: boolean;
37
39
  scrollAdjust: number;
38
40
  scrollAdjustPending: number;
39
41
  scrollAdjustUserOffset: number;
@@ -199,6 +201,7 @@ interface LegendListSpecificProps<ItemT, TItemType extends string | undefined> {
199
201
  extraData?: any;
200
202
  /**
201
203
  * In case items always have a fixed size, you can provide a function to return it.
204
+ * Change extraData when the fixed sizes returned by this callback change.
202
205
  */
203
206
  getFixedItemSize?: (item: ItemT, index: number, type: TItemType) => number | undefined;
204
207
  /**
@@ -225,6 +228,8 @@ interface LegendListSpecificProps<ItemT, TItemType extends string | undefined> {
225
228
  index: number;
226
229
  viewOffset?: number | undefined;
227
230
  viewPosition?: number | undefined;
231
+ /** Alignment used only when the item exceeds the viewport. Omit to preserve viewPosition. */
232
+ viewPositionFallback?: "start" | "end";
228
233
  };
229
234
  /**
230
235
  * Initial scroll position in pixels.
@@ -269,6 +274,11 @@ interface LegendListSpecificProps<ItemT, TItemType extends string | undefined> {
269
274
  /**
270
275
  * If true, auto-scrolls to end when new items are added.
271
276
  * Use an options object to opt into specific triggers and control whether that scroll is animated.
277
+ * Setting false pauses maintenance while retaining end-follow intent. Re-enabling resumes
278
+ * that intent even if content grew beyond the threshold; user or list navigation releases it.
279
+ * While paused, isFollowingEnd reports the retained intent.
280
+ * With a native screen reader enabled, unowned accessibility scrolls toward the start
281
+ * release following. Assistive-tech scrolls during library animations are not detected.
272
282
  * @default false
273
283
  */
274
284
  maintainScrollAtEnd?: boolean | MaintainScrollAtEndOptions;
@@ -279,11 +289,13 @@ interface LegendListSpecificProps<ItemT, TItemType extends string | undefined> {
279
289
  maintainScrollAtEndThreshold?: number;
280
290
  /**
281
291
  * Maintains visibility of content.
282
- * - scroll (default: true) stabilizes during size/layout changes while scrolling.
283
- * - data (default: false) stabilizes when the data array changes; passing true also sets the RN maintainVisibleContentPosition prop.
292
+ * - size (default: true) stabilizes during size/layout changes while scrolling.
293
+ * - data (default: false) stabilizes when the data array changes.
284
294
  * - shouldRestorePosition can opt out specific items from data-change anchoring.
285
295
  * - undefined (default) enables scroll stabilization but skips data-change anchoring.
286
- * - true enables both behaviors; false disables both.
296
+ * - true enables both JS behaviors; false disables both.
297
+ * Native iOS maintainVisibleContentPosition is enabled when either size or data stabilization is enabled,
298
+ * and disabled when both are disabled.
287
299
  */
288
300
  maintainVisibleContentPosition?: boolean | MaintainVisibleContentPositionConfig<ItemT>;
289
301
  /**
@@ -375,8 +387,25 @@ interface LegendListSpecificProps<ItemT, TItemType extends string | undefined> {
375
387
  */
376
388
  onRefresh?: () => void;
377
389
  /**
378
- * Called when the list scrolls.
379
- */
390
+ * Called once per accepted user gesture, in either direction: native drag (including
391
+ * momentum), web wheel/touch movement, non-repeated scroll keydown, or scrollbar drag.
392
+ * Wheel input at a boundary is ignored unless navigation is active. Without wheel
393
+ * momentum metadata, gesture boundaries are inferred from timing, direction and force.
394
+ * iOS status-bar scrolling emits on native onScrollToTop unless accessibility motion
395
+ * already reported it during the animation.
396
+ * With a native screen reader enabled, otherwise unowned scroll motion with stable
397
+ * content/viewport size is inferred as accessibility input (including focus navigation),
398
+ * once per burst; motion toward the start releases end following. Library animations
399
+ * and controller/native-ref command windows mask assistive-tech scrolling.
400
+ * Native commands bypassing the list and its refs (e.g. Reanimated scrollTo worklets)
401
+ * cannot be distinguished from accessibility input while a screen reader is on; call
402
+ * cancelScroll() on the JS thread before that navigation to release end following.
403
+ * Layout/clamp/MVCP events and commands through the list or its refs do not emit it.
404
+ * @experimental Native pointer/wheel-only input without a screen reader is not detected.
405
+ * Web scrollbar detection requires pointer events in a measurable, non-overlay gutter.
406
+ */
407
+ onUserScroll?: () => void;
408
+ /** Called when the list scrolls. */
380
409
  onScroll?: (event: NativeSyntheticEvent<NativeScrollEvent>) => void;
381
410
  /**
382
411
  * Called when scrolling reaches the start within onStartReachedThreshold.
@@ -508,6 +537,8 @@ interface AlwaysRenderConfig {
508
537
  keys?: string[];
509
538
  }
510
539
  interface MaintainScrollAtEndOnOptions {
540
+ /** Follow only additions that preserve every existing item key in order. */
541
+ dataAppend?: boolean;
511
542
  dataChange?: boolean;
512
543
  footerLayout?: boolean;
513
544
  itemLayout?: boolean;
@@ -549,9 +580,13 @@ type LegendListState$1 = {
549
580
  activeStickyIndex: number;
550
581
  contentLength: number;
551
582
  data: readonly any[];
583
+ dataKey?: Key;
552
584
  elementAtIndex: (index: number) => any;
553
585
  end: number;
554
586
  endBuffered: number;
587
+ /** Distance to the physical scroll edge, including the trailing inset. */
588
+ distanceFromEnd: number;
589
+ isFollowingEnd: boolean;
555
590
  isAtEnd: boolean;
556
591
  isAtStart: boolean;
557
592
  isNearEnd: boolean;
@@ -561,7 +596,10 @@ type LegendListState$1 = {
561
596
  isWithinMaintainScrollAtEndThreshold: boolean;
562
597
  getAverageItemSizes: () => Record<string, LegendListAverageItemSize>;
563
598
  indexByKey: (key: string) => number | undefined;
564
- listen: <T extends LegendListListenerType>(listenerType: T, callback: (value: ListenerTypeValueMap[T]) => void) => () => void;
599
+ listen: {
600
+ <T extends Exclude<LegendListListenerType, "isFollowingEnd">>(listenerType: T, callback: (value: Pick<ListenerTypeValueMap, LegendListListenerType>[T]) => void): () => void;
601
+ <T extends LegendListListenerType>(listenerType: T, callback: (value: Pick<ListenerTypeValueMap, LegendListListenerType>[T]) => void): () => void;
602
+ };
565
603
  listenToPosition: (key: string, callback: (value: number) => void) => () => void;
566
604
  positionAtIndex: (index: number) => number;
567
605
  positionByKey: (key: string) => number | undefined;
@@ -574,6 +612,28 @@ type LegendListState$1 = {
574
612
  startBuffered: number;
575
613
  };
576
614
  type LegendListRef$1 = {
615
+ /** Cancels queued and active scrolling, settles its promise, and stops at the observed offset. */
616
+ cancelScroll(): void;
617
+ /** Scrolls by stable item identity through prepends; resolves without scrolling if the key is missing or removed. */
618
+ scrollToKey(params: {
619
+ key: string;
620
+ animated?: boolean;
621
+ viewOffset?: number;
622
+ viewPosition?: number;
623
+ }): Promise<void>;
624
+ /**
625
+ * Captures an item's key and viewport offset, holding it through layout changes by default.
626
+ * Omit key to use the first visible item; set hold to false to read without side effects.
627
+ * Returns undefined before initial placement, during dataset replacement, or if no item is found.
628
+ * While following at the end, returns the anchor without interrupting end following.
629
+ */
630
+ anchorVisibleContent(options?: {
631
+ key?: string;
632
+ hold?: boolean;
633
+ }): {
634
+ key: string;
635
+ offset: number;
636
+ } | undefined;
577
637
  /**
578
638
  * Clears internal virtualization caches.
579
639
  * @param options - Cache clearing options.
@@ -616,20 +676,40 @@ type LegendListRef$1 = {
616
676
  * @param params - Parameters for scrolling.
617
677
  * @param params.animated - If true, animates the scroll. Default: true.
618
678
  * @param params.index - The index to scroll to.
679
+ * @param params.itemOffset - Region start measured from the item's start along the scroll axis. Default: 0 when itemLength is provided.
680
+ * @param params.itemLength - Region length along the scroll axis. Default: 0 when itemOffset is provided. Omit both to reveal the whole item.
681
+ * @param params.viewportMargin - Space to keep clear at the start and end of the viewport along the scroll axis.
682
+ * The region should be within the item. A visible region does not scroll; otherwise its nearest edge aligns inside the margins. A region larger than the available space aligns its start.
619
683
  */
620
684
  scrollIndexIntoView(params: {
621
685
  animated?: boolean | undefined;
622
686
  index: number;
687
+ itemOffset?: number;
688
+ itemLength?: number;
689
+ viewportMargin?: {
690
+ start?: number;
691
+ end?: number;
692
+ };
623
693
  }): Promise<void>;
624
694
  /**
625
- * Scrolls a specific index into view.
695
+ * Scrolls a specific item into view.
626
696
  * @param params - Parameters for scrolling.
627
697
  * @param params.animated - If true, animates the scroll. Default: true.
628
698
  * @param params.item - The item to scroll to.
699
+ * @param params.itemOffset - Region start measured from the item's start along the scroll axis. Default: 0 when itemLength is provided.
700
+ * @param params.itemLength - Region length along the scroll axis. Default: 0 when itemOffset is provided. Omit both to reveal the whole item.
701
+ * @param params.viewportMargin - Space to keep clear at the start and end of the viewport along the scroll axis.
702
+ * The region should be within the item. A visible region does not scroll; otherwise its nearest edge aligns inside the margins. A region larger than the available space aligns its start.
629
703
  */
630
704
  scrollItemIntoView(params: {
631
705
  animated?: boolean | undefined;
632
706
  item: any;
707
+ itemOffset?: number;
708
+ itemLength?: number;
709
+ viewportMargin?: {
710
+ start?: number;
711
+ end?: number;
712
+ };
633
713
  }): Promise<void>;
634
714
  /**
635
715
  * Scrolls to the end of the list.
@@ -651,6 +731,8 @@ type LegendListRef$1 = {
651
731
  index: number;
652
732
  viewOffset?: number | undefined;
653
733
  viewPosition?: number | undefined;
734
+ /** Alignment used only when the item exceeds the viewport. Omit to preserve viewPosition. */
735
+ viewPositionFallback?: "start" | "end";
654
736
  }): Promise<void>;
655
737
  /**
656
738
  * Scrolls to a specific item in the list.
@@ -665,6 +747,8 @@ type LegendListRef$1 = {
665
747
  item: any;
666
748
  viewOffset?: number | undefined;
667
749
  viewPosition?: number | undefined;
750
+ /** Alignment used only when the item exceeds the viewport. Omit to preserve viewPosition. */
751
+ viewPositionFallback?: "start" | "end";
668
752
  }): Promise<void>;
669
753
  /**
670
754
  * Scrolls to a specific offset in pixels.
@@ -704,6 +788,10 @@ interface ViewToken<ItemT = any> {
704
788
  interface ViewAmountToken<ItemT = any> extends ViewToken<ItemT> {
705
789
  percentOfScroller: number;
706
790
  percentVisible: number;
791
+ /**
792
+ * Viewport size used for this measurement, with any integration-reported
793
+ * occlusion (for example a keyboard) already subtracted.
794
+ */
707
795
  scrollSize: number;
708
796
  size: number;
709
797
  sizeVisible: number;
@@ -763,6 +851,8 @@ interface ScrollIndexWithOffset {
763
851
  index: number;
764
852
  viewOffset?: number;
765
853
  viewPosition?: number;
854
+ /** Alignment used only when the item exceeds the viewport. Omit to preserve viewPosition. */
855
+ viewPositionFallback?: "start" | "end";
766
856
  }
767
857
  interface ScrollIndexWithOffsetPosition extends ScrollIndexWithOffset {
768
858
  viewPosition?: number;
@@ -781,7 +871,9 @@ type LegendListPropsOverrides<ItemT, TItemType extends string | undefined> = Omi
781
871
  };
782
872
  type LegendListProps<ItemT = any, TItemType extends string | undefined = string | undefined> = LegendListPropsOverrides<ItemT, TItemType>;
783
873
  type LegendListRef = Omit<LegendListRef$1, "getAnimatableRef" | "getNativeScrollRef" | "getScrollResponder" | "reportContentInset"> & {
874
+ /** Call cancelScroll() before scrolling it directly so end following and list scrolling stop first. */
784
875
  getAnimatableRef(): React.ElementRef<typeof ScrollViewComponent>;
876
+ /** Call cancelScroll() before scrolling it directly so end following and list scrolling stop first. */
785
877
  getNativeScrollRef(): React.ElementRef<typeof ScrollViewComponent>;
786
878
  getScrollResponder(): ScrollResponderMixin;
787
879
  reportContentInset(inset?: Partial<Insets$1> | null): void;