@legendapp/list 3.0.0-beta.47 → 3.0.0-beta.48

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
@@ -4229,7 +4229,7 @@ function computeViewability(state, ctx, viewabilityConfig, containerId, key, scr
4229
4229
  }
4230
4230
  function checkIsViewable(state, ctx, viewabilityConfig, containerId, key, scrollSize, item, index) {
4231
4231
  let value = ctx.mapViewabilityAmountValues.get(containerId);
4232
- if (!value || value.key !== key) {
4232
+ if (!value || value.key !== key || value.index !== index) {
4233
4233
  value = computeViewability(state, ctx, viewabilityConfig, containerId, key, scrollSize, item, index);
4234
4234
  }
4235
4235
  return value.isViewable;
@@ -4244,7 +4244,7 @@ var unstableBatchedUpdates = ReactDOM__namespace.unstable_batchedUpdates;
4244
4244
  var batchedUpdates = typeof unstableBatchedUpdates === "function" ? unstableBatchedUpdates : (fn) => fn();
4245
4245
 
4246
4246
  // src/utils/findAvailableContainers.ts
4247
- function findAvailableContainers(ctx, numNeeded, startBuffered, endBuffered, pendingRemoval, requiredItemTypes, needNewContainers) {
4247
+ function findAvailableContainers(ctx, numNeeded, startBuffered, endBuffered, pendingRemoval, requiredItemTypes, needNewContainers, protectedKeys) {
4248
4248
  const numContainers = peek$(ctx, "numContainers");
4249
4249
  const state = ctx.state;
4250
4250
  const { stickyContainerPool, containerItemTypes } = state;
@@ -4312,6 +4312,7 @@ function findAvailableContainers(ctx, numNeeded, startBuffered, endBuffered, pen
4312
4312
  }
4313
4313
  const key = peek$(ctx, `containerItemKey${u}`);
4314
4314
  if (key === void 0) continue;
4315
+ if ((protectedKeys == null ? void 0 : protectedKeys.has(key)) && state.indexByKey.has(key)) continue;
4315
4316
  const index = state.indexByKey.get(key);
4316
4317
  const isOutOfView = index < startBuffered || index > endBuffered;
4317
4318
  if (isOutOfView) {
@@ -4447,7 +4448,7 @@ function handleStickyRecycling(ctx, stickyArray, scroll, drawDistance, currentSt
4447
4448
  function calculateItemsInView(ctx, params = {}) {
4448
4449
  const state = ctx.state;
4449
4450
  batchedUpdates(() => {
4450
- var _a3, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
4451
+ var _a3, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
4451
4452
  const {
4452
4453
  columns,
4453
4454
  columnSpans,
@@ -4549,17 +4550,31 @@ function calculateItemsInView(ctx, params = {}) {
4549
4550
  if (minIndexSizeChanged !== void 0) {
4550
4551
  state.minIndexSizeChanged = void 0;
4551
4552
  }
4553
+ let protectedContainerKeys;
4554
+ if (dataChanged && doMVCP && state.props.maintainVisibleContentPosition.data && state.didContainersLayout && state.idsInView.length > 0) {
4555
+ const shouldRestorePosition = state.props.maintainVisibleContentPosition.shouldRestorePosition;
4556
+ protectedContainerKeys = /* @__PURE__ */ new Set();
4557
+ for (const id of state.idsInView) {
4558
+ const index = indexByKey.get(id);
4559
+ if (index === void 0) continue;
4560
+ if (shouldRestorePosition && !shouldRestorePosition(data[index], index, data)) continue;
4561
+ protectedContainerKeys.add(id);
4562
+ }
4563
+ }
4564
+ const scrollBeforeMVCP = state.scroll;
4565
+ const scrollAdjustPendingBeforeMVCP = (_e = peek$(ctx, "scrollAdjustPending")) != null ? _e : 0;
4552
4566
  checkMVCP == null ? void 0 : checkMVCP();
4567
+ const didMVCPAdjustScroll = !!checkMVCP && (state.scroll !== scrollBeforeMVCP || ((_f = peek$(ctx, "scrollAdjustPending")) != null ? _f : 0) !== scrollAdjustPendingBeforeMVCP);
4553
4568
  let startNoBuffer = null;
4554
4569
  let startBuffered = null;
4555
4570
  let startBufferedId = null;
4556
4571
  let endNoBuffer = null;
4557
4572
  let endBuffered = null;
4558
- let loopStart = (_e = suppressInitialScrollSideEffects ? bootstrapInitialScrollState == null ? void 0 : bootstrapInitialScrollState.targetIndexSeed : void 0) != null ? _e : !dataChanged && startBufferedIdOrig ? indexByKey.get(startBufferedIdOrig) || 0 : 0;
4573
+ let loopStart = (_g = suppressInitialScrollSideEffects ? bootstrapInitialScrollState == null ? void 0 : bootstrapInitialScrollState.targetIndexSeed : void 0) != null ? _g : !dataChanged && startBufferedIdOrig ? indexByKey.get(startBufferedIdOrig) || 0 : 0;
4559
4574
  for (let i = loopStart; i >= 0; i--) {
4560
- const id = (_f = idCache[i]) != null ? _f : getId(state, i);
4575
+ const id = (_h = idCache[i]) != null ? _h : getId(state, i);
4561
4576
  const top = positions[i];
4562
- const size = (_g = sizes.get(id)) != null ? _g : getItemSize(ctx, id, i, data[i]);
4577
+ const size = (_i = sizes.get(id)) != null ? _i : getItemSize(ctx, id, i, data[i]);
4563
4578
  const bottom = top + size;
4564
4579
  if (bottom > scroll - scrollBufferTop) {
4565
4580
  loopStart = i;
@@ -4590,8 +4605,8 @@ function calculateItemsInView(ctx, params = {}) {
4590
4605
  let firstFullyOnScreenIndex;
4591
4606
  const dataLength = data.length;
4592
4607
  for (let i = Math.max(0, loopStart); i < dataLength && (!foundEnd || i <= maxIndexRendered); i++) {
4593
- const id = (_h = idCache[i]) != null ? _h : getId(state, i);
4594
- const size = (_i = sizes.get(id)) != null ? _i : getItemSize(ctx, id, i, data[i]);
4608
+ const id = (_j = idCache[i]) != null ? _j : getId(state, i);
4609
+ const size = (_k = sizes.get(id)) != null ? _k : getItemSize(ctx, id, i, data[i]);
4595
4610
  const top = positions[i];
4596
4611
  if (!foundEnd) {
4597
4612
  if (startNoBuffer === null && top + size > scroll) {
@@ -4630,7 +4645,7 @@ function calculateItemsInView(ctx, params = {}) {
4630
4645
  const firstVisibleAnchorIndex = firstFullyOnScreenIndex != null ? firstFullyOnScreenIndex : startNoBuffer;
4631
4646
  if (firstVisibleAnchorIndex !== null && firstVisibleAnchorIndex !== void 0 && endNoBuffer !== null) {
4632
4647
  for (let i = firstVisibleAnchorIndex; i <= endNoBuffer; i++) {
4633
- const id = (_j = idCache[i]) != null ? _j : getId(state, i);
4648
+ const id = (_l = idCache[i]) != null ? _l : getId(state, i);
4634
4649
  idsInView.push(id);
4635
4650
  }
4636
4651
  }
@@ -4663,7 +4678,7 @@ function calculateItemsInView(ctx, params = {}) {
4663
4678
  const needNewContainers = [];
4664
4679
  const needNewContainersSet = /* @__PURE__ */ new Set();
4665
4680
  for (let i = startBuffered; i <= endBuffered; i++) {
4666
- const id = (_k = idCache[i]) != null ? _k : getId(state, i);
4681
+ const id = (_m = idCache[i]) != null ? _m : getId(state, i);
4667
4682
  if (!containerItemKeys.has(id)) {
4668
4683
  needNewContainersSet.add(i);
4669
4684
  needNewContainers.push(i);
@@ -4672,7 +4687,7 @@ function calculateItemsInView(ctx, params = {}) {
4672
4687
  if (alwaysRenderArr.length > 0) {
4673
4688
  for (const index of alwaysRenderArr) {
4674
4689
  if (index < 0 || index >= dataLength) continue;
4675
- const id = (_l = idCache[index]) != null ? _l : getId(state, index);
4690
+ const id = (_n = idCache[index]) != null ? _n : getId(state, index);
4676
4691
  if (id && !containerItemKeys.has(id) && !needNewContainersSet.has(index)) {
4677
4692
  needNewContainersSet.add(index);
4678
4693
  needNewContainers.push(index);
@@ -4705,12 +4720,13 @@ function calculateItemsInView(ctx, params = {}) {
4705
4720
  endBuffered,
4706
4721
  pendingRemoval,
4707
4722
  requiredItemTypes,
4708
- needNewContainers
4723
+ needNewContainers,
4724
+ protectedContainerKeys
4709
4725
  );
4710
4726
  for (let idx = 0; idx < needNewContainers.length; idx++) {
4711
4727
  const i = needNewContainers[idx];
4712
4728
  const containerIndex = availableContainers[idx];
4713
- const id = (_m = idCache[i]) != null ? _m : getId(state, i);
4729
+ const id = (_o = idCache[i]) != null ? _o : getId(state, i);
4714
4730
  const oldKey = peek$(ctx, `containerItemKey${containerIndex}`);
4715
4731
  if (oldKey && oldKey !== id) {
4716
4732
  containerItemKeys.delete(oldKey);
@@ -4751,7 +4767,7 @@ function calculateItemsInView(ctx, params = {}) {
4751
4767
  if (alwaysRenderArr.length > 0) {
4752
4768
  for (const index of alwaysRenderArr) {
4753
4769
  if (index < 0 || index >= dataLength) continue;
4754
- const id = (_n = idCache[index]) != null ? _n : getId(state, index);
4770
+ const id = (_p = idCache[index]) != null ? _p : getId(state, index);
4755
4771
  const containerIndex = containerItemKeys.get(id);
4756
4772
  if (containerIndex !== void 0) {
4757
4773
  state.stickyContainerPool.add(containerIndex);
@@ -4812,16 +4828,18 @@ function calculateItemsInView(ctx, params = {}) {
4812
4828
  handleInitialScrollLayoutReady(ctx);
4813
4829
  }
4814
4830
  if (viewabilityConfigCallbackPairs && startNoBuffer !== null && endNoBuffer !== null) {
4815
- updateViewableItems(
4816
- ctx.state,
4817
- ctx,
4818
- viewabilityConfigCallbackPairs,
4819
- scrollLength,
4820
- startNoBuffer,
4821
- endNoBuffer,
4822
- startBuffered != null ? startBuffered : startNoBuffer,
4823
- endBuffered != null ? endBuffered : endNoBuffer
4824
- );
4831
+ if (!didMVCPAdjustScroll) {
4832
+ updateViewableItems(
4833
+ ctx.state,
4834
+ ctx,
4835
+ viewabilityConfigCallbackPairs,
4836
+ scrollLength,
4837
+ startNoBuffer,
4838
+ endNoBuffer,
4839
+ startBuffered != null ? startBuffered : startNoBuffer,
4840
+ endBuffered != null ? endBuffered : endNoBuffer
4841
+ );
4842
+ }
4825
4843
  }
4826
4844
  if (onStickyHeaderChange && stickyIndicesArr.length > 0 && nextActiveStickyIndex !== void 0 && nextActiveStickyIndex !== previousStickyIndex) {
4827
4845
  const item = data[nextActiveStickyIndex];
package/index.mjs CHANGED
@@ -4208,7 +4208,7 @@ function computeViewability(state, ctx, viewabilityConfig, containerId, key, scr
4208
4208
  }
4209
4209
  function checkIsViewable(state, ctx, viewabilityConfig, containerId, key, scrollSize, item, index) {
4210
4210
  let value = ctx.mapViewabilityAmountValues.get(containerId);
4211
- if (!value || value.key !== key) {
4211
+ if (!value || value.key !== key || value.index !== index) {
4212
4212
  value = computeViewability(state, ctx, viewabilityConfig, containerId, key, scrollSize, item, index);
4213
4213
  }
4214
4214
  return value.isViewable;
@@ -4223,7 +4223,7 @@ var unstableBatchedUpdates = ReactDOM.unstable_batchedUpdates;
4223
4223
  var batchedUpdates = typeof unstableBatchedUpdates === "function" ? unstableBatchedUpdates : (fn) => fn();
4224
4224
 
4225
4225
  // src/utils/findAvailableContainers.ts
4226
- function findAvailableContainers(ctx, numNeeded, startBuffered, endBuffered, pendingRemoval, requiredItemTypes, needNewContainers) {
4226
+ function findAvailableContainers(ctx, numNeeded, startBuffered, endBuffered, pendingRemoval, requiredItemTypes, needNewContainers, protectedKeys) {
4227
4227
  const numContainers = peek$(ctx, "numContainers");
4228
4228
  const state = ctx.state;
4229
4229
  const { stickyContainerPool, containerItemTypes } = state;
@@ -4291,6 +4291,7 @@ function findAvailableContainers(ctx, numNeeded, startBuffered, endBuffered, pen
4291
4291
  }
4292
4292
  const key = peek$(ctx, `containerItemKey${u}`);
4293
4293
  if (key === void 0) continue;
4294
+ if ((protectedKeys == null ? void 0 : protectedKeys.has(key)) && state.indexByKey.has(key)) continue;
4294
4295
  const index = state.indexByKey.get(key);
4295
4296
  const isOutOfView = index < startBuffered || index > endBuffered;
4296
4297
  if (isOutOfView) {
@@ -4426,7 +4427,7 @@ function handleStickyRecycling(ctx, stickyArray, scroll, drawDistance, currentSt
4426
4427
  function calculateItemsInView(ctx, params = {}) {
4427
4428
  const state = ctx.state;
4428
4429
  batchedUpdates(() => {
4429
- var _a3, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
4430
+ var _a3, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
4430
4431
  const {
4431
4432
  columns,
4432
4433
  columnSpans,
@@ -4528,17 +4529,31 @@ function calculateItemsInView(ctx, params = {}) {
4528
4529
  if (minIndexSizeChanged !== void 0) {
4529
4530
  state.minIndexSizeChanged = void 0;
4530
4531
  }
4532
+ let protectedContainerKeys;
4533
+ if (dataChanged && doMVCP && state.props.maintainVisibleContentPosition.data && state.didContainersLayout && state.idsInView.length > 0) {
4534
+ const shouldRestorePosition = state.props.maintainVisibleContentPosition.shouldRestorePosition;
4535
+ protectedContainerKeys = /* @__PURE__ */ new Set();
4536
+ for (const id of state.idsInView) {
4537
+ const index = indexByKey.get(id);
4538
+ if (index === void 0) continue;
4539
+ if (shouldRestorePosition && !shouldRestorePosition(data[index], index, data)) continue;
4540
+ protectedContainerKeys.add(id);
4541
+ }
4542
+ }
4543
+ const scrollBeforeMVCP = state.scroll;
4544
+ const scrollAdjustPendingBeforeMVCP = (_e = peek$(ctx, "scrollAdjustPending")) != null ? _e : 0;
4531
4545
  checkMVCP == null ? void 0 : checkMVCP();
4546
+ const didMVCPAdjustScroll = !!checkMVCP && (state.scroll !== scrollBeforeMVCP || ((_f = peek$(ctx, "scrollAdjustPending")) != null ? _f : 0) !== scrollAdjustPendingBeforeMVCP);
4532
4547
  let startNoBuffer = null;
4533
4548
  let startBuffered = null;
4534
4549
  let startBufferedId = null;
4535
4550
  let endNoBuffer = null;
4536
4551
  let endBuffered = null;
4537
- let loopStart = (_e = suppressInitialScrollSideEffects ? bootstrapInitialScrollState == null ? void 0 : bootstrapInitialScrollState.targetIndexSeed : void 0) != null ? _e : !dataChanged && startBufferedIdOrig ? indexByKey.get(startBufferedIdOrig) || 0 : 0;
4552
+ let loopStart = (_g = suppressInitialScrollSideEffects ? bootstrapInitialScrollState == null ? void 0 : bootstrapInitialScrollState.targetIndexSeed : void 0) != null ? _g : !dataChanged && startBufferedIdOrig ? indexByKey.get(startBufferedIdOrig) || 0 : 0;
4538
4553
  for (let i = loopStart; i >= 0; i--) {
4539
- const id = (_f = idCache[i]) != null ? _f : getId(state, i);
4554
+ const id = (_h = idCache[i]) != null ? _h : getId(state, i);
4540
4555
  const top = positions[i];
4541
- const size = (_g = sizes.get(id)) != null ? _g : getItemSize(ctx, id, i, data[i]);
4556
+ const size = (_i = sizes.get(id)) != null ? _i : getItemSize(ctx, id, i, data[i]);
4542
4557
  const bottom = top + size;
4543
4558
  if (bottom > scroll - scrollBufferTop) {
4544
4559
  loopStart = i;
@@ -4569,8 +4584,8 @@ function calculateItemsInView(ctx, params = {}) {
4569
4584
  let firstFullyOnScreenIndex;
4570
4585
  const dataLength = data.length;
4571
4586
  for (let i = Math.max(0, loopStart); i < dataLength && (!foundEnd || i <= maxIndexRendered); i++) {
4572
- const id = (_h = idCache[i]) != null ? _h : getId(state, i);
4573
- const size = (_i = sizes.get(id)) != null ? _i : getItemSize(ctx, id, i, data[i]);
4587
+ const id = (_j = idCache[i]) != null ? _j : getId(state, i);
4588
+ const size = (_k = sizes.get(id)) != null ? _k : getItemSize(ctx, id, i, data[i]);
4574
4589
  const top = positions[i];
4575
4590
  if (!foundEnd) {
4576
4591
  if (startNoBuffer === null && top + size > scroll) {
@@ -4609,7 +4624,7 @@ function calculateItemsInView(ctx, params = {}) {
4609
4624
  const firstVisibleAnchorIndex = firstFullyOnScreenIndex != null ? firstFullyOnScreenIndex : startNoBuffer;
4610
4625
  if (firstVisibleAnchorIndex !== null && firstVisibleAnchorIndex !== void 0 && endNoBuffer !== null) {
4611
4626
  for (let i = firstVisibleAnchorIndex; i <= endNoBuffer; i++) {
4612
- const id = (_j = idCache[i]) != null ? _j : getId(state, i);
4627
+ const id = (_l = idCache[i]) != null ? _l : getId(state, i);
4613
4628
  idsInView.push(id);
4614
4629
  }
4615
4630
  }
@@ -4642,7 +4657,7 @@ function calculateItemsInView(ctx, params = {}) {
4642
4657
  const needNewContainers = [];
4643
4658
  const needNewContainersSet = /* @__PURE__ */ new Set();
4644
4659
  for (let i = startBuffered; i <= endBuffered; i++) {
4645
- const id = (_k = idCache[i]) != null ? _k : getId(state, i);
4660
+ const id = (_m = idCache[i]) != null ? _m : getId(state, i);
4646
4661
  if (!containerItemKeys.has(id)) {
4647
4662
  needNewContainersSet.add(i);
4648
4663
  needNewContainers.push(i);
@@ -4651,7 +4666,7 @@ function calculateItemsInView(ctx, params = {}) {
4651
4666
  if (alwaysRenderArr.length > 0) {
4652
4667
  for (const index of alwaysRenderArr) {
4653
4668
  if (index < 0 || index >= dataLength) continue;
4654
- const id = (_l = idCache[index]) != null ? _l : getId(state, index);
4669
+ const id = (_n = idCache[index]) != null ? _n : getId(state, index);
4655
4670
  if (id && !containerItemKeys.has(id) && !needNewContainersSet.has(index)) {
4656
4671
  needNewContainersSet.add(index);
4657
4672
  needNewContainers.push(index);
@@ -4684,12 +4699,13 @@ function calculateItemsInView(ctx, params = {}) {
4684
4699
  endBuffered,
4685
4700
  pendingRemoval,
4686
4701
  requiredItemTypes,
4687
- needNewContainers
4702
+ needNewContainers,
4703
+ protectedContainerKeys
4688
4704
  );
4689
4705
  for (let idx = 0; idx < needNewContainers.length; idx++) {
4690
4706
  const i = needNewContainers[idx];
4691
4707
  const containerIndex = availableContainers[idx];
4692
- const id = (_m = idCache[i]) != null ? _m : getId(state, i);
4708
+ const id = (_o = idCache[i]) != null ? _o : getId(state, i);
4693
4709
  const oldKey = peek$(ctx, `containerItemKey${containerIndex}`);
4694
4710
  if (oldKey && oldKey !== id) {
4695
4711
  containerItemKeys.delete(oldKey);
@@ -4730,7 +4746,7 @@ function calculateItemsInView(ctx, params = {}) {
4730
4746
  if (alwaysRenderArr.length > 0) {
4731
4747
  for (const index of alwaysRenderArr) {
4732
4748
  if (index < 0 || index >= dataLength) continue;
4733
- const id = (_n = idCache[index]) != null ? _n : getId(state, index);
4749
+ const id = (_p = idCache[index]) != null ? _p : getId(state, index);
4734
4750
  const containerIndex = containerItemKeys.get(id);
4735
4751
  if (containerIndex !== void 0) {
4736
4752
  state.stickyContainerPool.add(containerIndex);
@@ -4791,16 +4807,18 @@ function calculateItemsInView(ctx, params = {}) {
4791
4807
  handleInitialScrollLayoutReady(ctx);
4792
4808
  }
4793
4809
  if (viewabilityConfigCallbackPairs && startNoBuffer !== null && endNoBuffer !== null) {
4794
- updateViewableItems(
4795
- ctx.state,
4796
- ctx,
4797
- viewabilityConfigCallbackPairs,
4798
- scrollLength,
4799
- startNoBuffer,
4800
- endNoBuffer,
4801
- startBuffered != null ? startBuffered : startNoBuffer,
4802
- endBuffered != null ? endBuffered : endNoBuffer
4803
- );
4810
+ if (!didMVCPAdjustScroll) {
4811
+ updateViewableItems(
4812
+ ctx.state,
4813
+ ctx,
4814
+ viewabilityConfigCallbackPairs,
4815
+ scrollLength,
4816
+ startNoBuffer,
4817
+ endNoBuffer,
4818
+ startBuffered != null ? startBuffered : startNoBuffer,
4819
+ endBuffered != null ? endBuffered : endNoBuffer
4820
+ );
4821
+ }
4804
4822
  }
4805
4823
  if (onStickyHeaderChange && stickyIndicesArr.length > 0 && nextActiveStickyIndex !== void 0 && nextActiveStickyIndex !== previousStickyIndex) {
4806
4824
  const item = data[nextActiveStickyIndex];
package/index.native.js CHANGED
@@ -855,6 +855,35 @@ var Container = typedMemo(function Container2({
855
855
  });
856
856
 
857
857
  // src/components/Containers.native.tsx
858
+ var ContainersLayer = typedMemo(function ContainersLayer2({ children, horizontal }) {
859
+ const ctx = useStateContext();
860
+ const columnWrapperStyle = ctx.columnWrapperStyle;
861
+ const animSize = useValue$("totalSize");
862
+ const otherAxisSize = useValue$("otherAxisSize");
863
+ const [readyToRender, numColumns] = useArr$(["readyToRender", "numColumns"]);
864
+ const style = horizontal ? { minHeight: otherAxisSize, opacity: readyToRender ? 1 : 0, width: animSize } : { height: animSize, minWidth: otherAxisSize, opacity: readyToRender ? 1 : 0 };
865
+ if (columnWrapperStyle) {
866
+ const { columnGap, rowGap, gap } = columnWrapperStyle;
867
+ const gapX = columnGap || gap || 0;
868
+ const gapY = rowGap || gap || 0;
869
+ if (horizontal) {
870
+ if (gapY && numColumns > 1) {
871
+ style.marginVertical = -gapY / 2;
872
+ }
873
+ if (gapX) {
874
+ style.marginRight = -gapX;
875
+ }
876
+ } else {
877
+ if (gapX && numColumns > 1) {
878
+ style.marginHorizontal = -gapX;
879
+ }
880
+ if (gapY) {
881
+ style.marginBottom = -gapY;
882
+ }
883
+ }
884
+ }
885
+ return /* @__PURE__ */ React2__namespace.createElement(ReactNative.Animated.View, { style }, children);
886
+ });
858
887
  var Containers = typedMemo(function Containers2({
859
888
  horizontal,
860
889
  recycleItems,
@@ -863,12 +892,7 @@ var Containers = typedMemo(function Containers2({
863
892
  updateItemSize: updateItemSize2,
864
893
  getRenderedItem: getRenderedItem2
865
894
  }) {
866
- const ctx = useStateContext();
867
- const columnWrapperStyle = ctx.columnWrapperStyle;
868
- const [numContainers, numColumns] = useArr$(["numContainersPooled", "numColumns"]);
869
- const animSize = useValue$("totalSize");
870
- const otherAxisSize = useValue$("otherAxisSize");
871
- const animOpacity = useValue$("readyToRender", { getValue: (value) => value ? 1 : 0 });
895
+ const [numContainers] = useArr$(["numContainersPooled"]);
872
896
  const containers = [];
873
897
  for (let i = 0; i < numContainers; i++) {
874
898
  containers.push(
@@ -887,28 +911,7 @@ var Containers = typedMemo(function Containers2({
887
911
  )
888
912
  );
889
913
  }
890
- const style = horizontal ? { minHeight: otherAxisSize, opacity: animOpacity, width: animSize } : { height: animSize, minWidth: otherAxisSize, opacity: animOpacity };
891
- if (columnWrapperStyle) {
892
- const { columnGap, rowGap, gap } = columnWrapperStyle;
893
- const gapX = columnGap || gap || 0;
894
- const gapY = rowGap || gap || 0;
895
- if (horizontal) {
896
- if (gapY && numColumns > 1) {
897
- style.marginVertical = -gapY / 2;
898
- }
899
- if (gapX) {
900
- style.marginRight = -gapX;
901
- }
902
- } else {
903
- if (gapX && numColumns > 1) {
904
- style.marginHorizontal = -gapX;
905
- }
906
- if (gapY) {
907
- style.marginBottom = -gapY;
908
- }
909
- }
910
- }
911
- return /* @__PURE__ */ React2__namespace.createElement(ReactNative.Animated.View, { style }, containers);
914
+ return /* @__PURE__ */ React2__namespace.createElement(ContainersLayer, { horizontal }, containers);
912
915
  });
913
916
  var ListComponentScrollView = ReactNative.Animated.ScrollView;
914
917
  function ScrollAdjust() {
@@ -3698,7 +3701,7 @@ function computeViewability(state, ctx, viewabilityConfig, containerId, key, scr
3698
3701
  }
3699
3702
  function checkIsViewable(state, ctx, viewabilityConfig, containerId, key, scrollSize, item, index) {
3700
3703
  let value = ctx.mapViewabilityAmountValues.get(containerId);
3701
- if (!value || value.key !== key) {
3704
+ if (!value || value.key !== key || value.index !== index) {
3702
3705
  value = computeViewability(state, ctx, viewabilityConfig, containerId, key, scrollSize, item, index);
3703
3706
  }
3704
3707
  return value.isViewable;
@@ -3713,7 +3716,7 @@ var unstableBatchedUpdates = ReactNative__namespace.unstable_batchedUpdates;
3713
3716
  var batchedUpdates = typeof unstableBatchedUpdates === "function" ? unstableBatchedUpdates : (fn) => fn();
3714
3717
 
3715
3718
  // src/utils/findAvailableContainers.ts
3716
- function findAvailableContainers(ctx, numNeeded, startBuffered, endBuffered, pendingRemoval, requiredItemTypes, needNewContainers) {
3719
+ function findAvailableContainers(ctx, numNeeded, startBuffered, endBuffered, pendingRemoval, requiredItemTypes, needNewContainers, protectedKeys) {
3717
3720
  const numContainers = peek$(ctx, "numContainers");
3718
3721
  const state = ctx.state;
3719
3722
  const { stickyContainerPool, containerItemTypes } = state;
@@ -3781,6 +3784,7 @@ function findAvailableContainers(ctx, numNeeded, startBuffered, endBuffered, pen
3781
3784
  }
3782
3785
  const key = peek$(ctx, `containerItemKey${u}`);
3783
3786
  if (key === void 0) continue;
3787
+ if ((protectedKeys == null ? void 0 : protectedKeys.has(key)) && state.indexByKey.has(key)) continue;
3784
3788
  const index = state.indexByKey.get(key);
3785
3789
  const isOutOfView = index < startBuffered || index > endBuffered;
3786
3790
  if (isOutOfView) {
@@ -3916,7 +3920,7 @@ function handleStickyRecycling(ctx, stickyArray, scroll, drawDistance, currentSt
3916
3920
  function calculateItemsInView(ctx, params = {}) {
3917
3921
  const state = ctx.state;
3918
3922
  batchedUpdates(() => {
3919
- var _a3, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
3923
+ var _a3, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
3920
3924
  const {
3921
3925
  columns,
3922
3926
  columnSpans,
@@ -4018,17 +4022,31 @@ function calculateItemsInView(ctx, params = {}) {
4018
4022
  if (minIndexSizeChanged !== void 0) {
4019
4023
  state.minIndexSizeChanged = void 0;
4020
4024
  }
4025
+ let protectedContainerKeys;
4026
+ if (dataChanged && doMVCP && state.props.maintainVisibleContentPosition.data && state.didContainersLayout && state.idsInView.length > 0) {
4027
+ const shouldRestorePosition = state.props.maintainVisibleContentPosition.shouldRestorePosition;
4028
+ protectedContainerKeys = /* @__PURE__ */ new Set();
4029
+ for (const id of state.idsInView) {
4030
+ const index = indexByKey.get(id);
4031
+ if (index === void 0) continue;
4032
+ if (shouldRestorePosition && !shouldRestorePosition(data[index], index, data)) continue;
4033
+ protectedContainerKeys.add(id);
4034
+ }
4035
+ }
4036
+ const scrollBeforeMVCP = state.scroll;
4037
+ const scrollAdjustPendingBeforeMVCP = (_e = peek$(ctx, "scrollAdjustPending")) != null ? _e : 0;
4021
4038
  checkMVCP == null ? void 0 : checkMVCP();
4039
+ const didMVCPAdjustScroll = !!checkMVCP && (state.scroll !== scrollBeforeMVCP || ((_f = peek$(ctx, "scrollAdjustPending")) != null ? _f : 0) !== scrollAdjustPendingBeforeMVCP);
4022
4040
  let startNoBuffer = null;
4023
4041
  let startBuffered = null;
4024
4042
  let startBufferedId = null;
4025
4043
  let endNoBuffer = null;
4026
4044
  let endBuffered = null;
4027
- let loopStart = (_e = suppressInitialScrollSideEffects ? bootstrapInitialScrollState == null ? void 0 : bootstrapInitialScrollState.targetIndexSeed : void 0) != null ? _e : !dataChanged && startBufferedIdOrig ? indexByKey.get(startBufferedIdOrig) || 0 : 0;
4045
+ let loopStart = (_g = suppressInitialScrollSideEffects ? bootstrapInitialScrollState == null ? void 0 : bootstrapInitialScrollState.targetIndexSeed : void 0) != null ? _g : !dataChanged && startBufferedIdOrig ? indexByKey.get(startBufferedIdOrig) || 0 : 0;
4028
4046
  for (let i = loopStart; i >= 0; i--) {
4029
- const id = (_f = idCache[i]) != null ? _f : getId(state, i);
4047
+ const id = (_h = idCache[i]) != null ? _h : getId(state, i);
4030
4048
  const top = positions[i];
4031
- const size = (_g = sizes.get(id)) != null ? _g : getItemSize(ctx, id, i, data[i]);
4049
+ const size = (_i = sizes.get(id)) != null ? _i : getItemSize(ctx, id, i, data[i]);
4032
4050
  const bottom = top + size;
4033
4051
  if (bottom > scroll - scrollBufferTop) {
4034
4052
  loopStart = i;
@@ -4059,8 +4077,8 @@ function calculateItemsInView(ctx, params = {}) {
4059
4077
  let firstFullyOnScreenIndex;
4060
4078
  const dataLength = data.length;
4061
4079
  for (let i = Math.max(0, loopStart); i < dataLength && (!foundEnd || i <= maxIndexRendered); i++) {
4062
- const id = (_h = idCache[i]) != null ? _h : getId(state, i);
4063
- const size = (_i = sizes.get(id)) != null ? _i : getItemSize(ctx, id, i, data[i]);
4080
+ const id = (_j = idCache[i]) != null ? _j : getId(state, i);
4081
+ const size = (_k = sizes.get(id)) != null ? _k : getItemSize(ctx, id, i, data[i]);
4064
4082
  const top = positions[i];
4065
4083
  if (!foundEnd) {
4066
4084
  if (startNoBuffer === null && top + size > scroll) {
@@ -4099,7 +4117,7 @@ function calculateItemsInView(ctx, params = {}) {
4099
4117
  const firstVisibleAnchorIndex = firstFullyOnScreenIndex != null ? firstFullyOnScreenIndex : startNoBuffer;
4100
4118
  if (firstVisibleAnchorIndex !== null && firstVisibleAnchorIndex !== void 0 && endNoBuffer !== null) {
4101
4119
  for (let i = firstVisibleAnchorIndex; i <= endNoBuffer; i++) {
4102
- const id = (_j = idCache[i]) != null ? _j : getId(state, i);
4120
+ const id = (_l = idCache[i]) != null ? _l : getId(state, i);
4103
4121
  idsInView.push(id);
4104
4122
  }
4105
4123
  }
@@ -4132,7 +4150,7 @@ function calculateItemsInView(ctx, params = {}) {
4132
4150
  const needNewContainers = [];
4133
4151
  const needNewContainersSet = /* @__PURE__ */ new Set();
4134
4152
  for (let i = startBuffered; i <= endBuffered; i++) {
4135
- const id = (_k = idCache[i]) != null ? _k : getId(state, i);
4153
+ const id = (_m = idCache[i]) != null ? _m : getId(state, i);
4136
4154
  if (!containerItemKeys.has(id)) {
4137
4155
  needNewContainersSet.add(i);
4138
4156
  needNewContainers.push(i);
@@ -4141,7 +4159,7 @@ function calculateItemsInView(ctx, params = {}) {
4141
4159
  if (alwaysRenderArr.length > 0) {
4142
4160
  for (const index of alwaysRenderArr) {
4143
4161
  if (index < 0 || index >= dataLength) continue;
4144
- const id = (_l = idCache[index]) != null ? _l : getId(state, index);
4162
+ const id = (_n = idCache[index]) != null ? _n : getId(state, index);
4145
4163
  if (id && !containerItemKeys.has(id) && !needNewContainersSet.has(index)) {
4146
4164
  needNewContainersSet.add(index);
4147
4165
  needNewContainers.push(index);
@@ -4174,12 +4192,13 @@ function calculateItemsInView(ctx, params = {}) {
4174
4192
  endBuffered,
4175
4193
  pendingRemoval,
4176
4194
  requiredItemTypes,
4177
- needNewContainers
4195
+ needNewContainers,
4196
+ protectedContainerKeys
4178
4197
  );
4179
4198
  for (let idx = 0; idx < needNewContainers.length; idx++) {
4180
4199
  const i = needNewContainers[idx];
4181
4200
  const containerIndex = availableContainers[idx];
4182
- const id = (_m = idCache[i]) != null ? _m : getId(state, i);
4201
+ const id = (_o = idCache[i]) != null ? _o : getId(state, i);
4183
4202
  const oldKey = peek$(ctx, `containerItemKey${containerIndex}`);
4184
4203
  if (oldKey && oldKey !== id) {
4185
4204
  containerItemKeys.delete(oldKey);
@@ -4220,7 +4239,7 @@ function calculateItemsInView(ctx, params = {}) {
4220
4239
  if (alwaysRenderArr.length > 0) {
4221
4240
  for (const index of alwaysRenderArr) {
4222
4241
  if (index < 0 || index >= dataLength) continue;
4223
- const id = (_n = idCache[index]) != null ? _n : getId(state, index);
4242
+ const id = (_p = idCache[index]) != null ? _p : getId(state, index);
4224
4243
  const containerIndex = containerItemKeys.get(id);
4225
4244
  if (containerIndex !== void 0) {
4226
4245
  state.stickyContainerPool.add(containerIndex);
@@ -4281,16 +4300,18 @@ function calculateItemsInView(ctx, params = {}) {
4281
4300
  handleInitialScrollLayoutReady(ctx);
4282
4301
  }
4283
4302
  if (viewabilityConfigCallbackPairs && startNoBuffer !== null && endNoBuffer !== null) {
4284
- updateViewableItems(
4285
- ctx.state,
4286
- ctx,
4287
- viewabilityConfigCallbackPairs,
4288
- scrollLength,
4289
- startNoBuffer,
4290
- endNoBuffer,
4291
- startBuffered != null ? startBuffered : startNoBuffer,
4292
- endBuffered != null ? endBuffered : endNoBuffer
4293
- );
4303
+ if (!didMVCPAdjustScroll) {
4304
+ updateViewableItems(
4305
+ ctx.state,
4306
+ ctx,
4307
+ viewabilityConfigCallbackPairs,
4308
+ scrollLength,
4309
+ startNoBuffer,
4310
+ endNoBuffer,
4311
+ startBuffered != null ? startBuffered : startNoBuffer,
4312
+ endBuffered != null ? endBuffered : endNoBuffer
4313
+ );
4314
+ }
4294
4315
  }
4295
4316
  if (onStickyHeaderChange && stickyIndicesArr.length > 0 && nextActiveStickyIndex !== void 0 && nextActiveStickyIndex !== previousStickyIndex) {
4296
4317
  const item = data[nextActiveStickyIndex];