@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.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];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legendapp/list",
3
- "version": "3.0.0-beta.46",
3
+ "version": "3.0.0-beta.48",
4
4
  "description": "Legend List is a drop-in replacement for FlatList with much better performance and supporting dynamically sized items.",
5
5
  "sideEffects": false,
6
6
  "private": false,
package/react-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];