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

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