@legendapp/list 3.0.0-beta.17 → 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;
@@ -3084,7 +3096,7 @@ function doInitialAllocateContainers(ctx) {
3084
3096
  const item = data[i];
3085
3097
  if (item !== void 0) {
3086
3098
  const itemType = (_a3 = getItemType == null ? void 0 : getItemType(item, i)) != null ? _a3 : "";
3087
- 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;
3088
3100
  }
3089
3101
  }
3090
3102
  averageItemSize = totalSize / num;
@@ -3271,7 +3283,7 @@ function updateItemSize(ctx, itemKey, sizeObj) {
3271
3283
  return;
3272
3284
  }
3273
3285
  const type = getItemType ? (_a3 = getItemType(itemData, index)) != null ? _a3 : "" : "";
3274
- const size2 = getFixedItemSize(index, itemData, type);
3286
+ const size2 = getFixedItemSize(itemData, index, type);
3275
3287
  if (size2 !== void 0 && size2 === sizesKnown.get(itemKey)) {
3276
3288
  return;
3277
3289
  }
@@ -3550,7 +3562,8 @@ function normalizeMaintainVisibleContentPosition(value) {
3550
3562
  if (value && typeof value === "object") {
3551
3563
  return {
3552
3564
  data: (_a3 = value.data) != null ? _a3 : false,
3553
- size: (_b = value.size) != null ? _b : true
3565
+ size: (_b = value.size) != null ? _b : true,
3566
+ shouldRestorePosition: value.shouldRestorePosition
3554
3567
  };
3555
3568
  }
3556
3569
  if (value === false) {
@@ -4030,6 +4043,8 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
4030
4043
  });
4031
4044
 
4032
4045
  exports.LegendList = LegendList;
4046
+ exports.typedForwardRef = typedForwardRef;
4047
+ exports.typedMemo = typedMemo;
4033
4048
  exports.useIsLastItem = useIsLastItem;
4034
4049
  exports.useListScrollSize = useListScrollSize;
4035
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;
@@ -3063,7 +3075,7 @@ function doInitialAllocateContainers(ctx) {
3063
3075
  const item = data[i];
3064
3076
  if (item !== void 0) {
3065
3077
  const itemType = (_a3 = getItemType == null ? void 0 : getItemType(item, i)) != null ? _a3 : "";
3066
- 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;
3067
3079
  }
3068
3080
  }
3069
3081
  averageItemSize = totalSize / num;
@@ -3250,7 +3262,7 @@ function updateItemSize(ctx, itemKey, sizeObj) {
3250
3262
  return;
3251
3263
  }
3252
3264
  const type = getItemType ? (_a3 = getItemType(itemData, index)) != null ? _a3 : "" : "";
3253
- const size2 = getFixedItemSize(index, itemData, type);
3265
+ const size2 = getFixedItemSize(itemData, index, type);
3254
3266
  if (size2 !== void 0 && size2 === sizesKnown.get(itemKey)) {
3255
3267
  return;
3256
3268
  }
@@ -3529,7 +3541,8 @@ function normalizeMaintainVisibleContentPosition(value) {
3529
3541
  if (value && typeof value === "object") {
3530
3542
  return {
3531
3543
  data: (_a3 = value.data) != null ? _a3 : false,
3532
- size: (_b = value.size) != null ? _b : true
3544
+ size: (_b = value.size) != null ? _b : true,
3545
+ shouldRestorePosition: value.shouldRestorePosition
3533
3546
  };
3534
3547
  }
3535
3548
  if (value === false) {
@@ -4008,4 +4021,4 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
4008
4021
  ), IS_DEV && ENABLE_DEBUG_VIEW && /* @__PURE__ */ React3.createElement(DebugView, { state: refState.current }));
4009
4022
  });
4010
4023
 
