@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/section-list.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as react_native from 'react-native';
2
- import { SectionListData, ScrollViewProps, NativeSyntheticEvent as NativeSyntheticEvent$1, NativeScrollEvent as NativeScrollEvent$1, ScrollView, StyleProp as StyleProp$1, ViewStyle as ViewStyle$1, ScrollViewComponent, ScrollResponderMixin, Insets as Insets$1, SectionBase, SectionListRenderItemInfo, SectionListScrollParams } from 'react-native';
2
+ import { SectionListData, ScrollViewProps, NativeSyntheticEvent as NativeSyntheticEvent$1, NativeScrollEvent as NativeScrollEvent$1, ScrollView, StyleProp as StyleProp$1, ViewStyle as ViewStyle$1, ScrollViewComponent, ScrollResponderMixin, Insets as Insets$1, SectionBase, SectionListRenderItemInfo, SectionListScrollParams as SectionListScrollParams$1 } from 'react-native';
3
3
  import * as React from 'react';
4
4
  import { Key } from 'react';
5
5
 
@@ -65,8 +65,8 @@ interface MaintainVisibleContentPositionNormalized<ItemT = any> {
65
65
  shouldRestorePosition?: (item: ItemT, index: number, data: readonly ItemT[]) => boolean;
66
66
  }
67
67
 
