@legendapp/list 3.0.0-beta.31 → 3.0.0-beta.33

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.
Files changed (55) hide show
  1. package/.DS_Store +0 -0
  2. package/README.md +7 -1
  3. package/animated.d.ts +600 -6
  4. package/animated.js +2 -2
  5. package/animated.mjs +1 -1
  6. package/index.d.ts +462 -109
  7. package/index.js +290 -147
  8. package/index.mjs +290 -147
  9. package/index.native.js +245 -122
  10. package/index.native.mjs +246 -123
  11. package/keyboard-controller.d.ts +611 -6
  12. package/keyboard-controller.js +2 -2
  13. package/keyboard-controller.mjs +1 -1
  14. package/keyboard.d.ts +204 -8
  15. package/keyboard.js +66 -52
  16. package/keyboard.mjs +69 -54
  17. package/{index.d.mts → list-react-native.d.ts} +103 -33
  18. package/list-react-native.js +4234 -0
  19. package/list-react-native.mjs +4204 -0
  20. package/{index.native.d.mts → list-react.d.ts} +363 -41
  21. package/list-react.js +4426 -0
  22. package/list-react.mjs +4396 -0
  23. package/package.json +52 -1
  24. package/reanimated.d.ts +595 -7
  25. package/reanimated.js +156 -11
  26. package/reanimated.mjs +153 -8
  27. package/section-list.d.ts +610 -14
  28. package/section-list.js +6 -6
  29. package/section-list.mjs +1 -1
  30. package/animated.d.mts +0 -9
  31. package/animated.native.d.mts +0 -9
  32. package/animated.native.d.ts +0 -9
  33. package/animated.native.js +0 -9
  34. package/animated.native.mjs +0 -7
  35. package/index.native.d.ts +0 -810
  36. package/keyboard-controller.d.mts +0 -12
  37. package/keyboard-controller.native.d.mts +0 -12
  38. package/keyboard-controller.native.d.ts +0 -12
  39. package/keyboard-controller.native.js +0 -69
  40. package/keyboard-controller.native.mjs +0 -48
  41. package/keyboard.d.mts +0 -13
  42. package/keyboard.native.d.mts +0 -13
  43. package/keyboard.native.d.ts +0 -13
  44. package/keyboard.native.js +0 -399
  45. package/keyboard.native.mjs +0 -377
  46. package/reanimated.d.mts +0 -18
  47. package/reanimated.native.d.mts +0 -18
  48. package/reanimated.native.d.ts +0 -18
  49. package/reanimated.native.js +0 -89
  50. package/reanimated.native.mjs +0 -65
  51. package/section-list.d.mts +0 -112
  52. package/section-list.native.d.mts +0 -112
  53. package/section-list.native.d.ts +0 -112
  54. package/section-list.native.js +0 -293
  55. package/section-list.native.mjs +0 -271
package/reanimated.js CHANGED
@@ -1,8 +1,10 @@
1
1
  'use strict';
2
2
 
3
- var React = require('react');
3
+ var React3 = require('react');
4
+ var reactNative = require('react-native');
4
5
  var Reanimated = require('react-native-reanimated');
5
- var list = require('@legendapp/list');
6
+ var reactNative$1 = require('@legendapp/list/react-native');
7
+ var shim = require('use-sync-external-store/shim');
6
8
 
7
9
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
8
10
 
@@ -24,11 +26,72 @@ function _interopNamespace(e) {
24
26
  return Object.freeze(n);
25
27
  }
26
28
 
27
- var React__namespace = /*#__PURE__*/_interopNamespace(React);
29
+ var React3__namespace = /*#__PURE__*/_interopNamespace(React3);
28
30
  var Reanimated__default = /*#__PURE__*/_interopDefault(Reanimated);
29
31
 
30
32
  // src/integrations/reanimated.tsx
31
33
 
