@legendapp/list 2.0.0-next.6 → 2.0.0-next.8

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
@@ -38,7 +38,8 @@ function StateProvider({ children }) {
38
38
  ["alignItemsPaddingTop", 0],
39
39
  ["stylePaddingTop", 0],
40
40
  ["headerSize", 0],
41
- ["numContainers", 0]
41
+ ["numContainers", 0],
42
+ ["totalSize", 0]
42
43
  ]),
43
44
  viewRefs: /* @__PURE__ */ new Map()
44
45
  }));
@@ -111,7 +112,7 @@ function getContentSize(ctx) {
111
112
  const stylePaddingTop = values.get("stylePaddingTop") || 0;
112
113
  const headerSize = values.get("headerSize") || 0;
113
114
  const footerSize = values.get("footerSize") || 0;
114
- const totalSize = values.get("totalSize") || 0;
115
+ const totalSize = values.get("totalSize");
115
116
  return headerSize + footerSize + totalSize + stylePaddingTop;
116
117
  }
117
118
  function useArr$(signalNames) {
@@ -595,13 +596,15 @@ function useSyncLayout({
595
596
  },
596
597
  [onChange]
597
598
  );
598
- React3.useLayoutEffect(() => {
599
- if (ref.current) {
600
- ref.current.measure((x, y, width, height) => {
601
- onChange({ height, width, x, y }, true);
602
- });
603
- }
604
- }, []);
599
+ if (IsNewArchitecture) {
600
+ React3.useLayoutEffect(() => {
601
+ if (ref.current) {
602
+ ref.current.measure((x, y, width, height) => {
603
+ onChange({ height, width, x, y }, true);
604
+ });
605
+ }
606
+ }, []);
607
+ }
605
608
  return { onLayout, ref };
606
609
  }
607
610
 
@@ -768,7 +771,7 @@ function getItemSize(state, key, index, data, useAverageSize) {
768
771
  return sizeKnown;
769
772
  }
770
773
  let size;
