@legendapp/list 3.0.0-beta.17 → 3.0.0-beta.18

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