@legendapp/list 3.0.0-beta.35 → 3.0.0-beta.37

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/reanimated.mjs CHANGED
@@ -1,105 +1,11 @@
1
- import * as React3 from 'react';
1
+ import * as React from 'react';
2
2
  import { useCallback, memo } from 'react';
3
3
  import { View } from 'react-native';
4
4
  import Reanimated, { useAnimatedRef, useScrollViewOffset, useAnimatedStyle, useSharedValue } from 'react-native-reanimated';
5
- import { LegendList } from '@legendapp/list/react-native';
6
- import { useSyncExternalStore } from 'use-sync-external-store/shim';
7
-
8
- // src/integrations/reanimated.tsx
9
-
10
- // src/constants.ts
11
- var POSITION_OUT_OF_VIEW = -1e7;
12
-
13
- // src/constants-platform.native.ts
14
- var f = global.nativeFabricUIManager;
15
- var IsNewArchitecture = f !== void 0 && f != null;
16
- var ContextState = React3.createContext(null);
17
- function createSelectorFunctionsArr(ctx, signalNames) {
18
- let lastValues = [];
19
- let lastSignalValues = [];
20
- return {
21
- get: () => {
22
- const currentValues = [];
23
- let hasChanged = false;
24
- for (let i = 0; i < signalNames.length; i++) {
25
- const value = peek$(ctx, signalNames[i]);
26
- currentValues.push(value);
27
- if (value !== lastSignalValues[i]) {
28
- hasChanged = true;
29
- }
30
- }
31
- lastSignalValues = currentValues;
32
- if (hasChanged) {
33
- lastValues = currentValues;
34
- }
35
- return lastValues;
36
- },
37
- subscribe: (cb) => {
38
- const listeners = [];
39
- for (const signalName of signalNames) {
40
- listeners.push(listen$(ctx, signalName, cb));
41
- }
42
- return () => {
43
- for (const listener of listeners) {
44
- listener();
45
- }
46
- };
47
- }
48
- };
49
- }
50
- function listen$(ctx, signalName, cb) {
51
- const { listeners } = ctx;
52
- let setListeners = listeners.get(signalName);
53
- if (!setListeners) {
54
- setListeners = /* @__PURE__ */ new Set();
55
- listeners.set(signalName, setListeners);
56
- }
57
- setListeners.add(cb);
58
- return () => setListeners.delete(cb);
59
- }
60
- function peek$(ctx, signalName) {
61
- const { values } = ctx;
62
- return values.get(signalName);
63
- }
64
- function useArr$(signalNames) {
65
- const ctx = React3.useContext(ContextState);
66
- const { subscribe, get } = React3.useMemo(() => createSelectorFunctionsArr(ctx, signalNames), [ctx, signalNames]);
67
- const value = useSyncExternalStore(subscribe, get);
68
- return value;
69
- }
70
-
71
- // src/utils/helpers.ts
72
- function isFunction(obj) {
73
- return typeof obj === "function";
74
- }
75
-
76
- // src/hooks/useCombinedRef.ts
77
- var useCombinedRef = (...refs) => {
78
- const callback = useCallback((element) => {
79
- for (const ref of refs) {
80
- if (!ref) {
81
- continue;
82
- }
83
- if (isFunction(ref)) {
84
- ref(element);
85
- } else {
86
- ref.current = element;
87
- }
88
- }
89
- }, refs);
90
- return callback;
91
- };
92
- var getComponent = (Component) => {
93
- if (React3.isValidElement(Component)) {
94
- return Component;
95
- }
96
- if (Component) {
97
- return /* @__PURE__ */ React3.createElement(Component, null);
98
- }
99
- return null;
100
- };
5
+ import { internal, LegendList } from '@legendapp/list/react-native';
101
6
 
102
7
  // src/integrations/reanimated.tsx
8
+ var { POSITION_OUT_OF_VIEW, IsNewArchitecture, useArr$, useCombinedRef, getComponent } = internal;
103
9
  var typedMemo = memo;
