@legendapp/list 3.0.0-beta.2 → 3.0.0-beta.21

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