@legendapp/list 1.0.0-beta.20 → 1.0.0-beta.21

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.
Files changed (3) hide show
  1. package/index.js +22 -16
  2. package/index.mjs +22 -16
  3. package/package.json +1 -1
package/index.js CHANGED
@@ -1705,12 +1705,18 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1705
1705
  React6.useImperativeHandle(
1706
1706
  forwardedRef,
1707
1707
  () => {
1708
- const scrollToIndex = ({ index, animated = true }) => {
1708
+ const scrollToIndex = ({
1709
+ index,
1710
+ viewOffset = 0,
1711
+ animated = true
1712
+ }) => {
1709
1713
  var _a2;
1710
1714
  const state = refState.current;
1711
1715
  const firstIndexOffset = calculateOffsetForIndex(index);
1712
- let firstIndexScrollPostion = firstIndexOffset;
1713
- if (maintainVisibleContentPosition) {
1716
+ let firstIndexScrollPostion = firstIndexOffset - viewOffset;
1717
+ const diff = Math.abs(state.scroll - firstIndexScrollPostion);
1718
+ const needsReanchoring = maintainVisibleContentPosition && diff > 100;
1719
+ if (needsReanchoring) {
1714
1720
  const id = getId(index);
1715
1721
  state.anchorElement = { id, coordinate: firstIndexOffset };
1716
1722
  (_a2 = state.belowAnchorElementPositions) == null ? void 0 : _a2.clear();
@@ -1719,20 +1725,20 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1719
1725
  state.scrollForNextCalculateItemsInView = void 0;
1720
1726
  state.startBufferedId = id;
1721
1727
  state.minIndexSizeChanged = index;
1722
- firstIndexScrollPostion = firstIndexOffset + state.scrollAdjustHandler.getAppliedAdjust();
1723
- state.scrollAdjustHandler.pauseAdjust();
1724
- setTimeout(
1725
- () => {
1726
- const wasAdjusted = state.scrollAdjustHandler.unPauseAdjust();
1727
- if (wasAdjusted) {
1728
- refState.current.scrollVelocity = 0;
1729
- refState.current.scrollHistory = [];
1730
- calculateItemsInView(0);
1731
- }
1732
- },
1733
- animated ? 1e3 : 50
1734
- );
1728
+ firstIndexScrollPostion = firstIndexOffset - viewOffset + state.scrollAdjustHandler.getAppliedAdjust();
1735
1729
  }
1730
+ state.scrollAdjustHandler.pauseAdjust();
1731
+ setTimeout(
1732
+ () => {
1733
+ const wasAdjusted = state.scrollAdjustHandler.unPauseAdjust();
1734
+ if (wasAdjusted) {
1735
+ refState.current.scrollVelocity = 0;
1736
+ refState.current.scrollHistory = [];
1737
+ calculateItemsInView(0);
1738
+ }
1739
+ },
1740
+ animated ? 1e3 : 50
1741
+ );
1736
1742
  const offset = horizontal ? { x: firstIndexScrollPostion, y: 0 } : { x: 0, y: firstIndexScrollPostion };
1737
1743
  if (maintainVisibleContentPosition) {
1738
1744
  setTimeout(() => {
package/index.mjs CHANGED
@@ -1684,12 +1684,18 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1684
1684
  useImperativeHandle(
1685
1685
  forwardedRef,
1686
1686
  () => {
1687
- const scrollToIndex = ({ index, animated = true }) => {
1687
+ const scrollToIndex = ({
1688
+ index,
1689
+ viewOffset = 0,
1690
+ animated = true
1691
+ }) => {
1688
1692
  var _a2;
1689
1693
  const state = refState.current;
1690
1694
  const firstIndexOffset = calculateOffsetForIndex(index);
1691
- let firstIndexScrollPostion = firstIndexOffset;
1692
- if (maintainVisibleContentPosition) {
1695
+ let firstIndexScrollPostion = firstIndexOffset - viewOffset;
1696
+ const diff = Math.abs(state.scroll - firstIndexScrollPostion);
1697
+ const needsReanchoring = maintainVisibleContentPosition && diff > 100;
1698
+ if (needsReanchoring) {
1693
1699
  const id = getId(index);
1694
1700
  state.anchorElement = { id, coordinate: firstIndexOffset };
1695
1701
  (_a2 = state.belowAnchorElementPositions) == null ? void 0 : _a2.clear();
@@ -1698,20 +1704,20 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1698
1704
  state.scrollForNextCalculateItemsInView = void 0;
1699
1705
  state.startBufferedId = id;
1700
1706
  state.minIndexSizeChanged = index;
1701
- firstIndexScrollPostion = firstIndexOffset + state.scrollAdjustHandler.getAppliedAdjust();
1702
- state.scrollAdjustHandler.pauseAdjust();
1703
- setTimeout(
1704
- () => {
1705
- const wasAdjusted = state.scrollAdjustHandler.unPauseAdjust();
1706
- if (wasAdjusted) {
1707
- refState.current.scrollVelocity = 0;
1708
- refState.current.scrollHistory = [];
1709
- calculateItemsInView(0);
1710
- }
1711
- },
1712
- animated ? 1e3 : 50
1713
- );
1707
+ firstIndexScrollPostion = firstIndexOffset - viewOffset + state.scrollAdjustHandler.getAppliedAdjust();
1714
1708
  }
1709
+ state.scrollAdjustHandler.pauseAdjust();
1710
+ setTimeout(
1711
+ () => {
1712
+ const wasAdjusted = state.scrollAdjustHandler.unPauseAdjust();
1713
+ if (wasAdjusted) {
1714
+ refState.current.scrollVelocity = 0;
1715
+ refState.current.scrollHistory = [];
1716
+ calculateItemsInView(0);
1717
+ }
1718
+ },
1719
+ animated ? 1e3 : 50
1720
+ );
1715
1721
  const offset = horizontal ? { x: firstIndexScrollPostion, y: 0 } : { x: 0, y: firstIndexScrollPostion };
1716
1722
  if (maintainVisibleContentPosition) {
1717
1723
  setTimeout(() => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legendapp/list",
3
- "version": "1.0.0-beta.20",
3
+ "version": "1.0.0-beta.21",
4
4
  "description": "Legend List aims to be a drop-in replacement for FlatList with much better performance and supporting dynamically sized items.",
5
5
  "sideEffects": false,
6
6
  "private": false,