@legendapp/list 3.0.0-beta.8 → 3.0.0

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 (49) hide show
  1. package/.DS_Store +0 -0
  2. package/CHANGELOG.md +21 -1
  3. package/README.md +8 -2
  4. package/animated.d.ts +659 -5
  5. package/animated.js +2 -2
  6. package/animated.mjs +1 -1
  7. package/keyboard-legacy.d.ts +226 -0
  8. package/keyboard-legacy.js +456 -0
  9. package/keyboard-legacy.mjs +435 -0
  10. package/keyboard.d.ts +261 -9
  11. package/keyboard.js +114 -135
  12. package/keyboard.mjs +115 -137
  13. package/package.json +55 -5
  14. package/{types-DjNeqVEk.d.mts → react-native.d.ts} +318 -278
  15. package/react-native.js +6453 -0
  16. package/react-native.mjs +6424 -0
  17. package/react-native.web.d.ts +771 -0
  18. package/react-native.web.js +7111 -0
  19. package/react-native.web.mjs +7082 -0
  20. package/react.d.ts +771 -0
  21. package/react.js +7111 -0
  22. package/react.mjs +7082 -0
  23. package/reanimated.d.ts +681 -8
  24. package/reanimated.js +225 -29
  25. package/reanimated.mjs +227 -31
  26. package/section-list.d.ts +663 -5
  27. package/section-list.js +39 -3720
  28. package/section-list.mjs +37 -3719
  29. package/animated.d.mts +0 -9
  30. package/index.d.mts +0 -23
  31. package/index.d.ts +0 -23
  32. package/index.js +0 -3826
  33. package/index.mjs +0 -3798
  34. package/index.native.d.mts +0 -23
  35. package/index.native.d.ts +0 -23
  36. package/index.native.js +0 -3580
  37. package/index.native.mjs +0 -3552
  38. package/keyboard-controller.d.mts +0 -12
  39. package/keyboard-controller.d.ts +0 -12
  40. package/keyboard-controller.js +0 -69
  41. package/keyboard-controller.mjs +0 -48
  42. package/keyboard.d.mts +0 -13
  43. package/reanimated.d.mts +0 -18
  44. package/section-list.d.mts +0 -113
  45. package/section-list.native.d.mts +0 -113
  46. package/section-list.native.d.ts +0 -113
  47. package/section-list.native.js +0 -3738
  48. package/section-list.native.mjs +0 -3717
  49. package/types-DjNeqVEk.d.ts +0 -669
