@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/react-native.mjs CHANGED
@@ -353,7 +353,7 @@ var PositionViewSticky = typedMemo(function PositionViewSticky2({
353
353
  () => getStickyPushLimit(ctx.state, index, itemKey),
354
354
  [ctx.state, index, itemKey, _totalSize]
355
355
  );
356
- const stickyPosition = React2.useMemo(() => {
356
+ const transform = React2.useMemo(() => {
357
357
  var _a3;
358
358
  if (animatedScrollY) {
359
359
  const stickyConfigOffset = (_a3 = stickyHeaderConfig == null ? void 0 : stickyHeaderConfig.offset) != null ? _a3 : 0;
@@ -378,13 +378,10 @@ var PositionViewSticky = typedMemo(function PositionViewSticky2({
378
378
  outputRange: [position, position + 5e3]
379
379
  });
380
380
  }
381
- return nextStickyPosition;
381
+ return horizontal ? [{ translateX: nextStickyPosition }] : [{ translateY: nextStickyPosition }];
382
382
  }
383
383
  }, [animatedScrollY, headerSize, position, pushLimit, stylePaddingTop, stickyHeaderConfig == null ? void 0 : stickyHeaderConfig.offset]);
384
- const viewStyle = React2.useMemo(
385
- () => [style, { zIndex: index + 1e3 }, horizontal ? { left: stickyPosition } : { top: stickyPosition }],
386
- [horizontal, index, stickyPosition, style]
387
- );
384
+ const viewStyle = React2.useMemo(() => [style, { zIndex: index + 1e3 }, { transform }], [style, transform]);
388
385
  const renderStickyHeaderBackdrop = React2.useMemo(() => {
389
386
  if (!(stickyHeaderConfig == null ? void 0 : stickyHeaderConfig.backdropComponent)) {
390
387
  return null;
@@ -837,6 +834,35 @@ var Container = typedMemo(function Container2({
837
834
  });
838
835
 
839
836
  // src/components/Containers.native.tsx
837
+ var ContainersLayer = typedMemo(function ContainersLayer2({ children, horizontal }) {
838
+ const ctx = useStateContext();
839
+ const columnWrapperStyle = ctx.columnWrapperStyle;
840
+ const animSize = useValue$("totalSize");
841
+ const otherAxisSize = useValue$("otherAxisSize");
842
+ const [readyToRender, numColumns] = useArr$(["readyToRender", "numColumns"]);
843
+ const style = horizontal ? { minHeight: otherAxisSize, opacity: readyToRender ? 1 : 0, width: animSize } : { height: animSize, minWidth: otherAxisSize, opacity: readyToRender ? 1 : 0 };
844
+ if (columnWrapperStyle) {
845
+ const { columnGap, rowGap, gap } = columnWrapperStyle;
846
+ const gapX = columnGap || gap || 0;
847
+ const gapY = rowGap || gap || 0;
848
+ if (horizontal) {
849
+ if (gapY && numColumns > 1) {
850
+ style.marginVertical = -gapY / 2;
851
+ }
852
+ if (gapX) {
853
+ style.marginRight = -gapX;
854
+ }
855
+ } else {
856
+ if (gapX && numColumns > 1) {
857
+ style.marginHorizontal = -gapX;
858
+ }
859
+ if (gapY) {
860
+ style.marginBottom = -gapY;
861
+ }
862
+ }
863
+ }
864
+ return /* @__PURE__ */ React2.createElement(Animated.View, { style }, children);
865
+ });
840
866
  var Containers = typedMemo(function Containers2({
841
867
  horizontal,
842
868
  recycleItems,
@@ -845,12 +871,7 @@ var Containers = typedMemo(function Containers2({
845
871
  updateItemSize: updateItemSize2,
846
872
  getRenderedItem: getRenderedItem2
847
873
  }) {
848
- const ctx = useStateContext();
849
- const columnWrapperStyle = ctx.columnWrapperStyle;
850
- const [numContainers, numColumns] = useArr$(["numContainersPooled", "numColumns"]);
851
- const animSize = useValue$("totalSize");
852
- const otherAxisSize = useValue$("otherAxisSize");
853
- const animOpacity = useValue$("readyToRender", { getValue: (value) => value ? 1 : 0 });
874
+ const [numContainers] = useArr$(["numContainersPooled"]);
854
875
  const containers = [];
855
876
  for (let i = 0; i < numContainers; i++) {
856
877
  containers.push(
@@ -869,28 +890,7 @@ var Containers = typedMemo(function Containers2({
869
890
  )
870
891
  );
871
892
  }
872
- const style = horizontal ? { minHeight: otherAxisSize, opacity: animOpacity, width: animSize } : { height: animSize, minWidth: otherAxisSize, opacity: animOpacity };
873
- if (columnWrapperStyle) {
874
- const { columnGap, rowGap, gap } = columnWrapperStyle;
875
- const gapX = columnGap || gap || 0;
876
- const gapY = rowGap || gap || 0;
877
- if (horizontal) {
878
- if (gapY && numColumns > 1) {
879
- style.marginVertical = -gapY / 2;
880
- }
881
- if (gapX) {
882
- style.marginRight = -gapX;
883
- }
884
- } else {
885
- if (gapX && numColumns > 1) {
886
- style.marginHorizontal = -gapX;
887
- }
888
- if (gapY) {
889
- style.marginBottom = -gapY;
890
- }
891
- }
892
- }
893
- return /* @__PURE__ */ React2.createElement(Animated.View, { style }, containers);
893
+ return /* @__PURE__ */ React2.createElement(ContainersLayer, { horizontal }, containers);
894
894
  });
895
895
  var ListComponentScrollView = Animated.ScrollView;
896
896
  function ScrollAdjust() {
@@ -3680,7 +3680,7 @@ function computeViewability(state, ctx, viewabilityConfig, containerId, key, scr
3680
3680
  }
3681
3681
  function checkIsViewable(state, ctx, viewabilityConfig, containerId, key, scrollSize, item, index) {
3682
3682
  let value = ctx.mapViewabilityAmountValues.get(containerId);
3683
- if (!value || value.key !== key) {
3683
+ if (!value || value.key !== key || value.index !== index) {
3684
3684
  value = computeViewability(state, ctx, viewabilityConfig, containerId, key, scrollSize, item, index);
3685
3685
  }
3686
3686
  return value.isViewable;
@@ -3695,7 +3695,7 @@ var unstableBatchedUpdates = ReactNative.unstable_batchedUpdates;
3695
3695
  var batchedUpdates = typeof unstableBatchedUpdates === "function" ? unstableBatchedUpdates : (fn) => fn();
3696
3696
 
3697
3697
  // src/utils/findAvailableContainers.ts
3698
- function findAvailableContainers(ctx, numNeeded, startBuffered, endBuffered, pendingRemoval, requiredItemTypes, needNewContainers) {
3698
+ function findAvailableContainers(ctx, numNeeded, startBuffered, endBuffered, pendingRemoval, requiredItemTypes, needNewContainers, protectedKeys) {
3699
3699
  const numContainers = peek$(ctx, "numContainers");
3700
3700
  const state = ctx.state;
3701
3701
  const { stickyContainerPool, containerItemTypes } = state;
@@ -3763,6 +3763,7 @@ function findAvailableContainers(ctx, numNeeded, startBuffered, endBuffered, pen
3763
3763
  }
3764
3764
  const key = peek$(ctx, `containerItemKey${u}`);
3765
3765
  if (key === void 0) continue;
3766
+ if ((protectedKeys == null ? void 0 : protectedKeys.has(key)) && state.indexByKey.has(key)) continue;
3766
3767
  const index = state.indexByKey.get(key);
3767
3768
  const isOutOfView = index < startBuffered || index > endBuffered;
3768
3769
  if (isOutOfView) {
@@ -3898,7 +3899,7 @@ function handleStickyRecycling(ctx, stickyArray, scroll, drawDistance, currentSt
3898
3899
  function calculateItemsInView(ctx, params = {}) {
3899
3900
  const state = ctx.state;
3900
3901
  batchedUpdates(() => {
3901
- var _a3, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
3902
+ var _a3, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
3902
3903
  const {
3903
3904
  columns,
3904
3905
  columnSpans,
@@ -4000,17 +4001,31 @@ function calculateItemsInView(ctx, params = {}) {
4000
4001
  if (minIndexSizeChanged !== void 0) {
4001
4002
  state.minIndexSizeChanged = void 0;
4002
4003
  }
4004
+ let protectedContainerKeys;
4005
+ if (dataChanged && doMVCP && state.props.maintainVisibleContentPosition.data && state.didContainersLayout && state.idsInView.length > 0) {
4006
+ const shouldRestorePosition = state.props.maintainVisibleContentPosition.shouldRestorePosition;
4007
+ protectedContainerKeys = /* @__PURE__ */ new Set();
4008
+ for (const id of state.idsInView) {
4009
+ const index = indexByKey.get(id);
4010
+ if (index === void 0) continue;
4011
+ if (shouldRestorePosition && !shouldRestorePosition(data[index], index, data)) continue;
4012
+ protectedContainerKeys.add(id);
4013
+ }
4014
+ }
4015
+ const scrollBeforeMVCP = state.scroll;
4016
+ const scrollAdjustPendingBeforeMVCP = (_e = peek$(ctx, "scrollAdjustPending")) != null ? _e : 0;
4003
4017
  checkMVCP == null ? void 0 : checkMVCP();
4018
+ const didMVCPAdjustScroll = !!checkMVCP && (state.scroll !== scrollBeforeMVCP || ((_f = peek$(ctx, "scrollAdjustPending")) != null ? _f : 0) !== scrollAdjustPendingBeforeMVCP);
4004
4019
  let startNoBuffer = null;
4005
4020
  let startBuffered = null;
4006
4021
  let startBufferedId = null;
4007
4022
  let endNoBuffer = null;
4008
4023
  let endBuffered = null;
4009
- let loopStart = (_e = suppressInitialScrollSideEffects ? bootstrapInitialScrollState == null ? void 0 : bootstrapInitialScrollState.targetIndexSeed : void 0) != null ? _e : !dataChanged && startBufferedIdOrig ? indexByKey.get(startBufferedIdOrig) || 0 : 0;
4024
+ let loopStart = (_g = suppressInitialScrollSideEffects ? bootstrapInitialScrollState == null ? void 0 : bootstrapInitialScrollState.targetIndexSeed : void 0) != null ? _g : !dataChanged && startBufferedIdOrig ? indexByKey.get(startBufferedIdOrig) || 0 : 0;
4010
4025
  for (let i = loopStart; i >= 0; i--) {
4011
- const id = (_f = idCache[i]) != null ? _f : getId(state, i);
4026
+ const id = (_h = idCache[i]) != null ? _h : getId(state, i);
4012
4027
  const top = positions[i];
4013
- const size = (_g = sizes.get(id)) != null ? _g : getItemSize(ctx, id, i, data[i]);
4028
+ const size = (_i = sizes.get(id)) != null ? _i : getItemSize(ctx, id, i, data[i]);
4014
4029
  const bottom = top + size;
4015
4030
  if (bottom > scroll - scrollBufferTop) {
4016
4031
  loopStart = i;
@@ -4041,8 +4056,8 @@ function calculateItemsInView(ctx, params = {}) {
4041
4056
  let firstFullyOnScreenIndex;
4042
4057
  const dataLength = data.length;
4043
4058
  for (let i = Math.max(0, loopStart); i < dataLength && (!foundEnd || i <= maxIndexRendered); i++) {
4044
- const id = (_h = idCache[i]) != null ? _h : getId(state, i);
4045
- const size = (_i = sizes.get(id)) != null ? _i : getItemSize(ctx, id, i, data[i]);
4059
+ const id = (_j = idCache[i]) != null ? _j : getId(state, i);
4060
+ const size = (_k = sizes.get(id)) != null ? _k : getItemSize(ctx, id, i, data[i]);
4046
4061
  const top = positions[i];
4047
4062
  if (!foundEnd) {
4048
4063
  if (startNoBuffer === null && top + size > scroll) {
@@ -4081,7 +4096,7 @@ function calculateItemsInView(ctx, params = {}) {
4081
4096
  const firstVisibleAnchorIndex = firstFullyOnScreenIndex != null ? firstFullyOnScreenIndex : startNoBuffer;
4082
4097
  if (firstVisibleAnchorIndex !== null && firstVisibleAnchorIndex !== void 0 && endNoBuffer !== null) {
4083
4098
  for (let i = firstVisibleAnchorIndex; i <= endNoBuffer; i++) {
4084
- const id = (_j = idCache[i]) != null ? _j : getId(state, i);
4099
+ const id = (_l = idCache[i]) != null ? _l : getId(state, i);
4085
4100
  idsInView.push(id);
4086
4101
  }
4087
4102
  }
@@ -4114,7 +4129,7 @@ function calculateItemsInView(ctx, params = {}) {
4114
4129
  const needNewContainers = [];
4115
4130
  const needNewContainersSet = /* @__PURE__ */ new Set();
4116
4131
  for (let i = startBuffered; i <= endBuffered; i++) {
4117
- const id = (_k = idCache[i]) != null ? _k : getId(state, i);
4132
+ const id = (_m = idCache[i]) != null ? _m : getId(state, i);
4118
4133
  if (!containerItemKeys.has(id)) {
4119
4134
  needNewContainersSet.add(i);
4120
4135
  needNewContainers.push(i);
@@ -4123,7 +4138,7 @@ function calculateItemsInView(ctx, params = {}) {
4123
4138
  if (alwaysRenderArr.length > 0) {
4124
4139
  for (const index of alwaysRenderArr) {
4125
4140
  if (index < 0 || index >= dataLength) continue;
4126
- const id = (_l = idCache[index]) != null ? _l : getId(state, index);
4141
+ const id = (_n = idCache[index]) != null ? _n : getId(state, index);
4127
4142
  if (id && !containerItemKeys.has(id) && !needNewContainersSet.has(index)) {
4128
4143
  needNewContainersSet.add(index);
4129
4144
  needNewContainers.push(index);
@@ -4156,12 +4171,13 @@ function calculateItemsInView(ctx, params = {}) {
4156
4171
  endBuffered,
4157
4172
  pendingRemoval,
4158
4173
  requiredItemTypes,
4159
- needNewContainers
4174
+ needNewContainers,
4175
+ protectedContainerKeys
4160
4176
  );
4161
4177
  for (let idx = 0; idx < needNewContainers.length; idx++) {
4162
4178
  const i = needNewContainers[idx];
4163
4179
  const containerIndex = availableContainers[idx];
4164
- const id = (_m = idCache[i]) != null ? _m : getId(state, i);
4180
+ const id = (_o = idCache[i]) != null ? _o : getId(state, i);
4165
4181
  const oldKey = peek$(ctx, `containerItemKey${containerIndex}`);
4166
4182
  if (oldKey && oldKey !== id) {
4167
4183
  containerItemKeys.delete(oldKey);
@@ -4202,7 +4218,7 @@ function calculateItemsInView(ctx, params = {}) {
4202
4218
  if (alwaysRenderArr.length > 0) {
4203
4219
  for (const index of alwaysRenderArr) {
4204
4220
  if (index < 0 || index >= dataLength) continue;
4205
- const id = (_n = idCache[index]) != null ? _n : getId(state, index);
4221
+ const id = (_p = idCache[index]) != null ? _p : getId(state, index);
4206
4222
  const containerIndex = containerItemKeys.get(id);
4207
4223
  if (containerIndex !== void 0) {
4208
4224
  state.stickyContainerPool.add(containerIndex);
@@ -4263,16 +4279,18 @@ function calculateItemsInView(ctx, params = {}) {
4263
4279
  handleInitialScrollLayoutReady(ctx);
4264
4280
  }
4265
4281
  if (viewabilityConfigCallbackPairs && startNoBuffer !== null && endNoBuffer !== null) {
4266
- updateViewableItems(
4267
- ctx.state,
4268
- ctx,
4269
- viewabilityConfigCallbackPairs,
4270
- scrollLength,
4271
- startNoBuffer,
4272
- endNoBuffer,
4273
- startBuffered != null ? startBuffered : startNoBuffer,
4274
- endBuffered != null ? endBuffered : endNoBuffer
4275
- );
4282
+ if (!didMVCPAdjustScroll) {
4283
+ updateViewableItems(
4284
+ ctx.state,
4285
+ ctx,
4286
+ viewabilityConfigCallbackPairs,
4287
+ scrollLength,
4288
+ startNoBuffer,
4289
+ endNoBuffer,
4290
+ startBuffered != null ? startBuffered : startNoBuffer,
4291
+ endBuffered != null ? endBuffered : endNoBuffer
4292
+ );
4293
+ }
4276
4294
  }
4277
4295
  if (onStickyHeaderChange && stickyIndicesArr.length > 0 && nextActiveStickyIndex !== void 0 && nextActiveStickyIndex !== previousStickyIndex) {
4278
4296
  const item = data[nextActiveStickyIndex];
@@ -4232,7 +4232,7 @@ function computeViewability(state, ctx, viewabilityConfig, containerId, key, scr
4232
4232
  }
4233
4233
  function checkIsViewable(state, ctx, viewabilityConfig, containerId, key, scrollSize, item, index) {
4234
4234
  let value = ctx.mapViewabilityAmountValues.get(containerId);
4235
- if (!value || value.key !== key) {
4235
+ if (!value || value.key !== key || value.index !== index) {
4236
4236
  value = computeViewability(state, ctx, viewabilityConfig, containerId, key, scrollSize, item, index);
4237
4237
  }
4238
4238
  return value.isViewable;
@@ -4247,7 +4247,7 @@ var unstableBatchedUpdates = ReactDOM__namespace.unstable_batchedUpdates;
4247
4247
  var batchedUpdates = typeof unstableBatchedUpdates === "function" ? unstableBatchedUpdates : (fn) => fn();
4248
4248
 
4249
4249
  // src/utils/findAvailableContainers.ts
4250
- function findAvailableContainers(ctx, numNeeded, startBuffered, endBuffered, pendingRemoval, requiredItemTypes, needNewContainers) {
4250
+ function findAvailableContainers(ctx, numNeeded, startBuffered, endBuffered, pendingRemoval, requiredItemTypes, needNewContainers, protectedKeys) {
4251
4251
  const numContainers = peek$(ctx, "numContainers");
4252
4252
  const state = ctx.state;
4253
4253
  const { stickyContainerPool, containerItemTypes } = state;
@@ -4315,6 +4315,7 @@ function findAvailableContainers(ctx, numNeeded, startBuffered, endBuffered, pen
4315
4315
  }
4316
4316
  const key = peek$(ctx, `containerItemKey${u}`);
4317
4317
  if (key === void 0) continue;
4318
+ if ((protectedKeys == null ? void 0 : protectedKeys.has(key)) && state.indexByKey.has(key)) continue;
4318
4319
  const index = state.indexByKey.get(key);
4319
4320
  const isOutOfView = index < startBuffered || index > endBuffered;
4320
4321
  if (isOutOfView) {
@@ -4450,7 +4451,7 @@ function handleStickyRecycling(ctx, stickyArray, scroll, drawDistance, currentSt
4450
4451
  function calculateItemsInView(ctx, params = {}) {
4451
4452
  const state = ctx.state;
4452
4453
  batchedUpdates(() => {
4453
- var _a3, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
4454
+ var _a3, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
4454
4455
  const {
4455
4456
  columns,
4456
4457
  columnSpans,
@@ -4552,17 +4553,31 @@ function calculateItemsInView(ctx, params = {}) {
4552
4553
  if (minIndexSizeChanged !== void 0) {
4553
4554
  state.minIndexSizeChanged = void 0;
4554
4555
  }
4556
+ let protectedContainerKeys;
4557
+ if (dataChanged && doMVCP && state.props.maintainVisibleContentPosition.data && state.didContainersLayout && state.idsInView.length > 0) {
4558
+ const shouldRestorePosition = state.props.maintainVisibleContentPosition.shouldRestorePosition;
4559
+ protectedContainerKeys = /* @__PURE__ */ new Set();
4560
+ for (const id of state.idsInView) {
4561
+ const index = indexByKey.get(id);
4562
+ if (index === void 0) continue;
4563
+ if (shouldRestorePosition && !shouldRestorePosition(data[index], index, data)) continue;
4564
+ protectedContainerKeys.add(id);
4565
+ }
4566
+ }
4567
+ const scrollBeforeMVCP = state.scroll;
4568
+ const scrollAdjustPendingBeforeMVCP = (_e = peek$(ctx, "scrollAdjustPending")) != null ? _e : 0;
4555
4569
  checkMVCP == null ? void 0 : checkMVCP();
4570
+ const didMVCPAdjustScroll = !!checkMVCP && (state.scroll !== scrollBeforeMVCP || ((_f = peek$(ctx, "scrollAdjustPending")) != null ? _f : 0) !== scrollAdjustPendingBeforeMVCP);
4556
4571
  let startNoBuffer = null;
4557
4572
  let startBuffered = null;
4558
4573
  let startBufferedId = null;
4559
4574
  let endNoBuffer = null;
4560
4575
  let endBuffered = null;
4561
- let loopStart = (_e = suppressInitialScrollSideEffects ? bootstrapInitialScrollState == null ? void 0 : bootstrapInitialScrollState.targetIndexSeed : void 0) != null ? _e : !dataChanged && startBufferedIdOrig ? indexByKey.get(startBufferedIdOrig) || 0 : 0;
4576
+ let loopStart = (_g = suppressInitialScrollSideEffects ? bootstrapInitialScrollState == null ? void 0 : bootstrapInitialScrollState.targetIndexSeed : void 0) != null ? _g : !dataChanged && startBufferedIdOrig ? indexByKey.get(startBufferedIdOrig) || 0 : 0;
4562
4577
  for (let i = loopStart; i >= 0; i--) {
4563
- const id = (_f = idCache[i]) != null ? _f : getId(state, i);
4578
+ const id = (_h = idCache[i]) != null ? _h : getId(state, i);
4564
4579
  const top = positions[i];
4565
- const size = (_g = sizes.get(id)) != null ? _g : getItemSize(ctx, id, i, data[i]);
4580
+ const size = (_i = sizes.get(id)) != null ? _i : getItemSize(ctx, id, i, data[i]);
4566
4581
  const bottom = top + size;
4567
4582
  if (bottom > scroll - scrollBufferTop) {
4568
4583
  loopStart = i;
@@ -4593,8 +4608,8 @@ function calculateItemsInView(ctx, params = {}) {
4593
4608
  let firstFullyOnScreenIndex;
4594
4609
  const dataLength = data.length;
4595
4610
  for (let i = Math.max(0, loopStart); i < dataLength && (!foundEnd || i <= maxIndexRendered); i++) {
4596
- const id = (_h = idCache[i]) != null ? _h : getId(state, i);
4597
- const size = (_i = sizes.get(id)) != null ? _i : getItemSize(ctx, id, i, data[i]);
4611
+ const id = (_j = idCache[i]) != null ? _j : getId(state, i);
4612
+ const size = (_k = sizes.get(id)) != null ? _k : getItemSize(ctx, id, i, data[i]);
4598
4613
  const top = positions[i];
4599
4614
  if (!foundEnd) {
4600
4615
  if (startNoBuffer === null && top + size > scroll) {
@@ -4633,7 +4648,7 @@ function calculateItemsInView(ctx, params = {}) {
4633
4648
  const firstVisibleAnchorIndex = firstFullyOnScreenIndex != null ? firstFullyOnScreenIndex : startNoBuffer;
4634
4649
  if (firstVisibleAnchorIndex !== null && firstVisibleAnchorIndex !== void 0 && endNoBuffer !== null) {
4635
4650
  for (let i = firstVisibleAnchorIndex; i <= endNoBuffer; i++) {
4636
- const id = (_j = idCache[i]) != null ? _j : getId(state, i);
4651
+ const id = (_l = idCache[i]) != null ? _l : getId(state, i);
4637
4652
  idsInView.push(id);
4638
4653
  }
4639
4654
  }
@@ -4666,7 +4681,7 @@ function calculateItemsInView(ctx, params = {}) {
4666
4681
  const needNewContainers = [];
4667
4682
  const needNewContainersSet = /* @__PURE__ */ new Set();
4668
4683
  for (let i = startBuffered; i <= endBuffered; i++) {
4669
- const id = (_k = idCache[i]) != null ? _k : getId(state, i);
4684
+ const id = (_m = idCache[i]) != null ? _m : getId(state, i);
4670
4685
  if (!containerItemKeys.has(id)) {
4671
4686
  needNewContainersSet.add(i);
4672
4687
  needNewContainers.push(i);
@@ -4675,7 +4690,7 @@ function calculateItemsInView(ctx, params = {}) {
4675
4690
  if (alwaysRenderArr.length > 0) {
4676
4691
  for (const index of alwaysRenderArr) {
4677
4692
  if (index < 0 || index >= dataLength) continue;
4678
- const id = (_l = idCache[index]) != null ? _l : getId(state, index);
4693
+ const id = (_n = idCache[index]) != null ? _n : getId(state, index);
4679
4694
  if (id && !containerItemKeys.has(id) && !needNewContainersSet.has(index)) {
4680
4695
  needNewContainersSet.add(index);
4681
4696
  needNewContainers.push(index);
@@ -4708,12 +4723,13 @@ function calculateItemsInView(ctx, params = {}) {
4708
4723
  endBuffered,
4709
4724
  pendingRemoval,
4710
4725
  requiredItemTypes,
4711
- needNewContainers
4726
+ needNewContainers,
4727
+ protectedContainerKeys
4712
4728
  );
4713
4729
  for (let idx = 0; idx < needNewContainers.length; idx++) {
4714
4730
  const i = needNewContainers[idx];
4715
4731
  const containerIndex = availableContainers[idx];
4716
- const id = (_m = idCache[i]) != null ? _m : getId(state, i);
4732
+ const id = (_o = idCache[i]) != null ? _o : getId(state, i);
4717
4733
  const oldKey = peek$(ctx, `containerItemKey${containerIndex}`);
4718
4734
  if (oldKey && oldKey !== id) {
4719
4735
  containerItemKeys.delete(oldKey);
@@ -4754,7 +4770,7 @@ function calculateItemsInView(ctx, params = {}) {
4754
4770
  if (alwaysRenderArr.length > 0) {
4755
4771
  for (const index of alwaysRenderArr) {
4756
4772
  if (index < 0 || index >= dataLength) continue;
4757
- const id = (_n = idCache[index]) != null ? _n : getId(state, index);
4773
+ const id = (_p = idCache[index]) != null ? _p : getId(state, index);
4758
4774
  const containerIndex = containerItemKeys.get(id);
4759
4775
  if (containerIndex !== void 0) {
4760
4776
  state.stickyContainerPool.add(containerIndex);
@@ -4815,16 +4831,18 @@ function calculateItemsInView(ctx, params = {}) {
4815
4831
  handleInitialScrollLayoutReady(ctx);
4816
4832
  }
4817
4833
  if (viewabilityConfigCallbackPairs && startNoBuffer !== null && endNoBuffer !== null) {
4818
- updateViewableItems(
4819
- ctx.state,
4820
- ctx,
4821
- viewabilityConfigCallbackPairs,
4822
- scrollLength,
4823
- startNoBuffer,
4824
- endNoBuffer,
4825
- startBuffered != null ? startBuffered : startNoBuffer,
4826
- endBuffered != null ? endBuffered : endNoBuffer
4827
- );
4834
+ if (!didMVCPAdjustScroll) {
4835
+ updateViewableItems(
4836
+ ctx.state,
4837
+ ctx,
4838
+ viewabilityConfigCallbackPairs,
4839
+ scrollLength,
4840
+ startNoBuffer,
4841
+ endNoBuffer,
4842
+ startBuffered != null ? startBuffered : startNoBuffer,
4843
+ endBuffered != null ? endBuffered : endNoBuffer
4844
+ );
4845
+ }
4828
4846
  }
4829
4847
  if (onStickyHeaderChange && stickyIndicesArr.length > 0 && nextActiveStickyIndex !== void 0 && nextActiveStickyIndex !== previousStickyIndex) {
4830
4848
  const item = data[nextActiveStickyIndex];
@@ -4211,7 +4211,7 @@ function computeViewability(state, ctx, viewabilityConfig, containerId, key, scr
4211
4211
  }
4212
4212
  function checkIsViewable(state, ctx, viewabilityConfig, containerId, key, scrollSize, item, index) {
4213
4213
  let value = ctx.mapViewabilityAmountValues.get(containerId);
4214
- if (!value || value.key !== key) {
4214
+ if (!value || value.key !== key || value.index !== index) {
4215
4215
  value = computeViewability(state, ctx, viewabilityConfig, containerId, key, scrollSize, item, index);
4216
4216
  }
4217
4217
  return value.isViewable;
@@ -4226,7 +4226,7 @@ var unstableBatchedUpdates = ReactDOM.unstable_batchedUpdates;
4226
4226
  var batchedUpdates = typeof unstableBatchedUpdates === "function" ? unstableBatchedUpdates : (fn) => fn();
4227
4227
 
4228
4228
  // src/utils/findAvailableContainers.ts
4229
- function findAvailableContainers(ctx, numNeeded, startBuffered, endBuffered, pendingRemoval, requiredItemTypes, needNewContainers) {
4229
+ function findAvailableContainers(ctx, numNeeded, startBuffered, endBuffered, pendingRemoval, requiredItemTypes, needNewContainers, protectedKeys) {
4230
4230
  const numContainers = peek$(ctx, "numContainers");
4231
4231
  const state = ctx.state;
4232
4232
  const { stickyContainerPool, containerItemTypes } = state;
@@ -4294,6 +4294,7 @@ function findAvailableContainers(ctx, numNeeded, startBuffered, endBuffered, pen
4294
4294
  }
4295
4295
  const key = peek$(ctx, `containerItemKey${u}`);
4296
4296
  if (key === void 0) continue;
4297
+ if ((protectedKeys == null ? void 0 : protectedKeys.has(key)) && state.indexByKey.has(key)) continue;
4297
4298
  const index = state.indexByKey.get(key);
4298
4299
  const isOutOfView = index < startBuffered || index > endBuffered;
4299
4300
  if (isOutOfView) {
@@ -4429,7 +4430,7 @@ function handleStickyRecycling(ctx, stickyArray, scroll, drawDistance, currentSt
4429
4430
  function calculateItemsInView(ctx, params = {}) {
4430
4431
  const state = ctx.state;
4431
4432
  batchedUpdates(() => {
4432
- var _a3, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
4433
+ var _a3, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
4433
4434
  const {
4434
4435
  columns,
4435
4436
  columnSpans,
@@ -4531,17 +4532,31 @@ function calculateItemsInView(ctx, params = {}) {
4531
4532
  if (minIndexSizeChanged !== void 0) {
4532
4533
  state.minIndexSizeChanged = void 0;
4533
4534
  }
4535
+ let protectedContainerKeys;
4536
+ if (dataChanged && doMVCP && state.props.maintainVisibleContentPosition.data && state.didContainersLayout && state.idsInView.length > 0) {
4537
+ const shouldRestorePosition = state.props.maintainVisibleContentPosition.shouldRestorePosition;
4538
+ protectedContainerKeys = /* @__PURE__ */ new Set();
4539
+ for (const id of state.idsInView) {
4540
+ const index = indexByKey.get(id);
4541
+ if (index === void 0) continue;
4542
+ if (shouldRestorePosition && !shouldRestorePosition(data[index], index, data)) continue;
4543
+ protectedContainerKeys.add(id);
4544
+ }
4545
+ }
4546
+ const scrollBeforeMVCP = state.scroll;
4547
+ const scrollAdjustPendingBeforeMVCP = (_e = peek$(ctx, "scrollAdjustPending")) != null ? _e : 0;
4534
4548
  checkMVCP == null ? void 0 : checkMVCP();
4549
+ const didMVCPAdjustScroll = !!checkMVCP && (state.scroll !== scrollBeforeMVCP || ((_f = peek$(ctx, "scrollAdjustPending")) != null ? _f : 0) !== scrollAdjustPendingBeforeMVCP);
4535
4550
  let startNoBuffer = null;
4536
4551
  let startBuffered = null;
4537
4552
  let startBufferedId = null;
4538
4553
  let endNoBuffer = null;
4539
4554
  let endBuffered = null;
4540
- let loopStart = (_e = suppressInitialScrollSideEffects ? bootstrapInitialScrollState == null ? void 0 : bootstrapInitialScrollState.targetIndexSeed : void 0) != null ? _e : !dataChanged && startBufferedIdOrig ? indexByKey.get(startBufferedIdOrig) || 0 : 0;
4555
+ let loopStart = (_g = suppressInitialScrollSideEffects ? bootstrapInitialScrollState == null ? void 0 : bootstrapInitialScrollState.targetIndexSeed : void 0) != null ? _g : !dataChanged && startBufferedIdOrig ? indexByKey.get(startBufferedIdOrig) || 0 : 0;
4541
4556
  for (let i = loopStart; i >= 0; i--) {
4542
- const id = (_f = idCache[i]) != null ? _f : getId(state, i);
4557
+ const id = (_h = idCache[i]) != null ? _h : getId(state, i);
4543
4558
  const top = positions[i];
4544
- const size = (_g = sizes.get(id)) != null ? _g : getItemSize(ctx, id, i, data[i]);
4559
+ const size = (_i = sizes.get(id)) != null ? _i : getItemSize(ctx, id, i, data[i]);
4545
4560
  const bottom = top + size;
4546
4561
  if (bottom > scroll - scrollBufferTop) {
4547
4562
  loopStart = i;
@@ -4572,8 +4587,8 @@ function calculateItemsInView(ctx, params = {}) {
4572
4587
  let firstFullyOnScreenIndex;
4573
4588
  const dataLength = data.length;
4574
4589
  for (let i = Math.max(0, loopStart); i < dataLength && (!foundEnd || i <= maxIndexRendered); i++) {
4575
- const id = (_h = idCache[i]) != null ? _h : getId(state, i);
4576
- const size = (_i = sizes.get(id)) != null ? _i : getItemSize(ctx, id, i, data[i]);
4590
+ const id = (_j = idCache[i]) != null ? _j : getId(state, i);
4591
+ const size = (_k = sizes.get(id)) != null ? _k : getItemSize(ctx, id, i, data[i]);
4577
4592
  const top = positions[i];
4578
4593
  if (!foundEnd) {
4579
4594
  if (startNoBuffer === null && top + size > scroll) {
@@ -4612,7 +4627,7 @@ function calculateItemsInView(ctx, params = {}) {
4612
4627
  const firstVisibleAnchorIndex = firstFullyOnScreenIndex != null ? firstFullyOnScreenIndex : startNoBuffer;
4613
4628
  if (firstVisibleAnchorIndex !== null && firstVisibleAnchorIndex !== void 0 && endNoBuffer !== null) {
4614
4629
  for (let i = firstVisibleAnchorIndex; i <= endNoBuffer; i++) {
4615
- const id = (_j = idCache[i]) != null ? _j : getId(state, i);
4630
+ const id = (_l = idCache[i]) != null ? _l : getId(state, i);
4616
4631
  idsInView.push(id);
4617
4632
  }
4618
4633
  }
@@ -4645,7 +4660,7 @@ function calculateItemsInView(ctx, params = {}) {
4645
4660
  const needNewContainers = [];
4646
4661
  const needNewContainersSet = /* @__PURE__ */ new Set();
4647
4662
  for (let i = startBuffered; i <= endBuffered; i++) {
4648
- const id = (_k = idCache[i]) != null ? _k : getId(state, i);
4663
+ const id = (_m = idCache[i]) != null ? _m : getId(state, i);
4649
4664
  if (!containerItemKeys.has(id)) {
4650
4665
  needNewContainersSet.add(i);
4651
4666
  needNewContainers.push(i);
@@ -4654,7 +4669,7 @@ function calculateItemsInView(ctx, params = {}) {
4654
4669
  if (alwaysRenderArr.length > 0) {
4655
4670
  for (const index of alwaysRenderArr) {
4656
4671
  if (index < 0 || index >= dataLength) continue;
4657
- const id = (_l = idCache[index]) != null ? _l : getId(state, index);
4672
+ const id = (_n = idCache[index]) != null ? _n : getId(state, index);
4658
4673
  if (id && !containerItemKeys.has(id) && !needNewContainersSet.has(index)) {
4659
4674
  needNewContainersSet.add(index);
4660
4675
  needNewContainers.push(index);
@@ -4687,12 +4702,13 @@ function calculateItemsInView(ctx, params = {}) {
4687
4702
  endBuffered,
4688
4703
  pendingRemoval,
4689
4704
  requiredItemTypes,
4690
- needNewContainers
4705
+ needNewContainers,
4706
+ protectedContainerKeys
4691
4707
  );
4692
4708
  for (let idx = 0; idx < needNewContainers.length; idx++) {
4693
4709
  const i = needNewContainers[idx];
4694
4710
  const containerIndex = availableContainers[idx];
4695
- const id = (_m = idCache[i]) != null ? _m : getId(state, i);
4711
+ const id = (_o = idCache[i]) != null ? _o : getId(state, i);
4696
4712
  const oldKey = peek$(ctx, `containerItemKey${containerIndex}`);
4697
4713
  if (oldKey && oldKey !== id) {
4698
4714
  containerItemKeys.delete(oldKey);
@@ -4733,7 +4749,7 @@ function calculateItemsInView(ctx, params = {}) {
4733
4749
  if (alwaysRenderArr.length > 0) {
4734
4750
  for (const index of alwaysRenderArr) {
4735
4751
  if (index < 0 || index >= dataLength) continue;
4736
- const id = (_n = idCache[index]) != null ? _n : getId(state, index);
4752
+ const id = (_p = idCache[index]) != null ? _p : getId(state, index);
4737
4753
  const containerIndex = containerItemKeys.get(id);
4738
4754
  if (containerIndex !== void 0) {
4739
4755
  state.stickyContainerPool.add(containerIndex);
@@ -4794,16 +4810,18 @@ function calculateItemsInView(ctx, params = {}) {
4794
4810
  handleInitialScrollLayoutReady(ctx);
4795
4811
  }
4796
4812
  if (viewabilityConfigCallbackPairs && startNoBuffer !== null && endNoBuffer !== null) {
4797
- updateViewableItems(
4798
- ctx.state,
4799
- ctx,
4800
- viewabilityConfigCallbackPairs,
4801
- scrollLength,
4802
- startNoBuffer,
4803
- endNoBuffer,
4804
- startBuffered != null ? startBuffered : startNoBuffer,
4805
- endBuffered != null ? endBuffered : endNoBuffer
4806
- );
4813
+ if (!didMVCPAdjustScroll) {
4814
+ updateViewableItems(
4815
+ ctx.state,
4816
+ ctx,
4817
+ viewabilityConfigCallbackPairs,
4818
+ scrollLength,
4819
+ startNoBuffer,
4820
+ endNoBuffer,
4821
+ startBuffered != null ? startBuffered : startNoBuffer,
4822
+ endBuffered != null ? endBuffered : endNoBuffer
4823
+ );
4824
+ }
4807
4825
  }
4808
4826
  if (onStickyHeaderChange && stickyIndicesArr.length > 0 && nextActiveStickyIndex !== void 0 && nextActiveStickyIndex !== previousStickyIndex) {
4809
4827
  const item = data[nextActiveStickyIndex];