4011
- 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;
@@ -2862,7 +2874,7 @@ function doInitialAllocateContainers(ctx) {
2862
2874
  const item = data[i];
2863
2875
  if (item !== void 0) {
2864
2876
  const itemType = (_a3 = getItemType == null ? void 0 : getItemType(item, i)) != null ? _a3 : "";
2865
- 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;
2866
2878
  }
2867
2879
  }
2868
2880
  averageItemSize = totalSize / num;
@@ -3049,7 +3061,7 @@ function updateItemSize(ctx, itemKey, sizeObj) {
3049
3061
  return;
3050
3062
  }
3051
3063
  const type = getItemType ? (_a3 = getItemType(itemData, index)) != null ? _a3 : "" : "";
3052
- const size2 = getFixedItemSize(index, itemData, type);
3064
+ const size2 = getFixedItemSize(itemData, index, type);
3053
3065
  if (size2 !== void 0 && size2 === sizesKnown.get(itemKey)) {
3054
3066
  return;
3055
3067
  }
@@ -3347,7 +3359,8 @@ function normalizeMaintainVisibleContentPosition(value) {
3347
3359
  if (value && typeof value === "object") {
3348
3360
  return {
3349
3361
  data: (_a3 = value.data) != null ? _a3 : false,
3350
- size: (_b = value.size) != null ? _b : true
3362
+ size: (_b = value.size) != null ? _b : true,
3363
+ shouldRestorePosition: value.shouldRestorePosition
3351
3364
  };
3352
3365
  }
3353
3366
  if (value === false) {
@@ -3844,6 +3857,8 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
3844
3857
  });
3845
3858
 
3846
3859
  exports.LegendList = LegendList;
3860
+ exports.typedForwardRef = typedForwardRef;
3861
+ exports.typedMemo = typedMemo;
3847
3862
  exports.useIsLastItem = useIsLastItem;
3848
3863
  exports.useListScrollSize = useListScrollSize;
3849
3864
  exports.useRecyclingEffect = useRecyclingEffect;
package/index.native.mjs CHANGED
@@ -1113,7 +1113,7 @@ function getItemSize(ctx, key, index, data, useAverageSize, preferCachedSize) {
1113
1113
  }
1114
1114
  }
1115
1115
  if (getFixedItemSize) {
1116
- size = getFixedItemSize(index, data, itemType);
1116
+ size = getFixedItemSize(data, index, itemType);
1117
1117
  if (size !== void 0) {
1118
1118
  sizesKnown.set(key, size);
1119
1119
  }
@@ -1131,7 +1131,7 @@ function getItemSize(ctx, key, index, data, useAverageSize, preferCachedSize) {
1131
1131
  }
1132
1132
  }
1133
1133
  if (size === void 0) {
1134
- size = getEstimatedItemSize ? getEstimatedItemSize(index, data, itemType) : estimatedItemSize;
1134
+ size = getEstimatedItemSize ? getEstimatedItemSize(data, index, itemType) : estimatedItemSize;
1135
1135
  }
1136
1136
  setSize(ctx, key, size);
1137
1137
  return size;