package/index.js DELETED
@@ -1,3826 +0,0 @@
1
- 'use strict';
2
-
3
- var React3 = require('react');
4
- var shim = require('use-sync-external-store/shim');
5
- var reactDom = require('react-dom');
6
-
7
- function _interopNamespace(e) {
8
- if (e && e.__esModule) return e;
9
- var n = Object.create(null);
10
- if (e) {
11
- Object.keys(e).forEach(function (k) {
12
- if (k !== 'default') {
13
- var d = Object.getOwnPropertyDescriptor(e, k);
14
- Object.defineProperty(n, k, d.get ? d : {
15
- enumerable: true,
16
- get: function () { return e[k]; }
17
- });
18
- }
19
- });
20
- }
21
- n.default = e;
22
- return Object.freeze(n);
23
- }
24
-
25
- var React3__namespace = /*#__PURE__*/_interopNamespace(React3);
26
-
27
- // src/components/LegendList.tsx
28
- React3.forwardRef(function AnimatedView2(props, ref) {
29
- return /* @__PURE__ */ React3__namespace.createElement("div", { ref, ...props });
30
- });
31
- var View = React3.forwardRef(function View2(props, ref) {
32
- return /* @__PURE__ */ React3__namespace.createElement("div", { ref, ...props });
33
- });
34
- var Text = View;
35
-
36
- // src/platform/Animated.tsx
37
- var createAnimatedValue = (value) => value;
38
-
39
- // src/state/state.tsx
40
- var ContextState = React3__namespace.createContext(null);
41
- function StateProvider({ children }) {
42
- const [value] = React3__namespace.useState(() => ({
43
- animatedScrollY: createAnimatedValue(0),
44
- columnWrapperStyle: void 0,
45
- internalState: void 0,
46
- listeners: /* @__PURE__ */ new Map(),
47
- mapViewabilityAmountCallbacks: /* @__PURE__ */ new Map(),
48
- mapViewabilityAmountValues: /* @__PURE__ */ new Map(),
49
- mapViewabilityCallbacks: /* @__PURE__ */ new Map(),
50
- mapViewabilityConfigStates: /* @__PURE__ */ new Map(),
51
- mapViewabilityValues: /* @__PURE__ */ new Map(),
52
- values: /* @__PURE__ */ new Map([
53
- ["alignItemsPaddingTop", 0],
54
- ["stylePaddingTop", 0],
55
- ["headerSize", 0],
56
- ["numContainers", 0],
57
- ["activeStickyIndex", void 0],
58
- ["totalSize", 0],
59
- ["scrollAdjustPending", 0],
60
- ["scrollingTo", void 0]
61
- ]),
62
- viewRefs: /* @__PURE__ */ new Map()
63
- }));
64
- return /* @__PURE__ */ React3__namespace.createElement(ContextState.Provider, { value }, children);
65
- }
66
- function useStateContext() {
67
- return React3__namespace.useContext(ContextState);
68
- }
69
- function createSelectorFunctionsArr(ctx, signalNames) {
70
- let lastValues = [];
71
- let lastSignalValues = [];
72
- return {
73
- get: () => {
74
- const currentValues = [];
75
- let hasChanged = false;
76
- for (let i = 0; i < signalNames.length; i++) {
77
- const value = peek$(ctx, signalNames[i]);
78
- currentValues.push(value);
79
- if (value !== lastSignalValues[i]) {
80
- hasChanged = true;
81
- }
82
- }
83
- lastSignalValues = currentValues;
84
- if (hasChanged) {
85
- lastValues = currentValues;
86
- }
87
- return lastValues;
88
- },
89
- subscribe: (cb) => {
90
- const listeners = [];
91
- for (const signalName of signalNames) {
92
- listeners.push(listen$(ctx, signalName, cb));
93
- }
94
- return () => {
95
- for (const listener of listeners) {
96
- listener();
97
- }
98
- };
99
- }
100
- };
101
- }
102
- function listen$(ctx, signalName, cb) {
103
- const { listeners } = ctx;
104
- let setListeners = listeners.get(signalName);
105
- if (!setListeners) {
106
- setListeners = /* @__PURE__ */ new Set();
107
- listeners.set(signalName, setListeners);
108
- }
109
- setListeners.add(cb);
110
- return () => setListeners.delete(cb);
111
- }
112
- function peek$(ctx, signalName) {
113
- const { values } = ctx;
114
- return values.get(signalName);
115
- }
116
- function set$(ctx, signalName, value) {
117
- const { listeners, values } = ctx;
118
- if (values.get(signalName) !== value) {
119
- values.set(signalName, value);
120
- const setListeners = listeners.get(signalName);
121
- if (setListeners) {
122
- for (const listener of setListeners) {
123
- listener(value);
124
- }
125
- }
126
- }
127
- }
128
- function getContentSize(ctx) {
129
- var _a3, _b;
130
- const { values, internalState } = ctx;
131
- const stylePaddingTop = values.get("stylePaddingTop") || 0;
132
- const stylePaddingBottom = (internalState == null ? void 0 : internalState.props.stylePaddingBottom) || 0;
133
- const headerSize = values.get("headerSize") || 0;
134
- const footerSize = values.get("footerSize") || 0;
135
- const totalSize = (_b = (_a3 = ctx.internalState) == null ? void 0 : _a3.pendingTotalSize) != null ? _b : values.get("totalSize");
136
- return headerSize + footerSize + totalSize + stylePaddingTop + stylePaddingBottom;
137
- }
138
- function useArr$(signalNames) {
139
- const ctx = React3__namespace.useContext(ContextState);
140
- const { subscribe, get } = React3__namespace.useMemo(() => createSelectorFunctionsArr(ctx, signalNames), [ctx, signalNames]);
141
- const value = shim.useSyncExternalStore(subscribe, get);
142
- return value;
143
- }
144
- function useSelector$(signalName, selector) {
145
- const ctx = React3__namespace.useContext(ContextState);
146
- const { subscribe, get } = React3__namespace.useMemo(() => createSelectorFunctionsArr(ctx, [signalName]), [ctx, signalName]);
147
- const value = shim.useSyncExternalStore(subscribe, () => selector(get()[0]));
148
- return value;
149
- }
150
-
151
- // src/components/DebugView.tsx
152
- var DebugRow = ({ children }) => {
153
- return /* @__PURE__ */ React3__namespace.createElement(View, { style: { alignItems: "center", flexDirection: "row", justifyContent: "space-between" } }, children);
154
- };
155
- var DebugView = React3__namespace.memo(function DebugView2({ state }) {
156
- const ctx = useStateContext();
157
- const [totalSize = 0, scrollAdjust = 0, rawScroll = 0, scroll = 0, _numContainers = 0, _numContainersPooled = 0] = useArr$([
158
- "totalSize",
159
- "scrollAdjust",
160
- "debugRawScroll",
161
- "debugComputedScroll",
162
- "numContainers",
163
- "numContainersPooled"
164
- ]);
165
- const contentSize = getContentSize(ctx);
166
- const [, forceUpdate] = React3.useReducer((x) => x + 1, 0);
167
- useInterval(() => {
168
- forceUpdate();
169
- }, 100);
170
- return /* @__PURE__ */ React3__namespace.createElement(
171
- View,
172
- {
173
- pointerEvents: "none",
174
- style: {
175
- // height: 100,
176
- backgroundColor: "#FFFFFFCC",
177
- borderRadius: 4,
178
- padding: 4,
179
- paddingBottom: 4,
180
- paddingLeft: 4,
181
- position: "absolute",
182
- right: 0,
183
- top: 0
184
- }
185
- },
186
- /* @__PURE__ */ React3__namespace.createElement(DebugRow, null, /* @__PURE__ */ React3__namespace.createElement(Text, null, "TotalSize:"), /* @__PURE__ */ React3__namespace.createElement(Text, null, totalSize.toFixed(2))),
187
- /* @__PURE__ */ React3__namespace.createElement(DebugRow, null, /* @__PURE__ */ React3__namespace.createElement(Text, null, "ContentSize:"), /* @__PURE__ */ React3__namespace.createElement(Text, null, contentSize.toFixed(2))),
188
- /* @__PURE__ */ React3__namespace.createElement(DebugRow, null, /* @__PURE__ */ React3__namespace.createElement(Text, null, "At end:"), /* @__PURE__ */ React3__namespace.createElement(Text, null, String(state.isAtEnd))),
189
- /* @__PURE__ */ React3__namespace.createElement(DebugRow, null, /* @__PURE__ */ React3__namespace.createElement(Text, null, "ScrollAdjust:"), /* @__PURE__ */ React3__namespace.createElement(Text, null, scrollAdjust.toFixed(2))),
190
- /* @__PURE__ */ React3__namespace.createElement(DebugRow, null, /* @__PURE__ */ React3__namespace.createElement(Text, null, "RawScroll: "), /* @__PURE__ */ React3__namespace.createElement(Text, null, rawScroll.toFixed(2))),
191
- /* @__PURE__ */ React3__namespace.createElement(DebugRow, null, /* @__PURE__ */ React3__namespace.createElement(Text, null, "ComputedScroll: "), /* @__PURE__ */ React3__namespace.createElement(Text, null, scroll.toFixed(2)))
192
- );
193
- });
194
- function useInterval(callback, delay) {
195
- React3.useEffect(() => {
196
- const interval = setInterval(callback, delay);
197
- return () => clearInterval(interval);
198
- }, [delay]);
199
- }
200
-
201
- // src/utils/devEnvironment.ts
202
- var metroDev = typeof __DEV__ !== "undefined" ? __DEV__ : void 0;
203
- var _a;
204
- var envMode = typeof process !== "undefined" && typeof process.env === "object" && process.env ? (_a = process.env.NODE_ENV) != null ? _a : process.env.MODE : void 0;
205
- var processDev = typeof envMode === "string" ? envMode.toLowerCase() !== "production" : void 0;
206
- var _a2;
207
- var IS_DEV = (_a2 = metroDev != null ? metroDev : processDev) != null ? _a2 : false;
208
-
209
- // src/constants.ts
210
- var POSITION_OUT_OF_VIEW = -1e7;
211
- var ENABLE_DEVMODE = IS_DEV && false;
212
- var ENABLE_DEBUG_VIEW = IS_DEV && false;
213
- var typedForwardRef = React3.forwardRef;
214
- var typedMemo = React3.memo;
215
-
216
- // src/utils/helpers.ts
217
- function isFunction(obj) {
218
- return typeof obj === "function";
219
- }
220
- function isArray(obj) {
221
- return Array.isArray(obj);
222
- }
223
- var warned = /* @__PURE__ */ new Set();
224
- function warnDevOnce(id, text) {
225
- if (IS_DEV && !warned.has(id)) {
226
- warned.add(id);
227
- console.warn(`[legend-list] ${text}`);
228
- }
229
- }
230
- function roundSize(size) {
231
- return Math.floor(size * 8) / 8;
232
- }
233
- function isNullOrUndefined(value) {
234
- return value === null || value === void 0;
235
- }
236
- function comparatorDefault(a, b) {
237
- return a - b;
238
- }
239
- function getPadding(s, type) {
240
- var _a3, _b, _c;
241
- return (_c = (_b = (_a3 = s[`padding${type}`]) != null ? _a3 : s.paddingVertical) != null ? _b : s.padding) != null ? _c : 0;
242
- }
243
- function extractPadding(style, contentContainerStyle, type) {
244
- return getPadding(style, type) + getPadding(contentContainerStyle, type);
245
- }
246
- function findContainerId(ctx, key) {
247
- const numContainers = peek$(ctx, "numContainers");
248
- for (let i = 0; i < numContainers; i++) {
249
- const itemKey = peek$(ctx, `containerItemKey${i}`);
250
- if (itemKey === key) {
251
- return i;
252
- }
253
- }
254
- return -1;
255
- }
256
-
257
- // src/components/PositionView.tsx
258
- var PositionViewState = typedMemo(function PositionViewState2({
259
- id,
260
- horizontal,
261
- style,
262
- refView,
263
- ...rest
264
- }) {
265
- const [position = POSITION_OUT_OF_VIEW] = useArr$([`containerPosition${id}`]);
266
- const base = {
267
- contain: "paint layout style"
268
- };
269
- const composed = isArray(style) ? Object.assign({}, ...style) : style;
270
- const combinedStyle = horizontal ? { ...base, ...composed, left: position } : { ...base, ...composed, top: position };
271
- return /* @__PURE__ */ React3__namespace.createElement("div", { ref: refView, style: combinedStyle, ...rest });
272
- });
273
- var PositionViewSticky = typedMemo(function PositionViewSticky2({
274
- id,
275
- horizontal,
276
- style,
277
- refView,
278
- index,
279
- stickyOffset,
280
- animatedScrollY: _animatedScrollY,
281
- children,
282
- ...rest
283
- }) {
284
- const [position = POSITION_OUT_OF_VIEW, headerSize = 0, activeStickyIndex] = useArr$([
285
- `containerPosition${id}`,
286
- "headerSize",
287
- "activeStickyIndex"
288
- ]);
289
- const base = {
290
- contain: "paint layout style"
291
- };
292
- const composed = React3__namespace.useMemo(
293
- () => {
294
- var _a3;
295
- return (_a3 = isArray(style) ? Object.assign({}, ...style) : style) != null ? _a3 : {};
296
- },
297
- [style]
298
- );
299
- const viewStyle = React3__namespace.useMemo(() => {
300
- var _a3;
301
- const styleBase = { ...base, ...composed };
302
- delete styleBase.transform;
303
- const offset = (_a3 = stickyOffset != null ? stickyOffset : headerSize) != null ? _a3 : 0;
304
- const isActive = activeStickyIndex === index;
305
- styleBase.position = isActive ? "sticky" : "absolute";
306
- styleBase.zIndex = index + 1e3;
307
- if (horizontal) {
308
- styleBase.left = isActive ? offset : position;
309
- } else {
310
- styleBase.top = isActive ? offset : position;
311
- }
312
- return styleBase;
313
- }, [composed, horizontal, position, index, stickyOffset, headerSize, activeStickyIndex]);
314
- return /* @__PURE__ */ React3__namespace.createElement("div", { ref: refView, style: viewStyle, ...rest }, children);
315
- });
316
- var PositionView = PositionViewState;
317
-
318
- // src/constants-platform.ts
319
- var IsNewArchitecture = true;
320
- function useInit(cb) {
321
- React3.useState(() => cb());
322
- }
323
-
324
- // src/state/ContextContainer.ts
325
- var ContextContainer = React3.createContext(null);
326
- function useViewability(callback, configId) {
327
- const ctx = useStateContext();
328
- const { containerId } = React3.useContext(ContextContainer);
329
- const key = containerId + (configId != null ? configId : "");
330
- useInit(() => {
331
- const value = ctx.mapViewabilityValues.get(key);
332
- if (value) {
333
- callback(value);
334
- }
335
- });
336
- ctx.mapViewabilityCallbacks.set(key, callback);
337
- React3.useEffect(
338
- () => () => {
339
- ctx.mapViewabilityCallbacks.delete(key);
340
- },
341
- []
342
- );
343
- }
344
- function useViewabilityAmount(callback) {
345
- const ctx = useStateContext();
346
- const { containerId } = React3.useContext(ContextContainer);
347
- useInit(() => {
348
- const value = ctx.mapViewabilityAmountValues.get(containerId);
349
- if (value) {
350
- callback(value);
351
- }
352
- });
353
- ctx.mapViewabilityAmountCallbacks.set(containerId, callback);
354
- React3.useEffect(
355
- () => () => {
356
- ctx.mapViewabilityAmountCallbacks.delete(containerId);
357
- },
358
- []
359
- );
360
- }
361
- function useRecyclingEffect(effect) {
362
- const { index, value } = React3.useContext(ContextContainer);
363
- const prevValues = React3.useRef({
364
- prevIndex: void 0,
365
- prevItem: void 0
366
- });
367
- React3.useEffect(() => {
368
- let ret;
369
- if (prevValues.current.prevIndex !== void 0 && prevValues.current.prevItem !== void 0) {
370
- ret = effect({
371
- index,
372
- item: value,
373
- prevIndex: prevValues.current.prevIndex,
374
- prevItem: prevValues.current.prevItem
375
- });
376
- }
377
- prevValues.current = {
378
- prevIndex: index,
379
- prevItem: value
380
- };
381
- return ret;
382
- }, [index, value, effect]);
383
- }
384
- function useRecyclingState(valueOrFun) {
385
- const { index, value, itemKey, triggerLayout } = React3.useContext(ContextContainer);
386
- const refState = React3.useRef({
387
- itemKey: null,
388
- value: null
389
- });
390
- const [_, setRenderNum] = React3.useState(0);
391
- const state = refState.current;
392
- if (state.itemKey !== itemKey) {
393
- state.itemKey = itemKey;
394
- state.value = isFunction(valueOrFun) ? valueOrFun({
395
- index,
396
- item: value,
397
- prevIndex: void 0,
398
- prevItem: void 0
399
- }) : valueOrFun;
400
- }
401
- const setState = React3.useCallback(
402
- (newState) => {
403
- state.value = isFunction(newState) ? newState(state.value) : newState;
404
- setRenderNum((v) => v + 1);
405
- triggerLayout();
406
- },
407
- [triggerLayout, state]
408
- );
409
- return [state.value, setState];
410
- }
411
- function useIsLastItem() {
412
- const { itemKey } = React3.useContext(ContextContainer);
413
- const isLast = useSelector$("lastItemKeys", (lastItemKeys) => (lastItemKeys == null ? void 0 : lastItemKeys.includes(itemKey)) || false);
414
- return isLast;
415
- }
416
- function useListScrollSize() {
417
- const [scrollSize] = useArr$(["scrollSize"]);
418
- return scrollSize;
419
- }
420
- function useSyncLayout() {
421
- {
422
- const { triggerLayout: syncLayout } = React3.useContext(ContextContainer);
423
- return syncLayout;
424
- }
425
- }
426
-
427
- // src/components/Separator.tsx
428
- function Separator({ ItemSeparatorComponent, leadingItem }) {
429
- const isLastItem = useIsLastItem();
430
- return isLastItem ? null : /* @__PURE__ */ React3__namespace.createElement(ItemSeparatorComponent, { leadingItem });
431
- }
432
-
433
- // src/hooks/createResizeObserver.ts
434
- var globalResizeObserver = null;
435
- function getGlobalResizeObserver() {
436
- if (!globalResizeObserver) {
437
- globalResizeObserver = new ResizeObserver((entries) => {
438
- for (const entry of entries) {
439
- const callbacks = callbackMap.get(entry.target);
440
- if (callbacks) {
441
- for (const callback of callbacks) {
442
- callback(entry);
443
- }
444
- }
445
- }
446
- });
447
- }
448
- return globalResizeObserver;
449
- }
450
- var callbackMap = /* @__PURE__ */ new WeakMap();
451
- function createResizeObserver(element, callback) {
452
- if (typeof ResizeObserver === "undefined") {
453
- return () => {
454
- };
455
- }
456
- if (!element) {
457
- return () => {
458
- };
459
- }
460
- const observer = getGlobalResizeObserver();
461
- let callbacks = callbackMap.get(element);
462
- if (!callbacks) {
463
- callbacks = /* @__PURE__ */ new Set();
464
- callbackMap.set(element, callbacks);
465
- observer.observe(element);
466
- }
467
- callbacks.add(callback);
468
- return () => {
469
- if (callbacks) {
470
- callbacks.delete(callback);
471
- if (callbacks.size === 0) {
472
- callbackMap.delete(element);
473
- observer.unobserve(element);
474
- }
475
- }
476
- };
477
- }
478
-
479
- // src/hooks/useOnLayoutSync.tsx
480
- function useOnLayoutSync({
481
- ref,
482
- onLayoutProp,
483
- onLayoutChange
484
- }, deps) {
485
- React3.useLayoutEffect(() => {
486
- var _a3, _b;
487
- const current = ref.current;
488
- const scrollableNode = (_b = (_a3 = current == null ? void 0 : current.getScrollableNode) == null ? void 0 : _a3.call(current)) != null ? _b : null;
489
- const element = scrollableNode || current;
490
- if (!element) {
491
- return;
492
- }
493
- const emit = (layout, fromLayoutEffect) => {
494
- if (layout.height === 0 && layout.width === 0) {
495
- return;
496
- }
497
- onLayoutChange(layout, fromLayoutEffect);
498
- onLayoutProp == null ? void 0 : onLayoutProp({ nativeEvent: { layout } });
499
- };
500
- const rect = element.getBoundingClientRect();
501
- emit(toLayout(rect), true);
502
- let prevRect = rect;
503
- return createResizeObserver(element, (entry) => {
504
- var _a4;
505
- const target = entry.target instanceof HTMLElement ? entry.target : void 0;
506
- const rectObserved = (_a4 = entry.contentRect) != null ? _a4 : target == null ? void 0 : target.getBoundingClientRect();
507
- if (rectObserved.width !== prevRect.width || rectObserved.height !== prevRect.height) {
508
- prevRect = rectObserved;
509
- emit(toLayout(rectObserved), false);
510
- }
511
- });
512
- }, deps || []);
513
- return {};
514
- }
515
- function toLayout(rect) {
516
- if (!rect) {
517
- return { height: 0, width: 0, x: 0, y: 0 };
518
- }
519
- return {
520
- height: rect.height,
521
- width: rect.width,
522
- x: rect.left,
523
- y: rect.top
524
- };
525
- }
526
-
527
- // src/components/Container.tsx
528
- var Container = typedMemo(function Container2({
529
- id,
530
- recycleItems,
531
- horizontal,
532
- getRenderedItem: getRenderedItem2,
533
- updateItemSize: updateItemSize2,
534
- ItemSeparatorComponent
535
- }) {
536
- const ctx = useStateContext();
537
- const { columnWrapperStyle, animatedScrollY } = ctx;
538
- const [column = 0, data, itemKey, numColumns, extraData, isSticky, stickyOffset] = useArr$([
539
- `containerColumn${id}`,
540
- `containerItemData${id}`,
541
- `containerItemKey${id}`,
542
- "numColumns",
543
- "extraData",
544
- `containerSticky${id}`,
545
- `containerStickyOffset${id}`
546
- ]);
547
- const itemLayoutRef = React3.useRef({
548
- horizontal,
549
- itemKey,
550
- updateItemSize: updateItemSize2
551
- });
552
- itemLayoutRef.current.horizontal = horizontal;
553
- itemLayoutRef.current.itemKey = itemKey;
554
- itemLayoutRef.current.updateItemSize = updateItemSize2;
555
- const ref = React3.useRef(null);
556
- const [layoutRenderCount, forceLayoutRender] = React3.useState(0);
557
- const otherAxisPos = numColumns > 1 ? `${(column - 1) / numColumns * 100}%` : 0;
558
- const otherAxisSize = numColumns > 1 ? `${1 / numColumns * 100}%` : void 0;
559
- const didLayoutRef = React3.useRef(false);
560
- const style = React3.useMemo(() => {
561
- let paddingStyles;
562
- if (columnWrapperStyle) {
563
- const { columnGap, rowGap, gap } = columnWrapperStyle;
564
- if (horizontal) {
565
- paddingStyles = {
566
- paddingRight: columnGap || gap || void 0,
567
- paddingVertical: numColumns > 1 ? (rowGap || gap || 0) / 2 : void 0
568
- };
569
- } else {
570
- paddingStyles = {
571
- paddingBottom: rowGap || gap || void 0,
572
- paddingHorizontal: numColumns > 1 ? (columnGap || gap || 0) / 2 : void 0
573
- };
574
- }
575
- }
576
- return horizontal ? {
577
- flexDirection: ItemSeparatorComponent ? "row" : void 0,
578
- height: otherAxisSize,
579
- left: 0,
580
- position: "absolute",
581
- top: otherAxisPos,
582
- ...paddingStyles || {}
583
- } : {
584
- left: otherAxisPos,
585
- position: "absolute",
586
- right: numColumns > 1 ? null : 0,
587
- top: 0,
588
- width: otherAxisSize,
589
- ...paddingStyles || {}
590
- };
591
- }, [horizontal, otherAxisPos, otherAxisSize, columnWrapperStyle, numColumns]);
592
- const renderedItemInfo = React3.useMemo(
593
- () => itemKey !== void 0 ? getRenderedItem2(itemKey) : null,
594
- [itemKey, data, extraData]
595
- );
596
- const { index, renderedItem } = renderedItemInfo || {};
597
- const contextValue = React3.useMemo(() => {
598
- ctx.viewRefs.set(id, ref);
599
- return {
600
- containerId: id,
601
- index,
602
- itemKey,
603
- triggerLayout: () => {
604
- forceLayoutRender((v) => v + 1);
605
- },
606
- value: data
607
- };
608
- }, [id, itemKey, index, data]);
609
- const onLayoutChange = React3.useCallback((rectangle) => {
610
- const {
611
- horizontal: currentHorizontal,
612
- itemKey: currentItemKey,
613
- updateItemSize: updateItemSizeFn
614
- } = itemLayoutRef.current;
615
- if (isNullOrUndefined(currentItemKey)) {
616
- return;
617
- }
618
- didLayoutRef.current = true;
619
- let layout = rectangle;
620
- roundSize(rectangle[currentHorizontal ? "width" : "height"]);
621
- const doUpdate = () => {
622
- itemLayoutRef.current.lastSize = { height: layout.height, width: layout.width };
623
- updateItemSizeFn(currentItemKey, layout);
624
- didLayoutRef.current = true;
625
- };
626
- {
627
- doUpdate();
628
- }
629
- }, []);
630
- const { onLayout } = useOnLayoutSync(
631
- {
632
- onLayoutChange,
633
- ref
634
- },
635
- [itemKey, layoutRenderCount]
636
- );
637
- const PositionComponent = isSticky ? PositionViewSticky : PositionView;
638
- return /* @__PURE__ */ React3__namespace.createElement(
639
- PositionComponent,
640
- {
641
- animatedScrollY: isSticky ? animatedScrollY : void 0,
642
- horizontal,
643
- id,
644
- index,
645
- key: recycleItems ? void 0 : itemKey,
646
- onLayout,
647
- refView: ref,
648
- stickyOffset: isSticky ? stickyOffset : void 0,
649
- style
650
- },
651
- /* @__PURE__ */ React3__namespace.createElement(ContextContainer.Provider, { value: contextValue }, renderedItem, renderedItemInfo && ItemSeparatorComponent && /* @__PURE__ */ React3__namespace.createElement(Separator, { ItemSeparatorComponent, leadingItem: renderedItemInfo.item }))
652
- );
653
- });
654
-
655
- // src/platform/Platform.ts
656
- var Platform = {
657
- // Widen the type to avoid unreachable-branch lints in cross-platform code that compares against other OSes
658
- OS: "web"
659
- };
660
-
661
- // src/utils/reordering.ts
662
- var mapFn = (element) => {
663
- const indexStr = element.getAttribute("index");
664
- return [element, indexStr === null ? null : parseInt(indexStr)];
665
- };
666
- function sortDOMElements(container) {
667
- const elements = Array.from(container.children);
668
- if (elements.length <= 1) return elements;
669
- const items = elements.map(mapFn);
670
- items.sort((a, b) => {
671
- const aKey = a[1];
672
- const bKey = b[1];
673
- if (aKey === null) {
674
- return 1;
675
- }
676
- if (bKey === null) {
677
- return -1;
678
- }
679
- return aKey - bKey;
680
- });
681
- const targetPositions = /* @__PURE__ */ new Map();
682
- items.forEach((item, index) => {
683
- targetPositions.set(item[0], index);
684
- });
685
- const currentPositions = elements.map((el) => targetPositions.get(el));
686
- const lis = findLIS(currentPositions);
687
- const stableIndices = new Set(lis);
688
- for (let targetPos = 0; targetPos < items.length; targetPos++) {
689
- const element = items[targetPos][0];
690
- const currentPos = elements.indexOf(element);
691
- if (!stableIndices.has(currentPos)) {
692
- let nextStableElement = null;
693
- for (let i = targetPos + 1; i < items.length; i++) {
694
- const nextEl = items[i][0];
695
- const nextCurrentPos = elements.indexOf(nextEl);
696
- if (stableIndices.has(nextCurrentPos)) {
697
- nextStableElement = nextEl;
698
- break;
699
- }
700
- }
701
- if (nextStableElement) {
702
- container.insertBefore(element, nextStableElement);
703
- } else {
704
- container.appendChild(element);
705
- }
706
- }
707
- }
708
- }
709
- function findLIS(arr) {
710
- const n = arr.length;
711
- const tails = [];
712
- const predecessors = new Array(n).fill(-1);
713
- const indices = [];
714
- for (let i = 0; i < n; i++) {
715
- const num = arr[i];
716
- let left = 0, right = tails.length;
717
- while (left < right) {
718
- const mid = Math.floor((left + right) / 2);
719
- if (arr[indices[mid]] < num) {
720
- left = mid + 1;
721
- } else {
722
- right = mid;
723
- }
724
- }
725
- if (left === tails.length) {
726
- tails.push(num);
727
- indices.push(i);
728
- } else {
729
- tails[left] = num;
730
- indices[left] = i;
731
- }
732
- if (left > 0) {
733
- predecessors[i] = indices[left - 1];
734
- }
735
- }
736
- const result = [];
737
- let k = indices[indices.length - 1];
738
- while (k !== -1) {
739
- result.unshift(k);
740
- k = predecessors[k];
741
- }
742
- return result;
743
- }
744
-
745
- // src/hooks/useDOMOrder.ts
746
- function useDOMOrder(ref) {
747
- const ctx = useStateContext();
748
- const debounceRef = React3.useRef(void 0);
749
- React3.useEffect(() => {
750
- const unsubscribe = listen$(ctx, "lastPositionUpdate", () => {
751
- if (debounceRef.current !== void 0) {
752
- clearTimeout(debounceRef.current);
753
- }
754
- debounceRef.current = setTimeout(() => {
755
- const parent = ref.current;
756
- if (parent) {
757
- sortDOMElements(parent);
758
- }
759
- debounceRef.current = void 0;
760
- }, 500);
761
- });
762
- return () => {
763
- unsubscribe();
764
- if (debounceRef.current !== void 0) {
765
- clearTimeout(debounceRef.current);
766
- }
767
- };
768
- }, [ctx]);
769
- }
770
-
771
- // src/components/Containers.tsx
772
- var ContainersInner = typedMemo(function ContainersInner2({ horizontal, numColumns, children }) {
773
- const ref = React3.useRef(null);
774
- const ctx = useStateContext();
775
- const columnWrapperStyle = ctx.columnWrapperStyle;
776
- const [totalSize, otherAxisSize] = useArr$(["totalSize", "otherAxisSize"]);
777
- useDOMOrder(ref);
778
- const style = horizontal ? { minHeight: otherAxisSize, position: "relative", width: totalSize } : { height: totalSize, minWidth: otherAxisSize, position: "relative" };
779
- if (columnWrapperStyle && numColumns > 1) {
780
- const { columnGap, rowGap, gap } = columnWrapperStyle;
781
- const gapX = columnGap || gap || 0;
782
- const gapY = rowGap || gap || 0;
783
- if (horizontal) {
784
- if (gapY) {
785
- style.marginTop = style.marginBottom = -gapY / 2;
786
- }
787
- if (gapX) {
788
- style.marginRight = -gapX;
789
- }
790
- } else {
791
- if (gapX) {
792
- style.marginLeft = style.marginRight = -gapX;
793
- }
794
- if (gapY) {
795
- style.marginBottom = -gapY;
796
- }
797
- }
798
- }
799
- return /* @__PURE__ */ React3__namespace.createElement("div", { ref, style }, children);
800
- });
801
- var Containers = typedMemo(function Containers2({
802
- horizontal,
803
- recycleItems,
804
- ItemSeparatorComponent,
805
- waitForInitialLayout,
806
- updateItemSize: updateItemSize2,
807
- getRenderedItem: getRenderedItem2
808
- }) {
809
- const [numContainers, numColumns] = useArr$(["numContainersPooled", "numColumns"]);
810
- const containers = [];
811
- for (let i = 0; i < numContainers; i++) {
812
- containers.push(
813
- /* @__PURE__ */ React3__namespace.createElement(
814
- Container,
815
- {
816
- getRenderedItem: getRenderedItem2,
817
- horizontal,
818
- ItemSeparatorComponent,
819
- id: i,
820
- key: i,
821
- recycleItems,
822
- updateItemSize: updateItemSize2
823
- }
824
- )
825
- );
826
- }
827
- return /* @__PURE__ */ React3__namespace.createElement(ContainersInner, { horizontal, numColumns, waitForInitialLayout }, containers);
828
- });
829
- function DevNumbers() {
830
- return IS_DEV && // biome-ignore lint/nursery/noShadow: const function name shadowing is intentional
831
- React3__namespace.memo(function DevNumbers2() {
832
- return Array.from({ length: 100 }).map((_, index) => /* @__PURE__ */ React3__namespace.createElement(
833
- "div",
834
- {
835
- key: index,
836
- style: {
837
- height: 100,
838
- pointerEvents: "none",
839
- position: "absolute",
840
- top: index * 100,
841
- width: "100%"
842
- }
843
- },
844
- /* @__PURE__ */ React3__namespace.createElement("div", { style: { color: "red" } }, index * 100)
845
- ));
846
- });
847
- }
848
-
849
- // src/platform/StyleSheet.tsx
850
- function flattenStyles(styles) {
851
- if (isArray(styles)) {
852
- return Object.assign({}, ...styles.filter(Boolean));
853
- }
854
- return styles;
855
- }
856
- var StyleSheet = {
857
- create: (styles) => styles,
858
- flatten: (style) => flattenStyles(style)
859
- };
860
-
861
- // src/components/ListComponentScrollView.tsx
862
- var ListComponentScrollView = React3.forwardRef(function ListComponentScrollView2({
863
- children,
864
- style,
865
- contentContainerStyle,
866
- horizontal = false,
867
- contentOffset,
868
- maintainVisibleContentPosition,
869
- onScroll: onScroll2,
870
- onMomentumScrollEnd,
871
- showsHorizontalScrollIndicator = true,
872
- showsVerticalScrollIndicator = true,
873
- refreshControl,
874
- onLayout,
875
- ...props
876
- }, ref) {
877
- const scrollRef = React3.useRef(null);
878
- const contentRef = React3.useRef(null);
879
- React3.useImperativeHandle(ref, () => {
880
- const api = {
881
- getBoundingClientRect: () => {
882
- var _a3;
883
- return (_a3 = scrollRef.current) == null ? void 0 : _a3.getBoundingClientRect();
884
- },
885
- getScrollableNode: () => scrollRef.current,
886
- getScrollResponder: () => scrollRef.current,
887
- scrollBy: (x, y) => {
888
- const el = scrollRef.current;
889
- if (!el) return;
890
- el.scrollBy(x, y);
891
- },
892
- scrollTo: (options) => {
893
- const el = scrollRef.current;
894
- if (!el) return;
895
- const { x = 0, y = 0, animated = true } = options;
896
- el.scrollTo({ behavior: animated ? "smooth" : "auto", left: x, top: y });
897
- },
898
- scrollToEnd: (options = {}) => {
899
- const el = scrollRef.current;
900
- if (!el) return;
901
- const { animated = true } = options;
902
- if (horizontal) {
903
- el.scrollTo({ behavior: animated ? "smooth" : "auto", left: el.scrollWidth });
904
- } else {
905
- el.scrollTo({ behavior: animated ? "smooth" : "auto", top: el.scrollHeight });
906
- }
907
- },
908
- scrollToOffset: (params) => {
909
- const el = scrollRef.current;
910
- if (!el) return;
911
- const { offset, animated = true } = params;
912
- if (horizontal) {
913
- el.scrollTo({ behavior: animated ? "smooth" : "auto", left: offset });
914
- } else {
915
- el.scrollTo({ behavior: animated ? "smooth" : "auto", top: offset });
916
- }
917
- }
918
- };
919
- return api;
920
- }, [horizontal]);
921
- const handleScroll = React3.useCallback(
922
- (event) => {
923
- if (!onScroll2 || !(event == null ? void 0 : event.target)) {
924
- return;
925
- }
926
- const target = event.target;
927
- const scrollEvent = {
928
- nativeEvent: {
929
- contentOffset: {
930
- x: target.scrollLeft,
931
- y: target.scrollTop
932
- },
933
- contentSize: {
934
- height: target.scrollHeight,
935
- width: target.scrollWidth
936
- },
937
- layoutMeasurement: {
938
- height: target.clientHeight,
939
- width: target.clientWidth
940
- }
941
- }
942
- };
943
- onScroll2(scrollEvent);
944
- },
945
- [onScroll2, onMomentumScrollEnd]
946
- );
947
- React3.useLayoutEffect(() => {
948
- const element = scrollRef.current;
949
- if (!element) return;
950
- element.addEventListener("scroll", handleScroll);
951
- return () => {
952
- element.removeEventListener("scroll", handleScroll);
953
- };
954
- }, [handleScroll]);
955
- React3.useEffect(() => {
956
- const doScroll = () => {
957
- if (contentOffset && scrollRef.current) {
958
- scrollRef.current.scrollLeft = contentOffset.x || 0;
959
- scrollRef.current.scrollTop = contentOffset.y || 0;
960
- }
961
- };
962
- doScroll();
963
- requestAnimationFrame(doScroll);
964
- }, [contentOffset == null ? void 0 : contentOffset.x, contentOffset == null ? void 0 : contentOffset.y]);
965
- React3.useLayoutEffect(() => {
966
- if (!onLayout || !scrollRef.current) return;
967
- const element = scrollRef.current;
968
- const fireLayout = () => {
969
- const rect = element.getBoundingClientRect();
970
- onLayout({
971
- nativeEvent: {
972
- layout: {
973
- height: rect.height,
974
- width: rect.width,
975
- x: rect.left,
976
- y: rect.top
977
- }
978
- }
979
- });
980
- };
981
- fireLayout();
982
- const resizeObserver = new ResizeObserver(() => {
983
- fireLayout();
984
- });
985
- resizeObserver.observe(element);
986
- return () => resizeObserver.disconnect();
987
- }, [onLayout]);
988
- const scrollViewStyle = {
989
- overflow: "auto",
990
- overflowX: horizontal ? "auto" : showsHorizontalScrollIndicator ? "auto" : "hidden",
991
- overflowY: horizontal ? showsVerticalScrollIndicator ? "auto" : "hidden" : "auto",
992
- position: "relative",
993
- // Ensure proper positioning context
994
- WebkitOverflowScrolling: "touch",
995
- // iOS momentum scrolling
996
- ...StyleSheet.flatten(style)
997
- };
998
- const contentStyle = {
999
- display: horizontal ? "flex" : "block",
1000
- flexDirection: horizontal ? "row" : void 0,
1001
- minHeight: horizontal ? void 0 : "100%",
1002
- minWidth: horizontal ? "100%" : void 0,
1003
- ...StyleSheet.flatten(contentContainerStyle)
1004
- };
1005
- return /* @__PURE__ */ React3__namespace.createElement("div", { ref: scrollRef, style: scrollViewStyle, ...props }, refreshControl, /* @__PURE__ */ React3__namespace.createElement("div", { ref: contentRef, style: contentStyle }, children));
1006
- });
1007
- function Padding() {
1008
- const [paddingTop] = useArr$(["alignItemsPaddingTop"]);
1009
- return /* @__PURE__ */ React3__namespace.createElement("div", { style: { paddingTop } });
1010
- }
1011
- function PaddingDevMode() {
1012
- const [paddingTop] = useArr$(["alignItemsPaddingTop"]);
1013
- return /* @__PURE__ */ React3__namespace.createElement(React3__namespace.Fragment, null, /* @__PURE__ */ React3__namespace.createElement("div", { style: { paddingTop } }), /* @__PURE__ */ React3__namespace.createElement(
1014
- "div",
1015
- {
1016
- style: {
1017
- backgroundColor: "green",
1018
- height: paddingTop,
1019
- left: 0,
1020
- position: "absolute",
1021
- right: 0,
1022
- top: 0
1023
- }
1024
- }
1025
- ));
1026
- }
1027
- function useValueListener$(key, callback) {
1028
- const ctx = useStateContext();
1029
- React3.useLayoutEffect(() => {
1030
- const unsubscribe = listen$(ctx, key, (value) => {
1031
- callback(value);
1032
- });
1033
- return unsubscribe;
1034
- }, [callback, ctx, key]);
1035
- }
1036
-
1037
- // src/components/ScrollAdjust.tsx
1038
- function ScrollAdjust() {
1039
- const ctx = useStateContext();
1040
- const lastScrollOffsetRef = React3__namespace.useRef(0);
1041
- const callback = React3__namespace.useCallback(() => {
1042
- var _a3;
1043
- const scrollAdjust = peek$(ctx, "scrollAdjust");
1044
- const scrollAdjustUserOffset = peek$(ctx, "scrollAdjustUserOffset");
1045
- const scrollOffset = (scrollAdjust || 0) + (scrollAdjustUserOffset || 0);
1046
- const scrollView = (_a3 = ctx.internalState) == null ? void 0 : _a3.refScroller.current;
1047
- if (scrollView && scrollOffset !== lastScrollOffsetRef.current) {
1048
- const scrollDelta = scrollOffset - lastScrollOffsetRef.current;
1049
- if (scrollDelta !== 0) {
1050
- const el = scrollView.getScrollableNode();
1051
- const prevScroll = el.scrollTop;
1052
- const nextScroll = prevScroll + scrollDelta;
1053
- const totalSize = el.scrollHeight;
1054
- if (scrollDelta > 0 && !ctx.internalState.adjustingFromInitialMount && totalSize < nextScroll + el.clientHeight) {
1055
- const child = el.firstElementChild;
1056
- const prevPaddingBottom = child.style.paddingBottom;
1057
- const pad = (nextScroll + el.clientHeight - totalSize) * 2;
1058
- child.style.paddingBottom = `${pad}px`;
1059
- void el.offsetHeight;
1060
- scrollView.scrollBy(0, scrollDelta);
1061
- requestAnimationFrame(() => {
1062
- child.style.paddingBottom = prevPaddingBottom;
1063
- });
1064
- } else {
1065
- scrollView.scrollBy(0, scrollDelta);
1066
- }
1067
- if (IS_DEV) {
1068
- console.log("ScrollAdjust (web scrollBy)", scrollDelta, "total offset:", scrollOffset);
1069
- }
1070
- }
1071
- lastScrollOffsetRef.current = scrollOffset;
1072
- }
1073
- }, [ctx]);
1074
- useValueListener$("scrollAdjust", callback);
1075
- useValueListener$("scrollAdjustUserOffset", callback);
1076
- return null;
1077
- }
1078
- function SnapWrapper({ ScrollComponent, ...props }) {
1079
- const [snapToOffsets] = useArr$(["snapToOffsets"]);
1080
- return /* @__PURE__ */ React3__namespace.createElement(ScrollComponent, { ...props, snapToOffsets });
1081
- }
1082
- var LayoutView = ({ onLayoutChange, refView, children, ...rest }) => {
1083
- const ref = refView != null ? refView : React3.useRef();
1084
- useOnLayoutSync({ onLayoutChange, ref });
1085
- return /* @__PURE__ */ React3__namespace.createElement("div", { ...rest, ref }, children);
1086
- };
1087
-
1088
- // src/components/ListComponent.tsx
1089
- var getComponent = (Component) => {
1090
- if (React3__namespace.isValidElement(Component)) {
1091
- return Component;
1092
- }
1093
- if (Component) {
1094
- return /* @__PURE__ */ React3__namespace.createElement(Component, null);
1095
- }
1096
- return null;
1097
- };
1098
- var ListComponent = typedMemo(function ListComponent2({
1099
- canRender,
1100
- style,
1101
- contentContainerStyle,
1102
- horizontal,
1103
- initialContentOffset,
1104
- recycleItems,
1105
- ItemSeparatorComponent,
1106
- alignItemsAtEnd,
1107
- waitForInitialLayout,
1108
- onScroll: onScroll2,
1109
- onLayout,
1110
- ListHeaderComponent,
1111
- ListHeaderComponentStyle,
1112
- ListFooterComponent,
1113
- ListFooterComponentStyle,
1114
- ListEmptyComponent,
1115
- getRenderedItem: getRenderedItem2,
1116
- updateItemSize: updateItemSize2,
1117
- refScrollView,
1118
- maintainVisibleContentPosition,
1119
- renderScrollComponent,
1120
- scrollAdjustHandler,
1121
- onLayoutHeader,
1122
- snapToIndices,
1123
- stickyHeaderIndices,
1124
- ...rest
1125
- }) {
1126
- const ctx = useStateContext();
1127
- const ScrollComponent = renderScrollComponent ? React3.useMemo(
1128
- () => React3__namespace.forwardRef((props, ref) => renderScrollComponent({ ...props, ref })),
1129
- [renderScrollComponent]
1130
- ) : ListComponentScrollView;
1131
- const SnapOrScroll = snapToIndices ? SnapWrapper : ScrollComponent;
1132
- return /* @__PURE__ */ React3__namespace.createElement(
1133
- SnapOrScroll,
1134
- {
1135
- ...rest,
1136
- contentContainerStyle: [
1137
- contentContainerStyle,
1138
- horizontal ? {
1139
- height: "100%"
1140
- } : {}
1141
- ],
1142
- contentOffset: initialContentOffset ? horizontal ? { x: initialContentOffset, y: 0 } : { x: 0, y: initialContentOffset } : void 0,
1143
- horizontal,
1144
- maintainVisibleContentPosition: maintainVisibleContentPosition ? { minIndexForVisible: 0 } : void 0,
1145
- onLayout,
1146
- onScroll: onScroll2,
1147
- ref: refScrollView,
1148
- ScrollComponent: snapToIndices ? ScrollComponent : void 0,
1149
- style
1150
- },
1151
- /* @__PURE__ */ React3__namespace.createElement(ScrollAdjust, null),
1152
- ENABLE_DEVMODE ? /* @__PURE__ */ React3__namespace.createElement(PaddingDevMode, null) : /* @__PURE__ */ React3__namespace.createElement(Padding, null),
1153
- ListHeaderComponent && /* @__PURE__ */ React3__namespace.createElement(LayoutView, { onLayoutChange: onLayoutHeader, style: ListHeaderComponentStyle }, getComponent(ListHeaderComponent)),
1154
- ListEmptyComponent && getComponent(ListEmptyComponent),
1155
- canRender && !ListEmptyComponent && /* @__PURE__ */ React3__namespace.createElement(
1156
- Containers,
1157
- {
1158
- getRenderedItem: getRenderedItem2,
1159
- horizontal,
1160
- ItemSeparatorComponent,
1161
- recycleItems,
1162
- updateItemSize: updateItemSize2,
1163
- waitForInitialLayout
1164
- }
1165
- ),
1166
- ListFooterComponent && /* @__PURE__ */ React3__namespace.createElement(
1167
- LayoutView,
1168
- {
1169
- onLayoutChange: (layout) => {
1170
- const size = layout[horizontal ? "width" : "height"];
1171
- set$(ctx, "footerSize", size);
1172
- },
1173
- style: ListFooterComponentStyle
1174
- },
1175
- getComponent(ListFooterComponent)
1176
- ),
1177
- IS_DEV && ENABLE_DEVMODE && /* @__PURE__ */ React3__namespace.createElement(DevNumbers, null)
1178
- );
1179
- });
1180
-
1181
- // src/utils/getId.ts
1182
- function getId(state, index) {
1183
- const { data, keyExtractor } = state.props;
1184
- if (!data) {
1185
- return "";
1186
- }
1187
- const ret = index < data.length ? keyExtractor ? keyExtractor(data[index], index) : index : null;
1188
- const id = ret;
1189
- state.idCache[index] = id;
1190
- return id;
1191
- }
1192
-
1193
- // src/core/calculateOffsetForIndex.ts
1194
- function calculateOffsetForIndex(ctx, state, index) {
1195
- let position = 0;
1196
- if (index !== void 0) {
1197
- position = (state == null ? void 0 : state.positions.get(getId(state, index))) || 0;
1198
- const paddingTop = peek$(ctx, "stylePaddingTop");
1199
- if (paddingTop) {
1200
- position += paddingTop;
1201
- }
1202
- const headerSize = peek$(ctx, "headerSize");
1203
- if (headerSize) {
1204
- position += headerSize;
1205
- }
1206
- }
1207
- return position;
1208
- }
1209
-
1210
- // src/utils/setPaddingTop.ts
1211
- function setPaddingTop(ctx, state, { stylePaddingTop, alignItemsPaddingTop }) {
1212
- if (stylePaddingTop !== void 0) {
1213
- const prevStylePaddingTop = peek$(ctx, "stylePaddingTop") || 0;
1214
- if (stylePaddingTop < prevStylePaddingTop) {
1215
- let prevTotalSize = peek$(ctx, "totalSize") || 0;
1216
- set$(ctx, "totalSize", prevTotalSize + prevStylePaddingTop);
1217
- state.timeoutSetPaddingTop = setTimeout(() => {
1218
- prevTotalSize = peek$(ctx, "totalSize") || 0;
1219
- set$(ctx, "totalSize", prevTotalSize - prevStylePaddingTop);
1220
- }, 16);
1221
- }
1222
- set$(ctx, "stylePaddingTop", stylePaddingTop);
1223
- }
1224
- if (alignItemsPaddingTop !== void 0) {
1225
- set$(ctx, "alignItemsPaddingTop", alignItemsPaddingTop);
1226
- }
1227
- }
1228
-
1229
- // src/utils/updateAlignItemsPaddingTop.ts
1230
- function updateAlignItemsPaddingTop(ctx, state) {
1231
- const {
1232
- scrollLength,
1233
- props: { alignItemsAtEnd, data }
1234
- } = state;
1235
- if (alignItemsAtEnd) {
1236
- let alignItemsPaddingTop = 0;
1237
- if ((data == null ? void 0 : data.length) > 0) {
1238
- const contentSize = getContentSize(ctx);
1239
- alignItemsPaddingTop = Math.max(0, Math.floor(scrollLength - contentSize));
1240
- }
1241
- setPaddingTop(ctx, state, { alignItemsPaddingTop });
1242
- }
1243
- }
1244
-
1245
- // src/core/addTotalSize.ts
1246
- function addTotalSize(ctx, state, key, add) {
1247
- const { alignItemsAtEnd } = state.props;
1248
- const prevTotalSize = state.totalSize;
1249
- let totalSize = state.totalSize;
1250
- if (key === null) {
1251
- totalSize = add;
1252
- if (state.timeoutSetPaddingTop) {
1253
- clearTimeout(state.timeoutSetPaddingTop);
1254
- state.timeoutSetPaddingTop = void 0;
1255
- }
1256
- } else {
1257
- totalSize += add;
1258
- }
1259
- if (prevTotalSize !== totalSize) {
1260
- {
1261
- state.pendingTotalSize = void 0;
1262
- state.totalSize = totalSize;
1263
- set$(ctx, "totalSize", totalSize);
1264
- if (alignItemsAtEnd) {
1265
- updateAlignItemsPaddingTop(ctx, state);
1266
- }
1267
- }
1268
- }
1269
- }
1270
-
1271
- // src/core/setSize.ts
1272
- function setSize(ctx, state, itemKey, size) {
1273
- const { sizes } = state;
1274
- const previousSize = sizes.get(itemKey);
1275
- const diff = previousSize !== void 0 ? size - previousSize : size;
1276
- if (diff !== 0) {
1277
- addTotalSize(ctx, state, itemKey, diff);
1278
- }
1279
- sizes.set(itemKey, size);
1280
- }
1281
-
1282
- // src/utils/getItemSize.ts
1283
- function getItemSize(ctx, state, key, index, data, useAverageSize, preferCachedSize) {
1284
- var _a3, _b;
1285
- const {
1286
- sizesKnown,
1287
- sizes,
1288
- averageSizes,
1289
- props: { estimatedItemSize, getEstimatedItemSize, getFixedItemSize, getItemType }
1290
- } = state;
1291
- const sizeKnown = sizesKnown.get(key);
1292
- if (sizeKnown !== void 0) {
1293
- return sizeKnown;
1294
- }
1295
- let size;
1296
- const itemType = getItemType ? (_a3 = getItemType(data, index)) != null ? _a3 : "" : "";
1297
- const scrollingTo = peek$(ctx, "scrollingTo");
1298
- if (preferCachedSize) {
1299
- const cachedSize = sizes.get(key);
1300
- if (cachedSize !== void 0) {
1301
- return cachedSize;
1302
- }
1303
- }
1304
- if (getFixedItemSize) {
1305
- size = getFixedItemSize(index, data, itemType);
1306
- if (size !== void 0) {
1307
- sizesKnown.set(key, size);
1308
- }
1309
- }
1310
- if (size === void 0 && useAverageSize && sizeKnown === void 0 && !scrollingTo) {
1311
- const averageSizeForType = (_b = averageSizes[itemType]) == null ? void 0 : _b.avg;
1312
- if (averageSizeForType !== void 0) {
1313
- size = roundSize(averageSizeForType);
1314
- }
1315
- }
1316
- if (size === void 0) {
1317
- size = sizes.get(key);
1318
- if (size !== void 0) {
1319
- return size;
1320
- }
1321
- }
1322
- if (size === void 0) {
1323
- size = getEstimatedItemSize ? getEstimatedItemSize(index, data, itemType) : estimatedItemSize;
1324
- }
1325
- setSize(ctx, state, key, size);
1326
- return size;
1327
- }
1328
-
1329
- // src/core/calculateOffsetWithOffsetPosition.ts
1330
- function calculateOffsetWithOffsetPosition(ctx, state, offsetParam, params) {
1331
- const { index, viewOffset, viewPosition } = params;
1332
- let offset = offsetParam;
1333
- if (viewOffset) {
1334
- offset -= viewOffset;
1335
- }
1336
- if (viewPosition !== void 0 && index !== void 0) {
1337
- offset -= viewPosition * (state.scrollLength - getItemSize(ctx, state, getId(state, index), index, state.props.data[index]));
1338
- }
1339
- return offset;
1340
- }
1341
-
1342
- // src/core/finishScrollTo.ts
1343
- function finishScrollTo(ctx, state) {
1344
- var _a3, _b;
1345
- if (state) {
1346
- state.scrollHistory.length = 0;
1347
- state.initialScroll = void 0;
1348
- state.initialAnchor = void 0;
1349
- set$(ctx, "scrollingTo", void 0);
1350
- if (state.pendingTotalSize !== void 0) {
1351
- addTotalSize(ctx, state, null, state.pendingTotalSize);
1352
- }
1353
- if ((_a3 = state.props) == null ? void 0 : _a3.data) {
1354
- (_b = state.triggerCalculateItemsInView) == null ? void 0 : _b.call(state, { forceFullItemPositions: true });
1355
- }
1356
- }
1357
- }
1358
-
1359
- // src/core/doScrollTo.ts
1360
- var SCROLL_END_IDLE_MS = 80;
1361
- var SCROLL_END_MAX_MS = 1500;
1362
- var SMOOTH_SCROLL_DURATION_MS = 320;
1363
- function doScrollTo(ctx, state, params) {
1364
- const { animated, horizontal, offset } = params;
1365
- const scroller = state.refScroller.current;
1366
- const node = typeof (scroller == null ? void 0 : scroller.getScrollableNode) === "function" ? scroller.getScrollableNode() : scroller;
1367
- if (node) {
1368
- const left = horizontal ? offset : 0;
1369
- const top = horizontal ? 0 : offset;
1370
- node.scrollTo({ behavior: animated ? "smooth" : "auto", left, top });
1371
- if (animated) {
1372
- listenForScrollEnd(ctx, state, node);
1373
- } else {
1374
- state.scroll = offset;
1375
- setTimeout(() => {
1376
- finishScrollTo(ctx, state);
1377
- }, 100);
1378
- }
1379
- }
1380
- }
1381
- function listenForScrollEnd(ctx, state, node) {
1382
- const supportsScrollEnd = "onscrollend" in node;
1383
- let idleTimeout;
1384
- let maxTimeout;
1385
- let settled = false;
1386
- const targetToken = peek$(ctx, "scrollingTo");
1387
- const finish = () => {
1388
- if (settled) return;
1389
- settled = true;
1390
- cleanup();
1391
- if (targetToken === peek$(ctx, "scrollingTo")) {
1392
- finishScrollTo(ctx, state);
1393
- }
1394
- };
1395
- const onScroll2 = () => {
1396
- if (idleTimeout) {
1397
- clearTimeout(idleTimeout);
1398
- }
1399
- idleTimeout = setTimeout(finish, SCROLL_END_IDLE_MS);
1400
- };
1401
- const cleanup = () => {
1402
- if (supportsScrollEnd) {
1403
- node.removeEventListener("scrollend", finish);
1404
- } else {
1405
- node.removeEventListener("scroll", onScroll2);
1406
- }
1407
- if (idleTimeout) {
1408
- clearTimeout(idleTimeout);
1409
- }
1410
- if (maxTimeout) {
1411
- clearTimeout(maxTimeout);
1412
- }
1413
- };
1414
- if (supportsScrollEnd) {
1415
- node.addEventListener("scrollend", finish, { once: true });
1416
- } else {
1417
- node.addEventListener("scroll", onScroll2);
1418
- idleTimeout = setTimeout(finish, SMOOTH_SCROLL_DURATION_MS);
1419
- maxTimeout = setTimeout(finish, SCROLL_END_MAX_MS);
1420
- }
1421
- return cleanup;
1422
- }
1423
-
1424
- // src/core/scrollTo.ts
1425
- function scrollTo(ctx, state, params) {
1426
- const { noScrollingTo, ...scrollTarget } = params;
1427
- const { animated, isInitialScroll, offset: scrollTargetOffset, precomputedWithViewOffset } = scrollTarget;
1428
- const {
1429
- props: { horizontal }
1430
- } = state;
1431
- let offset = precomputedWithViewOffset ? scrollTargetOffset : calculateOffsetWithOffsetPosition(ctx, state, scrollTargetOffset, scrollTarget);
1432
- if (Number.isFinite(state.scrollLength) && Number.isFinite(state.totalSize)) {
1433
- const maxOffset = Math.max(0, getContentSize(ctx) - state.scrollLength);
1434
- offset = Math.min(offset, maxOffset);
1435
- }
1436
- state.scrollHistory.length = 0;
1437
- if (!noScrollingTo) {
1438
- set$(ctx, "scrollingTo", scrollTarget);
1439
- }
1440
- state.scrollPending = offset;
1441
- if (!isInitialScroll || Platform.OS === "android") {
1442
- doScrollTo(ctx, state, { animated, horizontal, isInitialScroll, offset });
1443
- } else {
1444
- state.scroll = offset;
1445
- }
1446
- }
1447
-
1448
- // src/utils/checkThreshold.ts
1449
- var HYSTERESIS_MULTIPLIER = 1.3;
1450
- var checkThreshold = (distance, atThreshold, threshold, wasReached, snapshot, context, onReached, setSnapshot) => {
1451
- const absDistance = Math.abs(distance);
1452
- const within = atThreshold || threshold > 0 && absDistance <= threshold;
1453
- if (wasReached === null) {
1454
- if (!within && distance >= 0) {
1455
- console.log("checkThreshold A: false", distance);
1456
- return false;
1457
- }
1458
- return null;
1459
- }
1460
- const updateSnapshot = () => {
1461
- setSnapshot == null ? void 0 : setSnapshot({
1462
- atThreshold,
1463
- contentSize: context.contentSize,
1464
- dataLength: context.dataLength,
1465
- scrollPosition: context.scrollPosition
1466
- });
1467
- };
1468
- if (!wasReached) {
1469
- if (!within) {
1470
- return false;
1471
- }
1472
- onReached == null ? void 0 : onReached(distance);
1473
- updateSnapshot();
1474
- return true;
1475
- }
1476
- const reset = !atThreshold && threshold > 0 && absDistance >= threshold * HYSTERESIS_MULTIPLIER || !atThreshold && threshold <= 0 && absDistance > 0;
1477
- if (reset) {
1478
- setSnapshot == null ? void 0 : setSnapshot(void 0);
1479
- return false;
1480
- }
1481
- if (within) {
1482
- const changed = !snapshot || snapshot.atThreshold !== atThreshold || snapshot.contentSize !== context.contentSize || snapshot.dataLength !== context.dataLength;
1483
- if (changed) {
1484
- onReached == null ? void 0 : onReached(distance);
1485
- updateSnapshot();
1486
- }
1487
- }
1488
- return true;
1489
- };
1490
-
1491
- // src/utils/checkAtBottom.ts
1492
- function checkAtBottom(ctx, state) {
1493
- var _a3;
1494
- if (!state) {
1495
- return;
1496
- }
1497
- const {
1498
- queuedInitialLayout,
1499
- scrollLength,
1500
- scroll,
1501
- maintainingScrollAtEnd,
1502
- props: { maintainScrollAtEndThreshold, onEndReachedThreshold }
1503
- } = state;
1504
- const contentSize = getContentSize(ctx);
1505
- if (contentSize > 0 && queuedInitialLayout && !maintainingScrollAtEnd) {
1506
- const distanceFromEnd = contentSize - scroll - scrollLength;
1507
- const isContentLess = contentSize < scrollLength;
1508
- state.isAtEnd = isContentLess || distanceFromEnd < scrollLength * maintainScrollAtEndThreshold;
1509
- state.isEndReached = checkThreshold(
1510
- distanceFromEnd,
1511
- isContentLess,
1512
- onEndReachedThreshold * scrollLength,
1513
- state.isEndReached,
1514
- state.endReachedSnapshot,
1515
- {
1516
- contentSize,
1517
- dataLength: (_a3 = state.props.data) == null ? void 0 : _a3.length,
1518
- scrollPosition: scroll
1519
- },
1520
- (distance) => {
1521
- var _a4, _b;
1522
- return (_b = (_a4 = state.props).onEndReached) == null ? void 0 : _b.call(_a4, { distanceFromEnd: distance });
1523
- },
1524
- (snapshot) => {
1525
- state.endReachedSnapshot = snapshot;
1526
- }
1527
- );
1528
- }
1529
- }
1530
-
1531
- // src/utils/checkAtTop.ts
1532
- function checkAtTop(state) {
1533
- var _a3;
1534
- if (!state) {
1535
- return;
1536
- }
1537
- const {
1538
- scrollLength,
1539
- scroll,
1540
- props: { onStartReachedThreshold }
1541
- } = state;
1542
- const distanceFromTop = scroll;
1543
- state.isAtStart = distanceFromTop <= 0;
1544
- state.isStartReached = checkThreshold(
1545
- distanceFromTop,
1546
- false,
1547
- onStartReachedThreshold * scrollLength,
1548
- state.isStartReached,
1549
- state.startReachedSnapshot,
1550
- {
1551
- contentSize: state.totalSize,
1552
- dataLength: (_a3 = state.props.data) == null ? void 0 : _a3.length,
1553
- scrollPosition: scroll
1554
- },
1555
- (distance) => {
1556
- var _a4, _b;
1557
- return (_b = (_a4 = state.props).onStartReached) == null ? void 0 : _b.call(_a4, { distanceFromStart: distance });
1558
- },
1559
- (snapshot) => {
1560
- state.startReachedSnapshot = snapshot;
1561
- }
1562
- );
1563
- }
1564
-
1565
- // src/core/updateScroll.ts
1566
- function updateScroll(ctx, state, newScroll, forceUpdate) {
1567
- var _a3;
1568
- const scrollingTo = peek$(ctx, "scrollingTo");
1569
- state.hasScrolled = true;
1570
- state.lastBatchingAction = Date.now();
1571
- const currentTime = Date.now();
1572
- const adjust = state.scrollAdjustHandler.getAdjust();
1573
- const lastHistoryAdjust = state.lastScrollAdjustForHistory;
1574
- const adjustChanged = lastHistoryAdjust !== void 0 && Math.abs(adjust - lastHistoryAdjust) > 0.1;
1575
- if (adjustChanged) {
1576
- state.scrollHistory.length = 0;
1577
- }
1578
- state.lastScrollAdjustForHistory = adjust;
1579
- if (scrollingTo === void 0 && !(state.scrollHistory.length === 0 && newScroll === state.scroll)) {
1580
- if (!adjustChanged) {
1581
- state.scrollHistory.push({ scroll: newScroll, time: currentTime });
1582
- }
1583
- }
1584
- if (state.scrollHistory.length > 5) {
1585
- state.scrollHistory.shift();
1586
- }
1587
- state.scrollPrev = state.scroll;
1588
- state.scrollPrevTime = state.scrollTime;
1589
- state.scroll = newScroll;
1590
- state.scrollTime = currentTime;
1591
- const ignoreScrollFromMVCP = state.ignoreScrollFromMVCP;
1592
- if (ignoreScrollFromMVCP && !scrollingTo) {
1593
- const { lt, gt } = ignoreScrollFromMVCP;
1594
- if (lt && newScroll < lt || gt && newScroll > gt) {
1595
- state.ignoreScrollFromMVCPIgnored = true;
1596
- return;
1597
- }
1598
- }
1599
- const lastCalculated = state.scrollLastCalculate;
1600
- const shouldUpdate = state.dataChangeNeedsScrollUpdate || state.scrollLastCalculate === void 0 || lastCalculated === void 0 || Math.abs(state.scroll - lastCalculated) > 2;
1601
- if (shouldUpdate) {
1602
- state.scrollLastCalculate = state.scroll;
1603
- state.ignoreScrollFromMVCPIgnored = false;
1604
- (_a3 = state.triggerCalculateItemsInView) == null ? void 0 : _a3.call(state, { doMVCP: scrollingTo !== void 0 });
1605
- checkAtBottom(ctx, state);
1606
- checkAtTop(state);
1607
- state.dataChangeNeedsScrollUpdate = false;
1608
- }
1609
- }
1610
-
1611
- // src/utils/requestAdjust.ts
1612
- function requestAdjust(ctx, state, positionDiff, dataChanged) {
1613
- if (Math.abs(positionDiff) > 0.1) {
1614
- const doit = () => {
1615
- {
1616
- state.scrollAdjustHandler.requestAdjust(positionDiff);
1617
- if (state.adjustingFromInitialMount) {
1618
- state.adjustingFromInitialMount--;
1619
- }
1620
- }
1621
- };
1622
- state.scroll += positionDiff;
1623
- state.scrollForNextCalculateItemsInView = void 0;
1624
- const didLayout = peek$(ctx, "containersDidLayout");
1625
- if (didLayout) {
1626
- doit();
1627
- } else {
1628
- state.adjustingFromInitialMount = (state.adjustingFromInitialMount || 0) + 1;
1629
- requestAnimationFrame(doit);
1630
- }
1631
- }
1632
- }
1633
-
1634
- // src/core/ensureInitialAnchor.ts
1635
- var INITIAL_ANCHOR_TOLERANCE = 0.5;
1636
- var INITIAL_ANCHOR_MAX_ATTEMPTS = 4;
1637
- var INITIAL_ANCHOR_SETTLED_TICKS = 2;
1638
- function ensureInitialAnchor(ctx, state) {
1639
- var _a3, _b, _c, _d, _e;
1640
- const anchor = state.initialAnchor;
1641
- const item = state.props.data[anchor.index];
1642
- const containersDidLayout = peek$(ctx, "containersDidLayout");
1643
- if (!containersDidLayout) {
1644
- return;
1645
- }
1646
- const id = getId(state, anchor.index);
1647
- if (state.positions.get(id) === void 0) {
1648
- return;
1649
- }
1650
- const size = getItemSize(ctx, state, id, anchor.index, item, true, true);
1651
- if (size === void 0) {
1652
- return;
1653
- }
1654
- const availableSpace = Math.max(0, state.scrollLength - size);
1655
- const desiredOffset = calculateOffsetForIndex(ctx, state, anchor.index) - ((_a3 = anchor.viewOffset) != null ? _a3 : 0) - ((_b = anchor.viewPosition) != null ? _b : 0) * availableSpace;
1656
- const contentSize = getContentSize(ctx);
1657
- const maxOffset = Math.max(0, contentSize - state.scrollLength);
1658
- const clampedDesiredOffset = Math.max(0, Math.min(desiredOffset, maxOffset));
1659
- const delta = clampedDesiredOffset - state.scroll;
1660
- if (Math.abs(delta) <= INITIAL_ANCHOR_TOLERANCE) {
1661
- const settledTicks = ((_c = anchor.settledTicks) != null ? _c : 0) + 1;
1662
- if (settledTicks >= INITIAL_ANCHOR_SETTLED_TICKS) {
1663
- state.initialAnchor = void 0;
1664
- } else {
1665
- anchor.settledTicks = settledTicks;
1666
- }
1667
- return;
1668
- }
1669
- if (((_d = anchor.attempts) != null ? _d : 0) >= INITIAL_ANCHOR_MAX_ATTEMPTS) {
1670
- state.initialAnchor = void 0;
1671
- return;
1672
- }
1673
- const lastDelta = anchor.lastDelta;
1674
- if (lastDelta !== void 0 && Math.abs(delta) >= Math.abs(lastDelta)) {
1675
- state.initialAnchor = void 0;
1676
- return;
1677
- }
1678
- Object.assign(anchor, {
1679
- attempts: ((_e = anchor.attempts) != null ? _e : 0) + 1,
1680
- lastDelta: delta,
1681
- settledTicks: 0
1682
- });
1683
- requestAdjust(ctx, state, delta);
1684
- }
1685
-
1686
- // src/core/mvcp.ts
1687
- function prepareMVCP(ctx, state, dataChanged) {
1688
- const { idsInView, positions, props } = state;
1689
- const { maintainVisibleContentPosition } = props;
1690
- const scrollingTo = peek$(ctx, "scrollingTo");
1691
- let prevPosition;
1692
- let targetId;
1693
- const idsInViewWithPositions = [];
1694
- const scrollTarget = scrollingTo == null ? void 0 : scrollingTo.index;
1695
- const shouldMVCP = !dataChanged || maintainVisibleContentPosition;
1696
- const indexByKey = state.indexByKey;
1697
- if (shouldMVCP) {
1698
- if (scrollTarget !== void 0) {
1699
- targetId = getId(state, scrollTarget);
1700
- } else if (idsInView.length > 0 && peek$(ctx, "containersDidLayout")) {
1701
- if (dataChanged) {
1702
- for (let i = 0; i < idsInView.length; i++) {
1703
- const id = idsInView[i];
1704
- const index = indexByKey.get(id);
1705
- if (index !== void 0) {
1706
- idsInViewWithPositions.push({ id, position: positions.get(id) });
1707
- }
1708
- }
1709
- } else {
1710
- targetId = idsInView.find((id) => indexByKey.get(id) !== void 0);
1711
- }
1712
- }
1713
- if (targetId !== void 0) {
1714
- prevPosition = positions.get(targetId);
1715
- }
1716
- return () => {
1717
- let positionDiff;
1718
- if (dataChanged && targetId === void 0 && maintainVisibleContentPosition) {
1719
- for (let i = 0; i < idsInViewWithPositions.length; i++) {
1720
- const { id, position } = idsInViewWithPositions[i];
1721
- const newPosition = positions.get(id);
1722
- if (newPosition !== void 0) {
1723
- positionDiff = newPosition - position;
1724
- break;
1725
- }
1726
- }
1727
- }
1728
- if (targetId !== void 0 && prevPosition !== void 0) {
1729
- const newPosition = positions.get(targetId);
1730
- if (newPosition !== void 0) {
1731
- const totalSize = getContentSize(ctx);
1732
- let diff = newPosition - prevPosition;
1733
- if (diff !== 0 && state.scroll + state.scrollLength > totalSize) {
1734
- if (diff > 0) {
1735
- diff = Math.max(0, totalSize - state.scroll - state.scrollLength);
1736
- } else {
1737
- diff = 0;
1738
- }
1739
- }
1740
- positionDiff = diff;
1741
- }
1742
- }
1743
- if (positionDiff !== void 0 && Math.abs(positionDiff) > 0.1) {
1744
- requestAdjust(ctx, state, positionDiff);
1745
- }
1746
- };
1747
- }
1748
- }
1749
-
1750
- // src/core/prepareColumnStartState.ts
1751
- function prepareColumnStartState(ctx, state, startIndex, useAverageSize) {
1752
- var _a3;
1753
- const numColumns = peek$(ctx, "numColumns");
1754
- let rowStartIndex = startIndex;
1755
- const columnAtStart = state.columns.get(state.idCache[startIndex]);
1756
- if (columnAtStart !== 1) {
1757
- rowStartIndex = findRowStartIndex(state, numColumns, startIndex);
1758
- }
1759
- let currentRowTop = 0;
1760
- const curId = state.idCache[rowStartIndex];
1761
- const column = state.columns.get(curId);
1762
- if (rowStartIndex > 0) {
1763
- const prevIndex = rowStartIndex - 1;
1764
- const prevId = state.idCache[prevIndex];
1765
- const prevPosition = (_a3 = state.positions.get(prevId)) != null ? _a3 : 0;
1766
- const prevRowStart = findRowStartIndex(state, numColumns, prevIndex);
1767
- const prevRowHeight = calculateRowMaxSize(ctx, state, prevRowStart, prevIndex, useAverageSize);
1768
- currentRowTop = prevPosition + prevRowHeight;
1769
- }
1770
- return {
1771
- column,
1772
- currentRowTop,
1773
- startIndex: rowStartIndex
1774
- };
1775
- }
1776
- function findRowStartIndex(state, numColumns, index) {
1777
- if (numColumns <= 1) {
1778
- return Math.max(0, index);
1779
- }
1780
- let rowStart = Math.max(0, index);
1781
- while (rowStart > 0) {
1782
- const columnForIndex = state.columns.get(state.idCache[rowStart]);
1783
- if (columnForIndex === 1) {
1784
- break;
1785
- }
1786
- rowStart--;
1787
- }
1788
- return rowStart;
1789
- }
1790
- function calculateRowMaxSize(ctx, state, startIndex, endIndex, useAverageSize) {
1791
- if (endIndex < startIndex) {
1792
- return 0;
1793
- }
1794
- const { data } = state.props;
1795
- if (!data) {
1796
- return 0;
1797
- }
1798
- let maxSize = 0;
1799
- for (let i = startIndex; i <= endIndex; i++) {
1800
- if (i < 0 || i >= data.length) {
1801
- continue;
1802
- }
1803
- const id = state.idCache[i];
1804
- const size = getItemSize(ctx, state, id, i, data[i], useAverageSize);
1805
- if (size > maxSize) {
1806
- maxSize = size;
1807
- }
1808
- }
1809
- return maxSize;
1810
- }
1811
-
1812
- // src/core/updateTotalSize.ts
1813
- function updateTotalSize(ctx, state) {
1814
- const {
1815
- positions,
1816
- props: { data }
1817
- } = state;
1818
- if (data.length === 0) {
1819
- addTotalSize(ctx, state, null, 0);
1820
- } else {
1821
- const lastId = getId(state, data.length - 1);
1822
- if (lastId !== void 0) {
1823
- const lastPosition = positions.get(lastId);
1824
- if (lastPosition !== void 0) {
1825
- const lastSize = getItemSize(ctx, state, lastId, data.length - 1, data[data.length - 1]);
1826
- if (lastSize !== void 0) {
1827
- const totalSize = lastPosition + lastSize;
1828
- addTotalSize(ctx, state, null, totalSize);
1829
- }
1830
- }
1831
- }
1832
- }
1833
- }
1834
-
1835
- // src/utils/getScrollVelocity.ts
1836
- var getScrollVelocity = (state) => {
1837
- const { scrollHistory } = state;
1838
- let velocity = 0;
1839
- if (scrollHistory.length >= 1) {
1840
- const newest = scrollHistory[scrollHistory.length - 1];
1841
- let oldest;
1842
- let start = 0;
1843
- const now = Date.now();
1844
- for (let i = 0; i < scrollHistory.length - 1; i++) {
1845
- const entry = scrollHistory[i];
1846
- const nextEntry = scrollHistory[i + 1];
1847
- if (i > 0) {
1848
- const prevEntry = scrollHistory[i - 1];
1849
- const prevDirection = entry.scroll - prevEntry.scroll;
1850
- const currentDirection = nextEntry.scroll - entry.scroll;
1851
- if (prevDirection > 0 && currentDirection < 0 || prevDirection < 0 && currentDirection > 0) {
1852
- start = i;
1853
- break;
1854
- }
1855
- }
1856
- }
1857
- for (let i = start; i < scrollHistory.length - 1; i++) {
1858
- const entry = scrollHistory[i];
1859
- if (now - entry.time <= 1e3) {
1860
- oldest = entry;
1861
- break;
1862
- }
1863
- }
1864
- if (oldest && oldest !== newest) {
1865
- const scrollDiff = newest.scroll - oldest.scroll;
1866
- const timeDiff = newest.time - oldest.time;
1867
- velocity = timeDiff > 0 ? scrollDiff / timeDiff : 0;
1868
- }
1869
- }
1870
- return velocity;
1871
- };
1872
-
1873
- // src/utils/updateSnapToOffsets.ts
1874
- function updateSnapToOffsets(ctx, state) {
1875
- const {
1876
- positions,
1877
- props: { snapToIndices }
1878
- } = state;
1879
- const snapToOffsets = Array(snapToIndices.length);
1880
- for (let i = 0; i < snapToIndices.length; i++) {
1881
- const idx = snapToIndices[i];
1882
- const key = getId(state, idx);
1883
- snapToOffsets[i] = positions.get(key);
1884
- }
1885
- set$(ctx, "snapToOffsets", snapToOffsets);
1886
- }
1887
-
1888
- // src/core/updateItemPositions.ts
1889
- function updateItemPositions(ctx, state, dataChanged, { startIndex, scrollBottomBuffered, forceFullUpdate = false, doMVCP } = {
1890
- doMVCP: false,
1891
- forceFullUpdate: false,
1892
- scrollBottomBuffered: -1,
1893
- startIndex: 0
1894
- }) {
1895
- var _a3, _b, _c, _d, _e;
1896
- const {
1897
- columns,
1898
- indexByKey,
1899
- positions,
1900
- idCache,
1901
- sizesKnown,
1902
- props: { getEstimatedItemSize, snapToIndices, enableAverages }
1903
- } = state;
1904
- const data = state.props.data;
1905
- const dataLength = data.length;
1906
- const numColumns = peek$(ctx, "numColumns");
1907
- const scrollingTo = peek$(ctx, "scrollingTo");
1908
- const hasColumns = numColumns > 1;
1909
- const indexByKeyForChecking = IS_DEV ? /* @__PURE__ */ new Map() : void 0;
1910
- const shouldOptimize = !forceFullUpdate && !dataChanged && Math.abs(getScrollVelocity(state)) > 0;
1911
- const maxVisibleArea = scrollBottomBuffered + 1e3;
1912
- const useAverageSize = enableAverages && !getEstimatedItemSize;
1913
- const preferCachedSize = !doMVCP || dataChanged || state.scrollAdjustHandler.getAdjust() !== 0 || ((_a3 = peek$(ctx, "scrollAdjustPending")) != null ? _a3 : 0) !== 0;
1914
- let currentRowTop = 0;
1915
- let column = 1;
1916
- let maxSizeInRow = 0;
1917
- if (startIndex > 0) {
1918
- if (hasColumns) {
1919
- const { startIndex: processedStartIndex, currentRowTop: initialRowTop } = prepareColumnStartState(
1920
- ctx,
1921
- state,
1922
- startIndex,
1923
- useAverageSize
1924
- );
1925
- startIndex = processedStartIndex;
1926
- currentRowTop = initialRowTop;
1927
- } else if (startIndex < dataLength) {
1928
- const prevIndex = startIndex - 1;
1929
- const prevId = getId(state, prevIndex);
1930
- const prevPosition = (_b = positions.get(prevId)) != null ? _b : 0;
1931
- const prevSize = (_c = sizesKnown.get(prevId)) != null ? _c : getItemSize(ctx, state, prevId, prevIndex, data[prevIndex], useAverageSize, preferCachedSize);
1932
- currentRowTop = prevPosition + prevSize;
1933
- }
1934
- }
1935
- const needsIndexByKey = dataChanged || indexByKey.size === 0;
1936
- let didBreakEarly = false;
1937
- let breakAt;
1938
- for (let i = startIndex; i < dataLength; i++) {
1939
- if (shouldOptimize && breakAt !== void 0 && i > breakAt) {
1940
- didBreakEarly = true;
1941
- break;
1942
- }
1943
- if (shouldOptimize && breakAt === void 0 && !scrollingTo && !dataChanged && currentRowTop > maxVisibleArea) {
1944
- const itemsPerRow = hasColumns ? numColumns : 1;
1945
- breakAt = i + itemsPerRow + 10;
1946
- }
1947
- const id = (_d = idCache[i]) != null ? _d : getId(state, i);
1948
- const size = (_e = sizesKnown.get(id)) != null ? _e : getItemSize(ctx, state, id, i, data[i], useAverageSize, preferCachedSize);
1949
- if (IS_DEV && needsIndexByKey) {
1950
- if (indexByKeyForChecking.has(id)) {
1951
- console.error(
1952
- `[legend-list] Error: Detected overlapping key (${id}) which causes missing items and gaps and other terrrible things. Check that keyExtractor returns unique values.`
1953
- );
1954
- }
1955
- indexByKeyForChecking.set(id, i);
1956
- }
1957
- positions.set(id, currentRowTop);
1958
- if (needsIndexByKey) {
1959
- indexByKey.set(id, i);
1960
- }
1961
- columns.set(id, column);
1962
- if (hasColumns) {
1963
- if (size > maxSizeInRow) {
1964
- maxSizeInRow = size;
1965
- }
1966
- column++;
1967
- if (column > numColumns) {
1968
- currentRowTop += maxSizeInRow;
1969
- column = 1;
1970
- maxSizeInRow = 0;
1971
- }
1972
- } else {
1973
- currentRowTop += size;
1974
- }
1975
- }
1976
- if (!didBreakEarly) {
1977
- updateTotalSize(ctx, state);
1978
- }
1979
- if (snapToIndices) {
1980
- updateSnapToOffsets(ctx, state);
1981
- }
1982
- }
1983
-
1984
- // src/core/viewability.ts
1985
- function ensureViewabilityState(ctx, configId) {
1986
- let map = ctx.mapViewabilityConfigStates;
1987
- if (!map) {
1988
- map = /* @__PURE__ */ new Map();
1989
- ctx.mapViewabilityConfigStates = map;
1990
- }
1991
- let state = map.get(configId);
1992
- if (!state) {
1993
- state = { end: -1, previousEnd: -1, previousStart: -1, start: -1, viewableItems: [] };
1994
- map.set(configId, state);
1995
- }
1996
- return state;
1997
- }
1998
- function setupViewability(props) {
1999
- let { viewabilityConfig, viewabilityConfigCallbackPairs, onViewableItemsChanged } = props;
2000
- if (viewabilityConfig || onViewableItemsChanged) {
2001
- viewabilityConfigCallbackPairs = [
2002
- ...viewabilityConfigCallbackPairs || [],
2003
- {
2004
- onViewableItemsChanged,
2005
- viewabilityConfig: viewabilityConfig || {
2006
- viewAreaCoveragePercentThreshold: 0
2007
- }
2008
- }
2009
- ];
2010
- }
2011
- return viewabilityConfigCallbackPairs;
2012
- }
2013
- function updateViewableItems(state, ctx, viewabilityConfigCallbackPairs, scrollSize, start, end) {
2014
- const {
2015
- timeouts,
2016
- props: { data }
2017
- } = state;
2018
- for (const viewabilityConfigCallbackPair of viewabilityConfigCallbackPairs) {
2019
- const viewabilityState = ensureViewabilityState(ctx, viewabilityConfigCallbackPair.viewabilityConfig.id);
2020
- viewabilityState.start = start;
2021
- viewabilityState.end = end;
2022
- if (viewabilityConfigCallbackPair.viewabilityConfig.minimumViewTime) {
2023
- const timer = setTimeout(() => {
2024
- timeouts.delete(timer);
2025
- updateViewableItemsWithConfig(data, viewabilityConfigCallbackPair, state, ctx, scrollSize);
2026
- }, viewabilityConfigCallbackPair.viewabilityConfig.minimumViewTime);
2027
- timeouts.add(timer);
2028
- } else {
2029
- updateViewableItemsWithConfig(data, viewabilityConfigCallbackPair, state, ctx, scrollSize);
2030
- }
2031
- }
2032
- }
2033
- function updateViewableItemsWithConfig(data, viewabilityConfigCallbackPair, state, ctx, scrollSize) {
2034
- const { viewabilityConfig, onViewableItemsChanged } = viewabilityConfigCallbackPair;
2035
- const configId = viewabilityConfig.id;
2036
- const viewabilityState = ensureViewabilityState(ctx, configId);
2037
- const { viewableItems: previousViewableItems, start, end } = viewabilityState;
2038
- const viewabilityTokens = /* @__PURE__ */ new Map();
2039
- for (const [containerId, value] of ctx.mapViewabilityAmountValues) {
2040
- viewabilityTokens.set(
2041
- containerId,
2042
- computeViewability(
2043
- state,
2044
- ctx,
2045
- viewabilityConfig,
2046
- containerId,
2047
- value.key,
2048
- scrollSize,
2049
- value.item,
2050
- value.index
2051
- )
2052
- );
2053
- }
2054
- const changed = [];
2055
- if (previousViewableItems) {
2056
- for (const viewToken of previousViewableItems) {
2057
- const containerId = findContainerId(ctx, viewToken.key);
2058
- if (!checkIsViewable(
2059
- state,
2060
- ctx,
2061
- viewabilityConfig,
2062
- containerId,
2063
- viewToken.key,
2064
- scrollSize,
2065
- viewToken.item,
2066
- viewToken.index
2067
- )) {
2068
- viewToken.isViewable = false;
2069
- changed.push(viewToken);
2070
- }
2071
- }
2072
- }
2073
- const viewableItems = [];
2074
- for (let i = start; i <= end; i++) {
2075
- const item = data[i];
2076
- if (item) {
2077
- const key = getId(state, i);
2078
- const containerId = findContainerId(ctx, key);
2079
- if (checkIsViewable(state, ctx, viewabilityConfig, containerId, key, scrollSize, item, i)) {
2080
- const viewToken = {
2081
- containerId,
2082
- index: i,
2083
- isViewable: true,
2084
- item,
2085
- key
2086
- };
2087
- viewableItems.push(viewToken);
2088
- if (!(previousViewableItems == null ? void 0 : previousViewableItems.find((v) => v.key === viewToken.key))) {
2089
- changed.push(viewToken);
2090
- }
2091
- }
2092
- }
2093
- }
2094
- Object.assign(viewabilityState, {
2095
- previousEnd: end,
2096
- previousStart: start,
2097
- viewableItems
2098
- });
2099
- if (changed.length > 0) {
2100
- viewabilityState.viewableItems = viewableItems;
2101
- for (let i = 0; i < changed.length; i++) {
2102
- const change = changed[i];
2103
- maybeUpdateViewabilityCallback(ctx, configId, change.containerId, change);
2104
- }
2105
- if (onViewableItemsChanged) {
2106
- onViewableItemsChanged({ changed, viewableItems });
2107
- }
2108
- }
2109
- for (const [containerId, value] of ctx.mapViewabilityAmountValues) {
2110
- if (value.sizeVisible < 0) {
2111
- ctx.mapViewabilityAmountValues.delete(containerId);
2112
- }
2113
- }
2114
- }
2115
- function shallowEqual(prev, next) {
2116
- if (!prev) return false;
2117
- const keys = Object.keys(next);
2118
- for (let i = 0; i < keys.length; i++) {
2119
- const k = keys[i];
2120
- if (prev[k] !== next[k]) return false;
2121
- }
2122
- return true;
2123
- }
2124
- function computeViewability(state, ctx, viewabilityConfig, containerId, key, scrollSize, item, index) {
2125
- const { sizes, positions, scroll: scrollState } = state;
2126
- const topPad = (peek$(ctx, "stylePaddingTop") || 0) + (peek$(ctx, "headerSize") || 0);
2127
- const { itemVisiblePercentThreshold, viewAreaCoveragePercentThreshold } = viewabilityConfig;
2128
- const viewAreaMode = viewAreaCoveragePercentThreshold != null;
2129
- const viewablePercentThreshold = viewAreaMode ? viewAreaCoveragePercentThreshold : itemVisiblePercentThreshold;
2130
- const scroll = scrollState - topPad;
2131
- const top = positions.get(key) - scroll;
2132
- const size = sizes.get(key) || 0;
2133
- const bottom = top + size;
2134
- const isEntirelyVisible = top >= 0 && bottom <= scrollSize && bottom > top;
2135
- const sizeVisible = isEntirelyVisible ? size : Math.min(bottom, scrollSize) - Math.max(top, 0);
2136
- const percentVisible = size ? isEntirelyVisible ? 100 : 100 * (sizeVisible / size) : 0;
2137
- const percentOfScroller = size ? 100 * (sizeVisible / scrollSize) : 0;
2138
- const percent = isEntirelyVisible ? 100 : viewAreaMode ? percentOfScroller : percentVisible;
2139
- const isViewable = percent >= viewablePercentThreshold;
2140
- const value = {
2141
- containerId,
2142
- index,
2143
- isViewable,
2144
- item,
2145
- key,
2146
- percentOfScroller,
2147
- percentVisible,
2148
- scrollSize,
2149
- size,
2150
- sizeVisible
2151
- };
2152
- const prev = ctx.mapViewabilityAmountValues.get(containerId);
2153
- if (!shallowEqual(prev, value)) {
2154
- ctx.mapViewabilityAmountValues.set(containerId, value);
2155
- const cb = ctx.mapViewabilityAmountCallbacks.get(containerId);
2156
- if (cb) {
2157
- cb(value);
2158
- }
2159
- }
2160
- return value;
2161
- }
2162
- function checkIsViewable(state, ctx, viewabilityConfig, containerId, key, scrollSize, item, index) {
2163
- let value = ctx.mapViewabilityAmountValues.get(containerId);
2164
- if (!value || value.key !== key) {
2165
- value = computeViewability(state, ctx, viewabilityConfig, containerId, key, scrollSize, item, index);
2166
- }
2167
- return value.isViewable;
2168
- }
2169
- function maybeUpdateViewabilityCallback(ctx, configId, containerId, viewToken) {
2170
- const key = containerId + configId;
2171
- ctx.mapViewabilityValues.set(key, viewToken);
2172
- const cb = ctx.mapViewabilityCallbacks.get(key);
2173
- cb == null ? void 0 : cb(viewToken);
2174
- }
2175
-
2176
- // src/utils/checkAllSizesKnown.ts
2177
- function isNullOrUndefined2(value) {
2178
- return value === null || value === void 0;
2179
- }
2180
- function checkAllSizesKnown(state) {
2181
- const { startBuffered, endBuffered, sizesKnown } = state;
2182
- if (!isNullOrUndefined2(endBuffered) && !isNullOrUndefined2(startBuffered) && startBuffered >= 0 && endBuffered >= 0) {
2183
- let areAllKnown = true;
2184
- for (let i = startBuffered; areAllKnown && i <= endBuffered; i++) {
2185
- const key = getId(state, i);
2186
- areAllKnown && (areAllKnown = sizesKnown.has(key));
2187
- }
2188
- return areAllKnown;
2189
- }
2190
- return false;
2191
- }
2192
-
2193
- // src/utils/findAvailableContainers.ts
2194
- function findAvailableContainers(ctx, state, numNeeded, startBuffered, endBuffered, pendingRemoval, requiredItemTypes, needNewContainers) {
2195
- const numContainers = peek$(ctx, "numContainers");
2196
- const { stickyContainerPool, containerItemTypes } = state;
2197
- const result = [];
2198
- const availableContainers = [];
2199
- const pendingRemovalSet = new Set(pendingRemoval);
2200
- let pendingRemovalChanged = false;
2201
- const stickyIndicesSet = state.props.stickyIndicesSet;
2202
- const stickyItemIndices = (needNewContainers == null ? void 0 : needNewContainers.filter((index) => stickyIndicesSet.has(index))) || [];
2203
- const canReuseContainer = (containerIndex, requiredType) => {
2204
- if (!requiredType) return true;
2205
- const existingType = containerItemTypes.get(containerIndex);
2206
- if (!existingType) return true;
2207
- return existingType === requiredType;
2208
- };
2209
- const neededTypes = requiredItemTypes ? [...requiredItemTypes] : [];
2210
- let typeIndex = 0;
2211
- for (let i = 0; i < stickyItemIndices.length; i++) {
2212
- const requiredType = neededTypes[typeIndex];
2213
- let foundContainer = false;
2214
- for (const containerIndex of stickyContainerPool) {
2215
- const key = peek$(ctx, `containerItemKey${containerIndex}`);
2216
- const isPendingRemoval = pendingRemovalSet.has(containerIndex);
2217
- if ((key === void 0 || isPendingRemoval) && canReuseContainer(containerIndex, requiredType) && !result.includes(containerIndex)) {
2218
- result.push(containerIndex);
2219
- if (isPendingRemoval && pendingRemovalSet.delete(containerIndex)) {
2220
- pendingRemovalChanged = true;
2221
- }
2222
- foundContainer = true;
2223
- if (requiredItemTypes) typeIndex++;
2224
- break;
2225
- }
2226
- }
2227
- if (!foundContainer) {
2228
- const newContainerIndex = numContainers + result.filter((index) => index >= numContainers).length;
2229
- result.push(newContainerIndex);
2230
- stickyContainerPool.add(newContainerIndex);
2231
- if (requiredItemTypes) typeIndex++;
2232
- }
2233
- }
2234
- for (let u = 0; u < numContainers && result.length < numNeeded; u++) {
2235
- if (stickyContainerPool.has(u)) {
2236
- continue;
2237
- }
2238
- const key = peek$(ctx, `containerItemKey${u}`);
2239
- const requiredType = neededTypes[typeIndex];
2240
- const isPending = key !== void 0 && pendingRemovalSet.has(u);
2241
- const canUse = key === void 0 || isPending && canReuseContainer(u, requiredType);
2242
- if (canUse) {
2243
- if (isPending) {
2244
- pendingRemovalSet.delete(u);
2245
- pendingRemovalChanged = true;
2246
- }
2247
- result.push(u);
2248
- if (requiredItemTypes) {
2249
- typeIndex++;
2250
- }
2251
- }
2252
- }
2253
- for (let u = 0; u < numContainers && result.length < numNeeded; u++) {
2254
- if (stickyContainerPool.has(u)) {
2255
- continue;
2256
- }
2257
- const key = peek$(ctx, `containerItemKey${u}`);
2258
- if (key === void 0) continue;
2259
- const index = state.indexByKey.get(key);
2260
- const isOutOfView = index < startBuffered || index > endBuffered;
2261
- if (isOutOfView) {
2262
- const distance = index < startBuffered ? startBuffered - index : index - endBuffered;
2263
- if (!requiredItemTypes || typeIndex < neededTypes.length && canReuseContainer(u, neededTypes[typeIndex])) {
2264
- availableContainers.push({ distance, index: u });
2265
- }
2266
- }
2267
- }
2268
- const remaining = numNeeded - result.length;
2269
- if (remaining > 0) {
2270
- if (availableContainers.length > 0) {
2271
- if (availableContainers.length > remaining) {
2272
- availableContainers.sort(comparatorByDistance);
2273
- availableContainers.length = remaining;
2274
- }
2275
- for (const container of availableContainers) {
2276
- result.push(container.index);
2277
- if (requiredItemTypes) {
2278
- typeIndex++;
2279
- }
2280
- }
2281
- }
2282
- const stillNeeded = numNeeded - result.length;
2283
- if (stillNeeded > 0) {
2284
- for (let i = 0; i < stillNeeded; i++) {
2285
- result.push(numContainers + i);
2286
- }
2287
- if (IS_DEV && numContainers + stillNeeded > peek$(ctx, "numContainersPooled")) {
2288
- console.warn(
2289
- "[legend-list] No unused container available, so creating one on demand. This can be a minor performance issue and is likely caused by the estimatedItemSize being too large. Consider decreasing estimatedItemSize or increasing initialContainerPoolRatio.",
2290
- {
2291
- debugInfo: {
2292
- numContainers,
2293
- numContainersPooled: peek$(ctx, "numContainersPooled"),
2294
- numNeeded,
2295
- stillNeeded
2296
- }
2297
- }
2298
- );
2299
- }
2300
- }
2301
- }
2302
- if (pendingRemovalChanged) {
2303
- pendingRemoval.length = 0;
2304
- for (const value of pendingRemovalSet) {
2305
- pendingRemoval.push(value);
2306
- }
2307
- }
2308
- return result.sort(comparatorDefault);
2309
- }
2310
- function comparatorByDistance(a, b) {
2311
- return b.distance - a.distance;
2312
- }
2313
-
2314
- // src/core/scrollToIndex.ts
2315
- function scrollToIndex(ctx, state, { index, viewOffset = 0, animated = true, viewPosition }) {
2316
- if (index >= state.props.data.length) {
2317
- index = state.props.data.length - 1;
2318
- } else if (index < 0) {
2319
- index = 0;
2320
- }
2321
- const firstIndexOffset = calculateOffsetForIndex(ctx, state, index);
2322
- const isLast = index === state.props.data.length - 1;
2323
- if (isLast && viewPosition === void 0) {
2324
- viewPosition = 1;
2325
- }
2326
- state.scrollForNextCalculateItemsInView = void 0;
2327
- scrollTo(ctx, state, {
2328
- animated,
2329
- index,
2330
- offset: firstIndexOffset,
2331
- viewOffset,
2332
- viewPosition: viewPosition != null ? viewPosition : 0
2333
- });
2334
- }
2335
-
2336
- // src/utils/setDidLayout.ts
2337
- function setDidLayout(ctx, state) {
2338
- const {
2339
- loadStartTime,
2340
- initialScroll,
2341
- props: { onLoad }
2342
- } = state;
2343
- state.queuedInitialLayout = true;
2344
- checkAtBottom(ctx, state);
2345
- const setIt = () => {
2346
- set$(ctx, "containersDidLayout", true);
2347
- if (onLoad) {
2348
- onLoad({ elapsedTimeInMs: Date.now() - loadStartTime });
2349
- }
2350
- };
2351
- {
2352
- setIt();
2353
- }
2354
- }
2355
-
2356
- // src/core/calculateItemsInView.ts
2357
- function findCurrentStickyIndex(stickyArray, scroll, state) {
2358
- var _a3;
2359
- const idCache = state.idCache;
2360
- const positions = state.positions;
2361
- for (let i = stickyArray.length - 1; i >= 0; i--) {
2362
- const stickyIndex = stickyArray[i];
2363
- const stickyId = (_a3 = idCache[stickyIndex]) != null ? _a3 : getId(state, stickyIndex);
2364
- const stickyPos = stickyId ? positions.get(stickyId) : void 0;
2365
- if (stickyPos !== void 0 && scroll >= stickyPos) {
2366
- return i;
2367
- }
2368
- }
2369
- return -1;
2370
- }
2371
- function getActiveStickyIndices(ctx, state, stickyHeaderIndices) {
2372
- return new Set(
2373
- Array.from(state.stickyContainerPool).map((i) => peek$(ctx, `containerItemKey${i}`)).map((key) => key ? state.indexByKey.get(key) : void 0).filter((idx) => idx !== void 0 && stickyHeaderIndices.has(idx))
2374
- );
2375
- }
2376
- function handleStickyActivation(ctx, state, stickyHeaderIndices, stickyArray, currentStickyIdx, needNewContainers, startBuffered, endBuffered) {
2377
- var _a3;
2378
- const activeIndices = getActiveStickyIndices(ctx, state, stickyHeaderIndices);
2379
- state.activeStickyIndex = currentStickyIdx >= 0 ? stickyArray[currentStickyIdx] : void 0;
2380
- for (let offset = 0; offset <= 1; offset++) {
2381
- const idx = currentStickyIdx - offset;
2382
- if (idx < 0 || activeIndices.has(stickyArray[idx])) continue;
2383
- const stickyIndex = stickyArray[idx];
2384
- const stickyId = (_a3 = state.idCache[stickyIndex]) != null ? _a3 : getId(state, stickyIndex);
2385
- if (stickyId && !state.containerItemKeys.has(stickyId) && (stickyIndex < startBuffered || stickyIndex > endBuffered)) {
2386
- needNewContainers.push(stickyIndex);
2387
- }
2388
- }
2389
- }
2390
- function handleStickyRecycling(ctx, state, stickyArray, scroll, scrollBuffer, currentStickyIdx, pendingRemoval) {
2391
- var _a3, _b, _c;
2392
- for (const containerIndex of state.stickyContainerPool) {
2393
- const itemKey = peek$(ctx, `containerItemKey${containerIndex}`);
2394
- const itemIndex = itemKey ? state.indexByKey.get(itemKey) : void 0;
2395
- if (itemIndex === void 0) continue;
2396
- const arrayIdx = stickyArray.indexOf(itemIndex);
2397
- if (arrayIdx === -1) {
2398
- state.stickyContainerPool.delete(containerIndex);
2399
- set$(ctx, `containerSticky${containerIndex}`, false);
2400
- set$(ctx, `containerStickyOffset${containerIndex}`, void 0);
2401
- continue;
2402
- }
2403
- const isRecentSticky = arrayIdx >= currentStickyIdx - 1 && arrayIdx <= currentStickyIdx + 1;
2404
- if (isRecentSticky) continue;
2405
- const nextIndex = stickyArray[arrayIdx + 1];
2406
- let shouldRecycle = false;
2407
- if (nextIndex) {
2408
- const nextId = (_a3 = state.idCache[nextIndex]) != null ? _a3 : getId(state, nextIndex);
2409
- const nextPos = nextId ? state.positions.get(nextId) : void 0;
2410
- shouldRecycle = nextPos !== void 0 && scroll > nextPos + scrollBuffer * 2;
2411
- } else {
2412
- const currentId = (_b = state.idCache[itemIndex]) != null ? _b : getId(state, itemIndex);
2413
- if (currentId) {
2414
- const currentPos = state.positions.get(currentId);
2415
- const currentSize = (_c = state.sizes.get(currentId)) != null ? _c : getItemSize(ctx, state, currentId, itemIndex, state.props.data[itemIndex]);
2416
- shouldRecycle = currentPos !== void 0 && scroll > currentPos + currentSize + scrollBuffer * 3;
2417
- }
2418
- }
2419
- if (shouldRecycle) {
2420
- pendingRemoval.push(containerIndex);
2421
- }
2422
- }
2423
- }
2424
- function calculateItemsInView(ctx, state, params = {}) {
2425
- reactDom.unstable_batchedUpdates(() => {
2426
- var _a3, _b, _c, _d, _e, _f, _g, _h, _i, _j;
2427
- const {
2428
- columns,
2429
- containerItemKeys,
2430
- enableScrollForNextCalculateItemsInView,
2431
- idCache,
2432
- indexByKey,
2433
- initialScroll,
2434
- minIndexSizeChanged,
2435
- positions,
2436
- props: { getItemType, itemsAreEqual, keyExtractor, onStickyHeaderChange, scrollBuffer },
2437
- scrollForNextCalculateItemsInView,
2438
- scrollLength,
2439
- sizes,
2440
- startBufferedId: startBufferedIdOrig,
2441
- viewabilityConfigCallbackPairs
2442
- } = state;
2443
- const { data } = state.props;
2444
- const stickyIndicesArr = state.props.stickyIndicesArr || [];
2445
- const stickyIndicesSet = state.props.stickyIndicesSet || /* @__PURE__ */ new Set();
2446
- const prevNumContainers = peek$(ctx, "numContainers");
2447
- if (!data || scrollLength === 0 || !prevNumContainers) {
2448
- if (state.initialAnchor) {
2449
- ensureInitialAnchor(ctx, state);
2450
- }
2451
- return;
2452
- }
2453
- const totalSize = getContentSize(ctx);
2454
- const topPad = peek$(ctx, "stylePaddingTop") + peek$(ctx, "headerSize");
2455
- const numColumns = peek$(ctx, "numColumns");
2456
- const { dataChanged, doMVCP, forceFullItemPositions } = params;
2457
- const speed = getScrollVelocity(state);
2458
- const scrollExtra = 0;
2459
- const { queuedInitialLayout } = state;
2460
- let { scroll: scrollState } = state;
2461
- if (!queuedInitialLayout && initialScroll) {
2462
- const updatedOffset = calculateOffsetWithOffsetPosition(
2463
- ctx,
2464
- state,
2465
- calculateOffsetForIndex(ctx, state, initialScroll.index),
2466
- initialScroll
2467
- );
2468
- scrollState = updatedOffset;
2469
- }
2470
- const scrollAdjustPending = (_a3 = peek$(ctx, "scrollAdjustPending")) != null ? _a3 : 0;
2471
- const scrollAdjustPad = scrollAdjustPending - topPad;
2472
- let scroll = Math.round(scrollState + scrollExtra + scrollAdjustPad);
2473
- if (scroll + scrollLength > totalSize) {
2474
- scroll = Math.max(0, totalSize - scrollLength);
2475
- }
2476
- if (ENABLE_DEBUG_VIEW) {
2477
- set$(ctx, "debugRawScroll", scrollState);
2478
- set$(ctx, "debugComputedScroll", scroll);
2479
- }
2480
- const previousStickyIndex = state.activeStickyIndex;
2481
- const currentStickyIdx = stickyIndicesArr.length > 0 ? findCurrentStickyIndex(stickyIndicesArr, scroll, state) : -1;
2482
- const nextActiveStickyIndex = currentStickyIdx >= 0 ? stickyIndicesArr[currentStickyIdx] : void 0;
2483
- state.activeStickyIndex = nextActiveStickyIndex;
2484
- set$(ctx, "activeStickyIndex", nextActiveStickyIndex);
2485
- let scrollBufferTop = scrollBuffer;
2486
- let scrollBufferBottom = scrollBuffer;
2487
- if (speed > 0 || speed === 0 && scroll < Math.max(50, scrollBuffer)) {
2488
- scrollBufferTop = scrollBuffer * 0.5;
2489
- scrollBufferBottom = scrollBuffer * 1.5;
2490
- } else {
2491
- scrollBufferTop = scrollBuffer * 1.5;
2492
- scrollBufferBottom = scrollBuffer * 0.5;
2493
- }
2494
- const scrollTopBuffered = scroll - scrollBufferTop;
2495
- const scrollBottom = scroll + scrollLength + (scroll < 0 ? -scroll : 0);
2496
- const scrollBottomBuffered = scrollBottom + scrollBufferBottom;
2497
- if (!dataChanged && !forceFullItemPositions && scrollForNextCalculateItemsInView) {
2498
- const { top, bottom } = scrollForNextCalculateItemsInView;
2499
- if ((top === null || scrollTopBuffered > top) && (bottom === null || scrollBottomBuffered < bottom)) {
2500
- if (state.initialAnchor) {
2501
- ensureInitialAnchor(ctx, state);
2502
- }
2503
- return;
2504
- }
2505
- }
2506
- const checkMVCP = doMVCP ? prepareMVCP(ctx, state, dataChanged) : void 0;
2507
- if (dataChanged) {
2508
- indexByKey.clear();
2509
- idCache.length = 0;
2510
- positions.clear();
2511
- }
2512
- const startIndex = forceFullItemPositions || dataChanged ? 0 : (_b = minIndexSizeChanged != null ? minIndexSizeChanged : state.startBuffered) != null ? _b : 0;
2513
- updateItemPositions(ctx, state, dataChanged, {
2514
- doMVCP,
2515
- forceFullUpdate: !!forceFullItemPositions,
2516
- scrollBottomBuffered,
2517
- startIndex
2518
- });
2519
- if (minIndexSizeChanged !== void 0) {
2520
- state.minIndexSizeChanged = void 0;
2521
- }
2522
- checkMVCP == null ? void 0 : checkMVCP();
2523
- let startNoBuffer = null;
2524
- let startBuffered = null;
2525
- let startBufferedId = null;
2526
- let endNoBuffer = null;
2527
- let endBuffered = null;
2528
- let loopStart = !dataChanged && startBufferedIdOrig ? indexByKey.get(startBufferedIdOrig) || 0 : 0;
2529
- for (let i = loopStart; i >= 0; i--) {
2530
- const id = (_c = idCache[i]) != null ? _c : getId(state, i);
2531
- const top = positions.get(id);
2532
- const size = (_d = sizes.get(id)) != null ? _d : getItemSize(ctx, state, id, i, data[i]);
2533
- const bottom = top + size;
2534
- if (bottom > scroll - scrollBufferTop) {
2535
- loopStart = i;
2536
- } else {
2537
- break;
2538
- }
2539
- }
2540
- const loopStartMod = loopStart % numColumns;
2541
- if (loopStartMod > 0) {
2542
- loopStart -= loopStartMod;
2543
- }
2544
- let foundEnd = false;
2545
- let nextTop;
2546
- let nextBottom;
2547
- let maxIndexRendered = 0;
2548
- for (let i = 0; i < prevNumContainers; i++) {
2549
- const key = peek$(ctx, `containerItemKey${i}`);
2550
- if (key !== void 0) {
2551
- const index = indexByKey.get(key);
2552
- maxIndexRendered = Math.max(maxIndexRendered, index);
2553
- }
2554
- }
2555
- let firstFullyOnScreenIndex;
2556
- const dataLength = data.length;
2557
- for (let i = Math.max(0, loopStart); i < dataLength && (!foundEnd || i <= maxIndexRendered); i++) {
2558
- const id = (_e = idCache[i]) != null ? _e : getId(state, i);
2559
- const size = (_f = sizes.get(id)) != null ? _f : getItemSize(ctx, state, id, i, data[i]);
2560
- const top = positions.get(id);
2561
- if (!foundEnd) {
2562
- if (startNoBuffer === null && top + size > scroll) {
2563
- startNoBuffer = i;
2564
- }
2565
- if (firstFullyOnScreenIndex === void 0 && top >= scroll - 10) {
2566
- firstFullyOnScreenIndex = i;
2567
- }
2568
- if (startBuffered === null && top + size > scrollTopBuffered) {
2569
- startBuffered = i;
2570
- startBufferedId = id;
2571
- if (scrollTopBuffered < 0) {
2572
- nextTop = null;
2573
- } else {
2574
- nextTop = top;
2575
- }
2576
- }
2577
- if (startNoBuffer !== null) {
2578
- if (top <= scrollBottom) {
2579
- endNoBuffer = i;
2580
- }
2581
- if (top <= scrollBottomBuffered) {
2582
- endBuffered = i;
2583
- if (scrollBottomBuffered > totalSize) {
2584
- nextBottom = null;
2585
- } else {
2586
- nextBottom = top + size;
2587
- }
2588
- } else {
2589
- foundEnd = true;
2590
- }
2591
- }
2592
- }
2593
- }
2594
- const idsInView = [];
2595
- for (let i = firstFullyOnScreenIndex; i <= endNoBuffer; i++) {
2596
- const id = (_g = idCache[i]) != null ? _g : getId(state, i);
2597
- idsInView.push(id);
2598
- }
2599
- Object.assign(state, {
2600
- endBuffered,
2601
- endNoBuffer,
2602
- firstFullyOnScreenIndex,
2603
- idsInView,
2604
- startBuffered,
2605
- startBufferedId,
2606
- startNoBuffer
2607
- });
2608
- if (enableScrollForNextCalculateItemsInView && nextTop !== void 0 && nextBottom !== void 0) {
2609
- state.scrollForNextCalculateItemsInView = nextTop !== void 0 && nextBottom !== void 0 ? {
2610
- bottom: nextBottom,
2611
- top: nextTop
2612
- } : void 0;
2613
- }
2614
- let numContainers = prevNumContainers;
2615
- const pendingRemoval = [];
2616
- if (dataChanged) {
2617
- for (let i = 0; i < numContainers; i++) {
2618
- const itemKey = peek$(ctx, `containerItemKey${i}`);
2619
- if (!keyExtractor || itemKey && indexByKey.get(itemKey) === void 0) {
2620
- pendingRemoval.push(i);
2621
- }
2622
- }
2623
- }
2624
- if (startBuffered !== null && endBuffered !== null) {
2625
- const needNewContainers = [];
2626
- for (let i = startBuffered; i <= endBuffered; i++) {
2627
- const id = (_h = idCache[i]) != null ? _h : getId(state, i);
2628
- if (!containerItemKeys.has(id)) {
2629
- needNewContainers.push(i);
2630
- }
2631
- }
2632
- if (stickyIndicesArr.length > 0) {
2633
- handleStickyActivation(
2634
- ctx,
2635
- state,
2636
- stickyIndicesSet,
2637
- stickyIndicesArr,
2638
- currentStickyIdx,
2639
- needNewContainers,
2640
- startBuffered,
2641
- endBuffered
2642
- );
2643
- } else {
2644
- state.activeStickyIndex = void 0;
2645
- set$(ctx, "activeStickyIndex", void 0);
2646
- }
2647
- if (needNewContainers.length > 0) {
2648
- const requiredItemTypes = getItemType ? needNewContainers.map((i) => {
2649
- const itemType = getItemType(data[i], i);
2650
- return itemType ? String(itemType) : "";
2651
- }) : void 0;
2652
- const availableContainers = findAvailableContainers(
2653
- ctx,
2654
- state,
2655
- needNewContainers.length,
2656
- startBuffered,
2657
- endBuffered,
2658
- pendingRemoval,
2659
- requiredItemTypes,
2660
- needNewContainers
2661
- );
2662
- for (let idx = 0; idx < needNewContainers.length; idx++) {
2663
- const i = needNewContainers[idx];
2664
- const containerIndex = availableContainers[idx];
2665
- const id = (_i = idCache[i]) != null ? _i : getId(state, i);
2666
- const oldKey = peek$(ctx, `containerItemKey${containerIndex}`);
2667
- if (oldKey && oldKey !== id) {
2668
- containerItemKeys.delete(oldKey);
2669
- }
2670
- set$(ctx, `containerItemKey${containerIndex}`, id);
2671
- set$(ctx, `containerItemData${containerIndex}`, data[i]);
2672
- if (requiredItemTypes) {
2673
- state.containerItemTypes.set(containerIndex, requiredItemTypes[idx]);
2674
- }
2675
- containerItemKeys.add(id);
2676
- const containerSticky = `containerSticky${containerIndex}`;
2677
- if (stickyIndicesSet.has(i)) {
2678
- set$(ctx, containerSticky, true);
2679
- const topPadding = (peek$(ctx, "stylePaddingTop") || 0) + (peek$(ctx, "headerSize") || 0);
2680
- set$(ctx, `containerStickyOffset${containerIndex}`, topPadding);
2681
- state.stickyContainerPool.add(containerIndex);
2682
- } else if (peek$(ctx, containerSticky)) {
2683
- set$(ctx, containerSticky, false);
2684
- state.stickyContainerPool.delete(containerIndex);
2685
- }
2686
- if (containerIndex >= numContainers) {
2687
- numContainers = containerIndex + 1;
2688
- }
2689
- }
2690
- if (numContainers !== prevNumContainers) {
2691
- set$(ctx, "numContainers", numContainers);
2692
- if (numContainers > peek$(ctx, "numContainersPooled")) {
2693
- set$(ctx, "numContainersPooled", Math.ceil(numContainers * 1.5));
2694
- }
2695
- }
2696
- }
2697
- }
2698
- if (stickyIndicesArr.length > 0) {
2699
- handleStickyRecycling(ctx, state, stickyIndicesArr, scroll, scrollBuffer, currentStickyIdx, pendingRemoval);
2700
- }
2701
- let didChangePositions = false;
2702
- for (let i = 0; i < numContainers; i++) {
2703
- const itemKey = peek$(ctx, `containerItemKey${i}`);
2704
- if (pendingRemoval.includes(i)) {
2705
- if (itemKey !== void 0) {
2706
- containerItemKeys.delete(itemKey);
2707
- }
2708
- state.containerItemTypes.delete(i);
2709
- if (state.stickyContainerPool.has(i)) {
2710
- set$(ctx, `containerSticky${i}`, false);
2711
- set$(ctx, `containerStickyOffset${i}`, void 0);
2712
- state.stickyContainerPool.delete(i);
2713
- }
2714
- set$(ctx, `containerItemKey${i}`, void 0);
2715
- set$(ctx, `containerItemData${i}`, void 0);
2716
- set$(ctx, `containerPosition${i}`, POSITION_OUT_OF_VIEW);
2717
- set$(ctx, `containerColumn${i}`, -1);
2718
- } else {
2719
- const itemIndex = indexByKey.get(itemKey);
2720
- const item = data[itemIndex];
2721
- if (item !== void 0) {
2722
- const id = (_j = idCache[itemIndex]) != null ? _j : getId(state, itemIndex);
2723
- const positionValue = positions.get(id);
2724
- if (positionValue === void 0) {
2725
- set$(ctx, `containerPosition${i}`, POSITION_OUT_OF_VIEW);
2726
- } else {
2727
- const position = (positionValue || 0) - scrollAdjustPending;
2728
- const column = columns.get(id) || 1;
2729
- const prevPos = peek$(ctx, `containerPosition${i}`);
2730
- const prevColumn = peek$(ctx, `containerColumn${i}`);
2731
- const prevData = peek$(ctx, `containerItemData${i}`);
2732
- if (position > POSITION_OUT_OF_VIEW && position !== prevPos) {
2733
- set$(ctx, `containerPosition${i}`, position);
2734
- didChangePositions = true;
2735
- }
2736
- if (column >= 0 && column !== prevColumn) {
2737
- set$(ctx, `containerColumn${i}`, column);
2738
- }
2739
- if (prevData !== item && (itemsAreEqual ? !itemsAreEqual(prevData, item, itemIndex, data) : true)) {
2740
- set$(ctx, `containerItemData${i}`, item);
2741
- }
2742
- }
2743
- }
2744
- }
2745
- }
2746
- if (didChangePositions) {
2747
- set$(ctx, "lastPositionUpdate", Date.now());
2748
- }
2749
- if (!queuedInitialLayout && endBuffered !== null) {
2750
- if (checkAllSizesKnown(state)) {
2751
- setDidLayout(ctx, state);
2752
- }
2753
- }
2754
- if (viewabilityConfigCallbackPairs) {
2755
- updateViewableItems(state, ctx, viewabilityConfigCallbackPairs, scrollLength, startNoBuffer, endNoBuffer);
2756
- }
2757
- if (onStickyHeaderChange && stickyIndicesArr.length > 0 && nextActiveStickyIndex !== void 0 && nextActiveStickyIndex !== previousStickyIndex) {
2758
- const item = data[nextActiveStickyIndex];
2759
- if (item !== void 0) {
2760
- onStickyHeaderChange({ index: nextActiveStickyIndex, item });
2761
- }
2762
- }
2763
- });
2764
- if (state.initialAnchor) {
2765
- ensureInitialAnchor(ctx, state);
2766
- }
2767
- }
2768
-
2769
- // src/core/checkActualChange.ts
2770
- function checkActualChange(state, dataProp, previousData) {
2771
- if (!previousData || !dataProp || dataProp.length !== previousData.length) {
2772
- return true;
2773
- }
2774
- const {
2775
- idCache,
2776
- props: { keyExtractor }
2777
- } = state;
2778
- for (let i = 0; i < dataProp.length; i++) {
2779
- if (dataProp[i] !== previousData[i]) {
2780
- return true;
2781
- }
2782
- if (keyExtractor ? idCache[i] !== keyExtractor(previousData[i], i) : dataProp[i] !== previousData[i]) {
2783
- return true;
2784
- }
2785
- }
2786
- return false;
2787
- }
2788
-
2789
- // src/core/doMaintainScrollAtEnd.ts
2790
- function doMaintainScrollAtEnd(ctx, state, animated) {
2791
- const {
2792
- refScroller,
2793
- props: { maintainScrollAtEnd }
2794
- } = state;
2795
- if ((state == null ? void 0 : state.isAtEnd) && maintainScrollAtEnd && peek$(ctx, "containersDidLayout")) {
2796
- const paddingTop = peek$(ctx, "alignItemsPaddingTop");
2797
- if (paddingTop > 0) {
2798
- state.scroll = 0;
2799
- }
2800
- requestAnimationFrame(() => {
2801
- var _a3;
2802
- if (state == null ? void 0 : state.isAtEnd) {
2803
- state.maintainingScrollAtEnd = true;
2804
- (_a3 = refScroller.current) == null ? void 0 : _a3.scrollToEnd({
2805
- animated
2806
- });
2807
- setTimeout(
2808
- () => {
2809
- state.maintainingScrollAtEnd = false;
2810
- },
2811
- 0
2812
- );
2813
- }
2814
- });
2815
- return true;
2816
- }
2817
- return false;
2818
- }
2819
-
2820
- // src/utils/updateAveragesOnDataChange.ts
2821
- function updateAveragesOnDataChange(state, oldData, newData) {
2822
- var _a3;
2823
- const {
2824
- averageSizes,
2825
- sizesKnown,
2826
- indexByKey,
2827
- props: { itemsAreEqual, getItemType, keyExtractor }
2828
- } = state;
2829
- if (!itemsAreEqual || !oldData.length || !newData.length) {
2830
- for (const key in averageSizes) {
2831
- delete averageSizes[key];
2832
- }
2833
- return;
2834
- }
2835
- const itemTypesToPreserve = {};
2836
- const newDataLength = newData.length;
2837
- const oldDataLength = oldData.length;
2838
- for (let newIndex = 0; newIndex < newDataLength; newIndex++) {
2839
- const newItem = newData[newIndex];
2840
- const id = keyExtractor ? keyExtractor(newItem, newIndex) : String(newIndex);
2841
- const oldIndex = indexByKey.get(id);
2842
- if (oldIndex !== void 0 && oldIndex < oldDataLength) {
2843
- const knownSize = sizesKnown.get(id);
2844
- if (knownSize === void 0) continue;
2845
- const oldItem = oldData[oldIndex];
2846
- const areEqual = itemsAreEqual(oldItem, newItem, newIndex, newData);
2847
- if (areEqual) {
2848
- const itemType = getItemType ? (_a3 = getItemType(newItem, newIndex)) != null ? _a3 : "" : "";
2849
- let typeData = itemTypesToPreserve[itemType];
2850
- if (!typeData) {
2851
- typeData = itemTypesToPreserve[itemType] = { count: 0, totalSize: 0 };
2852
- }
2853
- typeData.totalSize += knownSize;
2854
- typeData.count++;
2855
- }
2856
- }
2857
- }
2858
- for (const key in averageSizes) {
2859
- delete averageSizes[key];
2860
- }
2861
- for (const itemType in itemTypesToPreserve) {
2862
- const { totalSize, count } = itemTypesToPreserve[itemType];
2863
- if (count > 0) {
2864
- averageSizes[itemType] = {
2865
- avg: totalSize / count,
2866
- num: count
2867
- };
2868
- }
2869
- }
2870
- }
2871
-
2872
- // src/core/checkResetContainers.ts
2873
- function checkResetContainers(ctx, state, dataProp) {
2874
- const { previousData } = state;
2875
- if (previousData) {
2876
- updateAveragesOnDataChange(state, previousData, dataProp);
2877
- }
2878
- const { maintainScrollAtEnd } = state.props;
2879
- calculateItemsInView(ctx, state, { dataChanged: true, doMVCP: true });
2880
- const shouldMaintainScrollAtEnd = maintainScrollAtEnd === true || maintainScrollAtEnd.onDataChange;
2881
- const didMaintainScrollAtEnd = shouldMaintainScrollAtEnd && doMaintainScrollAtEnd(ctx, state, false);
2882
- if (!didMaintainScrollAtEnd && previousData && dataProp.length > previousData.length) {
2883
- state.isEndReached = false;
2884
- }
2885
- if (!didMaintainScrollAtEnd) {
2886
- checkAtTop(state);
2887
- checkAtBottom(ctx, state);
2888
- }
2889
- delete state.previousData;
2890
- }
2891
-
2892
- // src/core/doInitialAllocateContainers.ts
2893
- function doInitialAllocateContainers(ctx, state) {
2894
- var _a3, _b, _c;
2895
- const {
2896
- scrollLength,
2897
- props: {
2898
- data,
2899
- getEstimatedItemSize,
2900
- getFixedItemSize,
2901
- getItemType,
2902
- scrollBuffer,
2903
- numColumns,
2904
- estimatedItemSize
2905
- }
2906
- } = state;
2907
- const hasContainers = peek$(ctx, "numContainers");
2908
- if (scrollLength > 0 && data.length > 0 && !hasContainers) {
2909
- let averageItemSize;
2910
- if (getFixedItemSize || getEstimatedItemSize) {
2911
- let totalSize = 0;
2912
- const num = Math.min(20, data.length);
2913
- for (let i = 0; i < num; i++) {
2914
- const item = data[i];
2915
- const itemType = getItemType ? (_a3 = getItemType(item, i)) != null ? _a3 : "" : "";
2916
- totalSize += (_c = (_b = getFixedItemSize == null ? void 0 : getFixedItemSize(i, item, itemType)) != null ? _b : getEstimatedItemSize == null ? void 0 : getEstimatedItemSize(i, item, itemType)) != null ? _c : estimatedItemSize;
2917
- }
2918
- averageItemSize = totalSize / num;
2919
- } else {
2920
- averageItemSize = estimatedItemSize;
2921
- }
2922
- const numContainers = Math.ceil((scrollLength + scrollBuffer * 2) / averageItemSize * numColumns);
2923
- for (let i = 0; i < numContainers; i++) {
2924
- set$(ctx, `containerPosition${i}`, POSITION_OUT_OF_VIEW);
2925
- set$(ctx, `containerColumn${i}`, -1);
2926
- }
2927
- set$(ctx, "numContainers", numContainers);
2928
- set$(ctx, "numContainersPooled", numContainers * state.props.initialContainerPoolRatio);
2929
- if (state.lastLayout) {
2930
- if (state.initialScroll) {
2931
- requestAnimationFrame(() => {
2932
- calculateItemsInView(ctx, state, { dataChanged: true, doMVCP: true });
2933
- });
2934
- } else {
2935
- calculateItemsInView(ctx, state, { dataChanged: true, doMVCP: true });
2936
- }
2937
- }
2938
- return true;
2939
- }
2940
- }
2941
-
2942
- // src/core/handleLayout.ts
2943
- function handleLayout(ctx, state, layout, setCanRender) {
2944
- const { maintainScrollAtEnd } = state.props;
2945
- const measuredLength = layout[state.props.horizontal ? "width" : "height"];
2946
- const previousLength = state.scrollLength;
2947
- const scrollLength = measuredLength > 0 ? measuredLength : previousLength;
2948
- const otherAxisSize = layout[state.props.horizontal ? "height" : "width"];
2949
- const needsCalculate = !state.lastLayout || scrollLength > state.scrollLength || state.lastLayout.x !== layout.x || state.lastLayout.y !== layout.y;
2950
- state.lastLayout = layout;
2951
- const prevOtherAxisSize = state.otherAxisSize;
2952
- const didChange = scrollLength !== state.scrollLength || otherAxisSize !== prevOtherAxisSize;
2953
- if (didChange) {
2954
- state.scrollLength = scrollLength;
2955
- state.otherAxisSize = otherAxisSize;
2956
- state.lastBatchingAction = Date.now();
2957
- state.scrollForNextCalculateItemsInView = void 0;
2958
- if (scrollLength > 0) {
2959
- doInitialAllocateContainers(ctx, state);
2960
- }
2961
- if (needsCalculate) {
2962
- calculateItemsInView(ctx, state, { doMVCP: true });
2963
- }
2964
- if (didChange || otherAxisSize !== prevOtherAxisSize) {
2965
- set$(ctx, "scrollSize", { height: layout.height, width: layout.width });
2966
- }
2967
- if (maintainScrollAtEnd === true || maintainScrollAtEnd.onLayout) {
2968
- doMaintainScrollAtEnd(ctx, state, false);
2969
- }
2970
- updateAlignItemsPaddingTop(ctx, state);
2971
- checkAtBottom(ctx, state);
2972
- checkAtTop(state);
2973
- if (state) {
2974
- state.needsOtherAxisSize = otherAxisSize - (state.props.stylePaddingTop || 0) < 10;
2975
- }
2976
- if (IS_DEV && measuredLength === 0) {
2977
- warnDevOnce(
2978
- "height0",
2979
- `List ${state.props.horizontal ? "width" : "height"} is 0. You may need to set a style or \`flex: \` for the list, because children are absolutely positioned.`
2980
- );
2981
- }
2982
- }
2983
- setCanRender(true);
2984
- }
2985
-
2986
- // src/core/onScroll.ts
2987
- function onScroll(ctx, state, event) {
2988
- var _a3, _b, _c;
2989
- const {
2990
- scrollProcessingEnabled,
2991
- props: { onScroll: onScrollProp }
2992
- } = state;
2993
- if (scrollProcessingEnabled === false) {
2994
- return;
2995
- }
2996
- if (((_b = (_a3 = event.nativeEvent) == null ? void 0 : _a3.contentSize) == null ? void 0 : _b.height) === 0 && ((_c = event.nativeEvent.contentSize) == null ? void 0 : _c.width) === 0) {
2997
- return;
2998
- }
2999
- let newScroll = event.nativeEvent.contentOffset[state.props.horizontal ? "x" : "y"];
3000
- state.scrollPending = newScroll;
3001
- const maxOffset = Math.max(0, getContentSize(ctx) - state.scrollLength);
3002
- if (state.initialScroll && newScroll > maxOffset) {
3003
- newScroll = maxOffset;
3004
- scrollTo(ctx, state, {
3005
- noScrollingTo: true,
3006
- offset: newScroll
3007
- });
3008
- }
3009
- updateScroll(ctx, state, newScroll);
3010
- onScrollProp == null ? void 0 : onScrollProp(event);
3011
- }
3012
-
3013
- // src/core/ScrollAdjustHandler.ts
3014
- var ScrollAdjustHandler = class {
3015
- constructor(ctx) {
3016
- this.appliedAdjust = 0;
3017
- this.pendingAdjust = 0;
3018
- this.context = ctx;
3019
- {
3020
- const commitPendingAdjust = () => {
3021
- const state = this.context.internalState;
3022
- const pending = this.pendingAdjust;
3023
- if (pending !== 0) {
3024
- this.pendingAdjust = 0;
3025
- this.appliedAdjust += pending;
3026
- state.scroll += pending;
3027
- state.scrollForNextCalculateItemsInView = void 0;
3028
- set$(this.context, "scrollAdjustPending", 0);
3029
- set$(this.context, "scrollAdjust", this.appliedAdjust);
3030
- calculateItemsInView(this.context, this.context.internalState);
3031
- }
3032
- };
3033
- listen$(this.context, "scrollingTo", (value) => {
3034
- if (value === void 0) {
3035
- commitPendingAdjust();
3036
- }
3037
- });
3038
- }
3039
- }
3040
- requestAdjust(add) {
3041
- const scrollingTo = peek$(this.context, "scrollingTo");
3042
- if ((scrollingTo == null ? void 0 : scrollingTo.animated) && !scrollingTo.isInitialScroll) {
3043
- this.pendingAdjust += add;
3044
- set$(this.context, "scrollAdjustPending", this.pendingAdjust);
3045
- } else {
3046
- this.appliedAdjust += add;
3047
- set$(this.context, "scrollAdjust", this.appliedAdjust);
3048
- }
3049
- }
3050
- getAdjust() {
3051
- return this.appliedAdjust;
3052
- }
3053
- };
3054
-
3055
- // src/core/updateItemSize.ts
3056
- function updateItemSize(ctx, state, itemKey, sizeObj) {
3057
- var _a3;
3058
- const {
3059
- sizesKnown,
3060
- props: {
3061
- getFixedItemSize,
3062
- getItemType,
3063
- horizontal,
3064
- suggestEstimatedItemSize,
3065
- onItemSizeChanged,
3066
- data,
3067
- maintainScrollAtEnd
3068
- }
3069
- } = state;
3070
- if (!data) return;
3071
- const index = state.indexByKey.get(itemKey);
3072
- if (getFixedItemSize) {
3073
- if (index === void 0) {
3074
- return;
3075
- }
3076
- const itemData = state.props.data[index];
3077
- if (itemData === void 0) {
3078
- return;
3079
- }
3080
- const type = getItemType ? (_a3 = getItemType(itemData, index)) != null ? _a3 : "" : "";
3081
- const size2 = getFixedItemSize(index, itemData, type);
3082
- if (size2 !== void 0 && size2 === sizesKnown.get(itemKey)) {
3083
- return;
3084
- }
3085
- }
3086
- const containersDidLayout = peek$(ctx, "containersDidLayout");
3087
- let needsRecalculate = !containersDidLayout;
3088
- let shouldMaintainScrollAtEnd = false;
3089
- let minIndexSizeChanged;
3090
- let maxOtherAxisSize = peek$(ctx, "otherAxisSize") || 0;
3091
- const prevSizeKnown = state.sizesKnown.get(itemKey);
3092
- const diff = updateOneItemSize(ctx, state, itemKey, sizeObj);
3093
- const size = roundSize(horizontal ? sizeObj.width : sizeObj.height);
3094
- if (diff !== 0) {
3095
- minIndexSizeChanged = minIndexSizeChanged !== void 0 ? Math.min(minIndexSizeChanged, index) : index;
3096
- const { startBuffered, endBuffered } = state;
3097
- needsRecalculate || (needsRecalculate = index >= startBuffered && index <= endBuffered);
3098
- if (!needsRecalculate) {
3099
- const numContainers = ctx.values.get("numContainers");
3100
- for (let i = 0; i < numContainers; i++) {
3101
- if (peek$(ctx, `containerItemKey${i}`) === itemKey) {
3102
- needsRecalculate = true;
3103
- break;
3104
- }
3105
- }
3106
- }
3107
- if (state.needsOtherAxisSize) {
3108
- const otherAxisSize = horizontal ? sizeObj.height : sizeObj.width;
3109
- maxOtherAxisSize = Math.max(maxOtherAxisSize, otherAxisSize);
3110
- }
3111
- if (prevSizeKnown !== void 0 && Math.abs(prevSizeKnown - size) > 5) {
3112
- shouldMaintainScrollAtEnd = true;
3113
- }
3114
- onItemSizeChanged == null ? void 0 : onItemSizeChanged({
3115
- index,
3116
- itemData: state.props.data[index],
3117
- itemKey,
3118
- previous: size - diff,
3119
- size
3120
- });
3121
- }
3122
- if (minIndexSizeChanged !== void 0) {
3123
- state.minIndexSizeChanged = state.minIndexSizeChanged !== void 0 ? Math.min(state.minIndexSizeChanged, minIndexSizeChanged) : minIndexSizeChanged;
3124
- }
3125
- if (IS_DEV && suggestEstimatedItemSize && minIndexSizeChanged !== void 0) {
3126
- if (state.timeoutSizeMessage) clearTimeout(state.timeoutSizeMessage);
3127
- state.timeoutSizeMessage = setTimeout(() => {
3128
- var _a4;
3129
- state.timeoutSizeMessage = void 0;
3130
- const num = state.sizesKnown.size;
3131
- const avg = (_a4 = state.averageSizes[""]) == null ? void 0 : _a4.avg;
3132
- console.warn(
3133
- `[legend-list] Based on the ${num} items rendered so far, the optimal estimated size is ${avg}.`
3134
- );
3135
- }, 1e3);
3136
- }
3137
- const cur = peek$(ctx, "otherAxisSize");
3138
- if (!cur || maxOtherAxisSize > cur) {
3139
- set$(ctx, "otherAxisSize", maxOtherAxisSize);
3140
- }
3141
- if (containersDidLayout || checkAllSizesKnown(state)) {
3142
- if (needsRecalculate) {
3143
- state.scrollForNextCalculateItemsInView = void 0;
3144
- calculateItemsInView(ctx, state, { doMVCP: true });
3145
- }
3146
- if (shouldMaintainScrollAtEnd) {
3147
- if (maintainScrollAtEnd === true || maintainScrollAtEnd.onItemLayout) {
3148
- doMaintainScrollAtEnd(ctx, state, false);
3149
- }
3150
- }
3151
- }
3152
- }
3153
- function updateOneItemSize(ctx, state, itemKey, sizeObj) {
3154
- var _a3;
3155
- const {
3156
- indexByKey,
3157
- sizesKnown,
3158
- averageSizes,
3159
- props: { data, horizontal, getEstimatedItemSize, getItemType, getFixedItemSize }
3160
- } = state;
3161
- if (!data) return 0;
3162
- const index = indexByKey.get(itemKey);
3163
- const prevSize = getItemSize(ctx, state, itemKey, index, data[index]);
3164
- const rawSize = horizontal ? sizeObj.width : sizeObj.height;
3165
- const size = Math.round(rawSize) ;
3166
- sizesKnown.set(itemKey, size);
3167
- if (!getEstimatedItemSize && !getFixedItemSize && size > 0) {
3168
- const itemType = getItemType ? (_a3 = getItemType(data[index], index)) != null ? _a3 : "" : "";
3169
- let averages = averageSizes[itemType];
3170
- if (!averages) {
3171
- averages = averageSizes[itemType] = { avg: 0, num: 0 };
3172
- }
3173
- averages.avg = (averages.avg * averages.num + size) / (averages.num + 1);
3174
- averages.num++;
3175
- }
3176
- if (!prevSize || Math.abs(prevSize - size) > 0.1) {
3177
- setSize(ctx, state, itemKey, size);
3178
- return size - prevSize;
3179
- }
3180
- return 0;
3181
- }
3182
- var useCombinedRef = (...refs) => {
3183
- const callback = React3.useCallback((element) => {
3184
- for (const ref of refs) {
3185
- if (!ref) {
3186
- continue;
3187
- }
3188
- if (isFunction(ref)) {
3189
- ref(element);
3190
- } else {
3191
- ref.current = element;
3192
- }
3193
- }
3194
- }, refs);
3195
- return callback;
3196
- };
3197
-
3198
- // src/platform/RefreshControl.tsx
3199
- function RefreshControl(_props) {
3200
- return null;
3201
- }
3202
-
3203
- // src/platform/useStickyScrollHandler.ts
3204
- function useStickyScrollHandler(_stickyHeaderIndices, _horizontal, _ctx, onScroll2) {
3205
- return onScroll2;
3206
- }
3207
-
3208
- // src/utils/createColumnWrapperStyle.ts
3209
- function createColumnWrapperStyle(contentContainerStyle) {
3210
- const { gap, columnGap, rowGap } = contentContainerStyle;
3211
- if (gap || columnGap || rowGap) {
3212
- contentContainerStyle.gap = void 0;
3213
- contentContainerStyle.columnGap = void 0;
3214
- contentContainerStyle.rowGap = void 0;
3215
- return {
3216
- columnGap,
3217
- gap,
3218
- rowGap
3219
- };
3220
- }
3221
- }
3222
-
3223
- // src/utils/createImperativeHandle.ts
3224
- function createImperativeHandle(ctx, state) {
3225
- const scrollIndexIntoView = (options) => {
3226
- if (state) {
3227
- const { index, ...rest } = options;
3228
- const { startNoBuffer, endNoBuffer } = state;
3229
- if (index < startNoBuffer || index > endNoBuffer) {
3230
- const viewPosition = index < startNoBuffer ? 0 : 1;
3231
- scrollToIndex(ctx, state, {
3232
- ...rest,
3233
- index,
3234
- viewPosition
3235
- });
3236
- }
3237
- }
3238
- };
3239
- const refScroller = state.refScroller;
3240
- return {
3241
- flashScrollIndicators: () => refScroller.current.flashScrollIndicators(),
3242
- getNativeScrollRef: () => refScroller.current,
3243
- getScrollableNode: () => refScroller.current.getScrollableNode(),
3244
- getScrollResponder: () => refScroller.current.getScrollResponder(),
3245
- getState: () => ({
3246
- activeStickyIndex: state.activeStickyIndex,
3247
- contentLength: state.totalSize,
3248
- data: state.props.data,
3249
- elementAtIndex: (index) => {
3250
- var _a3;
3251
- return (_a3 = ctx.viewRefs.get(findContainerId(ctx, getId(state, index)))) == null ? void 0 : _a3.current;
3252
- },
3253
- end: state.endNoBuffer,
3254
- endBuffered: state.endBuffered,
3255
- isAtEnd: state.isAtEnd,
3256
- isAtStart: state.isAtStart,
3257
- positionAtIndex: (index) => state.positions.get(getId(state, index)),
3258
- positions: state.positions,
3259
- scroll: state.scroll,
3260
- scrollLength: state.scrollLength,
3261
- sizeAtIndex: (index) => state.sizesKnown.get(getId(state, index)),
3262
- sizes: state.sizesKnown,
3263
- start: state.startNoBuffer,
3264
- startBuffered: state.startBuffered
3265
- }),
3266
- scrollIndexIntoView,
3267
- scrollItemIntoView: ({ item, ...props }) => {
3268
- const data = state.props.data;
3269
- const index = data.indexOf(item);
3270
- if (index !== -1) {
3271
- scrollIndexIntoView({ index, ...props });
3272
- }
3273
- },
3274
- scrollToEnd: (options) => {
3275
- const data = state.props.data;
3276
- const stylePaddingBottom = state.props.stylePaddingBottom;
3277
- const index = data.length - 1;
3278
- if (index !== -1) {
3279
- const paddingBottom = stylePaddingBottom || 0;
3280
- const footerSize = peek$(ctx, "footerSize") || 0;
3281
- scrollToIndex(ctx, state, {
3282
- index,
3283
- viewOffset: -paddingBottom - footerSize + ((options == null ? void 0 : options.viewOffset) || 0),
3284
- viewPosition: 1,
3285
- ...options
3286
- });
3287
- }
3288
- },
3289
- scrollToIndex: (params) => scrollToIndex(ctx, state, params),
3290
- scrollToItem: ({ item, ...props }) => {
3291
- const data = state.props.data;
3292
- const index = data.indexOf(item);
3293
- if (index !== -1) {
3294
- scrollToIndex(ctx, state, { index, ...props });
3295
- }
3296
- },
3297
- scrollToOffset: (params) => scrollTo(ctx, state, params),
3298
- setScrollProcessingEnabled: (enabled) => {
3299
- state.scrollProcessingEnabled = enabled;
3300
- },
3301
- setVisibleContentAnchorOffset: (value) => {
3302
- const val = isFunction(value) ? value(peek$(ctx, "scrollAdjustUserOffset") || 0) : value;
3303
- set$(ctx, "scrollAdjustUserOffset", val);
3304
- }
3305
- };
3306
- }
3307
- function getRenderedItem(ctx, state, key) {
3308
- var _a3;
3309
- if (!state) {
3310
- return null;
3311
- }
3312
- const {
3313
- indexByKey,
3314
- props: { data, getItemType, renderItem }
3315
- } = state;
3316
- const index = indexByKey.get(key);
3317
- if (index === void 0) {
3318
- return null;
3319
- }
3320
- let renderedItem = null;
3321
- const extraData = peek$(ctx, "extraData");
3322
- const item = data[index];
3323
- if (renderItem && !isNullOrUndefined(item)) {
3324
- const itemProps = {
3325
- data,
3326
- extraData,
3327
- index,
3328
- item,
3329
- type: getItemType ? (_a3 = getItemType(item, index)) != null ? _a3 : "" : ""
3330
- };
3331
- renderedItem = isFunction(renderItem) ? renderItem(itemProps) : React3__namespace.default.createElement(renderItem, itemProps);
3332
- }
3333
- return { index, item: data[index], renderedItem };
3334
- }
3335
- function useThrottleDebounce(mode) {
3336
- const timeoutRef = React3.useRef(null);
3337
- const lastCallTimeRef = React3.useRef(0);
3338
- const lastArgsRef = React3.useRef(null);
3339
- const clearTimeoutRef = () => {
3340
- if (timeoutRef.current) {
3341
- clearTimeout(timeoutRef.current);
3342
- timeoutRef.current = null;
3343
- }
3344
- };
3345
- const execute = React3.useCallback(
3346
- (callback, delay, ...args) => {
3347
- {
3348
- const now = Date.now();
3349
- lastArgsRef.current = args;
3350
- if (now - lastCallTimeRef.current >= delay) {
3351
- lastCallTimeRef.current = now;
3352
- callback(...args);
3353
- clearTimeoutRef();
3354
- } else {
3355
- clearTimeoutRef();
3356
- timeoutRef.current = setTimeout(
3357
- () => {
3358
- if (lastArgsRef.current) {
3359
- lastCallTimeRef.current = Date.now();
3360
- callback(...lastArgsRef.current);
3361
- timeoutRef.current = null;
3362
- lastArgsRef.current = null;
3363
- }
3364
- },
3365
- delay - (now - lastCallTimeRef.current)
3366
- );
3367
- }
3368
- }
3369
- },
3370
- [mode]
3371
- );
3372
- return execute;
3373
- }
3374
-
3375
- // src/utils/throttledOnScroll.ts
3376
- function useThrottledOnScroll(originalHandler, scrollEventThrottle) {
3377
- const throttle = useThrottleDebounce("throttle");
3378
- return (event) => throttle(originalHandler, scrollEventThrottle, { nativeEvent: event.nativeEvent });
3379
- }
3380
-
3381
- // src/components/LegendList.tsx
3382
- var DEFAULT_DRAW_DISTANCE = 250;
3383
- var DEFAULT_ITEM_SIZE = 100;
3384
- var LegendList = typedMemo(
3385
- // biome-ignore lint/nursery/noShadow: const function name shadowing is intentional
3386
- typedForwardRef(function LegendList2(props, forwardedRef) {
3387
- const { children, data: dataProp, renderItem: renderItemProp, ...restProps } = props;
3388
- const isChildrenMode = children !== void 0 && dataProp === void 0;
3389
- const processedProps = isChildrenMode ? {
3390
- ...restProps,
3391
- childrenMode: true,
3392
- data: (isArray(children) ? children : React3__namespace.Children.toArray(children)).flat(1),
3393
- renderItem: ({ item }) => item
3394
- } : {
3395
- ...restProps,
3396
- data: dataProp || [],
3397
- renderItem: renderItemProp
3398
- };
3399
- return /* @__PURE__ */ React3__namespace.createElement(StateProvider, null, /* @__PURE__ */ React3__namespace.createElement(LegendListInner, { ...processedProps, ref: forwardedRef }));
3400
- })
3401
- );
3402
- var LegendListInner = typedForwardRef(function LegendListInner2(props, forwardedRef) {
3403
- var _a3, _b;
3404
- const {
3405
- alignItemsAtEnd = false,
3406
- columnWrapperStyle,
3407
- contentContainerStyle: contentContainerStyleProp,
3408
- data: dataProp = [],
3409
- dataVersion,
3410
- drawDistance = 250,
3411
- enableAverages = true,
3412
- estimatedItemSize: estimatedItemSizeProp,
3413
- estimatedListSize,
3414
- extraData,
3415
- getEstimatedItemSize,
3416
- getFixedItemSize,
3417
- getItemType,
3418
- horizontal,
3419
- initialContainerPoolRatio = 2,
3420
- initialScrollAtEnd = false,
3421
- initialScrollIndex: initialScrollIndexProp,
3422
- initialScrollOffset: initialScrollOffsetProp,
3423
- itemsAreEqual,
3424
- keyExtractor: keyExtractorProp,
3425
- ListEmptyComponent,
3426
- ListHeaderComponent,
3427
- maintainScrollAtEnd = false,
3428
- maintainScrollAtEndThreshold = 0.1,
3429
- maintainVisibleContentPosition = false,
3430
- numColumns: numColumnsProp = 1,
3431
- onEndReached,
3432
- onEndReachedThreshold = 0.5,
3433
- onItemSizeChanged,
3434
- onLayout: onLayoutProp,
3435
- onLoad,
3436
- onMomentumScrollEnd,
3437
- onRefresh,
3438
- onScroll: onScrollProp,
3439
- onStartReached,
3440
- onStartReachedThreshold = 0.5,
3441
- onStickyHeaderChange,
3442
- onViewableItemsChanged,
3443
- progressViewOffset,
3444
- recycleItems = false,
3445
- refreshControl,
3446
- refreshing,
3447
- refScrollView,
3448
- renderItem,
3449
- scrollEventThrottle,
3450
- snapToIndices,
3451
- stickyHeaderIndices: stickyHeaderIndicesProp,
3452
- stickyIndices: stickyIndicesDeprecated,
3453
- style: styleProp,
3454
- suggestEstimatedItemSize,
3455
- viewabilityConfig,
3456
- viewabilityConfigCallbackPairs,
3457
- waitForInitialLayout = true,
3458
- ...rest
3459
- } = props;
3460
- const { childrenMode } = rest;
3461
- const contentContainerStyle = { ...StyleSheet.flatten(contentContainerStyleProp) };
3462
- const style = { ...StyleSheet.flatten(styleProp) };
3463
- const stylePaddingTopState = extractPadding(style, contentContainerStyle, "Top");
3464
- const stylePaddingBottomState = extractPadding(style, contentContainerStyle, "Bottom");
3465
- const [renderNum, setRenderNum] = React3.useState(0);
3466
- const initialScrollProp = initialScrollAtEnd ? { index: Math.max(0, dataProp.length - 1), viewOffset: -stylePaddingBottomState } : initialScrollIndexProp || initialScrollOffsetProp ? typeof initialScrollIndexProp === "object" ? { index: initialScrollIndexProp.index || 0, viewOffset: initialScrollIndexProp.viewOffset || 0 } : { index: initialScrollIndexProp || 0, viewOffset: initialScrollOffsetProp || 0 } : void 0;
3467
- const [canRender, setCanRender] = React3__namespace.useState(!IsNewArchitecture);
3468
- const ctx = useStateContext();
3469
- ctx.columnWrapperStyle = columnWrapperStyle || (contentContainerStyle ? createColumnWrapperStyle(contentContainerStyle) : void 0);
3470
- const refScroller = React3.useRef(null);
3471
- const combinedRef = useCombinedRef(refScroller, refScrollView);
3472
- const estimatedItemSize = estimatedItemSizeProp != null ? estimatedItemSizeProp : DEFAULT_ITEM_SIZE;
3473
- const scrollBuffer = (drawDistance != null ? drawDistance : DEFAULT_DRAW_DISTANCE) || 1;
3474
- const keyExtractor = keyExtractorProp != null ? keyExtractorProp : (_item, index) => index.toString();
3475
- const stickyHeaderIndices = stickyHeaderIndicesProp != null ? stickyHeaderIndicesProp : stickyIndicesDeprecated;
3476
- if (IS_DEV && stickyIndicesDeprecated && !stickyHeaderIndicesProp) {
3477
- warnDevOnce(
3478
- "stickyIndices",
3479
- "stickyIndices has been renamed to stickyHeaderIndices. Please update your props to use stickyHeaderIndices."
3480
- );
3481
- }
3482
- const refState = React3.useRef();
3483
- if (!refState.current) {
3484
- if (!ctx.internalState) {
3485
- const initialScrollLength = (estimatedListSize != null ? estimatedListSize : { height: 0, width: 0 } )[horizontal ? "width" : "height"];
3486
- ctx.internalState = {
3487
- activeStickyIndex: void 0,
3488
- averageSizes: {},
3489
- columns: /* @__PURE__ */ new Map(),
3490
- containerItemKeys: /* @__PURE__ */ new Set(),
3491
- containerItemTypes: /* @__PURE__ */ new Map(),
3492
- dataChangeNeedsScrollUpdate: false,
3493
- didColumnsChange: false,
3494
- didDataChange: false,
3495
- enableScrollForNextCalculateItemsInView: true,
3496
- endBuffered: -1,
3497
- endNoBuffer: -1,
3498
- endReachedSnapshot: void 0,
3499
- firstFullyOnScreenIndex: -1,
3500
- idCache: [],
3501
- idsInView: [],
3502
- indexByKey: /* @__PURE__ */ new Map(),
3503
- initialAnchor: (initialScrollProp == null ? void 0 : initialScrollProp.index) !== void 0 && (initialScrollProp == null ? void 0 : initialScrollProp.viewPosition) !== void 0 ? {
3504
- attempts: 0,
3505
- index: initialScrollProp.index,
3506
- settledTicks: 0,
3507
- viewOffset: (_a3 = initialScrollProp.viewOffset) != null ? _a3 : 0,
3508
- viewPosition: initialScrollProp.viewPosition
3509
- } : void 0,
3510
- initialScroll: initialScrollProp,
3511
- isAtEnd: false,
3512
- isAtStart: false,
3513
- isEndReached: null,
3514
- isFirst: true,
3515
- isStartReached: null,
3516
- lastBatchingAction: Date.now(),
3517
- lastLayout: void 0,
3518
- loadStartTime: Date.now(),
3519
- minIndexSizeChanged: 0,
3520
- nativeMarginTop: 0,
3521
- positions: /* @__PURE__ */ new Map(),
3522
- props: {},
3523
- queuedCalculateItemsInView: 0,
3524
- refScroller: void 0,
3525
- scroll: 0,
3526
- scrollAdjustHandler: new ScrollAdjustHandler(ctx),
3527
- scrollForNextCalculateItemsInView: void 0,
3528
- scrollHistory: [],
3529
- scrollLength: initialScrollLength,
3530
- scrollPending: 0,
3531
- scrollPrev: 0,
3532
- scrollPrevTime: 0,
3533
- scrollProcessingEnabled: true,
3534
- scrollTime: 0,
3535
- sizes: /* @__PURE__ */ new Map(),
3536
- sizesKnown: /* @__PURE__ */ new Map(),
3537
- startBuffered: -1,
3538
- startNoBuffer: -1,
3539
- startReachedSnapshot: void 0,
3540
- stickyContainerPool: /* @__PURE__ */ new Set(),
3541
- stickyContainers: /* @__PURE__ */ new Map(),
3542
- timeoutSizeMessage: 0,
3543
- timeouts: /* @__PURE__ */ new Set(),
3544
- totalSize: 0,
3545
- viewabilityConfigCallbackPairs: void 0
3546
- };
3547
- const internalState = ctx.internalState;
3548
- internalState.triggerCalculateItemsInView = (params) => calculateItemsInView(ctx, internalState, params);
3549
- set$(ctx, "maintainVisibleContentPosition", maintainVisibleContentPosition);
3550
- set$(ctx, "extraData", extraData);
3551
- }
3552
- refState.current = ctx.internalState;
3553
- }
3554
- const state = refState.current;
3555
- const isFirstLocal = state.isFirst;
3556
- state.didColumnsChange = numColumnsProp !== state.props.numColumns;
3557
- const didDataChangeLocal = state.props.dataVersion !== dataVersion || state.props.data !== dataProp && checkActualChange(state, dataProp, state.props.data);
3558
- if (didDataChangeLocal) {
3559
- state.dataChangeNeedsScrollUpdate = true;
3560
- state.didDataChange = true;
3561
- state.previousData = state.props.data;
3562
- }
3563
- const throttleScrollFn = scrollEventThrottle && onScrollProp ? useThrottledOnScroll(onScrollProp, scrollEventThrottle) : onScrollProp;
3564
- state.props = {
3565
- alignItemsAtEnd,
3566
- data: dataProp,
3567
- dataVersion,
3568
- enableAverages,
3569
- estimatedItemSize,
3570
- getEstimatedItemSize,
3571
- getFixedItemSize,
3572
- getItemType,
3573
- horizontal: !!horizontal,
3574
- initialContainerPoolRatio,
3575
- itemsAreEqual,
3576
- keyExtractor,
3577
- maintainScrollAtEnd,
3578
- maintainScrollAtEndThreshold,
3579
- maintainVisibleContentPosition,
3580
- numColumns: numColumnsProp,
3581
- onEndReached,
3582
- onEndReachedThreshold,
3583
- onItemSizeChanged,
3584
- onLoad,
3585
- onScroll: throttleScrollFn,
3586
- onStartReached,
3587
- onStartReachedThreshold,
3588
- onStickyHeaderChange,
3589
- recycleItems: !!recycleItems,
3590
- renderItem,
3591
- scrollBuffer,
3592
- snapToIndices,
3593
- stickyIndicesArr: stickyHeaderIndices != null ? stickyHeaderIndices : [],
3594
- stickyIndicesSet: React3.useMemo(() => new Set(stickyHeaderIndices != null ? stickyHeaderIndices : []), [stickyHeaderIndices == null ? void 0 : stickyHeaderIndices.join(",")]),
3595
- stylePaddingBottom: stylePaddingBottomState,
3596
- stylePaddingTop: stylePaddingTopState,
3597
- suggestEstimatedItemSize: !!suggestEstimatedItemSize
3598
- };
3599
- state.refScroller = refScroller;
3600
- const memoizedLastItemKeys = React3.useMemo(() => {
3601
- if (!dataProp.length) return [];
3602
- return Array.from(
3603
- { length: Math.min(numColumnsProp, dataProp.length) },
3604
- (_, i) => getId(state, dataProp.length - 1 - i)
3605
- );
3606
- }, [dataProp, dataVersion, numColumnsProp]);
3607
- const initializeStateVars = () => {
3608
- set$(ctx, "lastItemKeys", memoizedLastItemKeys);
3609
- set$(ctx, "numColumns", numColumnsProp);
3610
- const prevPaddingTop = peek$(ctx, "stylePaddingTop");
3611
- setPaddingTop(ctx, state, { stylePaddingTop: stylePaddingTopState });
3612
- refState.current.props.stylePaddingBottom = stylePaddingBottomState;
3613
- let paddingDiff = stylePaddingTopState - prevPaddingTop;
3614
- if (paddingDiff && prevPaddingTop !== void 0 && Platform.OS === "ios") {
3615
- if (state.scroll < 0) {
3616
- paddingDiff += state.scroll;
3617
- }
3618
- requestAdjust(ctx, state, paddingDiff);
3619
- }
3620
- };
3621
- if (isFirstLocal) {
3622
- initializeStateVars();
3623
- updateItemPositions(
3624
- ctx,
3625
- state,
3626
- /*dataChanged*/
3627
- true
3628
- );
3629
- }
3630
- const initialContentOffset = React3.useMemo(() => {
3631
- var _a4, _b2;
3632
- const { initialScroll } = refState.current;
3633
- if (!initialScroll) {
3634
- refState.current.initialAnchor = void 0;
3635
- return 0;
3636
- }
3637
- if (initialScroll.index !== void 0 && (!refState.current.initialAnchor || ((_a4 = refState.current.initialAnchor) == null ? void 0 : _a4.index) !== initialScroll.index)) {
3638
- refState.current.initialAnchor = {
3639
- attempts: 0,
3640
- index: initialScroll.index,
3641
- settledTicks: 0,
3642
- viewOffset: (_b2 = initialScroll.viewOffset) != null ? _b2 : 0,
3643
- viewPosition: initialScroll.viewPosition
3644
- };
3645
- }
3646
- if (initialScroll.contentOffset !== void 0) {
3647
- return initialScroll.contentOffset;
3648
- }
3649
- const baseOffset = initialScroll.index !== void 0 ? calculateOffsetForIndex(ctx, state, initialScroll.index) : 0;
3650
- const resolvedOffset = calculateOffsetWithOffsetPosition(ctx, state, baseOffset, initialScroll);
3651
- let clampedOffset = resolvedOffset;
3652
- if (Number.isFinite(state.scrollLength) && Number.isFinite(state.totalSize)) {
3653
- const maxOffset = Math.max(0, state.totalSize - state.scrollLength);
3654
- clampedOffset = Math.min(clampedOffset, maxOffset);
3655
- }
3656
- clampedOffset = Math.max(0, clampedOffset);
3657
- const updatedInitialScroll = { ...initialScroll, contentOffset: clampedOffset };
3658
- refState.current.initialScroll = updatedInitialScroll;
3659
- state.initialScroll = updatedInitialScroll;
3660
- return clampedOffset;
3661
- }, [renderNum]);
3662
- if (isFirstLocal || didDataChangeLocal || numColumnsProp !== peek$(ctx, "numColumns")) {
3663
- refState.current.lastBatchingAction = Date.now();
3664
- if (!keyExtractorProp && !isFirstLocal && didDataChangeLocal) {
3665
- IS_DEV && !childrenMode && warnDevOnce(
3666
- "keyExtractor",
3667
- "Changing data without a keyExtractor can cause slow performance and resetting scroll. If your list data can change you should use a keyExtractor with a unique id for best performance and behavior."
3668
- );
3669
- refState.current.sizes.clear();
3670
- refState.current.positions.clear();
3671
- refState.current.totalSize = 0;
3672
- set$(ctx, "totalSize", 0);
3673
- }
3674
- }
3675
- const onLayoutHeader = React3.useCallback((rect, fromLayoutEffect) => {
3676
- const { initialScroll } = refState.current;
3677
- const size = rect[horizontal ? "width" : "height"];
3678
- set$(ctx, "headerSize", size);
3679
- if ((initialScroll == null ? void 0 : initialScroll.index) !== void 0) {
3680
- {
3681
- if (fromLayoutEffect) {
3682
- setRenderNum((v) => v + 1);
3683
- }
3684
- }
3685
- }
3686
- }, []);
3687
- const doInitialScroll = React3.useCallback(() => {
3688
- var _a4;
3689
- const initialScroll = state.initialScroll;
3690
- if (initialScroll) {
3691
- scrollTo(ctx, state, {
3692
- animated: false,
3693
- index: (_a4 = state.initialScroll) == null ? void 0 : _a4.index,
3694
- isInitialScroll: true,
3695
- offset: initialContentOffset,
3696
- precomputedWithViewOffset: true
3697
- });
3698
- {
3699
- const unlisten = listen$(ctx, "containersDidLayout", (value) => {
3700
- if (value && peek$(ctx, "scrollingTo")) {
3701
- finishScrollTo(ctx, state);
3702
- unlisten();
3703
- }
3704
- });
3705
- }
3706
- }
3707
- }, [initialContentOffset]);
3708
- const onLayoutChange = React3.useCallback((layout) => {
3709
- doInitialScroll();
3710
- handleLayout(ctx, state, layout, setCanRender);
3711
- }, []);
3712
- const { onLayout } = useOnLayoutSync({
3713
- onLayoutChange,
3714
- onLayoutProp,
3715
- ref: refScroller
3716
- // the type of ScrollView doesn't include measure?
3717
- });
3718
- React3.useLayoutEffect(() => {
3719
- if (snapToIndices) {
3720
- updateSnapToOffsets(ctx, state);
3721
- }
3722
- }, [snapToIndices]);
3723
- React3.useLayoutEffect(() => {
3724
- const {
3725
- didColumnsChange,
3726
- didDataChange,
3727
- isFirst,
3728
- props: { data }
3729
- } = state;
3730
- const didAllocateContainers = data.length > 0 && doInitialAllocateContainers(ctx, state);
3731
- if (!didAllocateContainers && !isFirst && (didDataChange || didColumnsChange)) {
3732
- checkResetContainers(ctx, state, data);
3733
- }
3734
- state.didColumnsChange = false;
3735
- state.didDataChange = false;
3736
- state.isFirst = false;
3737
- }, [dataProp, dataVersion, numColumnsProp]);
3738
- React3.useLayoutEffect(() => {
3739
- set$(ctx, "extraData", extraData);
3740
- }, [extraData]);
3741
- React3.useLayoutEffect(initializeStateVars, [
3742
- dataVersion,
3743
- memoizedLastItemKeys.join(","),
3744
- numColumnsProp,
3745
- stylePaddingBottomState,
3746
- stylePaddingTopState
3747
- ]);
3748
- React3.useEffect(() => {
3749
- const viewability = setupViewability({
3750
- onViewableItemsChanged,
3751
- viewabilityConfig,
3752
- viewabilityConfigCallbackPairs
3753
- });
3754
- state.viewabilityConfigCallbackPairs = viewability;
3755
- state.enableScrollForNextCalculateItemsInView = !viewability;
3756
- }, [viewabilityConfig, viewabilityConfigCallbackPairs, onViewableItemsChanged]);
3757
- React3.useImperativeHandle(forwardedRef, () => createImperativeHandle(ctx, state), []);
3758
- {
3759
- React3.useEffect(doInitialScroll, []);
3760
- }
3761
- const fns = React3.useMemo(
3762
- () => ({
3763
- getRenderedItem: (key) => getRenderedItem(ctx, state, key),
3764
- onScroll: (event) => onScroll(ctx, state, event),
3765
- updateItemSize: (itemKey, sizeObj) => updateItemSize(ctx, state, itemKey, sizeObj)
3766
- }),
3767
- []
3768
- );
3769
- const onScrollHandler = useStickyScrollHandler(stickyHeaderIndices, horizontal, ctx, fns.onScroll);
3770
- return /* @__PURE__ */ React3__namespace.createElement(React3__namespace.Fragment, null, /* @__PURE__ */ React3__namespace.createElement(
3771
- ListComponent,
3772
- {
3773
- ...rest,
3774
- alignItemsAtEnd,
3775
- canRender,
3776
- contentContainerStyle,
3777
- getRenderedItem: fns.getRenderedItem,
3778
- horizontal,
3779
- initialContentOffset,
3780
- ListEmptyComponent: dataProp.length === 0 ? ListEmptyComponent : void 0,
3781
- ListHeaderComponent,
3782
- maintainVisibleContentPosition,
3783
- onLayout,
3784
- onLayoutHeader,
3785
- onMomentumScrollEnd: (event) => {
3786
- {
3787
- requestAnimationFrame(() => {
3788
- finishScrollTo(ctx, refState.current);
3789
- });
3790
- }
3791
- if (onMomentumScrollEnd) {
3792
- onMomentumScrollEnd(event);
3793
- }
3794
- },
3795
- onScroll: onScrollHandler,
3796
- recycleItems,
3797
- refreshControl: refreshControl ? stylePaddingTopState > 0 ? React3__namespace.cloneElement(refreshControl, {
3798
- progressViewOffset: (refreshControl.props.progressViewOffset || 0) + stylePaddingTopState
3799
- }) : refreshControl : onRefresh && /* @__PURE__ */ React3__namespace.createElement(
3800
- RefreshControl,
3801
- {
3802
- onRefresh,
3803
- progressViewOffset: (progressViewOffset || 0) + stylePaddingTopState,
3804
- refreshing: !!refreshing
3805
- }
3806
- ),
3807
- refScrollView: combinedRef,
3808
- scrollAdjustHandler: (_b = refState.current) == null ? void 0 : _b.scrollAdjustHandler,
3809
- scrollEventThrottle: 16 ,
3810
- snapToIndices,
3811
- stickyHeaderIndices,
3812
- style,
3813
- updateItemSize: fns.updateItemSize,
3814
- waitForInitialLayout
3815
- }
3816
- ), IS_DEV && ENABLE_DEBUG_VIEW && /* @__PURE__ */ React3__namespace.createElement(DebugView, { state: refState.current }));
3817
- });
3818
-
3819
- exports.LegendList = LegendList;
3820
- exports.useIsLastItem = useIsLastItem;
3821
- exports.useListScrollSize = useListScrollSize;
3822
- exports.useRecyclingEffect = useRecyclingEffect;
3823
- exports.useRecyclingState = useRecyclingState;
3824
- exports.useSyncLayout = useSyncLayout;
3825
- exports.useViewability = useViewability;
3826
- exports.useViewabilityAmount = useViewabilityAmount;