@legendapp/list 3.0.0-beta.16 → 3.0.0-beta.18

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
@@ -1403,7 +1403,7 @@ function getItemSize(ctx, key, index, data, useAverageSize, preferCachedSize) {
1403
1403
  }
1404
1404
  }
1405
1405
  if (getFixedItemSize) {
1406
- size = getFixedItemSize(index, data, itemType);
1406
+ size = getFixedItemSize(data, index, itemType);
1407
1407
  if (size !== void 0) {
1408
1408
  sizesKnown.set(key, size);
1409
1409
  }
@@ -1421,7 +1421,7 @@ function getItemSize(ctx, key, index, data, useAverageSize, preferCachedSize) {
1421
1421
  }
1422
1422
  }
1423
1423
  if (size === void 0) {
1424
- size = getEstimatedItemSize ? getEstimatedItemSize(index, data, itemType) : estimatedItemSize;
1424
+ size = getEstimatedItemSize ? getEstimatedItemSize(data, index, itemType) : estimatedItemSize;
1425
1425
  }
1426
1426
  setSize(ctx, key, size);
1427
1427
  return size;
@@ -1592,7 +1592,7 @@ function scrollTo(ctx, params) {
1592
1592
 
1593
1593
  // src/utils/checkThreshold.ts
1594
1594
  var HYSTERESIS_MULTIPLIER = 1.3;
1595
- var checkThreshold = (distance, atThreshold, threshold, wasReached, snapshot, context, onReached, setSnapshot) => {
1595
+ var checkThreshold = (distance, atThreshold, threshold, wasReached, snapshot, context, onReached, setSnapshot, allowReentryOnChange) => {
1596
1596
  const absDistance = Math.abs(distance);
1597
1597
  const within = atThreshold || threshold > 0 && absDistance <= threshold;
1598
1598
  if (wasReached === null) {
@@ -1602,7 +1602,7 @@ var checkThreshold = (distance, atThreshold, threshold, wasReached, snapshot, co
1602
1602
  return null;
1603
1603
  }
1604
1604
  const updateSnapshot = () => {
1605
- setSnapshot == null ? void 0 : setSnapshot({
1605
+ setSnapshot({
1606
1606
  atThreshold,
1607
1607
  contentSize: context.contentSize,
1608
1608
  dataLength: context.dataLength,
@@ -1613,19 +1613,21 @@ var checkThreshold = (distance, atThreshold, threshold, wasReached, snapshot, co
1613
1613
  if (!within) {
1614
1614
  return false;
1615
1615
  }
1616
- onReached == null ? void 0 : onReached(distance);
1616
+ onReached(distance);
1617
1617
  updateSnapshot();
1618
1618
  return true;
1619
1619
  }
1620
1620
  const reset = !atThreshold && threshold > 0 && absDistance >= threshold * HYSTERESIS_MULTIPLIER || !atThreshold && threshold <= 0 && absDistance > 0;
1621
1621
  if (reset) {
1622
- setSnapshot == null ? void 0 : setSnapshot(void 0);
1622
+ setSnapshot(void 0);
1623
1623
  return false;
1624
1624
  }
1625
1625
  if (within) {
1626
1626
  const changed = !snapshot || snapshot.atThreshold !== atThreshold || snapshot.contentSize !== context.contentSize || snapshot.dataLength !== context.dataLength;
1627
1627
  if (changed) {
1628
- onReached == null ? void 0 : onReached(distance);
1628
+ if (allowReentryOnChange) {
1629
+ onReached(distance);
1630
+ }
1629
1631
  updateSnapshot();
1630
1632
  }
1631
1633
  }
@@ -1668,7 +1670,8 @@ function checkAtBottom(ctx) {
1668
1670
  },
1669
1671
  (snapshot) => {
1670
1672
  state.endReachedSnapshot = snapshot;
1671
- }
1673
+ },
1674
+ true
1672
1675
  );
1673
1676
  }
1674
1677
  }
@@ -1703,7 +1706,8 @@ function checkAtTop(state) {
1703
1706
  },
1704
1707
  (snapshot) => {
1705
1708
  state.startReachedSnapshot = snapshot;
1706
- }
1709
+ },
1710
+ false
1707
1711
  );
1708
1712
  }
1709
1713
 
@@ -1782,7 +1786,7 @@ function prepareMVCP(ctx, dataChanged) {
1782
1786
  const state = ctx.state;
1783
1787
  const { idsInView, positions, props } = state;
1784
1788
  const {
1785
- maintainVisibleContentPosition: { data: mvcpData, size: mvcpScroll }
1789
+ maintainVisibleContentPosition: { data: mvcpData, size: mvcpScroll, shouldRestorePosition }
1786
1790
  } = props;
1787
1791
  const scrollingTo = state.scrollingTo;
1788
1792
  let prevPosition;
@@ -1814,8 +1818,16 @@ function prepareMVCP(ctx, dataChanged) {
1814
1818
  return () => {
1815
1819
  let positionDiff = 0;
1816
1820
  if (dataChanged && targetId === void 0 && mvcpData) {
1821
+ const data = state.props.data;
1817
1822
  for (let i = 0; i < idsInViewWithPositions.length; i++) {
1818
1823
  const { id, position } = idsInViewWithPositions[i];
1824
+ const index = indexByKey.get(id);
1825
+ if (index !== void 0 && shouldRestorePosition) {
1826
+ const item = data[index];
1827
+ if (item === void 0 || !shouldRestorePosition(item, index, data)) {
1828
+ continue;
1829
+ }
1830
+ }
1819
1831
  const newPosition = positions.get(id);
1820
1832
  if (newPosition !== void 0) {
1821
1833
  positionDiff = newPosition - position;
@@ -2471,9 +2483,13 @@ function setDidLayout(ctx) {
2471
2483
  onLoad({ elapsedTimeInMs: Date.now() - loadStartTime });
2472
2484
  }
2473
2485
  };
2474
- {
2475
- setIt();
2486
+ if ((initialScroll == null ? void 0 : initialScroll.index) !== void 0) {
2487
+ const target = initialScroll;
2488
+ const runScroll = () => scrollToIndex(ctx, { ...target, animated: false });
2489
+ runScroll();
2490
+ requestAnimationFrame(runScroll);
2476
2491
  }
2492
+ setIt();
2477
2493
  }
2478
2494
 
2479
2495
  // src/core/calculateItemsInView.ts
@@ -3080,7 +3096,7 @@ function doInitialAllocateContainers(ctx) {
3080
3096
  const item = data[i];
3081
3097
  if (item !== void 0) {
3082
3098
  const itemType = (_a3 = getItemType == null ? void 0 : getItemType(item, i)) != null ? _a3 : "";
3083
- totalSize += (_c = (_b = getFixedItemSize == null ? void 0 : getFixedItemSize(i, item, itemType)) != null ? _b : getEstimatedItemSize == null ? void 0 : getEstimatedItemSize(i, item, itemType)) != null ? _c : estimatedItemSize;
3099
+ totalSize += (_c = (_b = getFixedItemSize == null ? void 0 : getFixedItemSize(item, i, itemType)) != null ? _b : getEstimatedItemSize == null ? void 0 : getEstimatedItemSize(item, i, itemType)) != null ? _c : estimatedItemSize;
3084
3100
  }
3085
3101
  }
3086
3102
  averageItemSize = totalSize / num;
@@ -3267,7 +3283,7 @@ function updateItemSize(ctx, itemKey, sizeObj) {
3267
3283
  return;
3268
3284
  }
3269
3285
  const type = getItemType ? (_a3 = getItemType(itemData, index)) != null ? _a3 : "" : "";
3270
- const size2 = getFixedItemSize(index, itemData, type);
3286
+ const size2 = getFixedItemSize(itemData, index, type);
3271
3287
  if (size2 !== void 0 && size2 === sizesKnown.get(itemKey)) {
3272
3288
  return;
3273
3289
  }
@@ -3546,7 +3562,8 @@ function normalizeMaintainVisibleContentPosition(value) {
3546
3562
  if (value && typeof value === "object") {
3547
3563
  return {
3548
3564
  data: (_a3 = value.data) != null ? _a3 : false,
3549
- size: (_b = value.size) != null ? _b : true
3565
+ size: (_b = value.size) != null ? _b : true,
3566
+ shouldRestorePosition: value.shouldRestorePosition
3550
3567
  };
3551
3568
  }
3552
3569
  if (value === false) {
@@ -3691,7 +3708,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
3691
3708
  maintainVisibleContentPositionProp
3692
3709
  );
3693
3710
  const [renderNum, setRenderNum] = React3.useState(0);
3694
- const initialScrollProp = initialScrollAtEnd ? { index: Math.max(0, dataProp.length - 1), viewOffset: -stylePaddingBottomState } : initialScrollIndexProp || initialScrollOffsetProp ? typeof initialScrollIndexProp === "object" ? { index: initialScrollIndexProp.index || 0, viewOffset: initialScrollIndexProp.viewOffset || 0 } : { index: initialScrollIndexProp || 0, viewOffset: initialScrollOffsetProp || 0 } : void 0;
3711
+ const initialScrollProp = initialScrollAtEnd ? { index: Math.max(0, dataProp.length - 1), viewOffset: -stylePaddingBottomState, viewPosition: 1 } : initialScrollIndexProp || initialScrollOffsetProp ? typeof initialScrollIndexProp === "object" ? { index: initialScrollIndexProp.index || 0, viewOffset: initialScrollIndexProp.viewOffset || 0 } : { index: initialScrollIndexProp || 0, viewOffset: initialScrollOffsetProp || 0 } : void 0;
3695
3712
  const [canRender, setCanRender] = React3__namespace.useState(!IsNewArchitecture);
3696
3713
  const ctx = useStateContext();
3697
3714
  ctx.columnWrapperStyle = columnWrapperStyle || (contentContainerStyle ? createColumnWrapperStyle(contentContainerStyle) : void 0);
@@ -3905,8 +3922,8 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
3905
3922
  }
3906
3923
  }, []);
3907
3924
  const doInitialScroll = React3.useCallback(() => {
3908
- const initialScroll = state.initialScroll;
3909
- if (initialScroll) {
3925
+ const { initialScroll, didFinishInitialScroll, queuedInitialLayout, scrollingTo } = state;
3926
+ if (initialScroll && !queuedInitialLayout && !didFinishInitialScroll && !scrollingTo) {
3910
3927
  scrollTo(ctx, {
3911
3928
  animated: false,
3912
3929
  index: initialScroll == null ? void 0 : initialScroll.index,
@@ -4026,6 +4043,8 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
4026
4043
  });
4027
4044
 
4028
4045
  exports.LegendList = LegendList;
4046
+ exports.typedForwardRef = typedForwardRef;
4047
+ exports.typedMemo = typedMemo;
4029
4048
  exports.useIsLastItem = useIsLastItem;
4030
4049
  exports.useListScrollSize = useListScrollSize;
4031
4050
  exports.useRecyclingEffect = useRecyclingEffect;
package/index.mjs CHANGED
@@ -1382,7 +1382,7 @@ function getItemSize(ctx, key, index, data, useAverageSize, preferCachedSize) {
1382
1382
  }
1383
1383
  }
1384
1384
  if (getFixedItemSize) {
1385
- size = getFixedItemSize(index, data, itemType);
1385
+ size = getFixedItemSize(data, index, itemType);
1386
1386
  if (size !== void 0) {
1387
1387
  sizesKnown.set(key, size);
1388
1388
  }
@@ -1400,7 +1400,7 @@ function getItemSize(ctx, key, index, data, useAverageSize, preferCachedSize) {
1400
1400
  }
1401
1401
  }
1402
1402
  if (size === void 0) {
1403
- size = getEstimatedItemSize ? getEstimatedItemSize(index, data, itemType) : estimatedItemSize;
1403
+ size = getEstimatedItemSize ? getEstimatedItemSize(data, index, itemType) : estimatedItemSize;
1404
1404
  }
1405
1405
  setSize(ctx, key, size);
1406
1406
  return size;
@@ -1571,7 +1571,7 @@ function scrollTo(ctx, params) {
1571
1571
 
1572
1572
  // src/utils/checkThreshold.ts
1573
1573
  var HYSTERESIS_MULTIPLIER = 1.3;
1574
- var checkThreshold = (distance, atThreshold, threshold, wasReached, snapshot, context, onReached, setSnapshot) => {
1574
+ var checkThreshold = (distance, atThreshold, threshold, wasReached, snapshot, context, onReached, setSnapshot, allowReentryOnChange) => {
1575
1575
  const absDistance = Math.abs(distance);
1576
1576
  const within = atThreshold || threshold > 0 && absDistance <= threshold;
1577
1577
  if (wasReached === null) {
@@ -1581,7 +1581,7 @@ var checkThreshold = (distance, atThreshold, threshold, wasReached, snapshot, co
1581
1581
  return null;
1582
1582
  }
1583
1583
  const updateSnapshot = () => {
1584
- setSnapshot == null ? void 0 : setSnapshot({
1584
+ setSnapshot({
1585
1585
  atThreshold,
1586
1586
  contentSize: context.contentSize,
1587
1587
  dataLength: context.dataLength,
@@ -1592,19 +1592,21 @@ var checkThreshold = (distance, atThreshold, threshold, wasReached, snapshot, co
1592
1592
  if (!within) {
1593
1593
  return false;
1594
1594
  }
1595
- onReached == null ? void 0 : onReached(distance);
1595
+ onReached(distance);
1596
1596
  updateSnapshot();
1597
1597
  return true;
1598
1598
  }
1599
1599
  const reset = !atThreshold && threshold > 0 && absDistance >= threshold * HYSTERESIS_MULTIPLIER || !atThreshold && threshold <= 0 && absDistance > 0;
1600
1600
  if (reset) {
1601
- setSnapshot == null ? void 0 : setSnapshot(void 0);
1601
+ setSnapshot(void 0);
1602
1602
  return false;
1603
1603
  }
1604
1604
  if (within) {
1605
1605
  const changed = !snapshot || snapshot.atThreshold !== atThreshold || snapshot.contentSize !== context.contentSize || snapshot.dataLength !== context.dataLength;
1606
1606
  if (changed) {
1607
- onReached == null ? void 0 : onReached(distance);
1607
+ if (allowReentryOnChange) {
1608
+ onReached(distance);
1609
+ }
1608
1610
  updateSnapshot();
1609
1611
  }
1610
1612
  }
@@ -1647,7 +1649,8 @@ function checkAtBottom(ctx) {
1647
1649
  },
1648
1650
  (snapshot) => {
1649
1651
  state.endReachedSnapshot = snapshot;
1650
- }
1652
+ },
1653
+ true
1651
1654
  );
1652
1655
  }
1653
1656
  }
@@ -1682,7 +1685,8 @@ function checkAtTop(state) {
1682
1685
  },
1683
1686
  (snapshot) => {
1684
1687
  state.startReachedSnapshot = snapshot;
1685
- }
1688
+ },
1689
+ false
1686
1690
  );
1687
1691
  }
1688
1692
 
@@ -1761,7 +1765,7 @@ function prepareMVCP(ctx, dataChanged) {
1761
1765
  const state = ctx.state;
1762
1766
  const { idsInView, positions, props } = state;
1763
1767
  const {
1764
- maintainVisibleContentPosition: { data: mvcpData, size: mvcpScroll }
1768
+ maintainVisibleContentPosition: { data: mvcpData, size: mvcpScroll, shouldRestorePosition }
1765
1769
  } = props;
1766
1770
  const scrollingTo = state.scrollingTo;
1767
1771
  let prevPosition;
@@ -1793,8 +1797,16 @@ function prepareMVCP(ctx, dataChanged) {
1793
1797
  return () => {
1794
1798
  let positionDiff = 0;
1795
1799
  if (dataChanged && targetId === void 0 && mvcpData) {
1800
+ const data = state.props.data;
1796
1801
  for (let i = 0; i < idsInViewWithPositions.length; i++) {
1797
1802
  const { id, position } = idsInViewWithPositions[i];
1803
+ const index = indexByKey.get(id);
1804
+ if (index !== void 0 && shouldRestorePosition) {
1805
+ const item = data[index];
1806
+ if (item === void 0 || !shouldRestorePosition(item, index, data)) {
1807
+ continue;
1808
+ }
1809
+ }
1798
1810
  const newPosition = positions.get(id);
1799
1811
  if (newPosition !== void 0) {
1800
1812
  positionDiff = newPosition - position;
@@ -2450,9 +2462,13 @@ function setDidLayout(ctx) {
2450
2462
  onLoad({ elapsedTimeInMs: Date.now() - loadStartTime });
2451
2463
  }
2452
2464
  };
2453
- {
2454
- setIt();
2465
+ if ((initialScroll == null ? void 0 : initialScroll.index) !== void 0) {
2466
+ const target = initialScroll;
2467
+ const runScroll = () => scrollToIndex(ctx, { ...target, animated: false });
2468
+ runScroll();
2469
+ requestAnimationFrame(runScroll);
2455
2470
  }
2471
+ setIt();
2456
2472
  }
2457
2473
 
2458
2474
  // src/core/calculateItemsInView.ts
@@ -3059,7 +3075,7 @@ function doInitialAllocateContainers(ctx) {
3059
3075
  const item = data[i];
3060
3076
  if (item !== void 0) {
3061
3077
  const itemType = (_a3 = getItemType == null ? void 0 : getItemType(item, i)) != null ? _a3 : "";
3062
- totalSize += (_c = (_b = getFixedItemSize == null ? void 0 : getFixedItemSize(i, item, itemType)) != null ? _b : getEstimatedItemSize == null ? void 0 : getEstimatedItemSize(i, item, itemType)) != null ? _c : estimatedItemSize;
3078
+ totalSize += (_c = (_b = getFixedItemSize == null ? void 0 : getFixedItemSize(item, i, itemType)) != null ? _b : getEstimatedItemSize == null ? void 0 : getEstimatedItemSize(item, i, itemType)) != null ? _c : estimatedItemSize;
3063
3079
  }
3064
3080
  }
3065
3081
  averageItemSize = totalSize / num;
@@ -3246,7 +3262,7 @@ function updateItemSize(ctx, itemKey, sizeObj) {
3246
3262
  return;
3247
3263
  }
3248
3264
  const type = getItemType ? (_a3 = getItemType(itemData, index)) != null ? _a3 : "" : "";
3249
- const size2 = getFixedItemSize(index, itemData, type);
3265
+ const size2 = getFixedItemSize(itemData, index, type);
3250
3266
  if (size2 !== void 0 && size2 === sizesKnown.get(itemKey)) {
3251
3267
  return;
3252
3268
  }
@@ -3525,7 +3541,8 @@ function normalizeMaintainVisibleContentPosition(value) {
3525
3541
  if (value && typeof value === "object") {
3526
3542
  return {
3527
3543
  data: (_a3 = value.data) != null ? _a3 : false,
3528
- size: (_b = value.size) != null ? _b : true
3544
+ size: (_b = value.size) != null ? _b : true,
3545
+ shouldRestorePosition: value.shouldRestorePosition
3529
3546
  };
3530
3547
  }
3531
3548
  if (value === false) {
@@ -3670,7 +3687,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
3670
3687
  maintainVisibleContentPositionProp
3671
3688
  );
3672
3689
  const [renderNum, setRenderNum] = useState(0);
3673
- const initialScrollProp = initialScrollAtEnd ? { index: Math.max(0, dataProp.length - 1), viewOffset: -stylePaddingBottomState } : initialScrollIndexProp || initialScrollOffsetProp ? typeof initialScrollIndexProp === "object" ? { index: initialScrollIndexProp.index || 0, viewOffset: initialScrollIndexProp.viewOffset || 0 } : { index: initialScrollIndexProp || 0, viewOffset: initialScrollOffsetProp || 0 } : void 0;
3690
+ const initialScrollProp = initialScrollAtEnd ? { index: Math.max(0, dataProp.length - 1), viewOffset: -stylePaddingBottomState, viewPosition: 1 } : initialScrollIndexProp || initialScrollOffsetProp ? typeof initialScrollIndexProp === "object" ? { index: initialScrollIndexProp.index || 0, viewOffset: initialScrollIndexProp.viewOffset || 0 } : { index: initialScrollIndexProp || 0, viewOffset: initialScrollOffsetProp || 0 } : void 0;
3674
3691
  const [canRender, setCanRender] = React3.useState(!IsNewArchitecture);
3675
3692
  const ctx = useStateContext();
3676
3693
  ctx.columnWrapperStyle = columnWrapperStyle || (contentContainerStyle ? createColumnWrapperStyle(contentContainerStyle) : void 0);
@@ -3884,8 +3901,8 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
3884
3901
  }
3885
3902
  }, []);
3886
3903
  const doInitialScroll = useCallback(() => {
3887
- const initialScroll = state.initialScroll;
3888
- if (initialScroll) {
3904
+ const { initialScroll, didFinishInitialScroll, queuedInitialLayout, scrollingTo } = state;
3905
+ if (initialScroll && !queuedInitialLayout && !didFinishInitialScroll && !scrollingTo) {
3889
3906
  scrollTo(ctx, {
3890
3907
  animated: false,
3891
3908
  index: initialScroll == null ? void 0 : initialScroll.index,
@@ -4004,4 +4021,4 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
4004
4021
  ), IS_DEV && ENABLE_DEBUG_VIEW && /* @__PURE__ */ React3.createElement(DebugView, { state: refState.current }));
4005
4022
  });
4006
4023
 
4007
- export { LegendList, useIsLastItem, useListScrollSize, useRecyclingEffect, useRecyclingState, useSyncLayout, useViewability, useViewabilityAmount };
4024
+ export { LegendList, typedForwardRef, typedMemo, useIsLastItem, useListScrollSize, useRecyclingEffect, useRecyclingState, useSyncLayout, useViewability, useViewabilityAmount };
package/index.native.js CHANGED
@@ -1134,7 +1134,7 @@ function getItemSize(ctx, key, index, data, useAverageSize, preferCachedSize) {
1134
1134
  }
1135
1135
  }
1136
1136
  if (getFixedItemSize) {
1137
- size = getFixedItemSize(index, data, itemType);
1137
+ size = getFixedItemSize(data, index, itemType);
1138
1138
  if (size !== void 0) {
1139
1139
  sizesKnown.set(key, size);
1140
1140
  }
@@ -1152,7 +1152,7 @@ function getItemSize(ctx, key, index, data, useAverageSize, preferCachedSize) {
1152
1152
  }
1153
1153
  }
1154
1154
  if (size === void 0) {
1155
- size = getEstimatedItemSize ? getEstimatedItemSize(index, data, itemType) : estimatedItemSize;
1155
+ size = getEstimatedItemSize ? getEstimatedItemSize(data, index, itemType) : estimatedItemSize;
1156
1156
  }
1157
1157
  setSize(ctx, key, size);
1158
1158
  return size;
@@ -1322,7 +1322,7 @@ function scrollTo(ctx, params) {
1322
1322
 
1323
1323
  // src/utils/checkThreshold.ts
1324
1324
  var HYSTERESIS_MULTIPLIER = 1.3;
1325
- var checkThreshold = (distance, atThreshold, threshold, wasReached, snapshot, context, onReached, setSnapshot) => {
1325
+ var checkThreshold = (distance, atThreshold, threshold, wasReached, snapshot, context, onReached, setSnapshot, allowReentryOnChange) => {
1326
1326
  const absDistance = Math.abs(distance);
1327
1327
  const within = atThreshold || threshold > 0 && absDistance <= threshold;
1328
1328
  if (wasReached === null) {
@@ -1332,7 +1332,7 @@ var checkThreshold = (distance, atThreshold, threshold, wasReached, snapshot, co
1332
1332
  return null;
1333
1333
  }
1334
1334
  const updateSnapshot = () => {
1335
- setSnapshot == null ? void 0 : setSnapshot({
1335
+ setSnapshot({
1336
1336
  atThreshold,
1337
1337
  contentSize: context.contentSize,
1338
1338
  dataLength: context.dataLength,
@@ -1343,19 +1343,21 @@ var checkThreshold = (distance, atThreshold, threshold, wasReached, snapshot, co
1343
1343
  if (!within) {
1344
1344
  return false;
1345
1345
  }
1346
- onReached == null ? void 0 : onReached(distance);
1346
+ onReached(distance);
1347
1347
  updateSnapshot();
1348
1348
  return true;
1349
1349
  }
1350
1350
  const reset = !atThreshold && threshold > 0 && absDistance >= threshold * HYSTERESIS_MULTIPLIER || !atThreshold && threshold <= 0 && absDistance > 0;
1351
1351
  if (reset) {
1352
- setSnapshot == null ? void 0 : setSnapshot(void 0);
1352
+ setSnapshot(void 0);
1353
1353
  return false;
1354
1354
  }
1355
1355
  if (within) {
1356
1356
  const changed = !snapshot || snapshot.atThreshold !== atThreshold || snapshot.contentSize !== context.contentSize || snapshot.dataLength !== context.dataLength;
1357
1357
  if (changed) {
1358
- onReached == null ? void 0 : onReached(distance);
1358
+ if (allowReentryOnChange) {
1359
+ onReached(distance);
1360
+ }
1359
1361
  updateSnapshot();
1360
1362
  }
1361
1363
  }
@@ -1398,7 +1400,8 @@ function checkAtBottom(ctx) {
1398
1400
  },
1399
1401
  (snapshot) => {
1400
1402
  state.endReachedSnapshot = snapshot;
1401
- }
1403
+ },
1404
+ true
1402
1405
  );
1403
1406
  }
1404
1407
  }
@@ -1433,7 +1436,8 @@ function checkAtTop(state) {
1433
1436
  },
1434
1437
  (snapshot) => {
1435
1438
  state.startReachedSnapshot = snapshot;
1436
- }
1439
+ },
1440
+ false
1437
1441
  );
1438
1442
  }
1439
1443
 
@@ -1594,7 +1598,7 @@ function prepareMVCP(ctx, dataChanged) {
1594
1598
  const state = ctx.state;
1595
1599
  const { idsInView, positions, props } = state;
1596
1600
  const {
1597
- maintainVisibleContentPosition: { data: mvcpData, size: mvcpScroll }
1601
+ maintainVisibleContentPosition: { data: mvcpData, size: mvcpScroll, shouldRestorePosition }
1598
1602
  } = props;
1599
1603
  const scrollingTo = state.scrollingTo;
1600
1604
  let prevPosition;
@@ -1629,8 +1633,16 @@ function prepareMVCP(ctx, dataChanged) {
1629
1633
  return () => {
1630
1634
  let positionDiff = 0;
1631
1635
  if (dataChanged && targetId === void 0 && mvcpData) {
1636
+ const data = state.props.data;
1632
1637
  for (let i = 0; i < idsInViewWithPositions.length; i++) {
1633
1638
  const { id, position } = idsInViewWithPositions[i];
1639
+ const index = indexByKey.get(id);
1640
+ if (index !== void 0 && shouldRestorePosition) {
1641
+ const item = data[index];
1642
+ if (item === void 0 || !shouldRestorePosition(item, index, data)) {
1643
+ continue;
1644
+ }
1645
+ }
1634
1646
  const newPosition = positions.get(id);
1635
1647
  if (newPosition !== void 0) {
1636
1648
  positionDiff = newPosition - position;
@@ -2286,20 +2298,13 @@ function setDidLayout(ctx) {
2286
2298
  onLoad({ elapsedTimeInMs: Date.now() - loadStartTime });
2287
2299
  }
2288
2300
  };
2289
- if (Platform2.OS === "android" && initialScroll) {
2290
- if (IsNewArchitecture) {
2291
- scrollToIndex(ctx, { ...initialScroll, animated: false });
2292
- requestAnimationFrame(() => {
2293
- scrollToIndex(ctx, { ...initialScroll, animated: false });
2294
- setIt();
2295
- });
2296
- } else {
2297
- scrollToIndex(ctx, { ...initialScroll, animated: false });
2298
- setIt();
2299
- }
2300
- } else {
2301
- setIt();
2301
+ if ((initialScroll == null ? void 0 : initialScroll.index) !== void 0) {
2302
+ const target = initialScroll;
2303
+ const runScroll = () => scrollToIndex(ctx, { ...target, animated: false });
2304
+ runScroll();
2305
+ requestAnimationFrame(runScroll);
2302
2306
  }
2307
+ setIt();
2303
2308
  }
2304
2309
 
2305
2310
  // src/core/calculateItemsInView.ts
@@ -2869,7 +2874,7 @@ function doInitialAllocateContainers(ctx) {
2869
2874
  const item = data[i];
2870
2875
  if (item !== void 0) {
2871
2876
  const itemType = (_a3 = getItemType == null ? void 0 : getItemType(item, i)) != null ? _a3 : "";
2872
- totalSize += (_c = (_b = getFixedItemSize == null ? void 0 : getFixedItemSize(i, item, itemType)) != null ? _b : getEstimatedItemSize == null ? void 0 : getEstimatedItemSize(i, item, itemType)) != null ? _c : estimatedItemSize;
2877
+ totalSize += (_c = (_b = getFixedItemSize == null ? void 0 : getFixedItemSize(item, i, itemType)) != null ? _b : getEstimatedItemSize == null ? void 0 : getEstimatedItemSize(item, i, itemType)) != null ? _c : estimatedItemSize;
2873
2878
  }
2874
2879
  }
2875
2880
  averageItemSize = totalSize / num;
@@ -3056,7 +3061,7 @@ function updateItemSize(ctx, itemKey, sizeObj) {
3056
3061
  return;
3057
3062
  }
3058
3063
  const type = getItemType ? (_a3 = getItemType(itemData, index)) != null ? _a3 : "" : "";
3059
- const size2 = getFixedItemSize(index, itemData, type);
3064
+ const size2 = getFixedItemSize(itemData, index, type);
3060
3065
  if (size2 !== void 0 && size2 === sizesKnown.get(itemKey)) {
3061
3066
  return;
3062
3067
  }
@@ -3354,7 +3359,8 @@ function normalizeMaintainVisibleContentPosition(value) {
3354
3359
  if (value && typeof value === "object") {
3355
3360
  return {
3356
3361
  data: (_a3 = value.data) != null ? _a3 : false,
3357
- size: (_b = value.size) != null ? _b : true
3362
+ size: (_b = value.size) != null ? _b : true,
3363
+ shouldRestorePosition: value.shouldRestorePosition
3358
3364
  };
3359
3365
  }
3360
3366
  if (value === false) {
@@ -3499,7 +3505,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
3499
3505
  maintainVisibleContentPositionProp
3500
3506
  );
3501
3507
  const [renderNum, setRenderNum] = React2.useState(0);
3502
- const initialScrollProp = initialScrollAtEnd ? { index: Math.max(0, dataProp.length - 1), viewOffset: -stylePaddingBottomState } : initialScrollIndexProp || initialScrollOffsetProp ? typeof initialScrollIndexProp === "object" ? { index: initialScrollIndexProp.index || 0, viewOffset: initialScrollIndexProp.viewOffset || 0 } : { index: initialScrollIndexProp || 0, viewOffset: initialScrollOffsetProp || 0 } : void 0;
3508
+ const initialScrollProp = initialScrollAtEnd ? { index: Math.max(0, dataProp.length - 1), viewOffset: -stylePaddingBottomState, viewPosition: 1 } : initialScrollIndexProp || initialScrollOffsetProp ? typeof initialScrollIndexProp === "object" ? { index: initialScrollIndexProp.index || 0, viewOffset: initialScrollIndexProp.viewOffset || 0 } : { index: initialScrollIndexProp || 0, viewOffset: initialScrollOffsetProp || 0 } : void 0;
3503
3509
  const [canRender, setCanRender] = React2__namespace.useState(!IsNewArchitecture);
3504
3510
  const ctx = useStateContext();
3505
3511
  ctx.columnWrapperStyle = columnWrapperStyle || (contentContainerStyle ? createColumnWrapperStyle(contentContainerStyle) : void 0);
@@ -3725,8 +3731,8 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
3725
3731
  }
3726
3732
  }, []);
3727
3733
  const doInitialScroll = React2.useCallback(() => {
3728
- const initialScroll = state.initialScroll;
3729
- if (initialScroll) {
3734
+ const { initialScroll, didFinishInitialScroll, queuedInitialLayout, scrollingTo } = state;
3735
+ if (initialScroll && !queuedInitialLayout && !didFinishInitialScroll && !scrollingTo) {
3730
3736
  scrollTo(ctx, {
3731
3737
  animated: false,
3732
3738
  index: initialScroll == null ? void 0 : initialScroll.index,
@@ -3851,6 +3857,8 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
3851
3857
  });
3852
3858
 
3853
3859
  exports.LegendList = LegendList;
3860
+ exports.typedForwardRef = typedForwardRef;
3861
+ exports.typedMemo = typedMemo;
3854
3862
  exports.useIsLastItem = useIsLastItem;
3855
3863
  exports.useListScrollSize = useListScrollSize;
3856
3864
  exports.useRecyclingEffect = useRecyclingEffect;