771
- if (IsNewArchitecture && useAverageSize !== void 0 && sizeKnown === void 0 && !getEstimatedItemSize && !scrollingTo) {
774
+ if (useAverageSize !== void 0 && sizeKnown === void 0 && !getEstimatedItemSize && !scrollingTo) {
772
775
  size = useAverageSize;
773
776
  }
774
777
  if (size === void 0) {
@@ -867,14 +870,15 @@ function prepareMVCP(ctx, state) {
867
870
  }
868
871
 
869
872
  // src/utils/setPaddingTop.ts
870
- function setPaddingTop(ctx, { stylePaddingTop, alignItemsPaddingTop }) {
873
+ function setPaddingTop(ctx, state, { stylePaddingTop, alignItemsPaddingTop }) {
871
874
  if (stylePaddingTop !== void 0) {
872
875
  const prevStylePaddingTop = peek$(ctx, "stylePaddingTop") || 0;
873
876
  if (stylePaddingTop < prevStylePaddingTop) {
874
- const prevTotalSize = peek$(ctx, "totalSize") || 0;
877
+ let prevTotalSize = peek$(ctx, "totalSize");
875
878
  set$(ctx, "totalSize", prevTotalSize + prevStylePaddingTop);
876
- setTimeout(() => {
877
- set$(ctx, "totalSize", prevTotalSize);
879
+ state.timeoutSetPaddingTop = setTimeout(() => {
880
+ prevTotalSize = peek$(ctx, "totalSize");
881
+ set$(ctx, "totalSize", prevTotalSize - prevStylePaddingTop);
878
882
  }, 16);
879
883
  }
880
884
  set$(ctx, "stylePaddingTop", stylePaddingTop);
@@ -896,7 +900,7 @@ function updateAlignItemsPaddingTop(ctx, state) {
896
900
  const contentSize = getContentSize(ctx);
897
901
  alignItemsPaddingTop = Math.max(0, Math.floor(scrollLength - contentSize));
898
902
  }
899
- setPaddingTop(ctx, { alignItemsPaddingTop });
903
+ setPaddingTop(ctx, state, { alignItemsPaddingTop });
900
904
  }
901
905
  }
902
906
 
@@ -926,6 +930,10 @@ function addTotalSize(ctx, state, key, add) {
926
930
  const { alignItemsAtEnd } = state.props;
927
931
  {
928
932
  state.totalSize = add;
933
+ if (state.timeoutSetPaddingTop) {
934
+ clearTimeout(state.timeoutSetPaddingTop);
935
+ state.timeoutSetPaddingTop = void 0;
936
+ }
929
937
  }
930
938
  set$(ctx, "totalSize", state.totalSize);
931
939
  if (alignItemsAtEnd) {
@@ -1484,265 +1492,267 @@ function setDidLayout(ctx, state) {
1484
1492
 
1485
1493
  // src/core/calculateItemsInView.ts
1486
1494
  function calculateItemsInView(ctx, state, params = {}) {
1487
- var _a, _b, _c, _d, _e, _f, _g, _h;
1488
- const {
1489
- scrollLength,
1490
- startBufferedId: startBufferedIdOrig,
1491
- positions,
1492
- columns,
1493
- containerItemKeys,
1494
- idCache,
1495
- sizes,
1496
- indexByKey,
1497
- scrollForNextCalculateItemsInView,
1498
- enableScrollForNextCalculateItemsInView,
1499
- minIndexSizeChanged
1500
- } = state;
1501
- const data = state.props.data;
1502
- const prevNumContainers = peek$(ctx, "numContainers");
1503
- if (!data || scrollLength === 0 || !prevNumContainers) {
1504
- return;
1505
- }
1506
- const totalSize = peek$(ctx, "totalSize");
1507
- const topPad = peek$(ctx, "stylePaddingTop") + peek$(ctx, "headerSize");
1508
- const numColumns = peek$(ctx, "numColumns");
1509
- const previousScrollAdjust = 0;
1510
- const { dataChanged, doMVCP } = params;
1511
- const speed = getScrollVelocity(state);
1512
- if (doMVCP || dataChanged) {
1513
- const checkMVCP = doMVCP ? prepareMVCP(ctx, state) : void 0;
1514
- updateAllPositions(ctx, state, dataChanged);
1515
- checkMVCP == null ? void 0 : checkMVCP();
1516
- }
1517
- const scrollExtra = 0;
1518
- const { queuedInitialLayout } = state;
1519
- let { scroll: scrollState } = state;
1520
- const initialScroll = state.props.initialScroll;
1521
- if (!queuedInitialLayout && initialScroll) {
1522
- const updatedOffset = calculateOffsetWithOffsetPosition(
1523
- state,
1524
- calculateOffsetForIndex(ctx, state, initialScroll.index),
1525
- initialScroll
1526
- );
1527
- scrollState = updatedOffset;
1528
- }
1529
- const scrollAdjustPad = -previousScrollAdjust - topPad;
1530
- let scroll = scrollState + scrollExtra + scrollAdjustPad;
1531
- if (scroll + scrollLength > totalSize) {
1532
- scroll = totalSize - scrollLength;
1533
- }
1534
- if (ENABLE_DEBUG_VIEW) {
1535
- set$(ctx, "debugRawScroll", scrollState);
1536
- set$(ctx, "debugComputedScroll", scroll);
1537
- }
1538
- const scrollBuffer = state.props.scrollBuffer;
1539
- let scrollBufferTop = scrollBuffer;
1540
- let scrollBufferBottom = scrollBuffer;
1541
- if (speed > 0) {
1542
- scrollBufferTop = scrollBuffer * 0.5;
1543
- scrollBufferBottom = scrollBuffer * 1.5;
1544
- } else {
1545
- scrollBufferTop = scrollBuffer * 1.5;
1546
- scrollBufferBottom = scrollBuffer * 0.5;
1547
- }
1548
- const scrollTopBuffered = scroll - scrollBufferTop;
1549
- const scrollBottom = scroll + scrollLength;
1550
- const scrollBottomBuffered = scrollBottom + scrollBufferBottom;
1551
- if (scrollForNextCalculateItemsInView) {
1552
- const { top, bottom } = scrollForNextCalculateItemsInView;
1553
- if (scrollTopBuffered > top && scrollBottomBuffered < bottom) {
1495
+ reactNative.unstable_batchedUpdates(() => {
1496
+ var _a, _b, _c, _d, _e, _f, _g, _h;
1497
+ const {
1498
+ scrollLength,
1499
+ startBufferedId: startBufferedIdOrig,
1500
+ positions,
1501
+ columns,
1502
+ containerItemKeys,
1503
+ idCache,
1504
+ sizes,
1505
+ indexByKey,
1506
+ scrollForNextCalculateItemsInView,
1507
+ enableScrollForNextCalculateItemsInView,
1508
+ minIndexSizeChanged
1509
+ } = state;
1510
+ const data = state.props.data;
1511
+ const prevNumContainers = peek$(ctx, "numContainers");
1512
+ if (!data || scrollLength === 0 || !prevNumContainers) {
1554
1513
  return;
1555
1514
  }
1556
- }
1557
- let startNoBuffer = null;
1558
- let startBuffered = null;
1559
- let startBufferedId = null;
1560
- let endNoBuffer = null;
1561
- let endBuffered = null;
1562
- let loopStart = startBufferedIdOrig ? indexByKey.get(startBufferedIdOrig) || 0 : 0;
1563
- if (minIndexSizeChanged !== void 0) {
1564
- loopStart = Math.min(minIndexSizeChanged, loopStart);
1565
- state.minIndexSizeChanged = void 0;
1566
- }
1567
- for (let i = loopStart; i >= 0; i--) {
1568
- const id = (_a = idCache.get(i)) != null ? _a : getId(state, i);
1569
- const top = positions.get(id);
1570
- const size = (_b = sizes.get(id)) != null ? _b : getItemSize(state, id, i, data[i]);
1571
- const bottom = top + size;
1572
- if (bottom > scroll - scrollBuffer) {
1573
- loopStart = i;
1515
+ const totalSize = peek$(ctx, "totalSize");
1516
+ const topPad = peek$(ctx, "stylePaddingTop") + peek$(ctx, "headerSize");
1517
+ const numColumns = peek$(ctx, "numColumns");
1518
+ const previousScrollAdjust = 0;
1519
+ const { dataChanged, doMVCP } = params;
1520
+ const speed = getScrollVelocity(state);
1521
+ if (doMVCP || dataChanged) {
1522
+ const checkMVCP = doMVCP ? prepareMVCP(ctx, state) : void 0;
1523
+ updateAllPositions(ctx, state, dataChanged);
1524
+ checkMVCP == null ? void 0 : checkMVCP();
1525
+ }
1526
+ const scrollExtra = 0;
1527
+ const { queuedInitialLayout } = state;
1528
+ let { scroll: scrollState } = state;
1529
+ const initialScroll = state.props.initialScroll;
1530
+ if (!queuedInitialLayout && initialScroll) {
1531
+ const updatedOffset = calculateOffsetWithOffsetPosition(
1532
+ state,
1533
+ calculateOffsetForIndex(ctx, state, initialScroll.index),
1534
+ initialScroll
1535
+ );
1536
+ scrollState = updatedOffset;
1537
+ }
1538
+ const scrollAdjustPad = -previousScrollAdjust - topPad;
1539
+ let scroll = scrollState + scrollExtra + scrollAdjustPad;
1540
+ if (scroll + scrollLength > totalSize) {
1541
+ scroll = totalSize - scrollLength;
1542
+ }
1543
+ if (ENABLE_DEBUG_VIEW) {
1544
+ set$(ctx, "debugRawScroll", scrollState);
1545
+ set$(ctx, "debugComputedScroll", scroll);
1546
+ }
1547
+ const scrollBuffer = state.props.scrollBuffer;
1548
+ let scrollBufferTop = scrollBuffer;
1549
+ let scrollBufferBottom = scrollBuffer;
1550
+ if (speed > 0) {
1551
+ scrollBufferTop = scrollBuffer * 0.5;
1552
+ scrollBufferBottom = scrollBuffer * 1.5;
1574
1553
  } else {
1575
- break;
1554
+ scrollBufferTop = scrollBuffer * 1.5;
1555
+ scrollBufferBottom = scrollBuffer * 0.5;
1556
+ }
1557
+ const scrollTopBuffered = scroll - scrollBufferTop;
1558
+ const scrollBottom = scroll + scrollLength;
1559
+ const scrollBottomBuffered = scrollBottom + scrollBufferBottom;
1560
+ if (scrollForNextCalculateItemsInView) {
1561
+ const { top, bottom } = scrollForNextCalculateItemsInView;
1562
+ if (scrollTopBuffered > top && scrollBottomBuffered < bottom) {
1563
+ return;
1564
+ }
1576
1565
  }
1577
- }
1578
- const loopStartMod = loopStart % numColumns;
1579
- if (loopStartMod > 0) {
1580
- loopStart -= loopStartMod;
1581
- }
1582
- let foundEnd = false;
1583
- let nextTop;
1584
- let nextBottom;
1585
- let maxIndexRendered = 0;
1586
- for (let i = 0; i < prevNumContainers; i++) {
1587
- const key = peek$(ctx, `containerItemKey${i}`);
1588
- if (key !== void 0) {
1589
- const index = indexByKey.get(key);
1590
- maxIndexRendered = Math.max(maxIndexRendered, index);
1566
+ let startNoBuffer = null;
1567
+ let startBuffered = null;
1568
+ let startBufferedId = null;
1569
+ let endNoBuffer = null;
1570
+ let endBuffered = null;
1571
+ let loopStart = startBufferedIdOrig ? indexByKey.get(startBufferedIdOrig) || 0 : 0;
1572
+ if (minIndexSizeChanged !== void 0) {
1573
+ loopStart = Math.min(minIndexSizeChanged, loopStart);
1574
+ state.minIndexSizeChanged = void 0;
1575
+ }
1576
+ for (let i = loopStart; i >= 0; i--) {
1577
+ const id = (_a = idCache.get(i)) != null ? _a : getId(state, i);
1578
+ const top = positions.get(id);
1579
+ const size = (_b = sizes.get(id)) != null ? _b : getItemSize(state, id, i, data[i]);
1580
+ const bottom = top + size;
1581
+ if (bottom > scroll - scrollBuffer) {
1582
+ loopStart = i;
1583
+ } else {
1584
+ break;
1585
+ }
1591
1586
  }
1592
- }
1593
- let firstFullyOnScreenIndex;
1594
- const dataLength = data.length;
1595
- for (let i = Math.max(0, loopStart); i < dataLength && (!foundEnd || i <= maxIndexRendered); i++) {
1596
- const id = (_c = idCache.get(i)) != null ? _c : getId(state, i);
1597
- const size = (_d = sizes.get(id)) != null ? _d : getItemSize(state, id, i, data[i]);
1598
- const top = positions.get(id);
1599
- if (!foundEnd) {
1600
- if (startNoBuffer === null && top + size > scroll) {
1601
- startNoBuffer = i;
1602
- }
1603
- if (firstFullyOnScreenIndex === void 0 && top >= scroll - 10) {
1604
- firstFullyOnScreenIndex = i;
1605
- }
1606
- if (startBuffered === null && top + size > scrollTopBuffered) {
1607
- startBuffered = i;
1608
- startBufferedId = id;
1609
- nextTop = top;
1610
- }
1611
- if (startNoBuffer !== null) {
1612
- if (top <= scrollBottom) {
1613
- endNoBuffer = i;
1587
+ const loopStartMod = loopStart % numColumns;
1588
+ if (loopStartMod > 0) {
1589
+ loopStart -= loopStartMod;
1590
+ }
1591
+ let foundEnd = false;
1592
+ let nextTop;
1593
+ let nextBottom;
1594
+ let maxIndexRendered = 0;
1595
+ for (let i = 0; i < prevNumContainers; i++) {
1596
+ const key = peek$(ctx, `containerItemKey${i}`);
1597
+ if (key !== void 0) {
1598
+ const index = indexByKey.get(key);
1599
+ maxIndexRendered = Math.max(maxIndexRendered, index);
1600
+ }
1601
+ }
1602
+ let firstFullyOnScreenIndex;
1603
+ const dataLength = data.length;
1604
+ for (let i = Math.max(0, loopStart); i < dataLength && (!foundEnd || i <= maxIndexRendered); i++) {
1605
+ const id = (_c = idCache.get(i)) != null ? _c : getId(state, i);
1606
+ const size = (_d = sizes.get(id)) != null ? _d : getItemSize(state, id, i, data[i]);
1607
+ const top = positions.get(id);
1608
+ if (!foundEnd) {
1609
+ if (startNoBuffer === null && top + size > scroll) {
1610
+ startNoBuffer = i;
1611
+ }
1612
+ if (firstFullyOnScreenIndex === void 0 && top >= scroll - 10) {
1613
+ firstFullyOnScreenIndex = i;
1614
1614
  }
1615
- if (top <= scrollBottomBuffered) {
1616
- endBuffered = i;
1617
- nextBottom = top + size;
1618
- } else {
1619
- foundEnd = true;
1615
+ if (startBuffered === null && top + size > scrollTopBuffered) {
1616
+ startBuffered = i;
1617
+ startBufferedId = id;
1618
+ nextTop = top;
1619
+ }
1620
+ if (startNoBuffer !== null) {
1621
+ if (top <= scrollBottom) {
1622
+ endNoBuffer = i;
1623
+ }
1624
+ if (top <= scrollBottomBuffered) {
1625
+ endBuffered = i;
1626
+ nextBottom = top + size;
1627
+ } else {
1628
+ foundEnd = true;
1629
+ }
1620
1630
  }
1621
1631
  }
1622
1632
  }
1623
- }
1624
- const idsInView = [];
1625
- for (let i = firstFullyOnScreenIndex; i <= endNoBuffer; i++) {
1626
- const id = (_e = idCache.get(i)) != null ? _e : getId(state, i);
1627
- idsInView.push(id);
1628
- }
1629
- Object.assign(state, {
1630
- endBuffered,
1631
- endNoBuffer,
1632
- firstFullyOnScreenIndex,
1633
- idsInView,
1634
- startBuffered,
1635
- startBufferedId,
1636
- startNoBuffer
1637
- });
1638
- if (enableScrollForNextCalculateItemsInView && nextTop !== void 0 && nextBottom !== void 0) {
1639
- state.scrollForNextCalculateItemsInView = nextTop !== void 0 && nextBottom !== void 0 ? {
1640
- bottom: nextBottom,
1641
- top: nextTop
1642
- } : void 0;
1643
- }
1644
- const numContainers = peek$(ctx, "numContainers");
1645
- const pendingRemoval = [];
1646
- if (dataChanged) {
1647
- for (let i = 0; i < numContainers; i++) {
1648
- const itemKey = peek$(ctx, `containerItemKey${i}`);
1649
- if (!state.props.keyExtractor || itemKey && indexByKey.get(itemKey) === void 0) {
1650
- pendingRemoval.push(i);
1651
- }
1633
+ const idsInView = [];
1634
+ for (let i = firstFullyOnScreenIndex; i <= endNoBuffer; i++) {
1635
+ const id = (_e = idCache.get(i)) != null ? _e : getId(state, i);
1636
+ idsInView.push(id);
1652
1637
  }
1653
- }
1654
- if (startBuffered !== null && endBuffered !== null) {
1655
- let numContainers2 = prevNumContainers;
1656
- const needNewContainers = [];
1657
- for (let i = startBuffered; i <= endBuffered; i++) {
1658
- const id = (_f = idCache.get(i)) != null ? _f : getId(state, i);
1659
- if (!containerItemKeys.has(id)) {
1660
- needNewContainers.push(i);
1661
- }
1638
+ Object.assign(state, {
1639
+ endBuffered,
1640
+ endNoBuffer,
1641
+ firstFullyOnScreenIndex,
1642
+ idsInView,
1643
+ startBuffered,
1644
+ startBufferedId,
1645
+ startNoBuffer
1646
+ });
1647
+ if (enableScrollForNextCalculateItemsInView && nextTop !== void 0 && nextBottom !== void 0) {
1648
+ state.scrollForNextCalculateItemsInView = nextTop !== void 0 && nextBottom !== void 0 ? {
1649
+ bottom: nextBottom,
1650
+ top: nextTop
1651
+ } : void 0;
1662
1652
  }
1663
- if (needNewContainers.length > 0) {
1664
- const availableContainers = findAvailableContainers(
1665
- ctx,
1666
- state,
1667
- needNewContainers.length,
1668
- startBuffered,
1669
- endBuffered,
1670
- pendingRemoval
1671
- );
1672
- for (let idx = 0; idx < needNewContainers.length; idx++) {
1673
- const i = needNewContainers[idx];
1674
- const containerIndex = availableContainers[idx];
1675
- const id = (_g = idCache.get(i)) != null ? _g : getId(state, i);
1676
- const oldKey = peek$(ctx, `containerItemKey${containerIndex}`);
1677
- if (oldKey && oldKey !== id) {
1678
- containerItemKeys.delete(oldKey);
1679
- }
1680
- set$(ctx, `containerItemKey${containerIndex}`, id);
1681
- set$(ctx, `containerItemData${containerIndex}`, data[i]);
1682
- containerItemKeys.add(id);
1683
- if (containerIndex >= numContainers2) {
1684
- numContainers2 = containerIndex + 1;
1685
- }
1686
- }
1687
- if (numContainers2 !== prevNumContainers) {
1688
- set$(ctx, "numContainers", numContainers2);
1689
- if (numContainers2 > peek$(ctx, "numContainersPooled")) {
1690
- set$(ctx, "numContainersPooled", Math.ceil(numContainers2 * 1.5));
1653
+ const numContainers = peek$(ctx, "numContainers");
1654
+ const pendingRemoval = [];
1655
+ if (dataChanged) {
1656
+ for (let i = 0; i < numContainers; i++) {
1657
+ const itemKey = peek$(ctx, `containerItemKey${i}`);
1658
+ if (!state.props.keyExtractor || itemKey && indexByKey.get(itemKey) === void 0) {
1659
+ pendingRemoval.push(i);
1691
1660
  }
1692
1661
  }
1693
1662
  }
1694
- }
1695
- for (let i = 0; i < numContainers; i++) {
1696
- const itemKey = peek$(ctx, `containerItemKey${i}`);
1697
- if (pendingRemoval.includes(i)) {
1698
- if (itemKey) {
1699
- containerItemKeys.delete(itemKey);
1663
+ if (startBuffered !== null && endBuffered !== null) {
1664
+ let numContainers2 = prevNumContainers;
1665
+ const needNewContainers = [];
1666
+ for (let i = startBuffered; i <= endBuffered; i++) {
1667
+ const id = (_f = idCache.get(i)) != null ? _f : getId(state, i);
1668
+ if (!containerItemKeys.has(id)) {
1669
+ needNewContainers.push(i);
1670
+ }
1700
1671
  }
1701
- set$(ctx, `containerItemKey${i}`, void 0);
1702
- set$(ctx, `containerItemData${i}`, void 0);
1703
- set$(ctx, `containerPosition${i}`, POSITION_OUT_OF_VIEW);
1704
- set$(ctx, `containerColumn${i}`, -1);
1705
- } else {
1706
- const itemIndex = indexByKey.get(itemKey);
1707
- const item = data[itemIndex];
1708
- if (item !== void 0) {
1709
- const id = (_h = idCache.get(itemIndex)) != null ? _h : getId(state, itemIndex);
1710
- const position = positions.get(id);
1711
- if (position === void 0) {
1712
- set$(ctx, `containerPosition${i}`, POSITION_OUT_OF_VIEW);
1713
- } else {
1714
- const column = columns.get(id) || 1;
1715
- const prevPos = peek$(ctx, `containerPosition${i}`);
1716
- const prevColumn = peek$(ctx, `containerColumn${i}`);
1717
- const prevData = peek$(ctx, `containerItemData${i}`);
1718
- if (position > POSITION_OUT_OF_VIEW && position !== prevPos) {
1719
- set$(ctx, `containerPosition${i}`, position);
1672
+ if (needNewContainers.length > 0) {
1673
+ const availableContainers = findAvailableContainers(
1674
+ ctx,
1675
+ state,
1676
+ needNewContainers.length,
1677
+ startBuffered,
1678
+ endBuffered,
1679
+ pendingRemoval
1680
+ );
1681
+ for (let idx = 0; idx < needNewContainers.length; idx++) {
1682
+ const i = needNewContainers[idx];
1683
+ const containerIndex = availableContainers[idx];
1684
+ const id = (_g = idCache.get(i)) != null ? _g : getId(state, i);
1685
+ const oldKey = peek$(ctx, `containerItemKey${containerIndex}`);
1686
+ if (oldKey && oldKey !== id) {
1687
+ containerItemKeys.delete(oldKey);
1720
1688
  }
1721
- if (column >= 0 && column !== prevColumn) {
1722
- set$(ctx, `containerColumn${i}`, column);
1689
+ set$(ctx, `containerItemKey${containerIndex}`, id);
1690
+ set$(ctx, `containerItemData${containerIndex}`, data[i]);
1691
+ containerItemKeys.add(id);
1692
+ if (containerIndex >= numContainers2) {
1693
+ numContainers2 = containerIndex + 1;
1723
1694
  }
1724
- if (prevData !== item) {
1725
- set$(ctx, `containerItemData${i}`, data[itemIndex]);
1695
+ }
1696
+ if (numContainers2 !== prevNumContainers) {
1697
+ set$(ctx, "numContainers", numContainers2);
1698
+ if (numContainers2 > peek$(ctx, "numContainersPooled")) {
1699
+ set$(ctx, "numContainersPooled", Math.ceil(numContainers2 * 1.5));
1726
1700
  }
1727
1701
  }
1728
1702
  }
1729
1703
  }
1730
- }
1731
- if (!queuedInitialLayout && endBuffered !== null) {
1732
- if (checkAllSizesKnown(state)) {
1733
- setDidLayout(ctx, state);
1704
+ for (let i = 0; i < numContainers; i++) {
1705
+ const itemKey = peek$(ctx, `containerItemKey${i}`);
1706
+ if (pendingRemoval.includes(i)) {
1707
+ if (itemKey) {
1708
+ containerItemKeys.delete(itemKey);
1709
+ }
1710
+ set$(ctx, `containerItemKey${i}`, void 0);
1711
+ set$(ctx, `containerItemData${i}`, void 0);
1712
+ set$(ctx, `containerPosition${i}`, POSITION_OUT_OF_VIEW);
1713
+ set$(ctx, `containerColumn${i}`, -1);
1714
+ } else {
1715
+ const itemIndex = indexByKey.get(itemKey);
1716
+ const item = data[itemIndex];
1717
+ if (item !== void 0) {
1718
+ const id = (_h = idCache.get(itemIndex)) != null ? _h : getId(state, itemIndex);
1719
+ const position = positions.get(id);
1720
+ if (position === void 0) {
1721
+ set$(ctx, `containerPosition${i}`, POSITION_OUT_OF_VIEW);
1722
+ } else {
1723
+ const column = columns.get(id) || 1;
1724
+ const prevPos = peek$(ctx, `containerPosition${i}`);
1725
+ const prevColumn = peek$(ctx, `containerColumn${i}`);
1726
+ const prevData = peek$(ctx, `containerItemData${i}`);
1727
+ if (position > POSITION_OUT_OF_VIEW && position !== prevPos) {
1728
+ set$(ctx, `containerPosition${i}`, position);
1729
+ }
1730
+ if (column >= 0 && column !== prevColumn) {
1731
+ set$(ctx, `containerColumn${i}`, column);
1732
+ }
1733
+ if (prevData !== item) {
1734
+ set$(ctx, `containerItemData${i}`, data[itemIndex]);
1735
+ }
1736
+ }
1737
+ }
1738
+ }
1734
1739
  }
1735
- }
1736
- if (state.props.viewabilityConfigCallbackPairs) {
1737
- updateViewableItems(
1738
- state,
1739
- ctx,
1740
- state.props.viewabilityConfigCallbackPairs,
1741
- scrollLength,
1742
- startNoBuffer,
1743
- endNoBuffer
1744
- );
1745
- }
1740
+ if (!queuedInitialLayout && endBuffered !== null) {
1741
+ if (checkAllSizesKnown(state)) {
1742
+ setDidLayout(ctx, state);
1743
+ }
1744
+ }
1745
+ if (state.props.viewabilityConfigCallbackPairs) {
1746
+ updateViewableItems(
1747
+ state,
1748
+ ctx,
1749
+ state.props.viewabilityConfigCallbackPairs,
1750
+ scrollLength,
1751
+ startNoBuffer,
1752
+ endNoBuffer
1753
+ );
1754
+ }
1755
+ });
1746
1756
  }
1747
1757
 
1748
1758
  // src/core/doInitialAllocateContainers.ts
@@ -2016,32 +2026,20 @@ function updateItemSizes(ctx, state, itemUpdates) {
2016
2026
  }
2017
2027
  }
2018
2028
  function updateItemSize(ctx, state, itemKey, sizeObj) {
2019
- if (IsNewArchitecture) {
2020
- const { sizesKnown } = state;
2021
- const numContainers = peek$(ctx, "numContainers");
2022
- const changes = [];
2023
- for (let i = 0; i < numContainers; i++) {
2024
- const containerItemKey = peek$(ctx, `containerItemKey${i}`);
2025
- if (itemKey === containerItemKey) {
2026
- changes.push({ itemKey, sizeObj });
2027
- } else if (!sizesKnown.has(containerItemKey) && containerItemKey !== void 0) {
2028
- const containerRef = ctx.viewRefs.get(i);
2029
- if (containerRef == null ? void 0 : containerRef.current) {
2030
- let measured;
2031
- containerRef.current.measure((x, y, width, height) => {
2032
- measured = { height, width, x, y };
2033
- });
2034
- if (measured) {
2035
- changes.push({ itemKey: containerItemKey, sizeObj: measured });
2036
- }
2037
- }
2038
- }
2039
- }
2040
- if (changes.length > 0) {
2041
- updateItemSizes(ctx, state, changes);
2029
+ const { queuedItemSizeUpdates, queuedItemSizeUpdatesWaiting } = state;
2030
+ const containersDidLayout = peek$(ctx, "containersDidLayout");
2031
+ if (!containersDidLayout || !queuedItemSizeUpdatesWaiting) {
2032
+ updateItemSizes(ctx, state, [{ itemKey, sizeObj }]);
2033
+ if (containersDidLayout) {
2034
+ state.queuedItemSizeUpdatesWaiting = true;
2035
+ requestAnimationFrame(() => {
2036
+ state.queuedItemSizeUpdatesWaiting = false;
2037
+ updateItemSizes(ctx, state, queuedItemSizeUpdates);
2038
+ queuedItemSizeUpdates.length = 0;
2039
+ });
2042
2040
  }
2043
2041
  } else {
2044
- updateItemSizes(ctx, state, [{ itemKey, sizeObj }]);
2042
+ queuedItemSizeUpdates.push({ itemKey, sizeObj });
2045
2043
  }
2046
2044
  }
2047
2045
  function updateOneItemSize(state, itemKey, sizeObj) {
@@ -2222,6 +2220,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
2222
2220
  positions: /* @__PURE__ */ new Map(),
2223
2221
  props: {},
2224
2222
  queuedCalculateItemsInView: 0,
2223
+ queuedItemSizeUpdates: [],
2225
2224
  refScroller: void 0,
2226
2225
  scroll: 0,
2227
2226
  scrollAdjustHandler: new ScrollAdjustHandler(ctx),
@@ -2306,10 +2305,13 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
2306
2305
  set$(ctx, "lastItemKeys", memoizedLastItemKeys);
2307
2306
  set$(ctx, "numColumns", numColumnsProp);
2308
2307
  const prevPaddingTop = peek$(ctx, "stylePaddingTop");
2309
- setPaddingTop(ctx, { stylePaddingTop: stylePaddingTopState });
2308
+ setPaddingTop(ctx, state, { stylePaddingTop: stylePaddingTopState });
2310
2309
  refState.current.props.stylePaddingBottom = stylePaddingBottomState;
2311
- const paddingDiff = stylePaddingTopState - prevPaddingTop;
2310
+ let paddingDiff = stylePaddingTopState - prevPaddingTop;
2312
2311
  if (maintainVisibleContentPosition && paddingDiff && prevPaddingTop !== void 0 && reactNative.Platform.OS === "ios") {
2312
+ if (state.scroll < 0) {
2313
+ paddingDiff += state.scroll;
2314
+ }
2313
2315
  requestAdjust(ctx, state, paddingDiff);
2314
2316
  }
2315
2317
  };