@legendapp/list 1.0.0-beta.26 → 1.0.0-beta.28

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.mjs CHANGED
@@ -550,6 +550,7 @@ var ScrollAdjustHandler = class {
550
550
  this.appliedAdjust = 0;
551
551
  this.busy = false;
552
552
  this.isPaused = false;
553
+ this.isDisabled = false;
553
554
  this.context = ctx;
554
555
  }
555
556
  doAjdust() {
@@ -557,6 +558,9 @@ var ScrollAdjustHandler = class {
557
558
  this.busy = false;
558
559
  }
559
560
  requestAdjust(adjust, onAdjusted) {
561
+ if (this.isDisabled) {
562
+ return;
563
+ }
560
564
  const oldAdjustTop = peek$(this.context, "scrollAdjust");
561
565
  if (oldAdjustTop === adjust) {
562
566
  return;
@@ -574,6 +578,9 @@ var ScrollAdjustHandler = class {
574
578
  pauseAdjust() {
575
579
  this.isPaused = true;
576
580
  }
581
+ setDisableAdjust(disable) {
582
+ this.isDisabled = disable;
583
+ }
577
584
  // return true if it was paused
578
585
  unPauseAdjust() {
579
586
  if (this.isPaused) {
@@ -848,18 +855,6 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
848
855
  return 0;
849
856
  };
850
857
  const initialContentOffset = initialScrollOffset != null ? initialScrollOffset : useMemo(calculateOffsetForIndex, []);
851
- if (Platform.OS === "web") {
852
- useEffect(() => {
853
- var _a2;
854
- if (initialContentOffset) {
855
- (_a2 = refScroller.current) == null ? void 0 : _a2.scrollTo({
856
- x: horizontal ? initialContentOffset : 0,
857
- y: horizontal ? 0 : initialContentOffset,
858
- animated: false
859
- });
860
- }
861
- }, []);
862
- }
863
858
  if (!refState.current) {
864
859
  const initialScrollLength = Dimensions.get("window")[horizontal ? "width" : "height"];
865
860
  refState.current = {
@@ -1502,6 +1497,20 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1502
1497
  addTotalSize(null, totalSize, totalSizeBelowIndex);
1503
1498
  };
1504
1499
  const isFirst = !refState.current.renderItem;
1500
+ const memoizedLastItemKeys = useMemo(() => {
1501
+ if (!dataProp.length) return /* @__PURE__ */ new Set();
1502
+ return new Set(
1503
+ Array.from({ length: Math.min(numColumnsProp, dataProp.length) }, (_, i) => getId(dataProp.length - 1 - i))
1504
+ );
1505
+ }, [dataProp.length, numColumnsProp, dataProp.slice(-numColumnsProp).toString()]);
1506
+ const initalizeStateVars = () => {
1507
+ set$(ctx, "lastItemKeys", memoizedLastItemKeys);
1508
+ set$(ctx, "numColumns", numColumnsProp);
1509
+ set$(ctx, "stylePaddingTop", stylePaddingTop);
1510
+ };
1511
+ if (isFirst) {
1512
+ initalizeStateVars();
1513
+ }
1505
1514
  if (isFirst || didDataChange || numColumnsProp !== peek$(ctx, "numColumns")) {
1506
1515
  refState.current.lastBatchingAction = Date.now();
1507
1516
  if (!keyExtractorProp && !isFirst && didDataChange) {
@@ -1511,30 +1520,19 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1511
1520
  calcTotalSizesAndPositions({ forgetPositions: false });
1512
1521
  }
1513
1522
  useEffect(() => {
1514
- checkResetContainers(
1515
- /*isFirst*/
1516
- isFirst
1517
- );
1523
+ const didAllocateContainers = doInitialAllocateContainers();
1524
+ if (!didAllocateContainers) {
1525
+ checkResetContainers(
1526
+ /*isFirst*/
1527
+ isFirst
1528
+ );
1529
+ }
1518
1530
  }, [isFirst, dataProp, numColumnsProp]);
1519
1531
  useEffect(() => {
1520
1532
  set$(ctx, "extraData", extraData);
1521
1533
  }, [extraData]);
1522
1534
  refState.current.renderItem = renderItem;
1523
- const memoizedLastItemKeys = useMemo(() => {
1524
- if (!dataProp.length) return [];
1525
- return new Set(
1526
- Array.from({ length: Math.min(numColumnsProp, dataProp.length) }, (_, i) => getId(dataProp.length - 1 - i))
1527
- );
1528
- }, [dataProp.length, numColumnsProp, dataProp.slice(-numColumnsProp).toString()]);
1529
1535
  const stylePaddingTop = (_d = (_c = (_a = StyleSheet.flatten(style)) == null ? void 0 : _a.paddingTop) != null ? _c : (_b = StyleSheet.flatten(contentContainerStyle)) == null ? void 0 : _b.paddingTop) != null ? _d : 0;
1530
- const initalizeStateVars = () => {
1531
- set$(ctx, "lastItemKeys", memoizedLastItemKeys);
1532
- set$(ctx, "numColumns", numColumnsProp);
1533
- set$(ctx, "stylePaddingTop", stylePaddingTop);
1534
- };
1535
- if (isFirst) {
1536
- initalizeStateVars();
1537
- }
1538
1536
  useEffect(initalizeStateVars, [memoizedLastItemKeys, numColumnsProp, stylePaddingTop]);
1539
1537
  const getRenderedItem = useCallback((key) => {
1540
1538
  var _a2, _b2;
@@ -1562,6 +1560,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1562
1560
  const renderedItem = (_b2 = (_a2 = refState.current).renderItem) == null ? void 0 : _b2.call(_a2, {
1563
1561
  item: data[index],
1564
1562
  index,
1563
+ extraData: peek$(ctx, "extraData"),
1565
1564
  useViewability: useViewability2,
1566
1565
  useViewabilityAmount: useViewabilityAmount2,
1567
1566
  useRecyclingEffect: useRecyclingEffect2,
@@ -1572,9 +1571,9 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1572
1571
  const doInitialAllocateContainers = () => {
1573
1572
  var _a2;
1574
1573
  const state = refState.current;
1575
- const scrollLength = state.scrollLength;
1576
- if (scrollLength > 0 && !peek$(ctx, "numContainers")) {
1577
- const averageItemSize = (_a2 = estimatedItemSize != null ? estimatedItemSize : getEstimatedItemSize == null ? void 0 : getEstimatedItemSize(0, dataProp[0])) != null ? _a2 : DEFAULT_ITEM_SIZE;
1574
+ const { scrollLength, data } = state;
1575
+ if (scrollLength > 0 && data.length > 0 && !peek$(ctx, "numContainers")) {
1576
+ const averageItemSize = (_a2 = estimatedItemSize != null ? estimatedItemSize : getEstimatedItemSize == null ? void 0 : getEstimatedItemSize(0, data[0])) != null ? _a2 : DEFAULT_ITEM_SIZE;
1578
1577
  const numContainers = Math.ceil((scrollLength + scrollBuffer * 2) / averageItemSize) * numColumnsProp;
1579
1578
  for (let i = 0; i < numContainers; i++) {
1580
1579
  set$(ctx, `containerPosition${i}`, ANCHORED_POSITION_OUT_OF_VIEW);
@@ -1589,6 +1588,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1589
1588
  } else {
1590
1589
  calculateItemsInView();
1591
1590
  }
1591
+ return true;
1592
1592
  }
1593
1593
  };
1594
1594
  useInit(() => {
@@ -1667,20 +1667,26 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1667
1667
  if (needsCalculate) {
1668
1668
  const scrollVelocity = state.scrollVelocity;
1669
1669
  if ((Number.isNaN(scrollVelocity) || Math.abs(scrollVelocity) < 1) && (!waitForInitialLayout || state.numPendingInitialLayout < 0)) {
1670
+ const setDidLayout = () => {
1671
+ set$(ctx, "containersDidLayout", true);
1672
+ if (Platform.OS === "web") {
1673
+ setTimeout(() => {
1674
+ state.scrollAdjustHandler.setDisableAdjust(false);
1675
+ }, 32);
1676
+ }
1677
+ };
1670
1678
  if (Date.now() - state.lastBatchingAction < 500) {
1671
1679
  state.queuedCalculateItemsInView = requestAnimationFrame(() => {
1672
1680
  state.queuedCalculateItemsInView = void 0;
1673
1681
  calculateItemsInView();
1674
1682
  if (needsUpdateContainersDidLayout) {
1675
- set$(ctx, "containersDidLayout", true);
1683
+ setDidLayout();
1676
1684
  }
1677
1685
  });
1678
1686
  } else {
1679
1687
  calculateItemsInView();
1680
1688
  if (needsUpdateContainersDidLayout) {
1681
- queueMicrotask(() => {
1682
- set$(ctx, "containersDidLayout", true);
1683
- });
1689
+ queueMicrotask(setDidLayout);
1684
1690
  }
1685
1691
  }
1686
1692
  }
@@ -1692,6 +1698,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1692
1698
  const didChange = scrollLength !== state.scrollLength;
1693
1699
  state.scrollLength = scrollLength;
1694
1700
  state.lastBatchingAction = Date.now();
1701
+ state.scrollForNextCalculateItemsInView = void 0;
1695
1702
  doInitialAllocateContainers();
1696
1703
  doMaintainScrollAtEnd(false);
1697
1704
  doUpdatePaddingTop();
@@ -1776,39 +1783,39 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1776
1783
  let firstIndexScrollPostion = firstIndexOffset - viewOffset;
1777
1784
  const diff = Math.abs(state.scroll - firstIndexScrollPostion);
1778
1785
  const needsReanchoring = maintainVisibleContentPosition && diff > 100;
1786
+ state.scrollForNextCalculateItemsInView = void 0;
1779
1787
  if (needsReanchoring) {
1780
1788
  const id = getId(index);
1781
1789
  state.anchorElement = { id, coordinate: firstIndexOffset };
1782
1790
  (_a2 = state.belowAnchorElementPositions) == null ? void 0 : _a2.clear();
1783
1791
  state.positions.clear();
1784
1792
  calcTotalSizesAndPositions({ forgetPositions: true });
1785
- state.scrollForNextCalculateItemsInView = void 0;
1786
1793
  state.startBufferedId = id;
1787
1794
  state.minIndexSizeChanged = index;
1788
1795
  firstIndexScrollPostion = firstIndexOffset - viewOffset + state.scrollAdjustHandler.getAppliedAdjust();
1789
1796
  }
1790
- state.scrollAdjustHandler.pauseAdjust();
1797
+ state.scrollAdjustHandler.setDisableAdjust(true);
1791
1798
  setTimeout(
1792
1799
  () => {
1793
- const wasAdjusted = state.scrollAdjustHandler.unPauseAdjust();
1794
- if (wasAdjusted) {
1795
- refState.current.scrollVelocity = 0;
1796
- refState.current.scrollHistory = [];
1797
- calculateItemsInView();
1798
- }
1800
+ state.scrollAdjustHandler.setDisableAdjust(false);
1801
+ calculateItemsInView();
1799
1802
  },
1800
- animated ? 1e3 : 50
1803
+ animated ? 150 : 50
1801
1804
  );
1802
1805
  if (viewPosition) {
1803
1806
  firstIndexScrollPostion -= viewPosition * (state.scrollLength - getItemSize(getId(index), index, state.data[index]));
1804
1807
  }
1805
1808
  const offset = horizontal ? { x: firstIndexScrollPostion, y: 0 } : { x: 0, y: firstIndexScrollPostion };
1806
- if (maintainVisibleContentPosition) {
1807
- setTimeout(() => {
1809
+ refScroller.current.scrollTo({ ...offset, animated });
1810
+ const totalSizeWithScrollAdjust = peek$(ctx, "totalSizeWithScrollAdjust");
1811
+ if (maintainVisibleContentPosition && totalSizeWithScrollAdjust - firstIndexScrollPostion < state.scrollLength) {
1812
+ const doScrollTo = () => {
1808
1813
  refScroller.current.scrollTo({ ...offset, animated });
1809
- }, 50);
1810
- } else {
1811
- refScroller.current.scrollTo({ ...offset, animated });
1814
+ };
1815
+ setTimeout(doScrollTo, animated ? 150 : 50);
1816
+ if (animated) {
1817
+ setTimeout(doScrollTo, 350);
1818
+ }
1812
1819
  }
1813
1820
  };
1814
1821
  return {
@@ -1833,6 +1840,48 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1833
1840
  },
1834
1841
  []
1835
1842
  );
1843
+ if (Platform.OS === "web") {
1844
+ useEffect(() => {
1845
+ var _a2, _b2;
1846
+ if (initialContentOffset) {
1847
+ (_a2 = refState.current) == null ? void 0 : _a2.scrollAdjustHandler.setDisableAdjust(true);
1848
+ (_b2 = refScroller.current) == null ? void 0 : _b2.scrollTo({
1849
+ x: horizontal ? initialContentOffset : 0,
1850
+ y: horizontal ? 0 : initialContentOffset,
1851
+ animated: false
1852
+ });
1853
+ setTimeout(() => {
1854
+ var _a3;
1855
+ (_a3 = refState.current) == null ? void 0 : _a3.scrollAdjustHandler.setDisableAdjust(false);
1856
+ }, 0);
1857
+ }
1858
+ }, []);
1859
+ }
1860
+ if (isFirst) {
1861
+ refState.current.scrollAdjustHandler.setDisableAdjust(true);
1862
+ }
1863
+ useEffect(() => {
1864
+ setTimeout(
1865
+ () => {
1866
+ var _a2;
1867
+ return (_a2 = refState.current) == null ? void 0 : _a2.scrollAdjustHandler.setDisableAdjust(false);
1868
+ },
1869
+ initialContentOffset ? 1e3 : 0
1870
+ );
1871
+ if (initialContentOffset) {
1872
+ const doScrollTo = () => {
1873
+ var _a2;
1874
+ (_a2 = refScroller.current) == null ? void 0 : _a2.scrollTo({
1875
+ x: horizontal ? initialContentOffset : 0,
1876
+ y: horizontal ? 0 : initialContentOffset,
1877
+ animated: false
1878
+ });
1879
+ calculateItemsInView();
1880
+ };
1881
+ setTimeout(doScrollTo, 32);
1882
+ setTimeout(doScrollTo, 300);
1883
+ }
1884
+ }, []);
1836
1885
  return /* @__PURE__ */ React6.createElement(React6.Fragment, null, /* @__PURE__ */ React6.createElement(
1837
1886
  ListComponent,
1838
1887
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legendapp/list",
3
- "version": "1.0.0-beta.26",
3
+ "version": "1.0.0-beta.28",
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,