@legendapp/list 3.0.0-beta.9 → 3.0.0

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