@legendapp/list 2.0.13 → 2.0.14

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,6 @@
1
+ ## 2.0.14
2
+ - Feat: Add dataVersion prop to trigger re-render when mutating the data array in place
3
+
1
4
  ## 2.0.13
2
5
  - Feat: Allow returning undefined in getFixedItemSize to fall back to estimated size
3
6
  - Fix: scrollToIndex viewOffset was being subtracted twice, causing incorrect scroll positioning
package/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as React$1 from 'react';
2
- import { ComponentProps, ReactNode, Dispatch, SetStateAction } from 'react';
2
+ import { ComponentProps, Key, ReactNode, Dispatch, SetStateAction } from 'react';
3
3
  import { View, Animated, ScrollView, LayoutRectangle, ScrollViewComponent, ScrollResponderMixin, StyleProp, ViewStyle, NativeSyntheticEvent, NativeScrollEvent, ScrollViewProps } from 'react-native';
4
4
  import Animated$1 from 'react-native-reanimated';
5
5
 
@@ -99,6 +99,11 @@ interface LegendListSpecificProps<ItemT, TItemType extends string | undefined> {
99
99
  * Extra data to trigger re-rendering when changed.
100
100
  */
101
101
  extraData?: any;
102
+ /**
103
+ * Version token that forces the list to treat data as updated even when the array reference is stable.
104
+ * Increment or change this when mutating the data array in place.
105
+ */
106
+ dataVersion?: Key;
102
107
  /**
103
108
  * In case you have distinct item sizes, you can provide a function to get the size of an item.
104
109
  * Use instead of FlatList's getItemLayout or FlashList overrideItemLayout if you want to have accurate initialScrollOffset, you should provide this function
@@ -372,6 +377,7 @@ interface InternalState {
372
377
  props: {
373
378
  alignItemsAtEnd: boolean;
374
379
  data: readonly any[];
380
+ dataVersion: Key | undefined;
375
381
  estimatedItemSize: number | undefined;
376
382
  getEstimatedItemSize: LegendListProps["getEstimatedItemSize"];
377
383
  getFixedItemSize: LegendListProps["getFixedItemSize"];
package/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as React$1 from 'react';
2
- import { ComponentProps, ReactNode, Dispatch, SetStateAction } from 'react';
2
+ import { ComponentProps, Key, ReactNode, Dispatch, SetStateAction } from 'react';
3
3
  import { View, Animated, ScrollView, LayoutRectangle, ScrollViewComponent, ScrollResponderMixin, StyleProp, ViewStyle, NativeSyntheticEvent, NativeScrollEvent, ScrollViewProps } from 'react-native';
4
4
  import Animated$1 from 'react-native-reanimated';
5
5
 
@@ -99,6 +99,11 @@ interface LegendListSpecificProps<ItemT, TItemType extends string | undefined> {
99
99
  * Extra data to trigger re-rendering when changed.
100
100
  */
101
101
  extraData?: any;
102
+ /**
103
+ * Version token that forces the list to treat data as updated even when the array reference is stable.
104
+ * Increment or change this when mutating the data array in place.
105
+ */
106
+ dataVersion?: Key;
102
107
  /**
103
108
  * In case you have distinct item sizes, you can provide a function to get the size of an item.
104
109
  * Use instead of FlatList's getItemLayout or FlashList overrideItemLayout if you want to have accurate initialScrollOffset, you should provide this function
@@ -372,6 +377,7 @@ interface InternalState {
372
377
  props: {
373
378
  alignItemsAtEnd: boolean;
374
379
  data: readonly any[];
380
+ dataVersion: Key | undefined;
375
381
  estimatedItemSize: number | undefined;
376
382
  getEstimatedItemSize: LegendListProps["getEstimatedItemSize"];
377
383
  getFixedItemSize: LegendListProps["getFixedItemSize"];
package/index.js CHANGED
@@ -2738,6 +2738,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
2738
2738
  columnWrapperStyle,
2739
2739
  contentContainerStyle: contentContainerStyleProp,
2740
2740
  data: dataProp = [],
2741
+ dataVersion,
2741
2742
  drawDistance = 250,
2742
2743
  enableAverages = true,
2743
2744
  estimatedItemSize: estimatedItemSizeProp,
@@ -2862,7 +2863,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
2862
2863
  }
2863
2864
  const state = refState.current;
2864
2865
  const isFirst = !state.props.renderItem;
2865
- const didDataChange = state.props.data !== dataProp;
2866
+ const didDataChange = state.props.dataVersion !== dataVersion || state.props.data !== dataProp;
2866
2867
  if (didDataChange) {
2867
2868
  state.dataChangeNeedsScrollUpdate = true;
2868
2869
  }
@@ -2870,6 +2871,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
2870
2871
  state.props = {
2871
2872
  alignItemsAtEnd,
2872
2873
  data: dataProp,
2874
+ dataVersion,
2873
2875
  enableAverages,
2874
2876
  estimatedItemSize,
2875
2877
  getEstimatedItemSize,
@@ -2909,7 +2911,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
2909
2911
  { length: Math.min(numColumnsProp, dataProp.length) },
2910
2912
  (_, i) => getId(state, dataProp.length - 1 - i)
2911
2913
  );
2912
- }, [dataProp, numColumnsProp]);
2914
+ }, [dataProp, dataVersion, numColumnsProp]);
2913
2915
  const initializeStateVars = () => {
2914
2916
  set$(ctx, "lastItemKeys", memoizedLastItemKeys);
2915
2917
  set$(ctx, "numColumns", numColumnsProp);
@@ -2996,15 +2998,16 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
2996
2998
  dataProp
2997
2999
  );
2998
3000
  }
2999
- }, [dataProp, numColumnsProp]);
3001
+ }, [dataProp, dataVersion, numColumnsProp]);
3000
3002
  React2.useLayoutEffect(() => {
3001
3003
  set$(ctx, "extraData", extraData);
3002
3004
  }, [extraData]);
3003
3005
  React2.useLayoutEffect(initializeStateVars, [
3006
+ dataVersion,
3004
3007
  memoizedLastItemKeys.join(","),
3005
3008
  numColumnsProp,
3006
- stylePaddingTopState,
3007
- stylePaddingBottomState
3009
+ stylePaddingBottomState,
3010
+ stylePaddingTopState
3008
3011
  ]);
3009
3012
  React2.useEffect(() => {
3010
3013
  const viewability = setupViewability({
package/index.mjs CHANGED
@@ -2717,6 +2717,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
2717
2717
  columnWrapperStyle,
2718
2718
  contentContainerStyle: contentContainerStyleProp,
2719
2719
  data: dataProp = [],
2720
+ dataVersion,
2720
2721
  drawDistance = 250,
2721
2722
  enableAverages = true,
2722
2723
  estimatedItemSize: estimatedItemSizeProp,
@@ -2841,7 +2842,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
2841
2842
  }
2842
2843
  const state = refState.current;
2843
2844
  const isFirst = !state.props.renderItem;
2844
- const didDataChange = state.props.data !== dataProp;
2845
+ const didDataChange = state.props.dataVersion !== dataVersion || state.props.data !== dataProp;
2845
2846
  if (didDataChange) {
2846
2847
  state.dataChangeNeedsScrollUpdate = true;
2847
2848
  }
@@ -2849,6 +2850,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
2849
2850
  state.props = {
2850
2851
  alignItemsAtEnd,
2851
2852
  data: dataProp,
2853
+ dataVersion,
2852
2854
  enableAverages,
2853
2855
  estimatedItemSize,
2854
2856
  getEstimatedItemSize,
@@ -2888,7 +2890,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
2888
2890
  { length: Math.min(numColumnsProp, dataProp.length) },
2889
2891
  (_, i) => getId(state, dataProp.length - 1 - i)
2890
2892
  );
2891
- }, [dataProp, numColumnsProp]);
2893
+ }, [dataProp, dataVersion, numColumnsProp]);
2892
2894
  const initializeStateVars = () => {
2893
2895
  set$(ctx, "lastItemKeys", memoizedLastItemKeys);
2894
2896
  set$(ctx, "numColumns", numColumnsProp);
@@ -2975,15 +2977,16 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
2975
2977
  dataProp
2976
2978
  );
2977
2979
  }
2978
- }, [dataProp, numColumnsProp]);
2980
+ }, [dataProp, dataVersion, numColumnsProp]);
2979
2981
  useLayoutEffect(() => {
2980
2982
  set$(ctx, "extraData", extraData);
2981
2983
  }, [extraData]);
2982
2984
  useLayoutEffect(initializeStateVars, [
2985
+ dataVersion,
2983
2986
  memoizedLastItemKeys.join(","),
2984
2987
  numColumnsProp,
2985
- stylePaddingTopState,
2986
- stylePaddingBottomState
2988
+ stylePaddingBottomState,
2989
+ stylePaddingTopState
2987
2990
  ]);
2988
2991
  useEffect(() => {
2989
2992
  const viewability = setupViewability({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legendapp/list",
3
- "version": "2.0.13",
3
+ "version": "2.0.14",
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,