@@ -1301,7 +1301,7 @@ function scrollTo(ctx, params) {
1301
1301
 
1302
1302
  // src/utils/checkThreshold.ts
1303
1303
  var HYSTERESIS_MULTIPLIER = 1.3;
1304
- var checkThreshold = (distance, atThreshold, threshold, wasReached, snapshot, context, onReached, setSnapshot) => {
1304
+ var checkThreshold = (distance, atThreshold, threshold, wasReached, snapshot, context, onReached, setSnapshot, allowReentryOnChange) => {
1305
1305
  const absDistance = Math.abs(distance);
1306
1306
  const within = atThreshold || threshold > 0 && absDistance <= threshold;
1307
1307
  if (wasReached === null) {
@@ -1311,7 +1311,7 @@ var checkThreshold = (distance, atThreshold, threshold, wasReached, snapshot, co
1311
1311
  return null;
1312
1312
  }
1313
1313
  const updateSnapshot = () => {
1314
- setSnapshot == null ? void 0 : setSnapshot({
1314
+ setSnapshot({
1315
1315
  atThreshold,
1316
1316
  contentSize: context.contentSize,
1317
1317
  dataLength: context.dataLength,
@@ -1322,19 +1322,21 @@ var checkThreshold = (distance, atThreshold, threshold, wasReached, snapshot, co
1322
1322
  if (!within) {
1323
1323
  return false;
1324
1324
  }
1325
- onReached == null ? void 0 : onReached(distance);
1325
+ onReached(distance);
1326
1326
  updateSnapshot();
1327
1327
  return true;
1328
1328
  }
1329
1329
  const reset = !atThreshold && threshold > 0 && absDistance >= threshold * HYSTERESIS_MULTIPLIER || !atThreshold && threshold <= 0 && absDistance > 0;
1330
1330
  if (reset) {
1331
- setSnapshot == null ? void 0 : setSnapshot(void 0);
1331
+ setSnapshot(void 0);
1332
1332
  return false;
1333
1333
  }
1334
1334
  if (within) {
1335
1335
  const changed = !snapshot || snapshot.atThreshold !== atThreshold || snapshot.contentSize !== context.contentSize || snapshot.dataLength !== context.dataLength;
1336
1336
  if (changed) {
1337
- onReached == null ? void 0 : onReached(distance);
1337
+ if (allowReentryOnChange) {
1338
+ onReached(distance);
1339
+ }
1338
1340
  updateSnapshot();
1339
1341
  }
1340
1342
  }
@@ -1377,7 +1379,8 @@ function checkAtBottom(ctx) {
1377
1379
  },
1378
1380
  (snapshot) => {
1379
1381
  state.endReachedSnapshot = snapshot;
1380
- }
1382
+ },
1383
+ true
1381
1384
  );
1382
1385
  }
1383
1386
  }
@@ -1412,7 +1415,8 @@ function checkAtTop(state) {
1412
1415
  },
1413
1416
  (snapshot) => {
1414
1417
  state.startReachedSnapshot = snapshot;
1415
- }
1418
+ },
1419
+ false
1416
1420
  );
1417
1421
  }
1418
1422
 
@@ -1573,7 +1577,7 @@ function prepareMVCP(ctx, dataChanged) {
1573
1577
  const state = ctx.state;
1574
1578
  const { idsInView, positions, props } = state;
1575
1579
  const {
1576
- maintainVisibleContentPosition: { data: mvcpData, size: mvcpScroll }
1580
+ maintainVisibleContentPosition: { data: mvcpData, size: mvcpScroll, shouldRestorePosition }
1577
1581
  } = props;
1578
1582
  const scrollingTo = state.scrollingTo;
1579
1583
  let prevPosition;
@@ -1608,8 +1612,16 @@ function prepareMVCP(ctx, dataChanged) {
1608
1612
  return () => {
1609
1613
  let positionDiff = 0;
1610
1614
  if (dataChanged && targetId === void 0 && mvcpData) {
1615
+ const data = state.props.data;
1611
1616
  for (let i = 0; i < idsInViewWithPositions.length; i++) {
1612
1617
  const { id, position } = idsInViewWithPositions[i];
1618
+ const index = indexByKey.get(id);
1619
+ if (index !== void 0 && shouldRestorePosition) {
1620
+ const item = data[index];
1621
+ if (item === void 0 || !shouldRestorePosition(item, index, data)) {
1622
+ continue;
1623
+ }
1624
+ }
1613
1625
  const newPosition = positions.get(id);
1614
1626
  if (newPosition !== void 0) {
1615
1627
  positionDiff = newPosition - position;
@@ -2841,7 +2853,7 @@ function doInitialAllocateContainers(ctx) {
2841
2853
  const item = data[i];
2842
2854
  if (item !== void 0) {
2843
2855
  const itemType = (_a3 = getItemType == null ? void 0 : getItemType(item, i)) != null ? _a3 : "";
2844
- totalSize += (_c = (_b = getFixedItemSize == null ? void 0 : getFixedItemSize(i, item, itemType)) != null ? _b : getEstimatedItemSize == null ? void 0 : getEstimatedItemSize(i, item, itemType)) != null ? _c : estimatedItemSize;
2856
+ totalSize += (_c = (_b = getFixedItemSize == null ? void 0 : getFixedItemSize(item, i, itemType)) != null ? _b : getEstimatedItemSize == null ? void 0 : getEstimatedItemSize(item, i, itemType)) != null ? _c : estimatedItemSize;
2845
2857
  }
2846
2858
  }
2847
2859
  averageItemSize = totalSize / num;
@@ -3028,7 +3040,7 @@ function updateItemSize(ctx, itemKey, sizeObj) {
3028
3040
  return;
3029
3041
  }
3030
3042
  const type = getItemType ? (_a3 = getItemType(itemData, index)) != null ? _a3 : "" : "";
3031
- const size2 = getFixedItemSize(index, itemData, type);
3043
+ const size2 = getFixedItemSize(itemData, index, type);
3032
3044
  if (size2 !== void 0 && size2 === sizesKnown.get(itemKey)) {
3033
3045
  return;
3034
3046
  }
@@ -3326,7 +3338,8 @@ function normalizeMaintainVisibleContentPosition(value) {
3326
3338
  if (value && typeof value === "object") {
3327
3339
  return {
3328
3340
  data: (_a3 = value.data) != null ? _a3 : false,
3329
- size: (_b = value.size) != null ? _b : true
3341
+ size: (_b = value.size) != null ? _b : true,
3342
+ shouldRestorePosition: value.shouldRestorePosition
3330
3343
  };
3331
3344
  }
3332
3345
  if (value === false) {
@@ -3822,4 +3835,4 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
3822
3835
  ), IS_DEV && ENABLE_DEBUG_VIEW && /* @__PURE__ */ React2.createElement(DebugView, { state: refState.current }));
3823
3836
  });
3824
3837
 
3825
- export { LegendList, useIsLastItem, useListScrollSize, useRecyclingEffect, useRecyclingState, useSyncLayout, useViewability, useViewabilityAmount };
3838
+ export { LegendList, typedForwardRef, typedMemo, useIsLastItem, useListScrollSize, useRecyclingEffect, useRecyclingState, useSyncLayout, useViewability, useViewabilityAmount };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legendapp/list",
3
- "version": "3.0.0-beta.17",
3
+ "version": "3.0.0-beta.18",
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,
@@ -1,8 +1,7 @@
1
1
  import * as react_native from 'react-native';
2
2
  import { SectionListData, SectionBase, SectionListRenderItemInfo, SectionListScrollParams } from 'react-native';
3
3
  import * as React from 'react';
4
- import { a as LegendListRef, L as LegendListProps } from './types-Dj2MEm9V.mjs';
5
- import 'react-native-reanimated';
4
+ import { LegendListRef, LegendListProps } from '@legendapp/list';
6
5
 
7
6
  type SectionListSeparatorProps<ItemT, SectionT> = {
8
7
  leadingItem?: ItemT;
package/section-list.d.ts CHANGED
@@ -1,8 +1,7 @@
1
1
  import * as react_native from 'react-native';
2
2
  import { SectionListData, SectionBase, SectionListRenderItemInfo, SectionListScrollParams } from 'react-native';
3
3
  import * as React from 'react';
4
- import { a as LegendListRef, L as LegendListProps } from './types-Dj2MEm9V.js';
5
- import 'react-native-reanimated';
4
+ import { LegendListRef, LegendListProps } from '@legendapp/list';
6
5
 
7
6
  type SectionListSeparatorProps<ItemT, SectionT> = {
8
7
  leadingItem?: ItemT;