34
+ // src/constants.ts
35
+ var POSITION_OUT_OF_VIEW = -1e7;
36
+
37
+ // src/constants-platform.native.ts
38
+ var f = global.nativeFabricUIManager;
39
+ var IsNewArchitecture = f !== void 0 && f != null;
40
+ var ContextState = React3__namespace.createContext(null);
41
+ function createSelectorFunctionsArr(ctx, signalNames) {
42
+ let lastValues = [];
43
+ let lastSignalValues = [];
44
+ return {
45
+ get: () => {
46
+ const currentValues = [];
47
+ let hasChanged = false;
48
+ for (let i = 0; i < signalNames.length; i++) {
49
+ const value = peek$(ctx, signalNames[i]);
50
+ currentValues.push(value);
51
+ if (value !== lastSignalValues[i]) {
52
+ hasChanged = true;
53
+ }
54
+ }
55
+ lastSignalValues = currentValues;
56
+ if (hasChanged) {
57
+ lastValues = currentValues;
58
+ }
59
+ return lastValues;
60
+ },
61
+ subscribe: (cb) => {
62
+ const listeners = [];
63
+ for (const signalName of signalNames) {
64
+ listeners.push(listen$(ctx, signalName, cb));
65
+ }
66
+ return () => {
67
+ for (const listener of listeners) {
68
+ listener();
69
+ }
70
+ };
71
+ }
72
+ };
73
+ }
74
+ function listen$(ctx, signalName, cb) {
75
+ const { listeners } = ctx;
76
+ let setListeners = listeners.get(signalName);
77
+ if (!setListeners) {
78
+ setListeners = /* @__PURE__ */ new Set();
79
+ listeners.set(signalName, setListeners);
80
+ }
81
+ setListeners.add(cb);
82
+ return () => setListeners.delete(cb);
83
+ }
84
+ function peek$(ctx, signalName) {
85
+ const { values } = ctx;
86
+ return values.get(signalName);
87
+ }
88
+ function useArr$(signalNames) {
89
+ const ctx = React3__namespace.useContext(ContextState);
90
+ const { subscribe, get } = React3__namespace.useMemo(() => createSelectorFunctionsArr(ctx, signalNames), [ctx, signalNames]);
91
+ const value = shim.useSyncExternalStore(subscribe, get);
92
+ return value;
93
+ }
94
+
32
95
  // src/utils/helpers.ts
