@legendapp/list 2.0.18 → 2.0.19

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/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 2.0.19
2
+ - Fix: Add safety checks for getItemType, getEstimatedItemSize, getFixedItemSize, and keyExtractor to prevent calling when index is out of range
3
+ - Fix: Error with animatedProps in reanimated integration
4
+
1
5
  ## 2.0.18
2
6
  - Improvement: KeyboardAvoidingLegendList now supports KeyboardGestureArea with improved interactive behavior
3
7
 
package/index.js CHANGED
@@ -2091,7 +2091,7 @@ function calculateItemsInView(ctx, state, params = {}) {
2091
2091
  if (needNewContainers.length > 0) {
2092
2092
  const requiredItemTypes = getItemType ? needNewContainers.map((i) => {
2093
2093
  const itemType = getItemType(data[i], i);
2094
- return itemType ? String(itemType) : "";
2094
+ return itemType !== void 0 ? String(itemType) : "";
2095
2095
  }) : void 0;
2096
2096
  const availableContainers = findAvailableContainers(
2097
2097
  ctx,
@@ -2355,8 +2355,10 @@ function doInitialAllocateContainers(ctx, state) {
2355
2355
  const num = Math.min(20, data.length);
2356
2356
  for (let i = 0; i < num; i++) {
2357
2357
  const item = data[i];
2358
- const itemType = getItemType ? (_a = getItemType(item, i)) != null ? _a : "" : "";
2359
- totalSize += (_c = (_b = getFixedItemSize == null ? void 0 : getFixedItemSize(i, item, itemType)) != null ? _b : getEstimatedItemSize == null ? void 0 : getEstimatedItemSize(i, item, itemType)) != null ? _c : estimatedItemSize;
2358
+ if (item !== void 0) {
2359
+ const itemType = (_a = getItemType == null ? void 0 : getItemType(item, i)) != null ? _a : "";
2360
+ totalSize += (_c = (_b = getFixedItemSize == null ? void 0 : getFixedItemSize(i, item, itemType)) != null ? _b : getEstimatedItemSize == null ? void 0 : getEstimatedItemSize(i, item, itemType)) != null ? _c : estimatedItemSize;
2361
+ }
2360
2362
  }
2361
2363
  averageItemSize = totalSize / num;
2362
2364
  } else {
@@ -2644,6 +2646,12 @@ function updateOneItemSize(state, itemKey, sizeObj) {
2644
2646
  }
2645
2647
  return 0;
2646
2648
  }
2649
+ function useWrapIfItem(fn) {
2650
+ return React2.useMemo(
2651
+ () => fn ? (arg1, arg2, arg3) => arg1 !== void 0 && arg2 !== void 0 ? fn(arg1, arg2, arg3) : void 0 : void 0,
2652
+ [fn]
2653
+ );
2654
+ }
2647
2655
  var useCombinedRef = (...refs) => {
2648
2656
  const callback = React2.useCallback((element) => {
2649
2657
  for (const ref of refs) {
@@ -2913,14 +2921,14 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
2913
2921
  dataVersion,
2914
2922
  enableAverages,
2915
2923
  estimatedItemSize,
2916
- getEstimatedItemSize,
2917
- getFixedItemSize,
2918
- getItemType,
2924
+ getEstimatedItemSize: useWrapIfItem(getEstimatedItemSize),
2925
+ getFixedItemSize: useWrapIfItem(getFixedItemSize),
2926
+ getItemType: useWrapIfItem(getItemType),
2919
2927
  horizontal: !!horizontal,
2920
2928
  initialContainerPoolRatio,
2921
2929
  initialScroll,
2922
2930
  itemsAreEqual,
2923
- keyExtractor,
2931
+ keyExtractor: useWrapIfItem(keyExtractor),
2924
2932
  maintainScrollAtEnd,
2925
2933
  maintainScrollAtEndThreshold,
2926
2934
  maintainVisibleContentPosition,
package/index.mjs CHANGED
@@ -2070,7 +2070,7 @@ function calculateItemsInView(ctx, state, params = {}) {
2070
2070
  if (needNewContainers.length > 0) {
2071
2071
  const requiredItemTypes = getItemType ? needNewContainers.map((i) => {
2072
2072
  const itemType = getItemType(data[i], i);
2073
- return itemType ? String(itemType) : "";
2073
+ return itemType !== void 0 ? String(itemType) : "";
2074
2074
  }) : void 0;
2075
2075
  const availableContainers = findAvailableContainers(
2076
2076
  ctx,
@@ -2334,8 +2334,10 @@ function doInitialAllocateContainers(ctx, state) {
2334
2334
  const num = Math.min(20, data.length);
2335
2335
  for (let i = 0; i < num; i++) {
2336
2336
  const item = data[i];
2337
- const itemType = getItemType ? (_a = getItemType(item, i)) != null ? _a : "" : "";
2338
- totalSize += (_c = (_b = getFixedItemSize == null ? void 0 : getFixedItemSize(i, item, itemType)) != null ? _b : getEstimatedItemSize == null ? void 0 : getEstimatedItemSize(i, item, itemType)) != null ? _c : estimatedItemSize;
2337
+ if (item !== void 0) {
2338
+ const itemType = (_a = getItemType == null ? void 0 : getItemType(item, i)) != null ? _a : "";
2339
+ totalSize += (_c = (_b = getFixedItemSize == null ? void 0 : getFixedItemSize(i, item, itemType)) != null ? _b : getEstimatedItemSize == null ? void 0 : getEstimatedItemSize(i, item, itemType)) != null ? _c : estimatedItemSize;
2340
+ }
2339
2341
  }
2340
2342
  averageItemSize = totalSize / num;
2341
2343
  } else {
@@ -2623,6 +2625,12 @@ function updateOneItemSize(state, itemKey, sizeObj) {
2623
2625
  }
2624
2626
  return 0;
2625
2627
  }
2628
+ function useWrapIfItem(fn) {
2629
+ return useMemo(
2630
+ () => fn ? (arg1, arg2, arg3) => arg1 !== void 0 && arg2 !== void 0 ? fn(arg1, arg2, arg3) : void 0 : void 0,
2631
+ [fn]
2632
+ );
2633
+ }
2626
2634
  var useCombinedRef = (...refs) => {
2627
2635
  const callback = useCallback((element) => {
2628
2636
  for (const ref of refs) {
@@ -2892,14 +2900,14 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
2892
2900
  dataVersion,
2893
2901
  enableAverages,
2894
2902
  estimatedItemSize,
2895
- getEstimatedItemSize,
2896
- getFixedItemSize,
2897
- getItemType,
2903
+ getEstimatedItemSize: useWrapIfItem(getEstimatedItemSize),
2904
+ getFixedItemSize: useWrapIfItem(getFixedItemSize),
2905
+ getItemType: useWrapIfItem(getItemType),
2898
2906
  horizontal: !!horizontal,
2899
2907
  initialContainerPoolRatio,
2900
2908
  initialScroll,
2901
2909
  itemsAreEqual,
2902
- keyExtractor,
2910
+ keyExtractor: useWrapIfItem(keyExtractor),
2903
2911
  maintainScrollAtEnd,
2904
2912
  maintainScrollAtEndThreshold,
2905
2913
  maintainVisibleContentPosition,
package/keyboard.d.mts CHANGED
@@ -4,7 +4,7 @@ import { ReanimatedScrollEvent } from 'react-native-reanimated/lib/typescript/ho
4
4
  import { LegendListRef } from '@legendapp/list';
5
5
  import { AnimatedLegendListProps } from '@legendapp/list/reanimated';
6
6
 
7
- declare const KeyboardAvoidingLegendList: <ItemT>(props: Omit<AnimatedLegendListProps<ItemT>, "contentInset" | "onScroll"> & {
7
+ declare const KeyboardAvoidingLegendList: <ItemT>(props: Omit<AnimatedLegendListProps<ItemT>, "onScroll" | "contentInset"> & {
8
8
  onScroll?: (event: ReanimatedScrollEvent) => void;
9
9
  contentInset?: Insets | undefined;
10
10
  safeAreaInsetBottom?: number;
package/keyboard.d.ts CHANGED
@@ -4,7 +4,7 @@ import { ReanimatedScrollEvent } from 'react-native-reanimated/lib/typescript/ho
4
4
  import { LegendListRef } from '@legendapp/list';
5
5
  import { AnimatedLegendListProps } from '@legendapp/list/reanimated';
6
6
 
7
- declare const KeyboardAvoidingLegendList: <ItemT>(props: Omit<AnimatedLegendListProps<ItemT>, "contentInset" | "onScroll"> & {
7
+ declare const KeyboardAvoidingLegendList: <ItemT>(props: Omit<AnimatedLegendListProps<ItemT>, "onScroll" | "contentInset"> & {
8
8
  onScroll?: (event: ReanimatedScrollEvent) => void;
9
9
  contentInset?: Insets | undefined;
10
10
  safeAreaInsetBottom?: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legendapp/list",
3
- "version": "2.0.18",
3
+ "version": "2.0.19",
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/reanimated.js CHANGED
@@ -69,9 +69,18 @@ var AnimatedLegendListComponent = Reanimated__default.default.createAnimatedComp
69
69
  var AnimatedLegendList = typedMemo(
70
70
  React__namespace.forwardRef(function AnimatedLegendList2(props, ref) {
71
71
  const { refScrollView, ...rest } = props;
72
+ const { animatedProps } = props;
72
73
  const refLegendList = React__namespace.useRef(null);
73
74
  const combinedRef = useCombinedRef(refLegendList, ref);
74
- return /* @__PURE__ */ React__namespace.createElement(AnimatedLegendListComponent, { ref: refScrollView, refLegendList: combinedRef, ...rest });
75
+ return /* @__PURE__ */ React__namespace.createElement(
76
+ AnimatedLegendListComponent,
77
+ {
78
+ animatedPropsInternal: animatedProps,
79
+ ref: refScrollView,
80
+ refLegendList: combinedRef,
81
+ ...rest
82
+ }
83
+ );
75
84
  })
76
85
  );
77
86
 
package/reanimated.mjs CHANGED
@@ -45,9 +45,18 @@ var AnimatedLegendListComponent = Reanimated.createAnimatedComponent(LegendListF
45
45
  var AnimatedLegendList = typedMemo(
46
46
  React.forwardRef(function AnimatedLegendList2(props, ref) {
47
47
  const { refScrollView, ...rest } = props;
48
+ const { animatedProps } = props;
48
49
  const refLegendList = React.useRef(null);
49
50
  const combinedRef = useCombinedRef(refLegendList, ref);
50
- return /* @__PURE__ */ React.createElement(AnimatedLegendListComponent, { ref: refScrollView, refLegendList: combinedRef, ...rest });
51
+ return /* @__PURE__ */ React.createElement(
52
+ AnimatedLegendListComponent,
53
+ {
54
+ animatedPropsInternal: animatedProps,
55
+ ref: refScrollView,
56
+ refLegendList: combinedRef,
57
+ ...rest
58
+ }
59
+ );
51
60
  })
52
61
  );
53
62