@legendapp/list 3.0.0-beta.53 → 3.0.0-beta.55

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.
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react';
2
- import { ScrollViewComponent, ScrollResponderMixin, Insets as Insets$1, ScrollViewProps } from 'react-native';
2
+ import { ScrollViewComponent, ScrollResponderMixin, Insets as Insets$1, ScrollViewProps, View, LayoutChangeEvent } from 'react-native';
3
3
  import { KeyboardChatScrollViewProps } from 'react-native-keyboard-controller';
4
4
  import { SharedValue } from 'react-native-reanimated';
5
5
  import { AnimatedLegendListProps } from '@legendapp/list/reanimated';
@@ -71,6 +71,10 @@ interface AnchoredEndSpaceConfig$1 {
71
71
  includeInEndInset?: boolean;
72
72
  onSizeChanged?: (size: number) => void;
73
73
  }
74
+ interface LegendListAverageItemSize {
75
+ average: number;
76
+ count: number;
77
+ }
74
78
  type LegendListState = {
75
79
  activeStickyIndex: number;
76
80
  contentLength: number;
@@ -85,6 +89,7 @@ type LegendListState = {
85
89
  isEndReached: boolean;
86
90
  isStartReached: boolean;
87
91
  isWithinMaintainScrollAtEndThreshold: boolean;
92
+ getAverageItemSizes: () => Record<string, LegendListAverageItemSize>;
88
93
  listen: <T extends LegendListListenerType>(listenerType: T, callback: (value: ListenerTypeValueMap[T]) => void) => () => void;
89
94
  listenToPosition: (key: string, callback: (value: number) => void) => () => void;
90
95
  positionAtIndex: (index: number) => number;
@@ -237,6 +242,16 @@ type UseKeyboardScrollToEndOptions = {
237
242
  freeze?: SharedValue<boolean>;
238
243
  listRef: KeyboardScrollToEndListRef;
239
244
  };
245
+ type KeyboardChatComposerInsetListRef = {
246
+ current: Pick<LegendListRef, "reportContentInset"> | null;
247
+ };
248
+ type KeyboardChatComposerRef = {
249
+ current: Pick<View, "measure"> | null;
250
+ };
251
+ declare function useKeyboardChatComposerInset(listRef: KeyboardChatComposerInsetListRef, composerRef: KeyboardChatComposerRef, initialHeight?: number): {
252
+ contentInsetEndAdjustment: SharedValue<number>;
253
+ onComposerLayout: (event: LayoutChangeEvent) => void;
254
+ };
240
255
  declare function useKeyboardScrollToEnd({ freeze: freezeProp, listRef }: UseKeyboardScrollToEndOptions): {
241
256
  freeze: SharedValue<boolean>;
242
257
  scrollMessageToEnd: ({ animated, closeKeyboard }: ScrollMessageToEndOptions) => Promise<void>;
@@ -246,4 +261,4 @@ declare const KeyboardChatLegendList: <ItemT>(props: Omit<AnimatedLegendListProp
246
261
  contentInsetEndAdjustment?: SharedValue<number>;
247
262
  } & React.RefAttributes<LegendListRef>) => React.ReactElement | null;
248
263
 
249
- export { KeyboardChatLegendList, useKeyboardScrollToEnd };
264
+ export { KeyboardChatLegendList, useKeyboardChatComposerInset, useKeyboardScrollToEnd };
package/keyboard-chat.js CHANGED
@@ -28,6 +28,34 @@ var React__namespace = /*#__PURE__*/_interopNamespace(React);
28
28
 
29
29
  // src/integrations/keyboard-chat.tsx
30
30
  var { typedForwardRef, useCombinedRef } = reactNative.internal;
31
+ function useKeyboardChatComposerInset(listRef, composerRef, initialHeight = 0) {
32
+ const contentInsetEndAdjustment = reactNativeReanimated.useSharedValue(initialHeight);
33
+ const lastHeightRef = React.useRef(void 0);
34
+ const reportHeight = React.useCallback(
35
+ (height) => {
36
+ var _a;
37
+ if (Number.isFinite(height) && height !== lastHeightRef.current) {
38
+ lastHeightRef.current = height;
39
+ contentInsetEndAdjustment.value = height;
40
+ (_a = listRef.current) == null ? void 0 : _a.reportContentInset({ bottom: height });
41
+ }
42
+ },
43
+ [contentInsetEndAdjustment, listRef]
44
+ );
45
+ React.useLayoutEffect(() => {
46
+ var _a;
47
+ (_a = composerRef.current) == null ? void 0 : _a.measure((_x, _y, _width, height) => {
48
+ reportHeight(height);
49
+ });
50
+ }, [composerRef, reportHeight]);
51
+ const onComposerLayout = React.useCallback(
52
+ (event) => {
53
+ reportHeight(event.nativeEvent.layout.height);
54
+ },
55
+ [reportHeight]
56
+ );
57
+ return { contentInsetEndAdjustment, onComposerLayout };
58
+ }
31
59
  function useKeyboardScrollToEnd({ freeze: freezeProp, listRef }) {
32
60
  const internalFreeze = reactNativeReanimated.useSharedValue(false);
33
61
  const freeze = freezeProp != null ? freezeProp : internalFreeze;
@@ -123,4 +151,5 @@ var KeyboardChatLegendList = typedForwardRef(function KeyboardChatLegendList2(pr
123
151
  });
124
152
 
125
153
  exports.KeyboardChatLegendList = KeyboardChatLegendList;
154
+ exports.useKeyboardChatComposerInset = useKeyboardChatComposerInset;
126
155
  exports.useKeyboardScrollToEnd = useKeyboardScrollToEnd;
package/keyboard-chat.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react';
2
- import { useRef, useEffect, useMemo, useCallback } from 'react';
2
+ import { useRef, useEffect, useMemo, useCallback, useLayoutEffect } from 'react';
3
3
  import { KeyboardChatScrollView, KeyboardController } from 'react-native-keyboard-controller';
4
4
  import { useSharedValue } from 'react-native-reanimated';
5
5
  import { internal } from '@legendapp/list/react-native';
@@ -7,6 +7,34 @@ import { AnimatedLegendList } from '@legendapp/list/reanimated';
7
7
 
8
8
  // src/integrations/keyboard-chat.tsx
9
9
  var { typedForwardRef, useCombinedRef } = internal;
10
+ function useKeyboardChatComposerInset(listRef, composerRef, initialHeight = 0) {
11
+ const contentInsetEndAdjustment = useSharedValue(initialHeight);
12
+ const lastHeightRef = useRef(void 0);
13
+ const reportHeight = useCallback(
14
+ (height) => {
15
+ var _a;
16
+ if (Number.isFinite(height) && height !== lastHeightRef.current) {
17
+ lastHeightRef.current = height;
18
+ contentInsetEndAdjustment.value = height;
19
+ (_a = listRef.current) == null ? void 0 : _a.reportContentInset({ bottom: height });
20
+ }
21
+ },
22
+ [contentInsetEndAdjustment, listRef]
23
+ );
24
+ useLayoutEffect(() => {
25
+ var _a;
26
+ (_a = composerRef.current) == null ? void 0 : _a.measure((_x, _y, _width, height) => {
27
+ reportHeight(height);
28
+ });
29
+ }, [composerRef, reportHeight]);
30
+ const onComposerLayout = useCallback(
31
+ (event) => {
32
+ reportHeight(event.nativeEvent.layout.height);
33
+ },
34
+ [reportHeight]
35
+ );
36
+ return { contentInsetEndAdjustment, onComposerLayout };
37
+ }
10
38
  function useKeyboardScrollToEnd({ freeze: freezeProp, listRef }) {
11
39
  const internalFreeze = useSharedValue(false);
12
40
  const freeze = freezeProp != null ? freezeProp : internalFreeze;
@@ -101,4 +129,4 @@ var KeyboardChatLegendList = typedForwardRef(function KeyboardChatLegendList2(pr
101
129
  );
102
130
  });
103
131
 
104
- export { KeyboardChatLegendList, useKeyboardScrollToEnd };
132
+ export { KeyboardChatLegendList, useKeyboardChatComposerInset, useKeyboardScrollToEnd };
@@ -65,6 +65,10 @@ interface Insets {
65
65
  bottom: number;
66
66
  right: number;
67
67
  }
68
+ interface LegendListAverageItemSize {
69
+ average: number;
70
+ count: number;
71
+ }
68
72
  type LegendListState = {
69
73
  activeStickyIndex: number;
70
74
  contentLength: number;
@@ -79,6 +83,7 @@ type LegendListState = {
79
83
  isEndReached: boolean;
80
84
  isStartReached: boolean;
81
85
  isWithinMaintainScrollAtEndThreshold: boolean;
86
+ getAverageItemSizes: () => Record<string, LegendListAverageItemSize>;
82
87
  listen: <T extends LegendListListenerType>(listenerType: T, callback: (value: ListenerTypeValueMap[T]) => void) => () => void;
83
88
  listenToPosition: (key: string, callback: (value: number) => void) => () => void;
84
89
  positionAtIndex: (index: number) => number;
package/keyboard.d.ts CHANGED
@@ -63,6 +63,10 @@ interface Insets {
63
63
  bottom: number;
64
64
  right: number;
65
65
  }
66
+ interface LegendListAverageItemSize {
67
+ average: number;
68
+ count: number;
69
+ }
66
70
  type LegendListState = {
67
71
  activeStickyIndex: number;
68
72
  contentLength: number;
@@ -77,6 +81,7 @@ type LegendListState = {
77
81
  isEndReached: boolean;
78
82
  isStartReached: boolean;
79
83
  isWithinMaintainScrollAtEndThreshold: boolean;
84
+ getAverageItemSizes: () => Record<string, LegendListAverageItemSize>;
80
85
  listen: <T extends LegendListListenerType>(listenerType: T, callback: (value: ListenerTypeValueMap[T]) => void) => () => void;
81
86
  listenToPosition: (key: string, callback: (value: number) => void) => () => void;
82
87
  positionAtIndex: (index: number) => number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legendapp/list",
3
- "version": "3.0.0-beta.53",
3
+ "version": "3.0.0-beta.55",
4
4
  "description": "Legend List is a drop-in replacement for FlatList with much better performance and supporting dynamically sized items.",
5
5
  "sideEffects": false,
6
6
  "private": false,
package/react-native.d.ts CHANGED
@@ -160,7 +160,10 @@ interface LegendListSpecificProps<ItemT, TItemType extends string | undefined> {
160
160
  */
161
161
  extraData?: any;
162
162
  /**
163
- * In case you have distinct item sizes, you can provide a function to get the size of an item.
163
+ * Optional per-item size estimate used before a row is measured.
164
+ *
165
+ * @deprecated Prefer a single `estimatedItemSize` for initial size hints, or `getFixedItemSize`
166
+ * when item sizes are known exactly.
164
167
  */
165
168
  getEstimatedItemSize?: (item: ItemT, index: number, type: TItemType) => number;
166
169
  /**
@@ -178,8 +181,9 @@ interface LegendListSpecificProps<ItemT, TItemType extends string | undefined> {
178
181
  leadingItem: ItemT;
179
182
  }>;
180
183
  /**
181
- * Ratio of initial container pool size to data length (e.g., 0.5 for half).
182
- * @default 2
184
+ * Ratio used to size the initial recycled container pool.
185
+ * @deprecated The list now manages spare container capacity automatically.
186
+ * @default 3
183
187
  */
184
188
  initialContainerPoolRatio?: number | undefined;
185
189
  /**
@@ -230,6 +234,13 @@ interface LegendListSpecificProps<ItemT, TItemType extends string | undefined> {
230
234
  * Style for the header component.
231
235
  */
232
236
  ListHeaderComponentStyle?: StyleProp<ViewStyle> | undefined;
237
+ /**
238
+ * Estimated height of the ListHeaderComponent. Provide this when the expected header height
239
+ * is known before layout so that only the items actually visible below the header are rendered
240
+ * on the initial frame, rather than a full screen's worth of items that are hidden behind it.
241
+ * The measured header size still replaces this value after layout.
242
+ */
243
+ estimatedHeaderSize?: number;
233
244
  /**
234
245
  * If true, auto-scrolls to end when new items are added.
235
246
  * Use an options object to opt into specific triggers and control whether that scroll is animated.
@@ -264,6 +275,12 @@ interface LegendListSpecificProps<ItemT, TItemType extends string | undefined> {
264
275
  * @default 1
265
276
  */
266
277
  numColumns?: number;
278
+ /**
279
+ * Force RTL mode for this list instance.
280
+ * When undefined, uses React Native's global I18nManager.isRTL.
281
+ * @default undefined
282
+ */
283
+ rtl?: boolean;
267
284
  /**
268
285
  * Called when scrolling reaches the end within onEndReachedThreshold.
269
286
  */
@@ -360,12 +377,6 @@ interface LegendListSpecificProps<ItemT, TItemType extends string | undefined> {
360
377
  * Array of item indices to use as snap points.
361
378
  */
362
379
  snapToIndices?: number[];
363
- /**
364
- * This will log a suggested estimatedItemSize.
365
- * @required
366
- * @default false
367
- */
368
- suggestEstimatedItemSize?: boolean;
369
380
  /**
370
381
  * Configuration for determining item viewability.
371
382
  */
@@ -454,6 +465,10 @@ interface LegendListMetrics {
454
465
  headerSize: number;
455
466
  footerSize: number;
456
467
  }
468
+ interface LegendListAverageItemSize {
469
+ average: number;
470
+ count: number;
471
+ }
457
472
  interface LegendListRenderItemProps<ItemT, TItemType extends string | number | undefined = string | number | undefined> {
458
473
  data: readonly ItemT[];
459
474
  extraData: any;
@@ -475,6 +490,7 @@ type LegendListState$1 = {
475
490
  isEndReached: boolean;
476
491
  isStartReached: boolean;
477
492
  isWithinMaintainScrollAtEndThreshold: boolean;
493
+ getAverageItemSizes: () => Record<string, LegendListAverageItemSize>;
478
494
  listen: <T extends LegendListListenerType>(listenerType: T, callback: (value: ListenerTypeValueMap[T]) => void) => () => void;
479
495
  listenToPosition: (key: string, callback: (value: number) => void) => () => void;
480
496
  positionAtIndex: (index: number) => number;
@@ -715,4 +731,4 @@ declare function useSyncLayout(): () => void;
715
731
 
716
732
  declare const LegendList: LegendListComponent;
717
733
 
718
- export { type AlwaysRenderConfig, type ColumnWrapperStyle, type InitialScrollAnchor, type Insets, type LayoutRectangle, LegendList, type LegendListComponent, type LegendListMetrics, type LegendListProps, type LegendListRecyclingState, type LegendListRef, type LegendListRenderItemProps, type LegendListState, type MaintainScrollAtEndOnOptions, type MaintainScrollAtEndOptions, type MaintainVisibleContentPositionConfig, type NativeScrollEvent, type NativeSyntheticEvent, type OnViewableItemsChanged, type OnViewableItemsChangedInfo, type ScrollIndexWithOffset, type ScrollIndexWithOffsetAndContentOffset, type ScrollIndexWithOffsetPosition, type StickyHeaderConfig, type StyleProp, type ViewAmountToken, type ViewStyle, type ViewToken, type ViewabilityAmountCallback, type ViewabilityCallback, type ViewabilityConfig, type ViewabilityConfigCallbackPair, type ViewabilityConfigCallbackPairs, useIsLastItem, useListScrollSize, useRecyclingEffect, useRecyclingState, useSyncLayout, useViewability, useViewabilityAmount };
734
+ export { type AlwaysRenderConfig, type ColumnWrapperStyle, type InitialScrollAnchor, type Insets, type LayoutRectangle, LegendList, type LegendListAverageItemSize, type LegendListComponent, type LegendListMetrics, type LegendListProps, type LegendListRecyclingState, type LegendListRef, type LegendListRenderItemProps, type LegendListState, type MaintainScrollAtEndOnOptions, type MaintainScrollAtEndOptions, type MaintainVisibleContentPositionConfig, type NativeScrollEvent, type NativeSyntheticEvent, type OnViewableItemsChanged, type OnViewableItemsChangedInfo, type ScrollIndexWithOffset, type ScrollIndexWithOffsetAndContentOffset, type ScrollIndexWithOffsetPosition, type StickyHeaderConfig, type StyleProp, type ViewAmountToken, type ViewStyle, type ViewToken, type ViewabilityAmountCallback, type ViewabilityCallback, type ViewabilityConfig, type ViewabilityConfigCallbackPair, type ViewabilityConfigCallbackPairs, useIsLastItem, useListScrollSize, useRecyclingEffect, useRecyclingState, useSyncLayout, useViewability, useViewabilityAmount };