@legendapp/list 3.0.0-beta.46 → 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
@@ -374,7 +374,7 @@ var PositionViewSticky = typedMemo(function PositionViewSticky2({
374
374
  () => getStickyPushLimit(ctx.state, index, itemKey),
375
375
  [ctx.state, index, itemKey, _totalSize]
376
376
  );
377
- const stickyPosition = React2__namespace.useMemo(() => {
377
+ const transform = React2__namespace.useMemo(() => {
378
378
  var _a3;
379
379
  if (animatedScrollY) {
380
380
  const stickyConfigOffset = (_a3 = stickyHeaderConfig == null ? void 0 : stickyHeaderConfig.offset) != null ? _a3 : 0;
@@ -399,13 +399,10 @@ var PositionViewSticky = typedMemo(function PositionViewSticky2({
399
399
  outputRange: [position, position + 5e3]
400
400
  });
401
401
  }
402
- return nextStickyPosition;
402
+ return horizontal ? [{ translateX: nextStickyPosition }] : [{ translateY: nextStickyPosition }];
403
403
  }
404
404
  }, [animatedScrollY, headerSize, position, pushLimit, stylePaddingTop, stickyHeaderConfig == null ? void 0 : stickyHeaderConfig.offset]);
405
- const viewStyle = React2__namespace.useMemo(
406
- () => [style, { zIndex: index + 1e3 }, horizontal ? { left: stickyPosition } : { top: stickyPosition }],
407
- [horizontal, index, stickyPosition, style]
408
- );
405
+ const viewStyle = React2__namespace.useMemo(() => [style, { zIndex: index + 1e3 }, { transform }], [style, transform]);
409
406
  const renderStickyHeaderBackdrop = React2__namespace.useMemo(() => {
410
407
  if (!(stickyHeaderConfig == null ? void 0 : stickyHeaderConfig.backdropComponent)) {
411
408
  return null;
@@ -858,6 +855,35 @@ var Container = typedMemo(function Container2({
858
855
  });
859
856
 
860
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
+ });
861
887
  var Containers = typedMemo(function Containers2({
862
888
  horizontal,
863
889
  recycleItems,
@@ -866,12 +892,7 @@ var Containers = typedMemo(function Containers2({
866
892
  updateItemSize: updateItemSize2,
867
893
  getRenderedItem: getRenderedItem2
868
894
  }) {
869
- const ctx = useStateContext();
870
- const columnWrapperStyle = ctx.columnWrapperStyle;
871
- const [numContainers, numColumns] = useArr$(["numContainersPooled", "numColumns"]);
872
- const animSize = useValue$("totalSize");
873
- const otherAxisSize = useValue$("otherAxisSize");
874
- const animOpacity = useValue$("readyToRender", { getValue: (value) => value ? 1 : 0 });
895
+ const [numContainers] = useArr$(["numContainersPooled"]);
875
896
  const containers = [];
876
897
  for (let i = 0; i < numContainers; i++) {
877
898
  containers.push(
@@ -890,28 +911,7 @@ var Containers = typedMemo(function Containers2({
890
911
  )
891
912
  );
892
913
  }
893
- const style = horizontal ? { minHeight: otherAxisSize, opacity: animOpacity, width: animSize } : { height: animSize, minWidth: otherAxisSize, opacity: animOpacity };
894
- if (columnWrapperStyle) {
895
- const { columnGap, rowGap, gap } = columnWrapperStyle;
896
- const gapX = columnGap || gap || 0;
897
- const gapY = rowGap || gap || 0;
898
- if (horizontal) {
899
- if (gapY && numColumns > 1) {
900
- style.marginVertical = -gapY / 2;
901
- }
902
- if (gapX) {
903
- style.marginRight = -gapX;
904
- }
905
- } else {
906
- if (gapX && numColumns > 1) {
907
- style.marginHorizontal = -gapX;
908
- }
909
- if (gapY) {
910
- style.marginBottom = -gapY;
911
- }
912
- }
913
- }
914
- return /* @__PURE__ */ React2__namespace.createElement(ReactNative.Animated.View, { style }, containers);
914
+ return /* @__PURE__ */ React2__namespace.createElement(ContainersLayer, { horizontal }, containers);
915
915
  });
916
916
  var ListComponentScrollView = ReactNative.Animated.ScrollView;
917
917
  function ScrollAdjust() {
@@ -3701,7 +3701,7 @@ function computeViewability(state, ctx, viewabilityConfig, containerId, key, scr
3701
3701
  }
3702
3702
  function checkIsViewable(state, ctx, viewabilityConfig, containerId, key, scrollSize, item, index) {
3703
3703
  let value = ctx.mapViewabilityAmountValues.get(containerId);
3704
- if (!value || value.key !== key) {
3704
+ if (!value || value.key !== key || value.index !== index) {
3705
3705
  value = computeViewability(state, ctx, viewabilityConfig, containerId, key, scrollSize, item, index);
3706
3706
  }
3707
3707
  return value.isViewable;
@@ -3716,7 +3716,7 @@ var unstableBatchedUpdates = ReactNative__namespace.unstable_batchedUpdates;
3716
3716
  var batchedUpdates = typeof unstableBatchedUpdates === "function" ? unstableBatchedUpdates : (fn) => fn();
3717
3717
 
3718
3718
  // src/utils/findAvailableContainers.ts
3719
- function findAvailableContainers(ctx, numNeeded, startBuffered, endBuffered, pendingRemoval, requiredItemTypes, needNewContainers) {
3719
+ function findAvailableContainers(ctx, numNeeded, startBuffered, endBuffered, pendingRemoval, requiredItemTypes, needNewContainers, protectedKeys) {
3720
3720
  const numContainers = peek$(ctx, "numContainers");
3721
3721
  const state = ctx.state;
3722
3722
  const { stickyContainerPool, containerItemTypes } = state;
@@ -3784,6 +3784,7 @@ function findAvailableContainers(ctx, numNeeded, startBuffered, endBuffered, pen
3784
3784
  }
3785
3785
  const key = peek$(ctx, `containerItemKey${u}`);
3786
3786
  if (key === void 0) continue;
3787
+ if ((protectedKeys == null ? void 0 : protectedKeys.has(key)) && state.indexByKey.has(key)) continue;
3787
3788
  const index = state.indexByKey.get(key);
3788
3789
  const isOutOfView = index < startBuffered || index > endBuffered;
3789
3790
  if (isOutOfView) {
@@ -3919,7 +3920,7 @@ function handleStickyRecycling(ctx, stickyArray, scroll, drawDistance, currentSt
3919
3920
  function calculateItemsInView(ctx, params = {}) {
3920
3921
  const state = ctx.state;
3921
3922
  batchedUpdates(() => {
3922
- 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;
3923
3924
  const {
3924
3925
  columns,
3925
3926
  columnSpans,
@@ -4021,17 +4022,31 @@ function calculateItemsInView(ctx, params = {}) {
4021
4022
  if (minIndexSizeChanged !== void 0) {
4022
4023
  state.minIndexSizeChanged = void 0;
4023
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;
4024
4038
  checkMVCP == null ? void 0 : checkMVCP();
4039
+ const didMVCPAdjustScroll = !!checkMVCP && (state.scroll !== scrollBeforeMVCP || ((_f = peek$(ctx, "scrollAdjustPending")) != null ? _f : 0) !== scrollAdjustPendingBeforeMVCP);
4025
4040
  let startNoBuffer = null;
4026
4041
  let startBuffered = null;
4027
4042
  let startBufferedId = null;
4028
4043
  let endNoBuffer = null;
4029
4044
  let endBuffered = null;
4030
- 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;
4031
4046
  for (let i = loopStart; i >= 0; i--) {
4032
- const id = (_f = idCache[i]) != null ? _f : getId(state, i);
4047
+ const id = (_h = idCache[i]) != null ? _h : getId(state, i);
4033
4048
  const top = positions[i];
4034
- 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]);
4035
4050
  const bottom = top + size;
4036
4051
  if (bottom > scroll - scrollBufferTop) {
4037
4052
  loopStart = i;
@@ -4062,8 +4077,8 @@ function calculateItemsInView(ctx, params = {}) {
4062
4077
  let firstFullyOnScreenIndex;
4063
4078
  const dataLength = data.length;
4064
4079
  for (let i = Math.max(0, loopStart); i < dataLength && (!foundEnd || i <= maxIndexRendered); i++) {
4065
- const id = (_h = idCache[i]) != null ? _h : getId(state, i);
4066
- 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]);
4067
4082
  const top = positions[i];
4068
4083
  if (!foundEnd) {
4069
4084
  if (startNoBuffer === null && top + size > scroll) {
@@ -4102,7 +4117,7 @@ function calculateItemsInView(ctx, params = {}) {
4102
4117
  const firstVisibleAnchorIndex = firstFullyOnScreenIndex != null ? firstFullyOnScreenIndex : startNoBuffer;
4103
4118
  if (firstVisibleAnchorIndex !== null && firstVisibleAnchorIndex !== void 0 && endNoBuffer !== null) {
4104
4119
  for (let i = firstVisibleAnchorIndex; i <= endNoBuffer; i++) {
4105
- const id = (_j = idCache[i]) != null ? _j : getId(state, i);
4120
+ const id = (_l = idCache[i]) != null ? _l : getId(state, i);
4106
4121
  idsInView.push(id);
4107
4122
  }
4108
4123
  }
@@ -4135,7 +4150,7 @@ function calculateItemsInView(ctx, params = {}) {
4135
4150
  const needNewContainers = [];
4136
4151
  const needNewContainersSet = /* @__PURE__ */ new Set();
4137
4152
  for (let i = startBuffered; i <= endBuffered; i++) {
4138
- const id = (_k = idCache[i]) != null ? _k : getId(state, i);
4153
+ const id = (_m = idCache[i]) != null ? _m : getId(state, i);
4139
4154
  if (!containerItemKeys.has(id)) {
4140
4155
  needNewContainersSet.add(i);
4141
4156
  needNewContainers.push(i);
@@ -4144,7 +4159,7 @@ function calculateItemsInView(ctx, params = {}) {
4144
4159
  if (alwaysRenderArr.length > 0) {
4145
4160
  for (const index of alwaysRenderArr) {
4146
4161
  if (index < 0 || index >= dataLength) continue;
4147
- const id = (_l = idCache[index]) != null ? _l : getId(state, index);
4162
+ const id = (_n = idCache[index]) != null ? _n : getId(state, index);
4148
4163
  if (id && !containerItemKeys.has(id) && !needNewContainersSet.has(index)) {
4149
4164
  needNewContainersSet.add(index);
4150
4165
  needNewContainers.push(index);
@@ -4177,12 +4192,13 @@ function calculateItemsInView(ctx, params = {}) {
4177
4192
  endBuffered,
4178
4193
  pendingRemoval,
4179
4194
  requiredItemTypes,
4180
- needNewContainers
4195
+ needNewContainers,
4196
+ protectedContainerKeys
4181
4197
  );
4182
4198
  for (let idx = 0; idx < needNewContainers.length; idx++) {
4183
4199
  const i = needNewContainers[idx];
4184
4200
  const containerIndex = availableContainers[idx];
4185
- const id = (_m = idCache[i]) != null ? _m : getId(state, i);
4201
+ const id = (_o = idCache[i]) != null ? _o : getId(state, i);
4186
4202
  const oldKey = peek$(ctx, `containerItemKey${containerIndex}`);
4187
4203
  if (oldKey && oldKey !== id) {
4188
4204
  containerItemKeys.delete(oldKey);
@@ -4223,7 +4239,7 @@ function calculateItemsInView(ctx, params = {}) {
4223
4239
  if (alwaysRenderArr.length > 0) {
4224
4240
  for (const index of alwaysRenderArr) {
4225
4241
  if (index < 0 || index >= dataLength) continue;
4226
- const id = (_n = idCache[index]) != null ? _n : getId(state, index);
4242
+ const id = (_p = idCache[index]) != null ? _p : getId(state, index);
4227
4243
  const containerIndex = containerItemKeys.get(id);
4228
4244
  if (containerIndex !== void 0) {
4229
4245
  state.stickyContainerPool.add(containerIndex);
@@ -4284,16 +4300,18 @@ function calculateItemsInView(ctx, params = {}) {
4284
4300
  handleInitialScrollLayoutReady(ctx);
4285
4301
  }
4286
4302
  if (viewabilityConfigCallbackPairs && startNoBuffer !== null && endNoBuffer !== null) {
4287
- updateViewableItems(
4288
- ctx.state,
4289
- ctx,
4290
- viewabilityConfigCallbackPairs,
4291
- scrollLength,
4292
- startNoBuffer,
4293
- endNoBuffer,
4294
- startBuffered != null ? startBuffered : startNoBuffer,
4295
- endBuffered != null ? endBuffered : endNoBuffer
4296
- );
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
+ }
4297
4315
  }
4298
4316
  if (onStickyHeaderChange && stickyIndicesArr.length > 0 && nextActiveStickyIndex !== void 0 && nextActiveStickyIndex !== previousStickyIndex) {
4299
4317
  const item = data[nextActiveStickyIndex];