68
- 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}`;
69
- type LegendListListenerType = Extract<ListenerType, "activeStickyIndex" | "anchoredEndSpaceSize" | "footerSize" | "headerSize" | "isAtEnd" | "isAtStart" | "isNearEnd" | "isNearStart" | "isWithinMaintainScrollAtEndThreshold" | "adaptiveRender" | "lastItemKeys" | "lastPositionUpdate" | "numContainers" | "numContainersPooled" | "otherAxisSize" | "readyToRender" | "snapToOffsets" | "totalSize">;
68
+ 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}`;
69
+ type LegendListListenerType = Extract<ListenerType, "activeStickyIndex" | "anchoredEndSpaceSize" | "footerSize" | "headerSize" | "isFollowingEnd" | "isAtEnd" | "isAtStart" | "isNearEnd" | "isNearStart" | "isWithinMaintainScrollAtEndThreshold" | "adaptiveRender" | "lastItemKeys" | "lastPositionUpdate" | "numContainers" | "numContainersPooled" | "otherAxisSize" | "readyToRender" | "snapToOffsets" | "totalSize">;
70
70
  type ListenerTypeValueMap = {
71
71
  activeStickyIndex: number;
72
72
  alignItemsAtEndPadding: number;
@@ -78,6 +78,7 @@ type ListenerTypeValueMap = {
78
78
  extraData: any;
79
79
  footerSize: number;
80
80
  headerSize: number;
81
+ isFollowingEnd: boolean;
81
82
  isAtEnd: boolean;
82
83
  isAtStart: boolean;
83
84
  isNearEnd: boolean;
@@ -91,6 +92,7 @@ type ListenerTypeValueMap = {
91
92
  numContainersPooled: number;
92
93
  otherAxisSize: number;
93
94
  readyToRender: boolean;
95
+ isScrollActive: boolean;
94
96
  scrollAdjust: number;
95
97
  scrollAdjustPending: number;
96
98
  scrollAdjustUserOffset: number;
@@ -256,6 +258,7 @@ interface LegendListSpecificProps<ItemT, TItemType extends string | undefined> {
256
258
  extraData?: any;
257
259
  /**
258
260
  * In case items always have a fixed size, you can provide a function to return it.
261
+ * Change extraData when the fixed sizes returned by this callback change.
259
262
  */
260
263
  getFixedItemSize?: (item: ItemT, index: number, type: TItemType) => number | undefined;
261
264
  /**
@@ -282,6 +285,8 @@ interface LegendListSpecificProps<ItemT, TItemType extends string | undefined> {
282
285
  index: number;
283
286
  viewOffset?: number | undefined;
284
287
  viewPosition?: number | undefined;
288
+ /** Alignment used only when the item exceeds the viewport. Omit to preserve viewPosition. */
289
+ viewPositionFallback?: "start" | "end";
285
290
  };
286
291
  /**
287
292
  * Initial scroll position in pixels.
@@ -326,6 +331,11 @@ interface LegendListSpecificProps<ItemT, TItemType extends string | undefined> {
326
331
  /**
327
332
  * If true, auto-scrolls to end when new items are added.
328
333
  * Use an options object to opt into specific triggers and control whether that scroll is animated.
334
+ * Setting false pauses maintenance while retaining end-follow intent. Re-enabling resumes
335
+ * that intent even if content grew beyond the threshold; user or list navigation releases it.
336
+ * While paused, isFollowingEnd reports the retained intent.
337
+ * With a native screen reader enabled, unowned accessibility scrolls toward the start
338
+ * release following. Assistive-tech scrolls during library animations are not detected.
329
339
  * @default false
330
340
  */
331
341
  maintainScrollAtEnd?: boolean | MaintainScrollAtEndOptions;
@@ -336,11 +346,13 @@ interface LegendListSpecificProps<ItemT, TItemType extends string | undefined> {
336
346
  maintainScrollAtEndThreshold?: number;
337
347
  /**
338
348
  * Maintains visibility of content.
339
- * - scroll (default: true) stabilizes during size/layout changes while scrolling.
340
- * - data (default: false) stabilizes when the data array changes; passing true also sets the RN maintainVisibleContentPosition prop.
349
+ * - size (default: true) stabilizes during size/layout changes while scrolling.
350
+ * - data (default: false) stabilizes when the data array changes.
341
351
  * - shouldRestorePosition can opt out specific items from data-change anchoring.
342
352
  * - undefined (default) enables scroll stabilization but skips data-change anchoring.
343
- * - true enables both behaviors; false disables both.
353
+ * - true enables both JS behaviors; false disables both.
354
+ * Native iOS maintainVisibleContentPosition is enabled when either size or data stabilization is enabled,
355
+ * and disabled when both are disabled.
344
356
  */
345
357
  maintainVisibleContentPosition?: boolean | MaintainVisibleContentPositionConfig<ItemT>;
346
358
  /**
@@ -432,8 +444,25 @@ interface LegendListSpecificProps<ItemT, TItemType extends string | undefined> {
432
444
  */
433
445
  onRefresh?: () => void;
434
446
  /**
435
- * Called when the list scrolls.
436
- */
447
+ * Called once per accepted user gesture, in either direction: native drag (including
448
+ * momentum), web wheel/touch movement, non-repeated scroll keydown, or scrollbar drag.
449
+ * Wheel input at a boundary is ignored unless navigation is active. Without wheel
450
+ * momentum metadata, gesture boundaries are inferred from timing, direction and force.
451
+ * iOS status-bar scrolling emits on native onScrollToTop unless accessibility motion
452
+ * already reported it during the animation.
453
+ * With a native screen reader enabled, otherwise unowned scroll motion with stable
454
+ * content/viewport size is inferred as accessibility input (including focus navigation),
455
+ * once per burst; motion toward the start releases end following. Library animations
456
+ * and controller/native-ref command windows mask assistive-tech scrolling.
457
+ * Native commands bypassing the list and its refs (e.g. Reanimated scrollTo worklets)
458
+ * cannot be distinguished from accessibility input while a screen reader is on; call
459
+ * cancelScroll() on the JS thread before that navigation to release end following.
460
+ * Layout/clamp/MVCP events and commands through the list or its refs do not emit it.
461
+ * @experimental Native pointer/wheel-only input without a screen reader is not detected.
462
+ * Web scrollbar detection requires pointer events in a measurable, non-overlay gutter.
463
+ */
464
+ onUserScroll?: () => void;
465
+ /** Called when the list scrolls. */
437
466
  onScroll?: (event: NativeSyntheticEvent<NativeScrollEvent>) => void;
438
467
  /**
439
468
  * Called when scrolling reaches the start within onStartReachedThreshold.
@@ -565,6 +594,8 @@ interface AlwaysRenderConfig {
565
594
  keys?: string[];
566
595
  }
567
596
  interface MaintainScrollAtEndOnOptions {
597
+ /** Follow only additions that preserve every existing item key in order. */
598
+ dataAppend?: boolean;
568
599
  dataChange?: boolean;
569
600
  footerLayout?: boolean;
570
601
  itemLayout?: boolean;
@@ -606,9 +637,13 @@ type LegendListState = {
606
637
  activeStickyIndex: number;
607
638
  contentLength: number;
608
639
  data: readonly any[];
640
+ dataKey?: Key;
609
641
  elementAtIndex: (index: number) => any;
610
642
  end: number;
611
643
  endBuffered: number;
644
+ /** Distance to the physical scroll edge, including the trailing inset. */
645
+ distanceFromEnd: number;
646
+ isFollowingEnd: boolean;
612
647
  isAtEnd: boolean;
613
648
  isAtStart: boolean;
614
649
  isNearEnd: boolean;
@@ -618,7 +653,10 @@ type LegendListState = {
618
653
  isWithinMaintainScrollAtEndThreshold: boolean;
619
654
  getAverageItemSizes: () => Record<string, LegendListAverageItemSize>;
620
655
  indexByKey: (key: string) => number | undefined;
621
- listen: <T extends LegendListListenerType>(listenerType: T, callback: (value: ListenerTypeValueMap[T]) => void) => () => void;
656
+ listen: {
657
+ <T extends Exclude<LegendListListenerType, "isFollowingEnd">>(listenerType: T, callback: (value: Pick<ListenerTypeValueMap, LegendListListenerType>[T]) => void): () => void;
658
+ <T extends LegendListListenerType>(listenerType: T, callback: (value: Pick<ListenerTypeValueMap, LegendListListenerType>[T]) => void): () => void;
659
+ };
622
660
  listenToPosition: (key: string, callback: (value: number) => void) => () => void;
623
661
  positionAtIndex: (index: number) => number;
624
662
  positionByKey: (key: string) => number | undefined;
@@ -631,6 +669,28 @@ type LegendListState = {
631
669
  startBuffered: number;
632
670
  };
633
671
  type LegendListRef$1 = {
672
+ /** Cancels queued and active scrolling, settles its promise, and stops at the observed offset. */
673
+ cancelScroll(): void;
674
+ /** Scrolls by stable item identity through prepends; resolves without scrolling if the key is missing or removed. */
675
+ scrollToKey(params: {
676
+ key: string;
677
+ animated?: boolean;
678
+ viewOffset?: number;
679
+ viewPosition?: number;
680
+ }): Promise<void>;
681
+ /**
682
+ * Captures an item's key and viewport offset, holding it through layout changes by default.
683
+ * Omit key to use the first visible item; set hold to false to read without side effects.
684
+ * Returns undefined before initial placement, during dataset replacement, or if no item is found.
685
+ * While following at the end, returns the anchor without interrupting end following.
686
+ */
687
+ anchorVisibleContent(options?: {
688
+ key?: string;
689
+ hold?: boolean;
690
+ }): {
691
+ key: string;
692
+ offset: number;
693
+ } | undefined;
634
694
  /**
635
695
  * Clears internal virtualization caches.
636
696
  * @param options - Cache clearing options.
@@ -673,20 +733,40 @@ type LegendListRef$1 = {
673
733
  * @param params - Parameters for scrolling.
674
734
  * @param params.animated - If true, animates the scroll. Default: true.
675
735
  * @param params.index - The index to scroll to.
736
+ * @param params.itemOffset - Region start measured from the item's start along the scroll axis. Default: 0 when itemLength is provided.
737
+ * @param params.itemLength - Region length along the scroll axis. Default: 0 when itemOffset is provided. Omit both to reveal the whole item.
738
+ * @param params.viewportMargin - Space to keep clear at the start and end of the viewport along the scroll axis.
739
+ * 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.
676
740
  */
677
741
  scrollIndexIntoView(params: {
678
742
  animated?: boolean | undefined;
679
743
  index: number;
744
+ itemOffset?: number;
745
+ itemLength?: number;
746
+ viewportMargin?: {
747
+ start?: number;
748
+ end?: number;
749
+ };
680
750
  }): Promise<void>;
681
751
  /**
682
- * Scrolls a specific index into view.
752
+ * Scrolls a specific item into view.
683
753
  * @param params - Parameters for scrolling.
684
754
  * @param params.animated - If true, animates the scroll. Default: true.
685
755
  * @param params.item - The item to scroll to.
756
+ * @param params.itemOffset - Region start measured from the item's start along the scroll axis. Default: 0 when itemLength is provided.
757
+ * @param params.itemLength - Region length along the scroll axis. Default: 0 when itemOffset is provided. Omit both to reveal the whole item.
758
+ * @param params.viewportMargin - Space to keep clear at the start and end of the viewport along the scroll axis.
759
+ * 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.
686
760
  */
687
761
  scrollItemIntoView(params: {
688
762
  animated?: boolean | undefined;
689
763
  item: any;
764
+ itemOffset?: number;
765
+ itemLength?: number;
766
+ viewportMargin?: {
767
+ start?: number;
768
+ end?: number;
769
+ };
690
770
  }): Promise<void>;
691
771
  /**
692
772
  * Scrolls to the end of the list.
@@ -708,6 +788,8 @@ type LegendListRef$1 = {
708
788
  index: number;
709
789
  viewOffset?: number | undefined;
710
790
  viewPosition?: number | undefined;
791
+ /** Alignment used only when the item exceeds the viewport. Omit to preserve viewPosition. */
792
+ viewPositionFallback?: "start" | "end";
711
793
  }): Promise<void>;
712
794
  /**
713
795
  * Scrolls to a specific item in the list.
@@ -722,6 +804,8 @@ type LegendListRef$1 = {
722
804
  item: any;
723
805
  viewOffset?: number | undefined;
724
806
  viewPosition?: number | undefined;
807
+ /** Alignment used only when the item exceeds the viewport. Omit to preserve viewPosition. */
808
+ viewPositionFallback?: "start" | "end";
725
809
  }): Promise<void>;
726
810
  /**
727
811
  * Scrolls to a specific offset in pixels.
@@ -812,12 +896,17 @@ type LegendListPropsOverrides<ItemT, TItemType extends string | undefined> = Omi
812
896
  };
813
897
  type LegendListProps<ItemT = any, TItemType extends string | undefined = string | undefined> = LegendListPropsOverrides<ItemT, TItemType>;
814
898
  type LegendListRef = Omit<LegendListRef$1, "getAnimatableRef" | "getNativeScrollRef" | "getScrollResponder" | "reportContentInset"> & {
899
+ /** Call cancelScroll() before scrolling it directly so end following and list scrolling stop first. */
815
900
  getAnimatableRef(): React.ElementRef<typeof ScrollViewComponent>;
901
+ /** Call cancelScroll() before scrolling it directly so end following and list scrolling stop first. */
816
902
  getNativeScrollRef(): React.ElementRef<typeof ScrollViewComponent>;
817
903
  getScrollResponder(): ScrollResponderMixin;
818
904
  reportContentInset(inset?: Partial<Insets$1> | null): void;
819
905
  };
820
906
 
907
+ type SectionListScrollParams = SectionListScrollParams$1 & {
908
+ viewPositionFallback?: "start" | "end";
909
+ };
821
910
  type SectionListViewToken<ItemT, SectionT> = {
822
911
  item: ItemT;
823
912
  key: string;
@@ -866,6 +955,14 @@ type SectionListProps<ItemT, SectionT extends SectionBase<ItemT> = SectionBase<I
866
955
  stickySectionHeadersEnabled?: boolean;
867
956
  onViewableItemsChanged?: SectionListOnViewableItemsChanged<ItemT, SectionT>;
868
957
  };
958
+ /**
959
+ * Key-based methods use flattened keys: `${sectionKey}:item:${itemKey}` for items,
960
+ * `${sectionKey}:header` and `${sectionKey}:footer` for section chrome,
961
+ * `${sectionKey}:separator:${itemIndex}` for item separators, and
962
+ * `${sectionKey}:section-separator` for section separators.
963
+ * `sectionKey` is the section's key, or `section-${sectionIndex}` when omitted; `itemKey` comes
964
+ * from the section or list keyExtractor. anchorVisibleContent accepts and returns these same keys.
965
+ */
869
966
  type SectionListRef = LegendListRef & {
870
967
  scrollToLocation(params: SectionListScrollParams): void;
871
968
  };
package/section-list.js CHANGED
@@ -281,7 +281,14 @@ var SectionList = typedMemo(
281
281
  ]
282
282
  );
283
283
  const scrollToLocation = React__namespace.useCallback(
284
- ({ sectionIndex, itemIndex, viewOffset, viewPosition, animated }) => {
284
+ ({
285
+ sectionIndex,
286
+ itemIndex,
287
+ viewOffset,
288
+ viewPosition,
289
+ viewPositionFallback,
290
+ animated
291
+ }) => {
285
292
  var _a, _b, _c;
286
293
  const meta = sectionMeta[sectionIndex];
287
294
  if (!meta) return;
@@ -291,7 +298,8 @@ var SectionList = typedMemo(
291
298
  animated,
292
299
  index: target,
293
300
  viewOffset,
294
- viewPosition
301
+ viewPosition,
302
+ viewPositionFallback
295
303
  });
296
304
  },
297
305
  [sectionMeta]
package/section-list.mjs CHANGED
@@ -259,7 +259,14 @@ var SectionList = typedMemo(
259
259
  ]
260
260
  );
261
261
  const scrollToLocation = React.useCallback(
262
- ({ sectionIndex, itemIndex, viewOffset, viewPosition, animated }) => {
262
+ ({
263
+ sectionIndex,
264
+ itemIndex,
265
+ viewOffset,
266
+ viewPosition,
267
+ viewPositionFallback,
268
+ animated
269
+ }) => {
263
270
  var _a, _b, _c;
264
271
  const meta = sectionMeta[sectionIndex];
265
272
  if (!meta) return;
@@ -269,7 +276,8 @@ var SectionList = typedMemo(
269
276
  animated,
270
277
  index: target,
271
278
  viewOffset,
272
- viewPosition
279
+ viewPosition,
280
+ viewPositionFallback
273
281
  });
274
282
  },
275
283
  [sectionMeta]
package/.DS_Store DELETED
Binary file