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