@legendapp/list 2.0.4 → 2.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/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,17 @@ function updateAllPositions(ctx, state, dataChanged, startIndex = 0) {
1221
1216
  }
1222
1217
  }
1223
1218
  const needsIndexByKey = dataChanged || indexByKey.size === 0;
1219
+ let didBreakEarly = false;
1220
+ let breakAt;
1224
1221
  const dataLength = data.length;
1225
1222
  for (let i = startIndex; i < dataLength; i++) {
1223
+ if (breakAt && i > breakAt) {
1224
+ didBreakEarly = true;
1225
+ break;
1226
+ }
1227
+ if (!dataChanged && currentRowTop > maxVisibleArea) {
1228
+ breakAt = i + 10;
1229
+ }
1226
1230
  const id = (_e = idCache.get(i)) != null ? _e : getId(state, i);
1227
1231
  const size = (_f = sizesKnown.get(id)) != null ? _f : getItemSize(state, id, i, data[i], useAverageSize);
1228
1232
  if (__DEV__ && needsIndexByKey) {
@@ -1252,7 +1256,9 @@ function updateAllPositions(ctx, state, dataChanged, startIndex = 0) {
1252
1256
  currentRowTop += size;
1253
1257
  }
1254
1258
  }
1255
- updateTotalSize(ctx, state);
1259
+ if (!didBreakEarly) {
1260
+ updateTotalSize(ctx, state);
1261
+ }
1256
1262
  if (snapToIndices) {
1257
1263
  updateSnapToOffsets(ctx, state);
1258
1264
  }
@@ -1802,7 +1808,7 @@ function handleStickyRecycling(ctx, state, stickyArray, scroll, scrollBuffer, pe
1802
1808
  }
1803
1809
  function calculateItemsInView(ctx, state, params = {}) {
1804
1810
  batchedUpdates(() => {
1805
- var _a, _b, _c, _d, _e, _f, _g, _h;
1811
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
1806
1812
  const {
1807
1813
  columns,
1808
1814
  containerItemKeys,
@@ -1831,20 +1837,6 @@ function calculateItemsInView(ctx, state, params = {}) {
1831
1837
  const previousScrollAdjust = 0;
1832
1838
  const { dataChanged, doMVCP } = params;
1833
1839
  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
1840
  const scrollExtra = 0;
1849
1841
  const { queuedInitialLayout } = state;
1850
1842
  let { scroll: scrollState } = state;
@@ -1883,6 +1875,18 @@ function calculateItemsInView(ctx, state, params = {}) {
1883
1875
  return;
1884
1876
  }
1885
1877
  }
1878
+ const checkMVCP = doMVCP ? prepareMVCP(ctx, state, dataChanged) : void 0;
1879
+ if (dataChanged) {
1880
+ indexByKey.clear();
1881
+ idCache.clear();
1882
+ positions.clear();
1883
+ }
1884
+ const startIndex = dataChanged ? 0 : (_a = minIndexSizeChanged != null ? minIndexSizeChanged : state.startBuffered) != null ? _a : 0;
1885
+ updateItemPositions(ctx, state, dataChanged, { scrollBottomBuffered, startIndex });
1886
+ if (minIndexSizeChanged !== void 0) {
1887
+ state.minIndexSizeChanged = void 0;
1888
+ }
1889
+ checkMVCP == null ? void 0 : checkMVCP();
1886
1890
  let startNoBuffer = null;
1887
1891
  let startBuffered = null;
1888
1892
  let startBufferedId = null;
@@ -1890,9 +1894,9 @@ function calculateItemsInView(ctx, state, params = {}) {
1890
1894
  let endBuffered = null;
1891
1895
  let loopStart = startBufferedIdOrig ? indexByKey.get(startBufferedIdOrig) || 0 : 0;
1892
1896
  for (let i = loopStart; i >= 0; i--) {
1893
- const id = (_a = idCache.get(i)) != null ? _a : getId(state, i);
1897
+ const id = (_b = idCache.get(i)) != null ? _b : getId(state, i);
1894
1898
  const top = positions.get(id);
1895
- const size = (_b = sizes.get(id)) != null ? _b : getItemSize(state, id, i, data[i]);
1899
+ const size = (_c = sizes.get(id)) != null ? _c : getItemSize(state, id, i, data[i]);
1896
1900
  const bottom = top + size;
1897
1901
  if (bottom > scroll - scrollBuffer) {
1898
1902
  loopStart = i;
@@ -1918,8 +1922,8 @@ function calculateItemsInView(ctx, state, params = {}) {
1918
1922
  let firstFullyOnScreenIndex;
1919
1923
  const dataLength = data.length;
1920
1924
  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]);
1925
+ const id = (_d = idCache.get(i)) != null ? _d : getId(state, i);
1926
+ const size = (_e = sizes.get(id)) != null ? _e : getItemSize(state, id, i, data[i]);
1923
1927
  const top = positions.get(id);
1924
1928
  if (!foundEnd) {
1925
1929
  if (startNoBuffer === null && top + size > scroll) {
@@ -1948,7 +1952,7 @@ function calculateItemsInView(ctx, state, params = {}) {
1948
1952
  }
1949
1953
  const idsInView = [];
1950
1954
  for (let i = firstFullyOnScreenIndex; i <= endNoBuffer; i++) {
1951
- const id = (_e = idCache.get(i)) != null ? _e : getId(state, i);
1955
+ const id = (_f = idCache.get(i)) != null ? _f : getId(state, i);
1952
1956
  idsInView.push(id);
1953
1957
  }
1954
1958
  Object.assign(state, {
@@ -1980,7 +1984,7 @@ function calculateItemsInView(ctx, state, params = {}) {
1980
1984
  let numContainers2 = prevNumContainers;
1981
1985
  const needNewContainers = [];
1982
1986
  for (let i = startBuffered; i <= endBuffered; i++) {
1983
- const id = (_f = idCache.get(i)) != null ? _f : getId(state, i);
1987
+ const id = (_g = idCache.get(i)) != null ? _g : getId(state, i);
1984
1988
  if (!containerItemKeys.has(id)) {
1985
1989
  needNewContainers.push(i);
1986
1990
  }
@@ -2017,7 +2021,7 @@ function calculateItemsInView(ctx, state, params = {}) {
2017
2021
  for (let idx = 0; idx < needNewContainers.length; idx++) {
2018
2022
  const i = needNewContainers[idx];
2019
2023
  const containerIndex = availableContainers[idx];
2020
- const id = (_g = idCache.get(i)) != null ? _g : getId(state, i);
2024
+ const id = (_h = idCache.get(i)) != null ? _h : getId(state, i);
2021
2025
  const oldKey = peek$(ctx, `containerItemKey${containerIndex}`);
2022
2026
  if (oldKey && oldKey !== id) {
2023
2027
  containerItemKeys.delete(oldKey);
@@ -2072,7 +2076,7 @@ function calculateItemsInView(ctx, state, params = {}) {
2072
2076
  const itemIndex = indexByKey.get(itemKey);
2073
2077
  const item = data[itemIndex];
2074
2078
  if (item !== void 0) {
2075
- const id = (_h = idCache.get(itemIndex)) != null ? _h : getId(state, itemIndex);
2079
+ const id = (_i = idCache.get(itemIndex)) != null ? _i : getId(state, itemIndex);
2076
2080
  const position = positions.get(id);
2077
2081
  if (position === void 0) {
2078
2082
  set$(ctx, `containerPosition${i}`, POSITION_OUT_OF_VIEW);
@@ -2088,7 +2092,7 @@ function calculateItemsInView(ctx, state, params = {}) {
2088
2092
  set$(ctx, `containerColumn${i}`, column);
2089
2093
  }
2090
2094
  if (prevData !== item && (itemsAreEqual ? !itemsAreEqual(prevData, item, itemIndex, data) : true)) {
2091
- set$(ctx, `containerItemData${i}`, data[itemIndex]);
2095
+ set$(ctx, `containerItemData${i}`, item);
2092
2096
  }
2093
2097
  }
2094
2098
  }
@@ -2105,55 +2109,6 @@ function calculateItemsInView(ctx, state, params = {}) {
2105
2109
  });
2106
2110
  }
2107
2111
 
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
2112
  // src/core/doMaintainScrollAtEnd.ts
2158
2113
  function doMaintainScrollAtEnd(ctx, state, animated) {
2159
2114
  const {
@@ -2212,6 +2167,129 @@ function checkAtTop(state) {
2212
2167
  );
2213
2168
  }
2214
2169
 
2170
+ // src/utils/updateAveragesOnDataChange.ts
2171
+ function updateAveragesOnDataChange(state, oldData, newData) {
2172
+ var _a;
2173
+ const {
2174
+ averageSizes,
2175
+ sizesKnown,
2176
+ indexByKey,
2177
+ props: { itemsAreEqual, getItemType, keyExtractor }
2178
+ } = state;
2179
+ if (!itemsAreEqual || !oldData.length || !newData.length) {
2180
+ for (const key in averageSizes) {
2181
+ delete averageSizes[key];
2182
+ }
2183
+ return;
2184
+ }
2185
+ const itemTypesToPreserve = {};
2186
+ const newDataLength = newData.length;
2187
+ const oldDataLength = oldData.length;
2188
+ for (let newIndex = 0; newIndex < newDataLength; newIndex++) {
2189
+ const newItem = newData[newIndex];
2190
+ const id = keyExtractor ? keyExtractor(newItem, newIndex) : String(newIndex);
2191
+ const oldIndex = indexByKey.get(id);
2192
+ if (oldIndex !== void 0 && oldIndex < oldDataLength) {
2193
+ const knownSize = sizesKnown.get(id);
2194
+ if (knownSize === void 0) continue;
2195
+ const oldItem = oldData[oldIndex];
2196
+ const areEqual = itemsAreEqual(oldItem, newItem, newIndex, newData);
2197
+ if (areEqual) {
2198
+ const itemType = getItemType ? (_a = getItemType(newItem, newIndex)) != null ? _a : "" : "";
2199
+ let typeData = itemTypesToPreserve[itemType];
2200
+ if (!typeData) {
2201
+ typeData = itemTypesToPreserve[itemType] = { count: 0, totalSize: 0 };
2202
+ }
2203
+ typeData.totalSize += knownSize;
2204
+ typeData.count++;
2205
+ }
2206
+ }
2207
+ }
2208
+ for (const key in averageSizes) {
2209
+ delete averageSizes[key];
2210
+ }
2211
+ for (const itemType in itemTypesToPreserve) {
2212
+ const { totalSize, count } = itemTypesToPreserve[itemType];
2213
+ if (count > 0) {
2214
+ averageSizes[itemType] = {
2215
+ avg: totalSize / count,
2216
+ num: count
2217
+ };
2218
+ }
2219
+ }
2220
+ }
2221
+
2222
+ // src/core/checkResetContainers.ts
2223
+ function checkResetContainers(ctx, state, isFirst, dataProp) {
2224
+ if (state) {
2225
+ if (!isFirst && state.props.data !== dataProp) {
2226
+ updateAveragesOnDataChange(state, state.props.data, dataProp);
2227
+ }
2228
+ const { maintainScrollAtEnd } = state.props;
2229
+ if (!isFirst) {
2230
+ calculateItemsInView(ctx, state, { dataChanged: true, doMVCP: true });
2231
+ const shouldMaintainScrollAtEnd = maintainScrollAtEnd === true || maintainScrollAtEnd.onDataChange;
2232
+ const didMaintainScrollAtEnd = shouldMaintainScrollAtEnd && doMaintainScrollAtEnd(ctx, state, false);
2233
+ if (!didMaintainScrollAtEnd && dataProp.length > state.props.data.length) {
2234
+ state.isEndReached = false;
2235
+ }
2236
+ if (!didMaintainScrollAtEnd) {
2237
+ checkAtTop(state);
2238
+ checkAtBottom(ctx, state);
2239
+ }
2240
+ }
2241
+ }
2242
+ }
2243
+
2244
+ // src/core/doInitialAllocateContainers.ts
2245
+ function doInitialAllocateContainers(ctx, state) {
2246
+ var _a;
2247
+ const {
2248
+ scrollLength,
2249
+ props: {
2250
+ data,
2251
+ getEstimatedItemSize,
2252
+ getFixedItemSize,
2253
+ getItemType,
2254
+ scrollBuffer,
2255
+ numColumns,
2256
+ estimatedItemSize
2257
+ }
2258
+ } = state;
2259
+ const hasContainers = peek$(ctx, "numContainers");
2260
+ if (scrollLength > 0 && data.length > 0 && !hasContainers) {
2261
+ let averageItemSize;
2262
+ const fn = getFixedItemSize || getEstimatedItemSize;
2263
+ if (fn) {
2264
+ let totalSize = 0;
2265
+ const num = Math.min(20, data.length);
2266
+ for (let i = 0; i < num; i++) {
2267
+ totalSize += fn(0, data[0], getItemType ? (_a = getItemType(data[0], 0)) != null ? _a : "" : "");
2268
+ }
2269
+ averageItemSize = totalSize / num;
2270
+ } else {
2271
+ averageItemSize = estimatedItemSize;
2272
+ }
2273
+ const numContainers = Math.ceil((scrollLength + scrollBuffer * 2) / averageItemSize * numColumns);
2274
+ for (let i = 0; i < numContainers; i++) {
2275
+ set$(ctx, `containerPosition${i}`, POSITION_OUT_OF_VIEW);
2276
+ set$(ctx, `containerColumn${i}`, -1);
2277
+ }
2278
+ set$(ctx, "numContainers", numContainers);
2279
+ set$(ctx, "numContainersPooled", numContainers * state.props.initialContainerPoolRatio);
2280
+ if (!IsNewArchitecture || state.lastLayout) {
2281
+ if (state.props.initialScroll) {
2282
+ requestAnimationFrame(() => {
2283
+ calculateItemsInView(ctx, state, { dataChanged: true });
2284
+ });
2285
+ } else {
2286
+ calculateItemsInView(ctx, state, { dataChanged: true });
2287
+ }
2288
+ }
2289
+ return true;
2290
+ }
2291
+ }
2292
+
2215
2293
  // src/core/handleLayout.ts
2216
2294
  function handleLayout(ctx, state, layout, setCanRender) {
2217
2295
  const { maintainScrollAtEnd } = state.props;
@@ -2389,6 +2467,7 @@ function updateItemSize(ctx, state, itemKey, sizeObj) {
2389
2467
  if (prevSizeKnown !== void 0 && Math.abs(prevSizeKnown - size) > 5) {
2390
2468
  shouldMaintainScrollAtEnd = true;
2391
2469
  }
2470
+ addTotalSize(ctx, state, itemKey, diff);
2392
2471
  onItemSizeChanged == null ? void 0 : onItemSizeChanged({
2393
2472
  index,
2394
2473
  itemData: state.props.data[index],
@@ -2458,7 +2537,7 @@ function updateOneItemSize(state, itemKey, sizeObj) {
2458
2537
  return 0;
2459
2538
  }
2460
2539
  var useCombinedRef = (...refs) => {
2461
- const callback = React3.useCallback((element) => {
2540
+ const callback = React2.useCallback((element) => {
2462
2541
  for (const ref of refs) {
2463
2542
  if (!ref) {
2464
2543
  continue;
@@ -2509,7 +2588,7 @@ function getRenderedItem(ctx, state, key) {
2509
2588
  item: data[index],
2510
2589
  type: getItemType ? (_a = getItemType(data[index], index)) != null ? _a : "" : ""
2511
2590
  };
2512
- renderedItem = isFunction(renderItem) ? renderItem(itemProps) : React3__namespace.default.createElement(renderItem, itemProps);
2591
+ renderedItem = isFunction(renderItem) ? renderItem(itemProps) : React2__namespace.default.createElement(renderItem, itemProps);
2513
2592
  }
2514
2593
  return { index, item: data[index], renderedItem };
2515
2594
  }
@@ -2520,58 +2599,6 @@ function useThrottledOnScroll(originalHandler, scrollEventThrottle) {
2520
2599
  return (event) => throttle(originalHandler, scrollEventThrottle, { nativeEvent: event.nativeEvent });
2521
2600
  }
2522
2601
 
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
2602
  // src/components/LegendList.tsx
2576
2603
  var DEFAULT_DRAW_DISTANCE = 250;
2577
2604
  var DEFAULT_ITEM_SIZE = 100;
@@ -2581,14 +2608,14 @@ var LegendList = typedMemo(
2581
2608
  const isChildrenMode = children !== void 0 && dataProp === void 0;
2582
2609
  const processedProps = isChildrenMode ? {
2583
2610
  ...restProps,
2584
- data: (isArray(children) ? children : React3__namespace.Children.toArray(children)).flat(1),
2611
+ data: (isArray(children) ? children : React2__namespace.Children.toArray(children)).flat(1),
2585
2612
  renderItem: ({ item }) => item
2586
2613
  } : {
2587
2614
  ...restProps,
2588
2615
  data: dataProp || [],
2589
2616
  renderItem: renderItemProp
2590
2617
  };
2591
- return /* @__PURE__ */ React3__namespace.createElement(StateProvider, null, /* @__PURE__ */ React3__namespace.createElement(LegendListInner, { ...processedProps, ref: forwardedRef }));
2618
+ return /* @__PURE__ */ React2__namespace.createElement(StateProvider, null, /* @__PURE__ */ React2__namespace.createElement(LegendListInner, { ...processedProps, ref: forwardedRef }));
2592
2619
  })
2593
2620
  );
2594
2621
  var LegendListInner = typedForwardRef(function LegendListInner2(props, forwardedRef) {
@@ -2645,21 +2672,21 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
2645
2672
  waitForInitialLayout = true,
2646
2673
  ...rest
2647
2674
  } = props;
2648
- const [renderNum, setRenderNum] = React3.useState(0);
2675
+ const [renderNum, setRenderNum] = React2.useState(0);
2649
2676
  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);
2677
+ const [canRender, setCanRender] = React2__namespace.useState(!IsNewArchitecture);
2651
2678
  const contentContainerStyle = { ...reactNative.StyleSheet.flatten(contentContainerStyleProp) };
2652
2679
  const style = { ...reactNative.StyleSheet.flatten(styleProp) };
2653
2680
  const stylePaddingTopState = extractPadding(style, contentContainerStyle, "Top");
2654
2681
  const stylePaddingBottomState = extractPadding(style, contentContainerStyle, "Bottom");
2655
2682
  const ctx = useStateContext();
2656
2683
  ctx.columnWrapperStyle = columnWrapperStyle || (contentContainerStyle ? createColumnWrapperStyle(contentContainerStyle) : void 0);
2657
- const refScroller = React3.useRef(null);
2684
+ const refScroller = React2.useRef(null);
2658
2685
  const combinedRef = useCombinedRef(refScroller, refScrollView);
2659
2686
  const estimatedItemSize = estimatedItemSizeProp != null ? estimatedItemSizeProp : DEFAULT_ITEM_SIZE;
2660
2687
  const scrollBuffer = (drawDistance != null ? drawDistance : DEFAULT_DRAW_DISTANCE) || 1;
2661
2688
  const keyExtractor = keyExtractorProp != null ? keyExtractorProp : (_item, index) => index.toString();
2662
- const refState = React3.useRef();
2689
+ const refState = React2.useRef();
2663
2690
  if (!refState.current) {
2664
2691
  const initialScrollLength = (estimatedListSize != null ? estimatedListSize : IsNewArchitecture ? { height: 0, width: 0 } : reactNative.Dimensions.get("window"))[horizontal ? "width" : "height"];
2665
2692
  refState.current = {
@@ -2748,34 +2775,13 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
2748
2775
  scrollBuffer,
2749
2776
  snapToIndices,
2750
2777
  stickyIndicesArr: stickyIndices != null ? stickyIndices : [],
2751
- stickyIndicesSet: React3.useMemo(() => new Set(stickyIndices != null ? stickyIndices : []), [stickyIndices == null ? void 0 : stickyIndices.join(",")]),
2778
+ stickyIndicesSet: React2.useMemo(() => new Set(stickyIndices != null ? stickyIndices : []), [stickyIndices == null ? void 0 : stickyIndices.join(",")]),
2752
2779
  stylePaddingBottom: stylePaddingBottomState,
2753
2780
  stylePaddingTop: stylePaddingTopState,
2754
2781
  suggestEstimatedItemSize: !!suggestEstimatedItemSize
2755
2782
  };
2756
2783
  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(() => {
2784
+ const memoizedLastItemKeys = React2.useMemo(() => {
2779
2785
  if (!dataProp.length) return [];
2780
2786
  return Array.from(
2781
2787
  { length: Math.min(numColumnsProp, dataProp.length) },
@@ -2798,9 +2804,14 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
2798
2804
  };
2799
2805
  if (isFirst) {
2800
2806
  initializeStateVars();
2801
- updateAllPositions(ctx, state);
2807
+ updateItemPositions(
2808
+ ctx,
2809
+ state,
2810
+ /*dataChanged*/
2811
+ true
2812
+ );
2802
2813
  }
2803
- const initialContentOffset = React3.useMemo(() => {
2814
+ const initialContentOffset = React2.useMemo(() => {
2804
2815
  if (initialScroll) {
2805
2816
  const { index, viewOffset } = initialScroll;
2806
2817
  let initialContentOffset2 = viewOffset || 0;
@@ -2826,7 +2837,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
2826
2837
  refState.current.positions.clear();
2827
2838
  }
2828
2839
  }
2829
- const onLayoutHeader = React3.useCallback((rect, fromLayoutEffect) => {
2840
+ const onLayoutHeader = React2.useCallback((rect, fromLayoutEffect) => {
2830
2841
  const size = rect[horizontal ? "width" : "height"];
2831
2842
  set$(ctx, "headerSize", size);
2832
2843
  if ((initialScroll == null ? void 0 : initialScroll.index) !== void 0) {
@@ -2841,24 +2852,27 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
2841
2852
  }
2842
2853
  }
2843
2854
  }, []);
2844
- React3.useLayoutEffect(() => {
2855
+ React2.useLayoutEffect(() => {
2845
2856
  if (snapToIndices) {
2846
2857
  updateSnapToOffsets(ctx, state);
2847
2858
  }
2848
2859
  }, [snapToIndices]);
2849
- React3.useLayoutEffect(() => {
2860
+ React2.useLayoutEffect(() => {
2850
2861
  const didAllocateContainers = dataProp.length > 0 && doInitialAllocateContainersCallback();
2851
2862
  if (!didAllocateContainers) {
2852
2863
  checkResetContainers(
2864
+ ctx,
2865
+ state,
2853
2866
  /*isFirst*/
2854
- isFirst
2867
+ isFirst,
2868
+ dataProp
2855
2869
  );
2856
2870
  }
2857
2871
  }, [dataProp, numColumnsProp]);
2858
- React3.useLayoutEffect(() => {
2872
+ React2.useLayoutEffect(() => {
2859
2873
  set$(ctx, "extraData", extraData);
2860
2874
  }, [extraData]);
2861
- React3.useLayoutEffect(() => {
2875
+ React2.useLayoutEffect(() => {
2862
2876
  var _a2;
2863
2877
  if (IsNewArchitecture) {
2864
2878
  let measured;
@@ -2873,7 +2887,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
2873
2887
  }
2874
2888
  }
2875
2889
  }, []);
2876
- React3.useLayoutEffect(initializeStateVars, [
2890
+ React2.useLayoutEffect(initializeStateVars, [
2877
2891
  memoizedLastItemKeys.join(","),
2878
2892
  numColumnsProp,
2879
2893
  stylePaddingTopState,
@@ -2882,7 +2896,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
2882
2896
  const doInitialAllocateContainersCallback = () => {
2883
2897
  return doInitialAllocateContainers(ctx, state);
2884
2898
  };
2885
- React3.useEffect(() => {
2899
+ React2.useEffect(() => {
2886
2900
  const viewability = setupViewability({
2887
2901
  onViewableItemsChanged,
2888
2902
  viewabilityConfig,
@@ -2896,14 +2910,14 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
2896
2910
  doInitialAllocateContainersCallback();
2897
2911
  });
2898
2912
  }
2899
- const onLayout = React3.useCallback((event) => {
2913
+ const onLayout = React2.useCallback((event) => {
2900
2914
  const layout = event.nativeEvent.layout;
2901
2915
  handleLayout(ctx, state, layout, setCanRender);
2902
2916
  if (onLayoutProp) {
2903
2917
  onLayoutProp(event);
2904
2918
  }
2905
2919
  }, []);
2906
- React3.useImperativeHandle(forwardedRef, () => {
2920
+ React2.useImperativeHandle(forwardedRef, () => {
2907
2921
  const scrollIndexIntoView = (options) => {
2908
2922
  const state2 = refState.current;
2909
2923
  if (state2) {
@@ -2986,13 +3000,13 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
2986
3000
  };
2987
3001
  }, []);
2988
3002
  if (reactNative.Platform.OS === "web") {
2989
- React3.useEffect(() => {
3003
+ React2.useEffect(() => {
2990
3004
  if (initialContentOffset) {
2991
3005
  scrollTo(state, { animated: false, offset: initialContentOffset });
2992
3006
  }
2993
3007
  }, []);
2994
3008
  }
2995
- const fns = React3.useMemo(
3009
+ const fns = React2.useMemo(
2996
3010
  () => ({
2997
3011
  getRenderedItem: (key) => getRenderedItem(ctx, state, key),
2998
3012
  onScroll: (event) => onScroll(ctx, state, event),
@@ -3000,7 +3014,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
3000
3014
  }),
3001
3015
  []
3002
3016
  );
3003
- const onScrollHandler = React3.useMemo(() => {
3017
+ const onScrollHandler = React2.useMemo(() => {
3004
3018
  const onScrollFn = fns.onScroll;
3005
3019
  if (stickyIndices == null ? void 0 : stickyIndices.length) {
3006
3020
  const { animatedScrollY } = ctx;
@@ -3011,7 +3025,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
3011
3025
  }
3012
3026
  return onScrollFn;
3013
3027
  }, [stickyIndices == null ? void 0 : stickyIndices.length, horizontal, scrollEventThrottle]);
3014
- return /* @__PURE__ */ React3__namespace.createElement(React3__namespace.Fragment, null, /* @__PURE__ */ React3__namespace.createElement(
3028
+ return /* @__PURE__ */ React2__namespace.createElement(React2__namespace.Fragment, null, /* @__PURE__ */ React2__namespace.createElement(
3015
3029
  ListComponent,
3016
3030
  {
3017
3031
  ...rest,
@@ -3042,9 +3056,9 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
3042
3056
  },
3043
3057
  onScroll: onScrollHandler,
3044
3058
  recycleItems,
3045
- refreshControl: refreshControl ? stylePaddingTopState > 0 ? React3__namespace.cloneElement(refreshControl, {
3059
+ refreshControl: refreshControl ? stylePaddingTopState > 0 ? React2__namespace.cloneElement(refreshControl, {
3046
3060
  progressViewOffset: (refreshControl.props.progressViewOffset || 0) + stylePaddingTopState
3047
- }) : refreshControl : onRefresh && /* @__PURE__ */ React3__namespace.createElement(
3061
+ }) : refreshControl : onRefresh && /* @__PURE__ */ React2__namespace.createElement(
3048
3062
  reactNative.RefreshControl,
3049
3063
  {
3050
3064
  onRefresh,
@@ -3061,7 +3075,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
3061
3075
  updateItemSize: fns.updateItemSize,
3062
3076
  waitForInitialLayout
3063
3077
  }
3064
- ), __DEV__ && ENABLE_DEBUG_VIEW && /* @__PURE__ */ React3__namespace.createElement(DebugView, { state: refState.current }));
3078
+ ), __DEV__ && ENABLE_DEBUG_VIEW && /* @__PURE__ */ React2__namespace.createElement(DebugView, { state: refState.current }));
3065
3079
  });
3066
3080
 
3067
3081
  exports.LegendList = LegendList;