104
10
  var ReanimatedScrollBridge = typedMemo(function ReanimatedScrollBridgeComponent({
105
11
  forwardedRef,
@@ -109,13 +15,13 @@ var ReanimatedScrollBridge = typedMemo(function ReanimatedScrollBridgeComponent(
109
15
  const animatedScrollRef = useAnimatedRef();
110
16
  useScrollViewOffset(animatedScrollRef, scrollOffset);
111
17
  const combinedRef = useCombinedRef(animatedScrollRef, forwardedRef);
112
- return /* @__PURE__ */ React3.createElement(Reanimated.ScrollView, { ...props, ref: combinedRef });
18
+ return /* @__PURE__ */ React.createElement(Reanimated.ScrollView, { ...props, ref: combinedRef });
113
19
  });
114
20
  var StickyOverlay = typedMemo(function StickyOverlayComponent({ stickyHeaderConfig }) {
115
21
  if (!(stickyHeaderConfig == null ? void 0 : stickyHeaderConfig.backdropComponent)) {
116
22
  return null;
117
23
  }
118
- return /* @__PURE__ */ React3.createElement(
24
+ return /* @__PURE__ */ React.createElement(
119
25
  View,
120
26
  {
121
27
  style: {
@@ -141,25 +47,44 @@ var ReanimatedPositionViewSticky = typedMemo(function ReanimatedPositionViewStic
141
47
  const delta = Math.max(0, stickyScrollOffset.value - stickyStart);
142
48
  return horizontal ? { transform: [{ translateX: position + delta }] } : { transform: [{ translateY: position + delta }] };
143
49
  }, [horizontal, position, stickyStart]);
144
- const viewStyle = React3.useMemo(
50
+ const viewStyle = React.useMemo(
145
51
  () => [style, { zIndex: index + 1e3 }, transformStyle],
146
52
  [index, style, transformStyle]
147
53
  );
148
- return /* @__PURE__ */ React3.createElement(Reanimated.View, { ref: refView, style: viewStyle, ...rest }, /* @__PURE__ */ React3.createElement(StickyOverlay, { stickyHeaderConfig }), children);
54
+ return /* @__PURE__ */ React.createElement(Reanimated.View, { ref: refView, style: viewStyle, ...rest }, /* @__PURE__ */ React.createElement(StickyOverlay, { stickyHeaderConfig }), children);
149
55
  });
150
56
  var ReanimatedPositionView = typedMemo(function ReanimatedPositionViewComponent(props) {
151
- const { id, horizontal, style, refView, children, layoutTransition, ...rest } = props;
152
- const [positionValue = POSITION_OUT_OF_VIEW] = useArr$([`containerPosition${id}`]);
153
- const viewStyle = React3.useMemo(
57
+ const { id, horizontal, style, refView, children, recycleItems, layoutTransition, ...rest } = props;
58
+ const [positionValue = POSITION_OUT_OF_VIEW, itemKey] = useArr$([
59
+ `containerPosition${id}`,
60
+ `containerItemKey${id}`
61
+ ]);
62
+ const prevItemKeyRef = React.useRef(void 0);
63
+ const shouldSkipTransitionForRecycleReuse = !!recycleItems && itemKey !== void 0 && prevItemKeyRef.current !== void 0 && prevItemKeyRef.current !== itemKey;
64
+ React.useEffect(() => {
65
+ if (itemKey !== void 0) {
66
+ prevItemKeyRef.current = itemKey;
67
+ }
68
+ }, [itemKey]);
69
+ const viewStyle = React.useMemo(
154
70
  () => [style, horizontal ? { left: positionValue } : { top: positionValue }],
155
71
  [horizontal, positionValue, style]
156
72
  );
157
- return /* @__PURE__ */ React3.createElement(Reanimated.View, { layout: layoutTransition, ref: refView, style: viewStyle, ...rest }, children);
73
+ return /* @__PURE__ */ React.createElement(
74
+ Reanimated.View,
75
+ {
76
+ layout: shouldSkipTransitionForRecycleReuse ? void 0 : layoutTransition,
77
+ ref: refView,
78
+ style: viewStyle,
79
+ ...rest
80
+ },
81
+ children
82
+ );
158
83
  });
159
84
  var LegendListForwardedRef = typedMemo(
160
85
  // biome-ignore lint/nursery/noShadow: const function name shadowing is intentional
161
- React3.forwardRef(function LegendListForwardedRef2(props, ref) {
162
- const { itemLayoutAnimation, refLegendList, ...rest } = props;
86
+ React.forwardRef(function LegendListForwardedRef2(props, ref) {
87
+ const { itemLayoutAnimation, recycleItems, refLegendList, ...rest } = props;
163
88
  const refFn = useCallback(
164
89
  (r) => {
165
90
  refLegendList(r);
@@ -171,7 +96,7 @@ var LegendListForwardedRef = typedMemo(
171
96
  const renderReanimatedScrollComponent = useCallback(
172
97
  (scrollViewProps) => {
173
98
  const { ref: forwardedRef, ...restScrollViewProps } = scrollViewProps;
174
- return /* @__PURE__ */ React3.createElement(
99
+ return /* @__PURE__ */ React.createElement(
175
100
  ReanimatedScrollBridge,
176
101
  {
177
102
  ...restScrollViewProps,
@@ -182,23 +107,30 @@ var LegendListForwardedRef = typedMemo(
182
107
  },
183
108
  [stickyScrollOffset]
184
109
  );
185
- const stickyPositionComponentInternal = React3.useMemo(
110
+ const stickyPositionComponentInternal = React.useMemo(
186
111
  () => function StickyPositionComponent(stickyProps) {
187
- return /* @__PURE__ */ React3.createElement(ReanimatedPositionViewSticky, { ...stickyProps, stickyScrollOffset });
112
+ return /* @__PURE__ */ React.createElement(ReanimatedPositionViewSticky, { ...stickyProps, stickyScrollOffset });
188
113
  },
189
114
  [stickyScrollOffset]
190
115
  );
191
- const itemLayoutAnimationRef = React3.useRef(itemLayoutAnimation);
116
+ const itemLayoutAnimationRef = React.useRef(itemLayoutAnimation);
192
117
  itemLayoutAnimationRef.current = itemLayoutAnimation;
193
118
  const hasItemLayoutAnimation = !!itemLayoutAnimation;
194
- const positionComponentInternal = React3.useMemo(() => {
119
+ const positionComponentInternal = React.useMemo(() => {
195
120
  if (!hasItemLayoutAnimation) {
196
121
  return void 0;
197
122
  }
198
123
  return function PositionComponent(positionProps) {
199
- return /* @__PURE__ */ React3.createElement(ReanimatedPositionView, { ...positionProps, layoutTransition: itemLayoutAnimationRef.current });
124
+ return /* @__PURE__ */ React.createElement(
125
+ ReanimatedPositionView,
126
+ {
127
+ ...positionProps,
128
+ layoutTransition: itemLayoutAnimationRef.current,
129
+ recycleItems
130
+ }
131
+ );
200
132
  };
201
- }, [hasItemLayoutAnimation]);
133
+ }, [hasItemLayoutAnimation, recycleItems]);
202
134
  const legendListProps = {
203
135
  ...rest,
204
136
  positionComponentInternal,
@@ -207,18 +139,18 @@ var LegendListForwardedRef = typedMemo(
207
139
  stickyPositionComponentInternal
208
140
  } : {}
209
141
  };
210
- return /* @__PURE__ */ React3.createElement(LegendList, { ref: refFn, refScrollView: ref, ...legendListProps });
142
+ return /* @__PURE__ */ React.createElement(LegendList, { ref: refFn, refScrollView: ref, ...legendListProps });
211
143
  })
212
144
  );
213
145
  var AnimatedLegendListComponent = Reanimated.createAnimatedComponent(LegendListForwardedRef);
214
146
  var AnimatedLegendList = typedMemo(
215
147
  // biome-ignore lint/nursery/noShadow: const function name shadowing is intentional
216
- React3.forwardRef(function AnimatedLegendList2(props, ref) {
148
+ React.forwardRef(function AnimatedLegendList2(props, ref) {
217
149
  const { refScrollView, ...rest } = props;
218
150
  const { animatedProps } = props;
219
- const refLegendList = React3.useRef(null);
151
+ const refLegendList = React.useRef(null);
220
152
  const combinedRef = useCombinedRef(refLegendList, ref);
221
- return /* @__PURE__ */ React3.createElement(
153
+ return /* @__PURE__ */ React.createElement(
222
154
  AnimatedLegendListComponent,
223
155
  {
224
156
  animatedPropsInternal: animatedProps,
package/section-list.d.ts CHANGED
@@ -702,7 +702,7 @@ declare const SectionList: (<ItemT, SectionT extends SectionBase<ItemT, react_na
702
702
  section: SectionListData<ItemT, SectionT>;
703
703
  }) => React$1.ReactElement | null) | undefined;
704
704
  ItemSeparatorComponent?: React$1.ComponentType<SectionListSeparatorProps<ItemT, SectionT>> | null | undefined;
705
- SectionSeparatorComponent?: React$1.ReactElement<any, string | React$1.JSXElementConstructor<any>> | React$1.ComponentType<SectionListSeparatorProps<ItemT, SectionT>> | null | undefined;
705
+ SectionSeparatorComponent?: React$1.ReactElement<unknown, string | React$1.JSXElementConstructor<any>> | React$1.ComponentType<SectionListSeparatorProps<ItemT, SectionT>> | null | undefined;
706
706
  keyExtractor?: ((item: ItemT, index: number) => string) | undefined;
707
707
  stickySectionHeadersEnabled?: boolean;
708
708
  onViewableItemsChanged?: SectionListOnViewableItemsChanged<ItemT, SectionT> | undefined;