33
96
  function isFunction(obj) {
34
97
  return typeof obj === "function";
@@ -36,7 +99,7 @@ function isFunction(obj) {
36
99
 
37
100
  // src/hooks/useCombinedRef.ts
38
101
  var useCombinedRef = (...refs) => {
39
- const callback = React.useCallback((element) => {
102
+ const callback = React3.useCallback((element) => {
40
103
  for (const ref of refs) {
41
104
  if (!ref) {
42
105
  continue;
@@ -50,31 +113,113 @@ var useCombinedRef = (...refs) => {
50
113
  }, refs);
51
114
  return callback;
52
115
  };
116
+ var getComponent = (Component) => {
117
+ if (React3__namespace.isValidElement(Component)) {
118
+ return Component;
119
+ }
120
+ if (Component) {
121
+ return /* @__PURE__ */ React3__namespace.createElement(Component, null);
122
+ }
123
+ return null;
124
+ };
53
125
 
54
126
  // src/integrations/reanimated.tsx
55
- var typedMemo = React.memo;
127
+ var typedMemo = React3.memo;
128
+ var ReanimatedScrollBridge = typedMemo(function ReanimatedScrollBridgeComponent({
129
+ forwardedRef,
130
+ scrollOffset,
131
+ ...props
132
+ }) {
133
+ const animatedScrollRef = Reanimated.useAnimatedRef();
134
+ Reanimated.useScrollViewOffset(animatedScrollRef, scrollOffset);
135
+ const combinedRef = useCombinedRef(animatedScrollRef, forwardedRef);
136
+ return /* @__PURE__ */ React3__namespace.createElement(Reanimated__default.default.ScrollView, { ...props, ref: combinedRef });
137
+ });
138
+ var StickyOverlay = typedMemo(function StickyOverlayComponent({ stickyHeaderConfig }) {
139
+ if (!(stickyHeaderConfig == null ? void 0 : stickyHeaderConfig.backdropComponent)) {
140
+ return null;
141
+ }
142
+ return /* @__PURE__ */ React3__namespace.createElement(
143
+ reactNative.View,
144
+ {
145
+ style: {
146
+ inset: 0,
147
+ pointerEvents: "none",
148
+ position: "absolute"
149
+ }
150
+ },
151
+ getComponent(stickyHeaderConfig == null ? void 0 : stickyHeaderConfig.backdropComponent)
152
+ );
153
+ });
154
+ var ReanimatedPositionViewSticky = typedMemo(function ReanimatedPositionViewStickyComponent(props) {
155
+ var _a;
156
+ const { id, horizontal, style, refView, stickyScrollOffset, stickyHeaderConfig, index, children, ...rest } = props;
157
+ const [position = POSITION_OUT_OF_VIEW, headerSize = 0, stylePaddingTop = 0] = useArr$([
158
+ `containerPosition${id}`,
159
+ "headerSize",
160
+ "stylePaddingTop"
161
+ ]);
162
+ const stickyOffset = (_a = stickyHeaderConfig == null ? void 0 : stickyHeaderConfig.offset) != null ? _a : 0;
163
+ const stickyStart = position + headerSize + stylePaddingTop - stickyOffset;
164
+ const transformStyle = Reanimated.useAnimatedStyle(() => {
165
+ const delta = Math.max(0, stickyScrollOffset.value - stickyStart);
166
+ return horizontal ? { transform: [{ translateX: position + delta }] } : { transform: [{ translateY: position + delta }] };
167
+ }, [horizontal, position, stickyStart]);
168
+ const viewStyle = React3__namespace.useMemo(
169
+ () => [style, { zIndex: index + 1e3 }, transformStyle],
170
+ [index, style, transformStyle]
171
+ );
172
+ return /* @__PURE__ */ React3__namespace.createElement(Reanimated__default.default.View, { ref: refView, style: viewStyle, ...rest }, /* @__PURE__ */ React3__namespace.createElement(StickyOverlay, { stickyHeaderConfig }), children);
173
+ });
56
174
  var LegendListForwardedRef = typedMemo(
57
175
  // biome-ignore lint/nursery/noShadow: const function name shadowing is intentional
58
- React__namespace.forwardRef(function LegendListForwardedRef2(props, ref) {
176
+ React3__namespace.forwardRef(function LegendListForwardedRef2(props, ref) {
59
177
  const { refLegendList, ...rest } = props;
60
- const refFn = React.useCallback(
178
+ const refFn = React3.useCallback(
61
179
  (r) => {
62
180
  refLegendList(r);
63
181
  },
64
182
  [refLegendList]
65
183
  );
66
- return /* @__PURE__ */ React__namespace.createElement(list.LegendList, { ref: refFn, refScrollView: ref, ...rest });
184
+ const stickyScrollOffset = Reanimated.useSharedValue(0);
185
+ const shouldUseReanimatedScrollView = IsNewArchitecture;
186
+ const renderReanimatedScrollComponent = React3.useCallback(
187
+ (scrollViewProps) => {
188
+ const { ref: forwardedRef, ...restScrollViewProps } = scrollViewProps;
189
+ return /* @__PURE__ */ React3__namespace.createElement(
190
+ ReanimatedScrollBridge,
191
+ {
192
+ ...restScrollViewProps,
193
+ forwardedRef,
194
+ scrollOffset: stickyScrollOffset
195
+ }
196
+ );
197
+ },
198
+ [stickyScrollOffset]
199
+ );
200
+ const stickyPositionComponentInternal = React3__namespace.useMemo(
201
+ () => function StickyPositionComponent(stickyProps) {
202
+ return /* @__PURE__ */ React3__namespace.createElement(ReanimatedPositionViewSticky, { ...stickyProps, stickyScrollOffset });
203
+ },
204
+ [stickyScrollOffset]
205
+ );
206
+ const legendListProps = shouldUseReanimatedScrollView ? {
207
+ ...rest,
208
+ renderScrollComponent: renderReanimatedScrollComponent,
209
+ stickyPositionComponentInternal
210
+ } : rest;
211
+ return /* @__PURE__ */ React3__namespace.createElement(reactNative$1.LegendList, { ref: refFn, refScrollView: ref, ...legendListProps });
67
212
  })
68
213
  );
69
214
  var AnimatedLegendListComponent = Reanimated__default.default.createAnimatedComponent(LegendListForwardedRef);
70
215
  var AnimatedLegendList = typedMemo(
71
216
  // biome-ignore lint/nursery/noShadow: const function name shadowing is intentional
72
- React__namespace.forwardRef(function AnimatedLegendList2(props, ref) {
217
+ React3__namespace.forwardRef(function AnimatedLegendList2(props, ref) {
73
218
  const { refScrollView, ...rest } = props;
74
219
  const { animatedProps } = props;
75
- const refLegendList = React__namespace.useRef(null);
220
+ const refLegendList = React3__namespace.useRef(null);
76
221
  const combinedRef = useCombinedRef(refLegendList, ref);
77
- return /* @__PURE__ */ React__namespace.createElement(
222
+ return /* @__PURE__ */ React3__namespace.createElement(
78
223
  AnimatedLegendListComponent,
79
224
  {
80
225
  animatedPropsInternal: animatedProps,
package/reanimated.mjs CHANGED
@@ -1,10 +1,73 @@
1
- import * as React from 'react';
1
+ import * as React3 from 'react';
2
2
  import { useCallback, memo } from 'react';
3
- import Reanimated from 'react-native-reanimated';
4
- import { LegendList } from '@legendapp/list';
3
+ import { View } from 'react-native';
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';
5
7
 
6
8
  // src/integrations/reanimated.tsx
7
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
+
8
71
  // src/utils/helpers.ts
9
72
  function isFunction(obj) {
10
73
  return typeof obj === "function";
@@ -26,12 +89,67 @@ var useCombinedRef = (...refs) => {
26
89
  }, refs);
27
90
  return callback;
28
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
+ };
29
101
 
30
102
  // src/integrations/reanimated.tsx
31
103
  var typedMemo = memo;
104
+ var ReanimatedScrollBridge = typedMemo(function ReanimatedScrollBridgeComponent({
105
+ forwardedRef,
106
+ scrollOffset,
107
+ ...props
108
+ }) {
109
+ const animatedScrollRef = useAnimatedRef();
110
+ useScrollViewOffset(animatedScrollRef, scrollOffset);
111
+ const combinedRef = useCombinedRef(animatedScrollRef, forwardedRef);
112
+ return /* @__PURE__ */ React3.createElement(Reanimated.ScrollView, { ...props, ref: combinedRef });
113
+ });
114
+ var StickyOverlay = typedMemo(function StickyOverlayComponent({ stickyHeaderConfig }) {
115
+ if (!(stickyHeaderConfig == null ? void 0 : stickyHeaderConfig.backdropComponent)) {
116
+ return null;
117
+ }
118
+ return /* @__PURE__ */ React3.createElement(
119
+ View,
120
+ {
121
+ style: {
122
+ inset: 0,
123
+ pointerEvents: "none",
124
+ position: "absolute"
125
+ }
126
+ },
127
+ getComponent(stickyHeaderConfig == null ? void 0 : stickyHeaderConfig.backdropComponent)
128
+ );
129
+ });
130
+ var ReanimatedPositionViewSticky = typedMemo(function ReanimatedPositionViewStickyComponent(props) {
131
+ var _a;
132
+ const { id, horizontal, style, refView, stickyScrollOffset, stickyHeaderConfig, index, children, ...rest } = props;
133
+ const [position = POSITION_OUT_OF_VIEW, headerSize = 0, stylePaddingTop = 0] = useArr$([
134
+ `containerPosition${id}`,
135
+ "headerSize",
136
+ "stylePaddingTop"
137
+ ]);
138
+ const stickyOffset = (_a = stickyHeaderConfig == null ? void 0 : stickyHeaderConfig.offset) != null ? _a : 0;
139
+ const stickyStart = position + headerSize + stylePaddingTop - stickyOffset;
140
+ const transformStyle = useAnimatedStyle(() => {
141
+ const delta = Math.max(0, stickyScrollOffset.value - stickyStart);
142
+ return horizontal ? { transform: [{ translateX: position + delta }] } : { transform: [{ translateY: position + delta }] };
143
+ }, [horizontal, position, stickyStart]);
144
+ const viewStyle = React3.useMemo(
145
+ () => [style, { zIndex: index + 1e3 }, transformStyle],
146
+ [index, style, transformStyle]
147
+ );
148
+ return /* @__PURE__ */ React3.createElement(Reanimated.View, { ref: refView, style: viewStyle, ...rest }, /* @__PURE__ */ React3.createElement(StickyOverlay, { stickyHeaderConfig }), children);
149
+ });
32
150
  var LegendListForwardedRef = typedMemo(
33
151
  // biome-ignore lint/nursery/noShadow: const function name shadowing is intentional
34
- React.forwardRef(function LegendListForwardedRef2(props, ref) {
152
+ React3.forwardRef(function LegendListForwardedRef2(props, ref) {
35
153
  const { refLegendList, ...rest } = props;
36
154
  const refFn = useCallback(
37
155
  (r) => {
@@ -39,18 +157,45 @@ var LegendListForwardedRef = typedMemo(
39
157
  },
40
158
  [refLegendList]
41
159
  );
42
- return /* @__PURE__ */ React.createElement(LegendList, { ref: refFn, refScrollView: ref, ...rest });
160
+ const stickyScrollOffset = useSharedValue(0);
161
+ const shouldUseReanimatedScrollView = IsNewArchitecture;
162
+ const renderReanimatedScrollComponent = useCallback(
163
+ (scrollViewProps) => {
164
+ const { ref: forwardedRef, ...restScrollViewProps } = scrollViewProps;
165
+ return /* @__PURE__ */ React3.createElement(
166
+ ReanimatedScrollBridge,
167
+ {
168
+ ...restScrollViewProps,
169
+ forwardedRef,
170
+ scrollOffset: stickyScrollOffset
171
+ }
172
+ );
173
+ },
174
+ [stickyScrollOffset]
175
+ );
176
+ const stickyPositionComponentInternal = React3.useMemo(
177
+ () => function StickyPositionComponent(stickyProps) {
178
+ return /* @__PURE__ */ React3.createElement(ReanimatedPositionViewSticky, { ...stickyProps, stickyScrollOffset });
179
+ },
180
+ [stickyScrollOffset]
181
+ );
182
+ const legendListProps = shouldUseReanimatedScrollView ? {
183
+ ...rest,
184
+ renderScrollComponent: renderReanimatedScrollComponent,
185
+ stickyPositionComponentInternal
186
+ } : rest;
187
+ return /* @__PURE__ */ React3.createElement(LegendList, { ref: refFn, refScrollView: ref, ...legendListProps });
43
188
  })
44
189
  );
45
190
  var AnimatedLegendListComponent = Reanimated.createAnimatedComponent(LegendListForwardedRef);
46
191
  var AnimatedLegendList = typedMemo(
47
192
  // biome-ignore lint/nursery/noShadow: const function name shadowing is intentional
48
- React.forwardRef(function AnimatedLegendList2(props, ref) {
193
+ React3.forwardRef(function AnimatedLegendList2(props, ref) {
49
194
  const { refScrollView, ...rest } = props;
50
195
  const { animatedProps } = props;
51
- const refLegendList = React.useRef(null);
196
+ const refLegendList = React3.useRef(null);
52
197
  const combinedRef = useCombinedRef(refLegendList, ref);
53
- return /* @__PURE__ */ React.createElement(
198
+ return /* @__PURE__ */ React3.createElement(
54
199
  AnimatedLegendListComponent,
55
200
  {
56
201
  animatedPropsInternal: animatedProps,