@legendapp/list 2.0.4 → 2.0.5

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 (4) hide show
  1. package/CHANGELOG.md +44 -0
  2. package/index.js +290 -280
  3. package/index.mjs +234 -224
  4. package/package.json +1 -1
package/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var React3 = require('react');
3
+ var React2 = require('react');
4
4
  var reactNative = require('react-native');
5
5
  var shim = require('use-sync-external-store/shim');
6
6
 
@@ -22,12 +22,12 @@ function _interopNamespace(e) {
22
22
  return Object.freeze(n);
23
23
  }
24
24
 
25
- var React3__namespace = /*#__PURE__*/_interopNamespace(React3);
25
+ var React2__namespace = /*#__PURE__*/_interopNamespace(React2);
26
26
 
27
27
  // src/components/LegendList.tsx
28
- var ContextState = React3__namespace.createContext(null);
28
+ var ContextState = React2__namespace.createContext(null);
29
29
  function StateProvider({ children }) {
30
- const [value] = React3__namespace.useState(() => ({
30
+ const [value] = React2__namespace.useState(() => ({
31
31
  animatedScrollY: new reactNative.Animated.Value(0),
32
32
  columnWrapperStyle: void 0,
33
33
  listeners: /* @__PURE__ */ new Map(),
@@ -45,10 +45,10 @@ function StateProvider({ children }) {
45
45
  ]),
46
46
  viewRefs: /* @__PURE__ */ new Map()
47
47
  }));
48
- return /* @__PURE__ */ React3__namespace.createElement(ContextState.Provider, { value }, children);
48
+ return /* @__PURE__ */ React2__namespace.createElement(ContextState.Provider, { value }, children);
49
49
  }
50
50
  function useStateContext() {
51
- return React3__namespace.useContext(ContextState);
51
+ return React2__namespace.useContext(ContextState);
52
52
  }
53
53
  function createSelectorFunctionsArr(ctx, signalNames) {
54
54
  let lastValues = [];
@@ -118,23 +118,23 @@ function getContentSize(ctx) {
118
118
  return headerSize + footerSize + totalSize + stylePaddingTop;
119
119
  }
120
120
  function useArr$(signalNames) {
121
- const ctx = React3__namespace.useContext(ContextState);
122
- const { subscribe, get } = React3__namespace.useMemo(() => createSelectorFunctionsArr(ctx, signalNames), [ctx, signalNames]);
121
+ const ctx = React2__namespace.useContext(ContextState);
122
+ const { subscribe, get } = React2__namespace.useMemo(() => createSelectorFunctionsArr(ctx, signalNames), [ctx, signalNames]);
123
123
  const value = shim.useSyncExternalStore(subscribe, get);
124
124
  return value;
125
125
  }
126
126
  function useSelector$(signalName, selector) {
127
- const ctx = React3__namespace.useContext(ContextState);
128
- const { subscribe, get } = React3__namespace.useMemo(() => createSelectorFunctionsArr(ctx, [signalName]), [ctx, signalName]);
127
+ const ctx = React2__namespace.useContext(ContextState);
128
+ const { subscribe, get } = React2__namespace.useMemo(() => createSelectorFunctionsArr(ctx, [signalName]), [ctx, signalName]);
129
129
  const value = shim.useSyncExternalStore(subscribe, () => selector(get()[0]));
130
130
  return value;
131
131
  }
132
132
 
133
133
  // src/components/DebugView.tsx
134
134
  var DebugRow = ({ children }) => {
135
- return /* @__PURE__ */ React3__namespace.createElement(reactNative.View, { style: { alignItems: "center", flexDirection: "row", justifyContent: "space-between" } }, children);
135
+ return /* @__PURE__ */ React2__namespace.createElement(reactNative.View, { style: { alignItems: "center", flexDirection: "row", justifyContent: "space-between" } }, children);
136
136
  };
137
- var DebugView = React3__namespace.memo(function DebugView2({ state }) {
137
+ var DebugView = React2__namespace.memo(function DebugView2({ state }) {
138
138
  const ctx = useStateContext();
139
139
  const [totalSize = 0, scrollAdjust = 0, rawScroll = 0, scroll = 0, _numContainers = 0, _numContainersPooled = 0] = useArr$([
140
140
  "totalSize",
@@ -145,11 +145,11 @@ var DebugView = React3__namespace.memo(function DebugView2({ state }) {
145
145
  "numContainersPooled"
146
146
  ]);
147
147
  const contentSize = getContentSize(ctx);
148
- const [, forceUpdate] = React3.useReducer((x) => x + 1, 0);
148
+ const [, forceUpdate] = React2.useReducer((x) => x + 1, 0);
149
149
  useInterval(() => {
150
150
  forceUpdate();
151
151
  }, 100);
152
- return /* @__PURE__ */ React3__namespace.createElement(
152
+ return /* @__PURE__ */ React2__namespace.createElement(
153
153
  reactNative.View,
154
154
  {
155
155
  pointerEvents: "none",
@@ -165,24 +165,24 @@ var DebugView = React3__namespace.memo(function DebugView2({ state }) {
165
165
  top: 0
166
166
  }
167
167
  },
168
- /* @__PURE__ */ React3__namespace.createElement(DebugRow, null, /* @__PURE__ */ React3__namespace.createElement(reactNative.Text, null, "TotalSize:"), /* @__PURE__ */ React3__namespace.createElement(reactNative.Text, null, totalSize.toFixed(2))),
169
- /* @__PURE__ */ React3__namespace.createElement(DebugRow, null, /* @__PURE__ */ React3__namespace.createElement(reactNative.Text, null, "ContentSize:"), /* @__PURE__ */ React3__namespace.createElement(reactNative.Text, null, contentSize.toFixed(2))),
170
- /* @__PURE__ */ React3__namespace.createElement(DebugRow, null, /* @__PURE__ */ React3__namespace.createElement(reactNative.Text, null, "At end:"), /* @__PURE__ */ React3__namespace.createElement(reactNative.Text, null, String(state.isAtEnd))),
171
- /* @__PURE__ */ React3__namespace.createElement(reactNative.Text, null),
172
- /* @__PURE__ */ React3__namespace.createElement(DebugRow, null, /* @__PURE__ */ React3__namespace.createElement(reactNative.Text, null, "ScrollAdjust:"), /* @__PURE__ */ React3__namespace.createElement(reactNative.Text, null, scrollAdjust.toFixed(2))),
173
- /* @__PURE__ */ React3__namespace.createElement(reactNative.Text, null),
174
- /* @__PURE__ */ React3__namespace.createElement(DebugRow, null, /* @__PURE__ */ React3__namespace.createElement(reactNative.Text, null, "RawScroll: "), /* @__PURE__ */ React3__namespace.createElement(reactNative.Text, null, rawScroll.toFixed(2))),
175
- /* @__PURE__ */ React3__namespace.createElement(DebugRow, null, /* @__PURE__ */ React3__namespace.createElement(reactNative.Text, null, "ComputedScroll: "), /* @__PURE__ */ React3__namespace.createElement(reactNative.Text, null, scroll.toFixed(2)))
168
+ /* @__PURE__ */ React2__namespace.createElement(DebugRow, null, /* @__PURE__ */ React2__namespace.createElement(reactNative.Text, null, "TotalSize:"), /* @__PURE__ */ React2__namespace.createElement(reactNative.Text, null, totalSize.toFixed(2))),
169
+ /* @__PURE__ */ React2__namespace.createElement(DebugRow, null, /* @__PURE__ */ React2__namespace.createElement(reactNative.Text, null, "ContentSize:"), /* @__PURE__ */ React2__namespace.createElement(reactNative.Text, null, contentSize.toFixed(2))),
170
+ /* @__PURE__ */ React2__namespace.createElement(DebugRow, null, /* @__PURE__ */ React2__namespace.createElement(reactNative.Text, null, "At end:"), /* @__PURE__ */ React2__namespace.createElement(reactNative.Text, null, String(state.isAtEnd))),
171
+ /* @__PURE__ */ React2__namespace.createElement(reactNative.Text, null),
172
+ /* @__PURE__ */ React2__namespace.createElement(DebugRow, null, /* @__PURE__ */ React2__namespace.createElement(reactNative.Text, null, "ScrollAdjust:"), /* @__PURE__ */ React2__namespace.createElement(reactNative.Text, null, scrollAdjust.toFixed(2))),
173
+ /* @__PURE__ */ React2__namespace.createElement(reactNative.Text, null),
174
+ /* @__PURE__ */ React2__namespace.createElement(DebugRow, null, /* @__PURE__ */ React2__namespace.createElement(reactNative.Text, null, "RawScroll: "), /* @__PURE__ */ React2__namespace.createElement(reactNative.Text, null, rawScroll.toFixed(2))),
175
+ /* @__PURE__ */ React2__namespace.createElement(DebugRow, null, /* @__PURE__ */ React2__namespace.createElement(reactNative.Text, null, "ComputedScroll: "), /* @__PURE__ */ React2__namespace.createElement(reactNative.Text, null, scroll.toFixed(2)))
176
176
  );
177
177
  });
178
178
  function useInterval(callback, delay) {
179
- React3.useEffect(() => {
179
+ React2.useEffect(() => {
180
180
  const interval = setInterval(callback, delay);
181
181
  return () => clearInterval(interval);
182
182
  }, [delay]);
183
183
  }
184
- var LeanViewComponent = React3__namespace.forwardRef((props, ref) => {
185
- return React3__namespace.createElement("RCTView", { ...props, ref });
184
+ var LeanViewComponent = React2__namespace.forwardRef((props, ref) => {
185
+ return React2__namespace.createElement("RCTView", { ...props, ref });
186
186
  });
187
187
  LeanViewComponent.displayName = "RCTView";
188
188
  var LeanView = reactNative.Platform.OS === "android" || reactNative.Platform.OS === "ios" ? LeanViewComponent : reactNative.View;
@@ -193,7 +193,7 @@ var ENABLE_DEVMODE = __DEV__ && false;
193
193
  var ENABLE_DEBUG_VIEW = __DEV__ && false;
194
194
  var IsNewArchitecture = global.nativeFabricUIManager != null;
195
195
  var useAnimatedValue = (initialValue) => {
196
- return React3.useRef(new reactNative.Animated.Value(initialValue)).current;
196
+ return React2.useRef(new reactNative.Animated.Value(initialValue)).current;
197
197
  };
198
198
 
199
199
  // src/hooks/useValue$.ts
@@ -202,7 +202,7 @@ function useValue$(key, params) {
202
202
  const { getValue, delay } = params || {};
203
203
  const ctx = useStateContext();
204
204
  const animValue = useAnimatedValue((_a = getValue ? getValue(peek$(ctx, key)) : peek$(ctx, key)) != null ? _a : 0);
205
- React3.useMemo(() => {
205
+ React2.useMemo(() => {
206
206
  let newValue;
207
207
  let prevValue;
208
208
  let didQueueTask = false;
@@ -232,8 +232,8 @@ function useValue$(key, params) {
232
232
  }, []);
233
233
  return animValue;
234
234
  }
235
- var typedForwardRef = React3.forwardRef;
236
- var typedMemo = React3.memo;
235
+ var typedForwardRef = React2.forwardRef;
236
+ var typedMemo = React2.memo;
237
237
 
238
238
  // src/components/PositionView.tsx
239
239
  var PositionViewState = typedMemo(function PositionView({
@@ -244,7 +244,7 @@ var PositionViewState = typedMemo(function PositionView({
244
244
  ...rest
245
245
  }) {
246
246
  const [position = POSITION_OUT_OF_VIEW] = useArr$([`containerPosition${id}`]);
247
- return /* @__PURE__ */ React3__namespace.createElement(
247
+ return /* @__PURE__ */ React2__namespace.createElement(
248
248
  LeanView,
249
249
  {
250
250
  ref: refView,
@@ -266,7 +266,7 @@ var PositionViewAnimated = typedMemo(function PositionView2({
266
266
  const position$ = useValue$(`containerPosition${id}`, {
267
267
  getValue: (v) => v != null ? v : POSITION_OUT_OF_VIEW
268
268
  });
269
- return /* @__PURE__ */ React3__namespace.createElement(
269
+ return /* @__PURE__ */ React2__namespace.createElement(
270
270
  reactNative.Animated.View,
271
271
  {
272
272
  ref: refView,
@@ -289,7 +289,7 @@ var PositionViewSticky = typedMemo(function PositionViewSticky2({
289
289
  ...rest
290
290
  }) {
291
291
  const [position = POSITION_OUT_OF_VIEW, headerSize] = useArr$([`containerPosition${id}`, "headerSize"]);
292
- const transform = React3__namespace.useMemo(() => {
292
+ const transform = React2__namespace.useMemo(() => {
293
293
  if (animatedScrollY && stickyOffset) {
294
294
  const stickyPosition = animatedScrollY.interpolate({
295
295
  extrapolate: "clamp",
@@ -299,18 +299,13 @@ var PositionViewSticky = typedMemo(function PositionViewSticky2({
299
299
  return horizontal ? [{ translateX: stickyPosition }] : [{ translateY: stickyPosition }];
300
300
  }
301
301
  }, [animatedScrollY, headerSize, horizontal, stickyOffset, position]);
302
- const viewStyle = React3__namespace.useMemo(() => [style, { zIndex: index + 1e3 }, { transform }], [style, transform]);
303
- return /* @__PURE__ */ React3__namespace.createElement(reactNative.Animated.View, { ref: refView, style: viewStyle, ...rest });
302
+ const viewStyle = React2__namespace.useMemo(() => [style, { zIndex: index + 1e3 }, { transform }], [style, transform]);
303
+ return /* @__PURE__ */ React2__namespace.createElement(reactNative.Animated.View, { ref: refView, style: viewStyle, ...rest });
304
304
  });
305
305
  var PositionView3 = IsNewArchitecture ? PositionViewState : PositionViewAnimated;
306
- function Separator({ ItemSeparatorComponent, itemKey, leadingItem }) {
307
- const [lastItemKeys] = useArr$(["lastItemKeys"]);
308
- const isALastItem = lastItemKeys.includes(itemKey);
309
- return isALastItem ? null : /* @__PURE__ */ React3__namespace.createElement(ItemSeparatorComponent, { leadingItem });
310
- }
311
306
  var symbolFirst = Symbol();
312
307
  function useInit(cb) {
313
- const refValue = React3.useRef(symbolFirst);
308
+ const refValue = React2.useRef(symbolFirst);
314
309
  if (refValue.current === symbolFirst) {
315
310
  refValue.current = cb();
316
311
  }
@@ -349,10 +344,10 @@ function extractPadding(style, contentContainerStyle, type) {
349
344
  }
350
345
 
351
346
  // src/state/ContextContainer.ts
352
- var ContextContainer = React3.createContext(null);
347
+ var ContextContainer = React2.createContext(null);
353
348
  function useViewability(callback, configId) {
354
349
  const ctx = useStateContext();
355
- const { containerId } = React3.useContext(ContextContainer);
350
+ const { containerId } = React2.useContext(ContextContainer);
356
351
  const key = containerId + (configId != null ? configId : "");
357
352
  useInit(() => {
358
353
  const value = ctx.mapViewabilityValues.get(key);
@@ -361,7 +356,7 @@ function useViewability(callback, configId) {
361
356
  }
362
357
  });
363
358
  ctx.mapViewabilityCallbacks.set(key, callback);
364
- React3.useEffect(
359
+ React2.useEffect(
365
360
  () => () => {
366
361
  ctx.mapViewabilityCallbacks.delete(key);
367
362
  },
@@ -370,7 +365,7 @@ function useViewability(callback, configId) {
370
365
  }
371
366
  function useViewabilityAmount(callback) {
372
367
  const ctx = useStateContext();
373
- const { containerId } = React3.useContext(ContextContainer);
368
+ const { containerId } = React2.useContext(ContextContainer);
374
369
  useInit(() => {
375
370
  const value = ctx.mapViewabilityAmountValues.get(containerId);
376
371
  if (value) {
@@ -378,7 +373,7 @@ function useViewabilityAmount(callback) {
378
373
  }
379
374
  });
380
375
  ctx.mapViewabilityAmountCallbacks.set(containerId, callback);
381
- React3.useEffect(
376
+ React2.useEffect(
382
377
  () => () => {
383
378
  ctx.mapViewabilityAmountCallbacks.delete(containerId);
384
379
  },
@@ -386,12 +381,12 @@ function useViewabilityAmount(callback) {
386
381
  );
387
382
  }
388
383
  function useRecyclingEffect(effect) {
389
- const { index, value } = React3.useContext(ContextContainer);
390
- const prevValues = React3.useRef({
384
+ const { index, value } = React2.useContext(ContextContainer);
385
+ const prevValues = React2.useRef({
391
386
  prevIndex: void 0,
392
387
  prevItem: void 0
393
388
  });
394
- React3.useEffect(() => {
389
+ React2.useEffect(() => {
395
390
  let ret;
396
391
  if (prevValues.current.prevIndex !== void 0 && prevValues.current.prevItem !== void 0) {
397
392
  ret = effect({
@@ -409,12 +404,12 @@ function useRecyclingEffect(effect) {
409
404
  }, [index, value, effect]);
410
405
  }
411
406
  function useRecyclingState(valueOrFun) {
412
- const { index, value, itemKey, triggerLayout } = React3.useContext(ContextContainer);
413
- const refState = React3.useRef({
407
+ const { index, value, itemKey, triggerLayout } = React2.useContext(ContextContainer);
408
+ const refState = React2.useRef({
414
409
  itemKey: null,
415
410
  value: null
416
411
  });
417
- const [_, setRenderNum] = React3.useState(0);
412
+ const [_, setRenderNum] = React2.useState(0);
418
413
  const state = refState.current;
419
414
  if (state.itemKey !== itemKey) {
420
415
  state.itemKey = itemKey;
@@ -425,7 +420,7 @@ function useRecyclingState(valueOrFun) {
425
420
  prevItem: void 0
426
421
  }) : valueOrFun;
427
422
  }
428
- const setState = React3.useCallback(
423
+ const setState = React2.useCallback(
429
424
  (newState) => {
430
425
  state.value = isFunction(newState) ? newState(state.value) : newState;
431
426
  setRenderNum((v) => v + 1);
@@ -436,7 +431,7 @@ function useRecyclingState(valueOrFun) {
436
431
  return [state.value, setState];
437
432
  }
438
433
  function useIsLastItem() {
439
- const { itemKey } = React3.useContext(ContextContainer);
434
+ const { itemKey } = React2.useContext(ContextContainer);
440
435
  const isLast = useSelector$("lastItemKeys", (lastItemKeys) => (lastItemKeys == null ? void 0 : lastItemKeys.includes(itemKey)) || false);
441
436
  return isLast;
442
437
  }
@@ -448,13 +443,19 @@ var noop = () => {
448
443
  };
449
444
  function useSyncLayout() {
450
445
  if (IsNewArchitecture) {
451
- const { triggerLayout: syncLayout } = React3.useContext(ContextContainer);
446
+ const { triggerLayout: syncLayout } = React2.useContext(ContextContainer);
452
447
  return syncLayout;
453
448
  } else {
454
449
  return noop;
455
450
  }
456
451
  }
457
452
 
453
+ // src/components/Separator.tsx
454
+ function Separator({ ItemSeparatorComponent, leadingItem }) {
455
+ const isLastItem = useIsLastItem();
456
+ return isLastItem ? null : /* @__PURE__ */ React2__namespace.createElement(ItemSeparatorComponent, { leadingItem });
457
+ }
458
+
458
459
  // src/components/Container.tsx
459
460
  var Container = typedMemo(function Container2({
460
461
  id,
@@ -475,13 +476,13 @@ var Container = typedMemo(function Container2({
475
476
  `containerSticky${id}`,
476
477
  `containerStickyOffset${id}`
477
478
  ]);
478
- const refLastSize = React3.useRef();
479
- const ref = React3.useRef(null);
480
- const [layoutRenderCount, forceLayoutRender] = React3.useState(0);
479
+ const refLastSize = React2.useRef();
480
+ const ref = React2.useRef(null);
481
+ const [layoutRenderCount, forceLayoutRender] = React2.useState(0);
481
482
  const otherAxisPos = numColumns > 1 ? `${(column - 1) / numColumns * 100}%` : 0;
482
483
  const otherAxisSize = numColumns > 1 ? `${1 / numColumns * 100}%` : void 0;
483
484
  let didLayout = false;
484
- const style = React3.useMemo(() => {
485
+ const style = React2.useMemo(() => {
485
486
  let paddingStyles;
486
487
  if (columnWrapperStyle) {
487
488
  const { columnGap, rowGap, gap } = columnWrapperStyle;
@@ -513,12 +514,12 @@ var Container = typedMemo(function Container2({
513
514
  ...paddingStyles || {}
514
515
  };
515
516
  }, [horizontal, otherAxisPos, otherAxisSize, columnWrapperStyle, numColumns]);
516
- const renderedItemInfo = React3.useMemo(
517
+ const renderedItemInfo = React2.useMemo(
517
518
  () => itemKey !== void 0 ? getRenderedItem2(itemKey) : null,
518
519
  [itemKey, data, extraData]
519
520
  );
520
521
  const { index, renderedItem } = renderedItemInfo || {};
521
- const contextValue = React3.useMemo(() => {
522
+ const contextValue = React2.useMemo(() => {
522
523
  ctx.viewRefs.set(id, ref);
523
524
  return {
524
525
  containerId: id,
@@ -551,7 +552,7 @@ var Container = typedMemo(function Container2({
551
552
  }
552
553
  };
553
554
  if (IsNewArchitecture) {
554
- React3.useLayoutEffect(() => {
555
+ React2.useLayoutEffect(() => {
555
556
  var _a, _b;
556
557
  if (!isNullOrUndefined(itemKey)) {
557
558
  const measured = (_b = (_a = ref.current) == null ? void 0 : _a.unstable_getBoundingClientRect) == null ? void 0 : _b.call(_a);
@@ -564,7 +565,7 @@ var Container = typedMemo(function Container2({
564
565
  }
565
566
  }, [itemKey, layoutRenderCount]);
566
567
  } else {
567
- React3.useEffect(() => {
568
+ React2.useEffect(() => {
568
569
  if (!isNullOrUndefined(itemKey)) {
569
570
  const timeout = setTimeout(() => {
570
571
  if (!didLayout && refLastSize.current) {
@@ -578,7 +579,7 @@ var Container = typedMemo(function Container2({
578
579
  }, [itemKey]);
579
580
  }
580
581
  const PositionComponent = isSticky ? PositionViewSticky : PositionView3;
581
- return /* @__PURE__ */ React3__namespace.createElement(
582
+ return /* @__PURE__ */ React2__namespace.createElement(
582
583
  PositionComponent,
583
584
  {
584
585
  animatedScrollY: isSticky ? animatedScrollY : void 0,
@@ -591,14 +592,7 @@ var Container = typedMemo(function Container2({
591
592
  stickyOffset: isSticky ? stickyOffset : void 0,
592
593
  style
593
594
  },
594
- /* @__PURE__ */ React3__namespace.createElement(ContextContainer.Provider, { value: contextValue }, renderedItem, renderedItemInfo && ItemSeparatorComponent && /* @__PURE__ */ React3__namespace.createElement(
595
- Separator,
596
- {
597
- ItemSeparatorComponent,
598
- itemKey,
599
- leadingItem: renderedItemInfo.item
600
- }
601
- ))
595
+ /* @__PURE__ */ React2__namespace.createElement(ContextContainer.Provider, { value: contextValue }, renderedItem, renderedItemInfo && ItemSeparatorComponent && /* @__PURE__ */ React2__namespace.createElement(Separator, { ItemSeparatorComponent, leadingItem: renderedItemInfo.item }))
602
596
  );
603
597
  });
604
598
 
@@ -623,7 +617,7 @@ var Containers = typedMemo(function Containers2({
623
617
  const containers = [];
624
618
  for (let i = 0; i < numContainers; i++) {
625
619
  containers.push(
626
- /* @__PURE__ */ React3__namespace.createElement(
620
+ /* @__PURE__ */ React2__namespace.createElement(
627
621
  Container,
628
622
  {
629
623
  getRenderedItem: getRenderedItem2,
@@ -658,13 +652,13 @@ var Containers = typedMemo(function Containers2({
658
652
  }
659
653
  }
660
654
  }
661
- return /* @__PURE__ */ React3__namespace.createElement(reactNative.Animated.View, { style }, containers);
655
+ return /* @__PURE__ */ React2__namespace.createElement(reactNative.Animated.View, { style }, containers);
662
656
  });
663
657
  function ScrollAdjust() {
664
658
  const bias = 1e7;
665
659
  const [scrollAdjust, scrollAdjustUserOffset] = useArr$(["scrollAdjust", "scrollAdjustUserOffset"]);
666
660
  const scrollOffset = (scrollAdjust || 0) + (scrollAdjustUserOffset || 0) + bias;
667
- return /* @__PURE__ */ React3__namespace.createElement(
661
+ return /* @__PURE__ */ React2__namespace.createElement(
668
662
  reactNative.View,
669
663
  {
670
664
  style: {
@@ -677,23 +671,21 @@ function ScrollAdjust() {
677
671
  }
678
672
  );
679
673
  }
680
-
681
- // src/components/SnapWrapper.tsx
682
674
  function SnapWrapper({ ScrollComponent, ...props }) {
683
675
  const [snapToOffsets] = useArr$(["snapToOffsets"]);
684
- return /* @__PURE__ */ React.createElement(ScrollComponent, { ...props, snapToOffsets });
676
+ return /* @__PURE__ */ React2__namespace.default.createElement(ScrollComponent, { ...props, snapToOffsets });
685
677
  }
686
678
  function useThrottleDebounce(mode) {
687
- const timeoutRef = React3.useRef(null);
688
- const lastCallTimeRef = React3.useRef(0);
689
- const lastArgsRef = React3.useRef(null);
679
+ const timeoutRef = React2.useRef(null);
680
+ const lastCallTimeRef = React2.useRef(0);
681
+ const lastArgsRef = React2.useRef(null);
690
682
  const clearTimeoutRef = () => {
691
683
  if (timeoutRef.current) {
692
684
  clearTimeout(timeoutRef.current);
693
685
  timeoutRef.current = null;
694
686
  }
695
687
  };
696
- const execute = React3.useCallback(
688
+ const execute = React2.useCallback(
697
689
  (callback, delay, ...args) => {
698
690
  {
699
691
  const now = Date.now();
@@ -727,15 +719,15 @@ function useThrottleDebounce(mode) {
727
719
  function useSyncLayout2({
728
720
  onChange
729
721
  }) {
730
- const ref = React3.useRef(null);
731
- const onLayout = React3.useCallback(
722
+ const ref = React2.useRef(null);
723
+ const onLayout = React2.useCallback(
732
724
  (event) => {
733
725
  onChange(event.nativeEvent.layout, false);
734
726
  },
735
727
  [onChange]
736
728
  );
737
729
  if (IsNewArchitecture) {
738
- React3.useLayoutEffect(() => {
730
+ React2.useLayoutEffect(() => {
739
731
  if (ref.current) {
740
732
  ref.current.measure((x, y, width, height) => {
741
733
  onChange({ height, width, x, y }, true);
@@ -748,21 +740,21 @@ function useSyncLayout2({
748
740
 
749
741
  // src/components/ListComponent.tsx
750
742
  var getComponent = (Component) => {
751
- if (React3__namespace.isValidElement(Component)) {
743
+ if (React2__namespace.isValidElement(Component)) {
752
744
  return Component;
753
745
  }
754
746
  if (Component) {
755
- return /* @__PURE__ */ React3__namespace.createElement(Component, null);
747
+ return /* @__PURE__ */ React2__namespace.createElement(Component, null);
756
748
  }
757
749
  return null;
758
750
  };
759
751
  var Padding = () => {
760
752
  const animPaddingTop = useValue$("alignItemsPaddingTop", { delay: 0 });
761
- return /* @__PURE__ */ React3__namespace.createElement(reactNative.Animated.View, { style: { paddingTop: animPaddingTop } });
753
+ return /* @__PURE__ */ React2__namespace.createElement(reactNative.Animated.View, { style: { paddingTop: animPaddingTop } });
762
754
  };
763
755
  var PaddingDevMode = () => {
764
756
  const animPaddingTop = useValue$("alignItemsPaddingTop", { delay: 0 });
765
- return /* @__PURE__ */ React3__namespace.createElement(React3__namespace.Fragment, null, /* @__PURE__ */ React3__namespace.createElement(reactNative.Animated.View, { style: { paddingTop: animPaddingTop } }), /* @__PURE__ */ React3__namespace.createElement(
757
+ return /* @__PURE__ */ React2__namespace.createElement(React2__namespace.Fragment, null, /* @__PURE__ */ React2__namespace.createElement(reactNative.Animated.View, { style: { paddingTop: animPaddingTop } }), /* @__PURE__ */ React2__namespace.createElement(
766
758
  reactNative.Animated.View,
767
759
  {
768
760
  style: {
@@ -808,11 +800,11 @@ var ListComponent = typedMemo(function ListComponent2({
808
800
  const { onLayout: onLayoutHeaderSync, ref: refHeader } = useSyncLayout2({
809
801
  onChange: onLayoutHeader
810
802
  });
811
- const ScrollComponent = renderScrollComponent ? React3.useMemo(
812
- () => React3__namespace.forwardRef((props, ref) => renderScrollComponent({ ...props, ref })),
803
+ const ScrollComponent = renderScrollComponent ? React2.useMemo(
804
+ () => React2__namespace.forwardRef((props, ref) => renderScrollComponent({ ...props, ref })),
813
805
  [renderScrollComponent]
814
806
  ) : reactNative.Animated.ScrollView;
815
- React3__namespace.useEffect(() => {
807
+ React2__namespace.useEffect(() => {
816
808
  if (canRender) {
817
809
  setTimeout(() => {
818
810
  scrollAdjustHandler.setMounted();
@@ -820,7 +812,7 @@ var ListComponent = typedMemo(function ListComponent2({
820
812
  }
821
813
  }, [canRender]);
822
814
  const SnapOrScroll = snapToIndices ? SnapWrapper : ScrollComponent;
823
- return /* @__PURE__ */ React3__namespace.createElement(
815
+ return /* @__PURE__ */ React2__namespace.createElement(
824
816
  SnapOrScroll,
825
817
  {
826
818
  ...rest,
@@ -839,11 +831,11 @@ var ListComponent = typedMemo(function ListComponent2({
839
831
  ScrollComponent: snapToIndices ? ScrollComponent : void 0,
840
832
  style
841
833
  },
842
- maintainVisibleContentPosition && /* @__PURE__ */ React3__namespace.createElement(ScrollAdjust, null),
843
- ENABLE_DEVMODE ? /* @__PURE__ */ React3__namespace.createElement(PaddingDevMode, null) : /* @__PURE__ */ React3__namespace.createElement(Padding, null),
844
- ListHeaderComponent && /* @__PURE__ */ React3__namespace.createElement(reactNative.View, { onLayout: onLayoutHeaderSync, ref: refHeader, style: ListHeaderComponentStyle }, getComponent(ListHeaderComponent)),
834
+ maintainVisibleContentPosition && /* @__PURE__ */ React2__namespace.createElement(ScrollAdjust, null),
835
+ ENABLE_DEVMODE ? /* @__PURE__ */ React2__namespace.createElement(PaddingDevMode, null) : /* @__PURE__ */ React2__namespace.createElement(Padding, null),
836
+ ListHeaderComponent && /* @__PURE__ */ React2__namespace.createElement(reactNative.View, { onLayout: onLayoutHeaderSync, ref: refHeader, style: ListHeaderComponentStyle }, getComponent(ListHeaderComponent)),
845
837
  ListEmptyComponent && getComponent(ListEmptyComponent),
846
- canRender && /* @__PURE__ */ React3__namespace.createElement(
838
+ canRender && /* @__PURE__ */ React2__namespace.createElement(
847
839
  Containers,
848
840
  {
849
841
  getRenderedItem: getRenderedItem2,
@@ -854,7 +846,7 @@ var ListComponent = typedMemo(function ListComponent2({
854
846
  waitForInitialLayout
855
847
  }
856
848
  ),
857
- ListFooterComponent && /* @__PURE__ */ React3__namespace.createElement(
849
+ ListFooterComponent && /* @__PURE__ */ React2__namespace.createElement(
858
850
  reactNative.View,
859
851
  {
860
852
  onLayout: (event) => {
@@ -865,11 +857,11 @@ var ListComponent = typedMemo(function ListComponent2({
865
857
  },
866
858
  getComponent(ListFooterComponent)
867
859
  ),
868
- __DEV__ && ENABLE_DEVMODE && /* @__PURE__ */ React3__namespace.createElement(DevNumbers, null)
860
+ __DEV__ && ENABLE_DEVMODE && /* @__PURE__ */ React2__namespace.createElement(DevNumbers, null)
869
861
  );
870
862
  });
871
- var DevNumbers = __DEV__ && React3__namespace.memo(function DevNumbers2() {
872
- return Array.from({ length: 100 }).map((_, index) => /* @__PURE__ */ React3__namespace.createElement(
863
+ var DevNumbers = __DEV__ && React2__namespace.memo(function DevNumbers2() {
864
+ return Array.from({ length: 100 }).map((_, index) => /* @__PURE__ */ React2__namespace.createElement(
873
865
  reactNative.View,
874
866
  {
875
867
  key: index,
@@ -881,7 +873,7 @@ var DevNumbers = __DEV__ && React3__namespace.memo(function DevNumbers2() {
881
873
  width: "100%"
882
874
  }
883
875
  },
884
- /* @__PURE__ */ React3__namespace.createElement(reactNative.Text, { style: { color: "red" } }, index * 100)
876
+ /* @__PURE__ */ React2__namespace.createElement(reactNative.Text, { style: { color: "red" } }, index * 100)
885
877
  ));
886
878
  });
887
879
 
@@ -1160,12 +1152,14 @@ function updateTotalSize(ctx, state) {
1160
1152
  }
1161
1153
  function addTotalSize(ctx, state, key, add) {
1162
1154
  const { alignItemsAtEnd } = state.props;
1163
- {
1155
+ if (key === null) {
1164
1156
  state.totalSize = add;
1165
1157
  if (state.timeoutSetPaddingTop) {
1166
1158
  clearTimeout(state.timeoutSetPaddingTop);
1167
1159
  state.timeoutSetPaddingTop = void 0;
1168
1160
  }
1161
+ } else {
1162
+ state.totalSize += add;
1169
1163
  }
1170
1164
  set$(ctx, "totalSize", state.totalSize);
1171
1165
  if (alignItemsAtEnd) {
@@ -1188,8 +1182,8 @@ function updateSnapToOffsets(ctx, state) {
1188
1182
  set$(ctx, "snapToOffsets", snapToOffsets);
1189
1183
  }
1190
1184
 
1191
- // src/core/updateAllPositions.ts
1192
- function updateAllPositions(ctx, state, dataChanged, startIndex = 0) {
1185
+ // src/core/updateItemPositions.ts
1186
+ function updateItemPositions(ctx, state, dataChanged, { startIndex, scrollBottomBuffered } = { scrollBottomBuffered: -1, startIndex: 0 }) {
1193
1187
  var _a, _b, _c, _d, _e, _f;
1194
1188
  const {
1195
1189
  columns,
@@ -1202,6 +1196,7 @@ function updateAllPositions(ctx, state, dataChanged, startIndex = 0) {
1202
1196
  const data = state.props.data;
1203
1197
  const numColumns = peek$(ctx, "numColumns");
1204
1198
  const indexByKeyForChecking = __DEV__ ? /* @__PURE__ */ new Map() : void 0;
1199
+ const maxVisibleArea = scrollBottomBuffered + 1e3;
1205
1200
  const useAverageSize = enableAverages && !getEstimatedItemSize;
1206
1201
  let currentRowTop = 0;
1207
1202
  let column = 1;
@@ -1221,8 +1216,13 @@ function updateAllPositions(ctx, state, dataChanged, startIndex = 0) {
1221
1216
  }
1222
1217
  }
1223
1218
  const needsIndexByKey = dataChanged || indexByKey.size === 0;
1219
+ let didBreakEarly = false;
1224
1220
  const dataLength = data.length;
1225
1221
  for (let i = startIndex; i < dataLength; i++) {
1222
+ if (!dataChanged && currentRowTop > maxVisibleArea) {
1223
+ didBreakEarly = true;
1224
+ break;
1225
+ }
1226
1226
  const id = (_e = idCache.get(i)) != null ? _e : getId(state, i);
1227
1227
  const size = (_f = sizesKnown.get(id)) != null ? _f : getItemSize(state, id, i, data[i], useAverageSize);
1228
1228
  if (__DEV__ && needsIndexByKey) {
@@ -1252,7 +1252,9 @@ function updateAllPositions(ctx, state, dataChanged, startIndex = 0) {
1252
1252
  currentRowTop += size;
1253
1253
  }
1254
1254
  }
1255
- updateTotalSize(ctx, state);
1255
+ if (!didBreakEarly) {
1256
+ updateTotalSize(ctx, state);
1257
+ }
1256
1258
  if (snapToIndices) {
1257
1259
  updateSnapToOffsets(ctx, state);
1258
1260
  }
@@ -1802,7 +1804,7 @@ function handleStickyRecycling(ctx, state, stickyArray, scroll, scrollBuffer, pe
1802
1804
  }
1803
1805
  function calculateItemsInView(ctx, state, params = {}) {
1804
1806
  batchedUpdates(() => {
1805
- var _a, _b, _c, _d, _e, _f, _g, _h;
1807
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
1806
1808
  const {
1807
1809
  columns,
1808
1810
  containerItemKeys,
@@ -1831,20 +1833,6 @@ function calculateItemsInView(ctx, state, params = {}) {
1831
1833
  const previousScrollAdjust = 0;
1832
1834
  const { dataChanged, doMVCP } = params;
1833
1835
  const speed = getScrollVelocity(state);
1834
- if (doMVCP || dataChanged) {
1835
- const checkMVCP = doMVCP ? prepareMVCP(ctx, state, dataChanged) : void 0;
1836
- if (dataChanged) {
1837
- indexByKey.clear();
1838
- idCache.clear();
1839
- positions.clear();
1840
- }
1841
- const startIndex = dataChanged ? 0 : minIndexSizeChanged != null ? minIndexSizeChanged : 0;
1842
- updateAllPositions(ctx, state, dataChanged, startIndex);
1843
- if (minIndexSizeChanged !== void 0) {
1844
- state.minIndexSizeChanged = void 0;
1845
- }
1846
- checkMVCP == null ? void 0 : checkMVCP();
1847
- }
1848
1836
  const scrollExtra = 0;
1849
1837
  const { queuedInitialLayout } = state;
1850
1838
  let { scroll: scrollState } = state;
@@ -1883,6 +1871,18 @@ function calculateItemsInView(ctx, state, params = {}) {
1883
1871
  return;
1884
1872
  }
1885
1873
  }
1874
+ const checkMVCP = doMVCP ? prepareMVCP(ctx, state, dataChanged) : void 0;
1875
+ if (dataChanged) {
1876
+ indexByKey.clear();
1877
+ idCache.clear();
1878
+ positions.clear();
1879
+ }
1880
+ const startIndex = dataChanged ? 0 : (_a = minIndexSizeChanged != null ? minIndexSizeChanged : state.startBuffered) != null ? _a : 0;
1881
+ updateItemPositions(ctx, state, dataChanged, { scrollBottomBuffered, startIndex });
1882
+ if (minIndexSizeChanged !== void 0) {
1883
+ state.minIndexSizeChanged = void 0;
1884
+ }
1885
+ checkMVCP == null ? void 0 : checkMVCP();
1886
1886
  let startNoBuffer = null;
1887
1887
  let startBuffered = null;
1888
1888
  let startBufferedId = null;
@@ -1890,9 +1890,9 @@ function calculateItemsInView(ctx, state, params = {}) {
1890
1890
  let endBuffered = null;
1891
1891
  let loopStart = startBufferedIdOrig ? indexByKey.get(startBufferedIdOrig) || 0 : 0;
1892
1892
  for (let i = loopStart; i >= 0; i--) {
1893
- const id = (_a = idCache.get(i)) != null ? _a : getId(state, i);
1893
+ const id = (_b = idCache.get(i)) != null ? _b : getId(state, i);
1894
1894
  const top = positions.get(id);
1895
- const size = (_b = sizes.get(id)) != null ? _b : getItemSize(state, id, i, data[i]);
1895
+ const size = (_c = sizes.get(id)) != null ? _c : getItemSize(state, id, i, data[i]);
1896
1896
  const bottom = top + size;
1897
1897
  if (bottom > scroll - scrollBuffer) {
1898
1898
  loopStart = i;
@@ -1918,8 +1918,8 @@ function calculateItemsInView(ctx, state, params = {}) {
1918
1918
  let firstFullyOnScreenIndex;
1919
1919
  const dataLength = data.length;
1920
1920
  for (let i = Math.max(0, loopStart); i < dataLength && (!foundEnd || i <= maxIndexRendered); i++) {
1921
- const id = (_c = idCache.get(i)) != null ? _c : getId(state, i);
1922
- const size = (_d = sizes.get(id)) != null ? _d : getItemSize(state, id, i, data[i]);
1921
+ const id = (_d = idCache.get(i)) != null ? _d : getId(state, i);
1922
+ const size = (_e = sizes.get(id)) != null ? _e : getItemSize(state, id, i, data[i]);
1923
1923
  const top = positions.get(id);
1924
1924
  if (!foundEnd) {
1925
1925
  if (startNoBuffer === null && top + size > scroll) {
@@ -1948,7 +1948,7 @@ function calculateItemsInView(ctx, state, params = {}) {
1948
1948
  }
1949
1949
  const idsInView = [];
1950
1950
  for (let i = firstFullyOnScreenIndex; i <= endNoBuffer; i++) {
1951
- const id = (_e = idCache.get(i)) != null ? _e : getId(state, i);
1951
+ const id = (_f = idCache.get(i)) != null ? _f : getId(state, i);
1952
1952
  idsInView.push(id);
1953
1953
  }
1954
1954
  Object.assign(state, {
@@ -1980,7 +1980,7 @@ function calculateItemsInView(ctx, state, params = {}) {
1980
1980
  let numContainers2 = prevNumContainers;
1981
1981
  const needNewContainers = [];
1982
1982
  for (let i = startBuffered; i <= endBuffered; i++) {
1983
- const id = (_f = idCache.get(i)) != null ? _f : getId(state, i);
1983
+ const id = (_g = idCache.get(i)) != null ? _g : getId(state, i);
1984
1984
  if (!containerItemKeys.has(id)) {
1985
1985
  needNewContainers.push(i);
1986
1986
  }
@@ -2017,7 +2017,7 @@ function calculateItemsInView(ctx, state, params = {}) {
2017
2017
  for (let idx = 0; idx < needNewContainers.length; idx++) {
2018
2018
  const i = needNewContainers[idx];
2019
2019
  const containerIndex = availableContainers[idx];
2020
- const id = (_g = idCache.get(i)) != null ? _g : getId(state, i);
2020
+ const id = (_h = idCache.get(i)) != null ? _h : getId(state, i);
2021
2021
  const oldKey = peek$(ctx, `containerItemKey${containerIndex}`);
2022
2022
  if (oldKey && oldKey !== id) {
2023
2023
  containerItemKeys.delete(oldKey);
@@ -2072,7 +2072,7 @@ function calculateItemsInView(ctx, state, params = {}) {
2072
2072
  const itemIndex = indexByKey.get(itemKey);
2073
2073
  const item = data[itemIndex];
2074
2074
  if (item !== void 0) {
2075
- const id = (_h = idCache.get(itemIndex)) != null ? _h : getId(state, itemIndex);
2075
+ const id = (_i = idCache.get(itemIndex)) != null ? _i : getId(state, itemIndex);
2076
2076
  const position = positions.get(id);
2077
2077
  if (position === void 0) {
2078
2078
  set$(ctx, `containerPosition${i}`, POSITION_OUT_OF_VIEW);
@@ -2088,7 +2088,7 @@ function calculateItemsInView(ctx, state, params = {}) {
2088
2088
  set$(ctx, `containerColumn${i}`, column);
2089
2089
  }
2090
2090
  if (prevData !== item && (itemsAreEqual ? !itemsAreEqual(prevData, item, itemIndex, data) : true)) {
2091
- set$(ctx, `containerItemData${i}`, data[itemIndex]);
2091
+ set$(ctx, `containerItemData${i}`, item);
2092
2092
  }
2093
2093
  }
2094
2094
  }
@@ -2105,55 +2105,6 @@ function calculateItemsInView(ctx, state, params = {}) {
2105
2105
  });
2106
2106
  }
2107
2107
 
2108
- // src/core/doInitialAllocateContainers.ts
2109
- function doInitialAllocateContainers(ctx, state) {
2110
- var _a;
2111
- const {
2112
- scrollLength,
2113
- props: {
2114
- data,
2115
- getEstimatedItemSize,
2116
- getFixedItemSize,
2117
- getItemType,
2118
- scrollBuffer,
2119
- numColumns,
2120
- estimatedItemSize
2121
- }
2122
- } = state;
2123
- const hasContainers = peek$(ctx, "numContainers");
2124
- if (scrollLength > 0 && data.length > 0 && !hasContainers) {
2125
- let averageItemSize;
2126
- const fn = getFixedItemSize || getEstimatedItemSize;
2127
- if (fn) {
2128
- let totalSize = 0;
2129
- const num = Math.min(20, data.length);
2130
- for (let i = 0; i < num; i++) {
2131
- totalSize += fn(0, data[0], getItemType ? (_a = getItemType(data[0], 0)) != null ? _a : "" : "");
2132
- }
2133
- averageItemSize = totalSize / num;
2134
- } else {
2135
- averageItemSize = estimatedItemSize;
2136
- }
2137
- const numContainers = Math.ceil((scrollLength + scrollBuffer * 2) / averageItemSize * numColumns);
2138
- for (let i = 0; i < numContainers; i++) {
2139
- set$(ctx, `containerPosition${i}`, POSITION_OUT_OF_VIEW);
2140
- set$(ctx, `containerColumn${i}`, -1);
2141
- }
2142
- set$(ctx, "numContainers", numContainers);
2143
- set$(ctx, "numContainersPooled", numContainers * state.props.initialContainerPoolRatio);
2144
- if (!IsNewArchitecture || state.lastLayout) {
2145
- if (state.props.initialScroll) {
2146
- requestAnimationFrame(() => {
2147
- calculateItemsInView(ctx, state, { dataChanged: true });
2148
- });
2149
- } else {
2150
- calculateItemsInView(ctx, state, { dataChanged: true });
2151
- }
2152
- }
2153
- return true;
2154
- }
2155
- }
2156
-
2157
2108
  // src/core/doMaintainScrollAtEnd.ts
2158
2109
  function doMaintainScrollAtEnd(ctx, state, animated) {
2159
2110
  const {
@@ -2212,6 +2163,129 @@ function checkAtTop(state) {
2212
2163
  );
2213
2164
  }
2214
2165
 
2166
+ // src/utils/updateAveragesOnDataChange.ts
2167
+ function updateAveragesOnDataChange(state, oldData, newData) {
2168
+ var _a;
2169
+ const {
2170
+ averageSizes,
2171
+ sizesKnown,
2172
+ indexByKey,
2173
+ props: { itemsAreEqual, getItemType, keyExtractor }
2174
+ } = state;
2175
+ if (!itemsAreEqual || !oldData.length || !newData.length) {
2176
+ for (const key in averageSizes) {
2177
+ delete averageSizes[key];
2178
+ }
2179
+ return;
2180
+ }
2181
+ const itemTypesToPreserve = {};
2182
+ const newDataLength = newData.length;
2183
+ const oldDataLength = oldData.length;
2184
+ for (let newIndex = 0; newIndex < newDataLength; newIndex++) {
2185
+ const newItem = newData[newIndex];
2186
+ const id = keyExtractor ? keyExtractor(newItem, newIndex) : String(newIndex);
2187
+ const oldIndex = indexByKey.get(id);
2188
+ if (oldIndex !== void 0 && oldIndex < oldDataLength) {
2189
+ const knownSize = sizesKnown.get(id);
2190
+ if (knownSize === void 0) continue;
2191
+ const oldItem = oldData[oldIndex];
2192
+ const areEqual = itemsAreEqual(oldItem, newItem, newIndex, newData);
2193
+ if (areEqual) {
2194
+ const itemType = getItemType ? (_a = getItemType(newItem, newIndex)) != null ? _a : "" : "";
2195
+ let typeData = itemTypesToPreserve[itemType];
2196
+ if (!typeData) {
2197
+ typeData = itemTypesToPreserve[itemType] = { count: 0, totalSize: 0 };
2198
+ }
2199
+ typeData.totalSize += knownSize;
2200
+ typeData.count++;
2201
+ }
2202
+ }
2203
+ }
2204
+ for (const key in averageSizes) {
2205
+ delete averageSizes[key];
2206
+ }
2207
+ for (const itemType in itemTypesToPreserve) {
2208
+ const { totalSize, count } = itemTypesToPreserve[itemType];
2209
+ if (count > 0) {
2210
+ averageSizes[itemType] = {
2211
+ avg: totalSize / count,
2212
+ num: count
2213
+ };
2214
+ }
2215
+ }
2216
+ }
2217
+
2218
+ // src/core/checkResetContainers.ts
2219
+ function checkResetContainers(ctx, state, isFirst, dataProp) {
2220
+ if (state) {
2221
+ if (!isFirst && state.props.data !== dataProp) {
2222
+ updateAveragesOnDataChange(state, state.props.data, dataProp);
2223
+ }
2224
+ const { maintainScrollAtEnd } = state.props;
2225
+ if (!isFirst) {
2226
+ calculateItemsInView(ctx, state, { dataChanged: true, doMVCP: true });
2227
+ const shouldMaintainScrollAtEnd = maintainScrollAtEnd === true || maintainScrollAtEnd.onDataChange;
2228
+ const didMaintainScrollAtEnd = shouldMaintainScrollAtEnd && doMaintainScrollAtEnd(ctx, state, false);
2229
+ if (!didMaintainScrollAtEnd && dataProp.length > state.props.data.length) {
2230
+ state.isEndReached = false;
2231
+ }
2232
+ if (!didMaintainScrollAtEnd) {
2233
+ checkAtTop(state);
2234
+ checkAtBottom(ctx, state);
2235
+ }
2236
+ }
2237
+ }
2238
+ }
2239
+
2240
+ // src/core/doInitialAllocateContainers.ts
2241
+ function doInitialAllocateContainers(ctx, state) {
2242
+ var _a;
2243
+ const {
2244
+ scrollLength,
2245
+ props: {
2246
+ data,
2247
+ getEstimatedItemSize,
2248
+ getFixedItemSize,
2249
+ getItemType,
2250
+ scrollBuffer,
2251
+ numColumns,
2252
+ estimatedItemSize
2253
+ }
2254
+ } = state;
2255
+ const hasContainers = peek$(ctx, "numContainers");
2256
+ if (scrollLength > 0 && data.length > 0 && !hasContainers) {
2257
+ let averageItemSize;
2258
+ const fn = getFixedItemSize || getEstimatedItemSize;
2259
+ if (fn) {
2260
+ let totalSize = 0;
2261
+ const num = Math.min(20, data.length);
2262
+ for (let i = 0; i < num; i++) {
2263
+ totalSize += fn(0, data[0], getItemType ? (_a = getItemType(data[0], 0)) != null ? _a : "" : "");
2264
+ }
2265
+ averageItemSize = totalSize / num;
2266
+ } else {
2267
+ averageItemSize = estimatedItemSize;
2268
+ }
2269
+ const numContainers = Math.ceil((scrollLength + scrollBuffer * 2) / averageItemSize * numColumns);
2270
+ for (let i = 0; i < numContainers; i++) {
2271
+ set$(ctx, `containerPosition${i}`, POSITION_OUT_OF_VIEW);
2272
+ set$(ctx, `containerColumn${i}`, -1);
2273
+ }
2274
+ set$(ctx, "numContainers", numContainers);
2275
+ set$(ctx, "numContainersPooled", numContainers * state.props.initialContainerPoolRatio);
2276
+ if (!IsNewArchitecture || state.lastLayout) {
2277
+ if (state.props.initialScroll) {
2278
+ requestAnimationFrame(() => {
2279
+ calculateItemsInView(ctx, state, { dataChanged: true });
2280
+ });
2281
+ } else {
2282
+ calculateItemsInView(ctx, state, { dataChanged: true });
2283
+ }
2284
+ }
2285
+ return true;
2286
+ }
2287
+ }
2288
+
2215
2289
  // src/core/handleLayout.ts
2216
2290
  function handleLayout(ctx, state, layout, setCanRender) {
2217
2291
  const { maintainScrollAtEnd } = state.props;
@@ -2389,6 +2463,7 @@ function updateItemSize(ctx, state, itemKey, sizeObj) {
2389
2463
  if (prevSizeKnown !== void 0 && Math.abs(prevSizeKnown - size) > 5) {
2390
2464
  shouldMaintainScrollAtEnd = true;
2391
2465
  }
2466
+ addTotalSize(ctx, state, itemKey, diff);
2392
2467
  onItemSizeChanged == null ? void 0 : onItemSizeChanged({
2393
2468
  index,
2394
2469
  itemData: state.props.data[index],
@@ -2458,7 +2533,7 @@ function updateOneItemSize(state, itemKey, sizeObj) {
2458
2533
  return 0;
2459
2534
  }
2460
2535
  var useCombinedRef = (...refs) => {
2461
- const callback = React3.useCallback((element) => {
2536
+ const callback = React2.useCallback((element) => {
2462
2537
  for (const ref of refs) {
2463
2538
  if (!ref) {
2464
2539
  continue;
@@ -2509,7 +2584,7 @@ function getRenderedItem(ctx, state, key) {
2509
2584
  item: data[index],
2510
2585
  type: getItemType ? (_a = getItemType(data[index], index)) != null ? _a : "" : ""
2511
2586
  };
2512
- renderedItem = isFunction(renderItem) ? renderItem(itemProps) : React3__namespace.default.createElement(renderItem, itemProps);
2587
+ renderedItem = isFunction(renderItem) ? renderItem(itemProps) : React2__namespace.default.createElement(renderItem, itemProps);
2513
2588
  }
2514
2589
  return { index, item: data[index], renderedItem };
2515
2590
  }
@@ -2520,58 +2595,6 @@ function useThrottledOnScroll(originalHandler, scrollEventThrottle) {
2520
2595
  return (event) => throttle(originalHandler, scrollEventThrottle, { nativeEvent: event.nativeEvent });
2521
2596
  }
2522
2597
 
2523
- // src/utils/updateAveragesOnDataChange.ts
2524
- function updateAveragesOnDataChange(state, oldData, newData) {
2525
- var _a;
2526
- const {
2527
- averageSizes,
2528
- sizesKnown,
2529
- indexByKey,
2530
- props: { itemsAreEqual, getItemType, keyExtractor }
2531
- } = state;
2532
- if (!itemsAreEqual || !oldData.length || !newData.length) {
2533
- for (const key in averageSizes) {
2534
- delete averageSizes[key];
2535
- }
2536
- return;
2537
- }
2538
- const itemTypesToPreserve = {};
2539
- const newDataLength = newData.length;
2540
- const oldDataLength = oldData.length;
2541
- for (let newIndex = 0; newIndex < newDataLength; newIndex++) {
2542
- const newItem = newData[newIndex];
2543
- const id = keyExtractor ? keyExtractor(newItem, newIndex) : String(newIndex);
2544
- const oldIndex = indexByKey.get(id);
2545
- if (oldIndex !== void 0 && oldIndex < oldDataLength) {
2546
- const knownSize = sizesKnown.get(id);
2547
- if (knownSize === void 0) continue;
2548
- const oldItem = oldData[oldIndex];
2549
- const areEqual = itemsAreEqual(oldItem, newItem, newIndex, newData);
2550
- if (areEqual) {
2551
- const itemType = getItemType ? (_a = getItemType(newItem, newIndex)) != null ? _a : "" : "";
2552
- let typeData = itemTypesToPreserve[itemType];
2553
- if (!typeData) {
2554
- typeData = itemTypesToPreserve[itemType] = { count: 0, totalSize: 0 };
2555
- }
2556
- typeData.totalSize += knownSize;
2557
- typeData.count++;
2558
- }
2559
- }
2560
- }
2561
- for (const key in averageSizes) {
2562
- delete averageSizes[key];
2563
- }
2564
- for (const itemType in itemTypesToPreserve) {
2565
- const { totalSize, count } = itemTypesToPreserve[itemType];
2566
- if (count > 0) {
2567
- averageSizes[itemType] = {
2568
- avg: totalSize / count,
2569
- num: count
2570
- };
2571
- }
2572
- }
2573
- }
2574
-
2575
2598
  // src/components/LegendList.tsx
2576
2599
  var DEFAULT_DRAW_DISTANCE = 250;
2577
2600
  var DEFAULT_ITEM_SIZE = 100;
@@ -2581,14 +2604,14 @@ var LegendList = typedMemo(
2581
2604
  const isChildrenMode = children !== void 0 && dataProp === void 0;
2582
2605
  const processedProps = isChildrenMode ? {
2583
2606
  ...restProps,
2584
- data: (isArray(children) ? children : React3__namespace.Children.toArray(children)).flat(1),
2607
+ data: (isArray(children) ? children : React2__namespace.Children.toArray(children)).flat(1),
2585
2608
  renderItem: ({ item }) => item
2586
2609
  } : {
2587
2610
  ...restProps,
2588
2611
  data: dataProp || [],
2589
2612
  renderItem: renderItemProp
2590
2613
  };
2591
- return /* @__PURE__ */ React3__namespace.createElement(StateProvider, null, /* @__PURE__ */ React3__namespace.createElement(LegendListInner, { ...processedProps, ref: forwardedRef }));
2614
+ return /* @__PURE__ */ React2__namespace.createElement(StateProvider, null, /* @__PURE__ */ React2__namespace.createElement(LegendListInner, { ...processedProps, ref: forwardedRef }));
2592
2615
  })
2593
2616
  );
2594
2617
  var LegendListInner = typedForwardRef(function LegendListInner2(props, forwardedRef) {
@@ -2645,21 +2668,21 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
2645
2668
  waitForInitialLayout = true,
2646
2669
  ...rest
2647
2670
  } = props;
2648
- const [renderNum, setRenderNum] = React3.useState(0);
2671
+ const [renderNum, setRenderNum] = React2.useState(0);
2649
2672
  const initialScroll = initialScrollIndexProp || initialScrollOffsetProp ? typeof initialScrollIndexProp === "object" ? { index: initialScrollIndexProp.index || 0, viewOffset: initialScrollIndexProp.viewOffset || 0 } : { index: initialScrollIndexProp || 0, viewOffset: initialScrollOffsetProp || 0 } : void 0;
2650
- const [canRender, setCanRender] = React3__namespace.useState(!IsNewArchitecture);
2673
+ const [canRender, setCanRender] = React2__namespace.useState(!IsNewArchitecture);
2651
2674
  const contentContainerStyle = { ...reactNative.StyleSheet.flatten(contentContainerStyleProp) };
2652
2675
  const style = { ...reactNative.StyleSheet.flatten(styleProp) };
2653
2676
  const stylePaddingTopState = extractPadding(style, contentContainerStyle, "Top");
2654
2677
  const stylePaddingBottomState = extractPadding(style, contentContainerStyle, "Bottom");
2655
2678
  const ctx = useStateContext();
2656
2679
  ctx.columnWrapperStyle = columnWrapperStyle || (contentContainerStyle ? createColumnWrapperStyle(contentContainerStyle) : void 0);
2657
- const refScroller = React3.useRef(null);
2680
+ const refScroller = React2.useRef(null);
2658
2681
  const combinedRef = useCombinedRef(refScroller, refScrollView);
2659
2682
  const estimatedItemSize = estimatedItemSizeProp != null ? estimatedItemSizeProp : DEFAULT_ITEM_SIZE;
2660
2683
  const scrollBuffer = (drawDistance != null ? drawDistance : DEFAULT_DRAW_DISTANCE) || 1;
2661
2684
  const keyExtractor = keyExtractorProp != null ? keyExtractorProp : (_item, index) => index.toString();
2662
- const refState = React3.useRef();
2685
+ const refState = React2.useRef();
2663
2686
  if (!refState.current) {
2664
2687
  const initialScrollLength = (estimatedListSize != null ? estimatedListSize : IsNewArchitecture ? { height: 0, width: 0 } : reactNative.Dimensions.get("window"))[horizontal ? "width" : "height"];
2665
2688
  refState.current = {
@@ -2748,34 +2771,13 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
2748
2771
  scrollBuffer,
2749
2772
  snapToIndices,
2750
2773
  stickyIndicesArr: stickyIndices != null ? stickyIndices : [],
2751
- stickyIndicesSet: React3.useMemo(() => new Set(stickyIndices != null ? stickyIndices : []), [stickyIndices == null ? void 0 : stickyIndices.join(",")]),
2774
+ stickyIndicesSet: React2.useMemo(() => new Set(stickyIndices != null ? stickyIndices : []), [stickyIndices == null ? void 0 : stickyIndices.join(",")]),
2752
2775
  stylePaddingBottom: stylePaddingBottomState,
2753
2776
  stylePaddingTop: stylePaddingTopState,
2754
2777
  suggestEstimatedItemSize: !!suggestEstimatedItemSize
2755
2778
  };
2756
2779
  state.refScroller = refScroller;
2757
- const checkResetContainers = (isFirst2) => {
2758
- const state2 = refState.current;
2759
- if (state2) {
2760
- if (!isFirst2 && state2.props.data !== dataProp) {
2761
- updateAveragesOnDataChange(state2, state2.props.data, dataProp);
2762
- }
2763
- state2.props.data = dataProp;
2764
- if (!isFirst2) {
2765
- calculateItemsInView(ctx, state2, { dataChanged: true, doMVCP: true });
2766
- const shouldMaintainScrollAtEnd = maintainScrollAtEnd === true || maintainScrollAtEnd.onDataChange;
2767
- const didMaintainScrollAtEnd = shouldMaintainScrollAtEnd && doMaintainScrollAtEnd(ctx, state2, false);
2768
- if (!didMaintainScrollAtEnd && dataProp.length > state2.props.data.length) {
2769
- state2.isEndReached = false;
2770
- }
2771
- if (!didMaintainScrollAtEnd) {
2772
- checkAtTop(state2);
2773
- checkAtBottom(ctx, state2);
2774
- }
2775
- }
2776
- }
2777
- };
2778
- const memoizedLastItemKeys = React3.useMemo(() => {
2780
+ const memoizedLastItemKeys = React2.useMemo(() => {
2779
2781
  if (!dataProp.length) return [];
2780
2782
  return Array.from(
2781
2783
  { length: Math.min(numColumnsProp, dataProp.length) },
@@ -2798,9 +2800,14 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
2798
2800
  };
2799
2801
  if (isFirst) {
2800
2802
  initializeStateVars();
2801
- updateAllPositions(ctx, state);
2803
+ updateItemPositions(
2804
+ ctx,
2805
+ state,
2806
+ /*dataChanged*/
2807
+ true
2808
+ );
2802
2809
  }
2803
- const initialContentOffset = React3.useMemo(() => {
2810
+ const initialContentOffset = React2.useMemo(() => {
2804
2811
  if (initialScroll) {
2805
2812
  const { index, viewOffset } = initialScroll;
2806
2813
  let initialContentOffset2 = viewOffset || 0;
@@ -2826,7 +2833,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
2826
2833
  refState.current.positions.clear();
2827
2834
  }
2828
2835
  }
2829
- const onLayoutHeader = React3.useCallback((rect, fromLayoutEffect) => {
2836
+ const onLayoutHeader = React2.useCallback((rect, fromLayoutEffect) => {
2830
2837
  const size = rect[horizontal ? "width" : "height"];
2831
2838
  set$(ctx, "headerSize", size);
2832
2839
  if ((initialScroll == null ? void 0 : initialScroll.index) !== void 0) {
@@ -2841,24 +2848,27 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
2841
2848
  }
2842
2849
  }
2843
2850
  }, []);
2844
- React3.useLayoutEffect(() => {
2851
+ React2.useLayoutEffect(() => {
2845
2852
  if (snapToIndices) {
2846
2853
  updateSnapToOffsets(ctx, state);
2847
2854
  }
2848
2855
  }, [snapToIndices]);
2849
- React3.useLayoutEffect(() => {
2856
+ React2.useLayoutEffect(() => {
2850
2857
  const didAllocateContainers = dataProp.length > 0 && doInitialAllocateContainersCallback();
2851
2858
  if (!didAllocateContainers) {
2852
2859
  checkResetContainers(
2860
+ ctx,
2861
+ state,
2853
2862
  /*isFirst*/
2854
- isFirst
2863
+ isFirst,
2864
+ dataProp
2855
2865
  );
2856
2866
  }
2857
2867
  }, [dataProp, numColumnsProp]);
2858
- React3.useLayoutEffect(() => {
2868
+ React2.useLayoutEffect(() => {
2859
2869
  set$(ctx, "extraData", extraData);
2860
2870
  }, [extraData]);
2861
- React3.useLayoutEffect(() => {
2871
+ React2.useLayoutEffect(() => {
2862
2872
  var _a2;
2863
2873
  if (IsNewArchitecture) {
2864
2874
  let measured;
@@ -2873,7 +2883,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
2873
2883
  }
2874
2884
  }
2875
2885
  }, []);
2876
- React3.useLayoutEffect(initializeStateVars, [
2886
+ React2.useLayoutEffect(initializeStateVars, [
2877
2887
  memoizedLastItemKeys.join(","),
2878
2888
  numColumnsProp,
2879
2889
  stylePaddingTopState,
@@ -2882,7 +2892,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
2882
2892
  const doInitialAllocateContainersCallback = () => {
2883
2893
  return doInitialAllocateContainers(ctx, state);
2884
2894
  };
2885
- React3.useEffect(() => {
2895
+ React2.useEffect(() => {
2886
2896
  const viewability = setupViewability({
2887
2897
  onViewableItemsChanged,
2888
2898
  viewabilityConfig,
@@ -2896,14 +2906,14 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
2896
2906
  doInitialAllocateContainersCallback();
2897
2907
  });
2898
2908
  }
2899
- const onLayout = React3.useCallback((event) => {
2909
+ const onLayout = React2.useCallback((event) => {
2900
2910
  const layout = event.nativeEvent.layout;
2901
2911
  handleLayout(ctx, state, layout, setCanRender);
2902
2912
  if (onLayoutProp) {
2903
2913
  onLayoutProp(event);
2904
2914
  }
2905
2915
  }, []);
2906
- React3.useImperativeHandle(forwardedRef, () => {
2916
+ React2.useImperativeHandle(forwardedRef, () => {
2907
2917
  const scrollIndexIntoView = (options) => {
2908
2918
  const state2 = refState.current;
2909
2919
  if (state2) {
@@ -2986,13 +2996,13 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
2986
2996
  };
2987
2997
  }, []);
2988
2998
  if (reactNative.Platform.OS === "web") {
2989
- React3.useEffect(() => {
2999
+ React2.useEffect(() => {
2990
3000
  if (initialContentOffset) {
2991
3001
  scrollTo(state, { animated: false, offset: initialContentOffset });
2992
3002
  }
2993
3003
  }, []);
2994
3004
  }
2995
- const fns = React3.useMemo(
3005
+ const fns = React2.useMemo(
2996
3006
  () => ({
2997
3007
  getRenderedItem: (key) => getRenderedItem(ctx, state, key),
2998
3008
  onScroll: (event) => onScroll(ctx, state, event),
@@ -3000,7 +3010,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
3000
3010
  }),
3001
3011
  []
3002
3012
  );
3003
- const onScrollHandler = React3.useMemo(() => {
3013
+ const onScrollHandler = React2.useMemo(() => {
3004
3014
  const onScrollFn = fns.onScroll;
3005
3015
  if (stickyIndices == null ? void 0 : stickyIndices.length) {
3006
3016
  const { animatedScrollY } = ctx;
@@ -3011,7 +3021,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
3011
3021
  }
3012
3022
  return onScrollFn;
3013
3023
  }, [stickyIndices == null ? void 0 : stickyIndices.length, horizontal, scrollEventThrottle]);
3014
- return /* @__PURE__ */ React3__namespace.createElement(React3__namespace.Fragment, null, /* @__PURE__ */ React3__namespace.createElement(
3024
+ return /* @__PURE__ */ React2__namespace.createElement(React2__namespace.Fragment, null, /* @__PURE__ */ React2__namespace.createElement(
3015
3025
  ListComponent,
3016
3026
  {
3017
3027
  ...rest,
@@ -3042,9 +3052,9 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
3042
3052
  },
3043
3053
  onScroll: onScrollHandler,
3044
3054
  recycleItems,
3045
- refreshControl: refreshControl ? stylePaddingTopState > 0 ? React3__namespace.cloneElement(refreshControl, {
3055
+ refreshControl: refreshControl ? stylePaddingTopState > 0 ? React2__namespace.cloneElement(refreshControl, {
3046
3056
  progressViewOffset: (refreshControl.props.progressViewOffset || 0) + stylePaddingTopState
3047
- }) : refreshControl : onRefresh && /* @__PURE__ */ React3__namespace.createElement(
3057
+ }) : refreshControl : onRefresh && /* @__PURE__ */ React2__namespace.createElement(
3048
3058
  reactNative.RefreshControl,
3049
3059
  {
3050
3060
  onRefresh,
@@ -3061,7 +3071,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
3061
3071
  updateItemSize: fns.updateItemSize,
3062
3072
  waitForInitialLayout
3063
3073
  }
3064
- ), __DEV__ && ENABLE_DEBUG_VIEW && /* @__PURE__ */ React3__namespace.createElement(DebugView, { state: refState.current }));
3074
+ ), __DEV__ && ENABLE_DEBUG_VIEW && /* @__PURE__ */ React2__namespace.createElement(DebugView, { state: refState.current }));
3065
3075
  });
3066
3076
 
3067
3077
  exports.LegendList = LegendList;