@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.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as React3 from 'react';
2
2
  import React3__default, { useReducer, useEffect, createContext, useRef, useState, useMemo, useLayoutEffect, useCallback, useImperativeHandle, useContext, forwardRef, memo } from 'react';
3
- import { View, Text, Platform, Animated, ScrollView, StyleSheet, Dimensions, RefreshControl } from 'react-native';
3
+ import { View, Text, Platform, Animated, ScrollView, StyleSheet, Dimensions, RefreshControl, unstable_batchedUpdates } from 'react-native';
4
4
  import { useSyncExternalStore } from 'use-sync-external-store/shim';
5
5
 
6
6
  // src/components/LazyLegendList.tsx
@@ -17,7 +17,8 @@ function StateProvider({ children }) {
17
17
  ["alignItemsPaddingTop", 0],
18
18
  ["stylePaddingTop", 0],
19
19
  ["headerSize", 0],
20
- ["numContainers", 0]
20
+ ["numContainers", 0],
21
+ ["totalSize", 0]
21
22
  ]),
22
23
  viewRefs: /* @__PURE__ */ new Map()
23
24
  }));
@@ -90,7 +91,7 @@ function getContentSize(ctx) {
90
91
  const stylePaddingTop = values.get("stylePaddingTop") || 0;
91
92
  const headerSize = values.get("headerSize") || 0;
92
93
  const footerSize = values.get("footerSize") || 0;
93
- const totalSize = values.get("totalSize") || 0;
94
+ const totalSize = values.get("totalSize");
94
95
  return headerSize + footerSize + totalSize + stylePaddingTop;
95
96
  }
96
97
  function useArr$(signalNames) {
@@ -574,13 +575,15 @@ function useSyncLayout({
574
575
  },
575
576
  [onChange]
576
577
  );
577
- useLayoutEffect(() => {
578
- if (ref.current) {
579
- ref.current.measure((x, y, width, height) => {
580
- onChange({ height, width, x, y }, true);
581
- });
582
- }
583
- }, []);
578
+ if (IsNewArchitecture) {
579
+ useLayoutEffect(() => {
580
+ if (ref.current) {
581
+ ref.current.measure((x, y, width, height) => {
582
+ onChange({ height, width, x, y }, true);
583
+ });
584
+ }
585
+ }, []);
586
+ }
584
587
  return { onLayout, ref };
585
588
  }
586
589
 
@@ -747,7 +750,7 @@ function getItemSize(state, key, index, data, useAverageSize) {
747
750
  return sizeKnown;
748
751
  }
749
752
  let size;
750
- if (IsNewArchitecture && useAverageSize !== void 0 && sizeKnown === void 0 && !getEstimatedItemSize && !scrollingTo) {
753
+ if (useAverageSize !== void 0 && sizeKnown === void 0 && !getEstimatedItemSize && !scrollingTo) {
751
754
  size = useAverageSize;
752
755
  }
753
756
  if (size === void 0) {
@@ -846,14 +849,15 @@ function prepareMVCP(ctx, state) {
846
849
  }
847
850
 
848
851
  // src/utils/setPaddingTop.ts
849
- function setPaddingTop(ctx, { stylePaddingTop, alignItemsPaddingTop }) {
852
+ function setPaddingTop(ctx, state, { stylePaddingTop, alignItemsPaddingTop }) {
850
853
  if (stylePaddingTop !== void 0) {
851
854
  const prevStylePaddingTop = peek$(ctx, "stylePaddingTop") || 0;
852
855
  if (stylePaddingTop < prevStylePaddingTop) {
853
- const prevTotalSize = peek$(ctx, "totalSize") || 0;
856
+ let prevTotalSize = peek$(ctx, "totalSize");
854
857
  set$(ctx, "totalSize", prevTotalSize + prevStylePaddingTop);
855
- setTimeout(() => {
856
- set$(ctx, "totalSize", prevTotalSize);
858
+ state.timeoutSetPaddingTop = setTimeout(() => {
859
+ prevTotalSize = peek$(ctx, "totalSize");
860
+ set$(ctx, "totalSize", prevTotalSize - prevStylePaddingTop);
857
861
  }, 16);
858
862
  }
859
863
  set$(ctx, "stylePaddingTop", stylePaddingTop);
@@ -875,7 +879,7 @@ function updateAlignItemsPaddingTop(ctx, state) {
875
879
  const contentSize = getContentSize(ctx);
876
880
  alignItemsPaddingTop = Math.max(0, Math.floor(scrollLength - contentSize));
877
881
  }
878
- setPaddingTop(ctx, { alignItemsPaddingTop });
882
+ setPaddingTop(ctx, state, { alignItemsPaddingTop });
879
883
  }
880
884
  }
881
885
 
@@ -905,6 +909,10 @@ function addTotalSize(ctx, state, key, add) {
905
909
  const { alignItemsAtEnd } = state.props;
906
910
  {
907
911
  state.totalSize = add;
912
+ if (state.timeoutSetPaddingTop) {
913
+ clearTimeout(state.timeoutSetPaddingTop);
914
+ state.timeoutSetPaddingTop = void 0;
915
+ }
908
916
  }
909
917
  set$(ctx, "totalSize", state.totalSize);
910
918
  if (alignItemsAtEnd) {
@@ -1463,265 +1471,267 @@ function setDidLayout(ctx, state) {
1463
1471
 
1464
1472
  // src/core/calculateItemsInView.ts
1465
1473
  function calculateItemsInView(ctx, state, params = {}) {
1466
- var _a, _b, _c, _d, _e, _f, _g, _h;
1467
- const {
1468
- scrollLength,
1469
- startBufferedId: startBufferedIdOrig,
1470
- positions,
1471
- columns,
1472
- containerItemKeys,
1473
- idCache,
1474
- sizes,
1475
- indexByKey,
1476
- scrollForNextCalculateItemsInView,
1477
- enableScrollForNextCalculateItemsInView,
1478
- minIndexSizeChanged
1479
- } = state;
1480
- const data = state.props.data;
1481
- const prevNumContainers = peek$(ctx, "numContainers");
1482
- if (!data || scrollLength === 0 || !prevNumContainers) {
1483
- return;
1484
- }
1485
- const totalSize = peek$(ctx, "totalSize");
1486
- const topPad = peek$(ctx, "stylePaddingTop") + peek$(ctx, "headerSize");
1487
- const numColumns = peek$(ctx, "numColumns");
1488
- const previousScrollAdjust = 0;
1489
- const { dataChanged, doMVCP } = params;
1490
- const speed = getScrollVelocity(state);
1491
- if (doMVCP || dataChanged) {
1492
- const checkMVCP = doMVCP ? prepareMVCP(ctx, state) : void 0;
1493
- updateAllPositions(ctx, state, dataChanged);
1494
- checkMVCP == null ? void 0 : checkMVCP();
1495
- }
1496
- const scrollExtra = 0;
1497
- const { queuedInitialLayout } = state;
1498
- let { scroll: scrollState } = state;
1499
- const initialScroll = state.props.initialScroll;
1500
- if (!queuedInitialLayout && initialScroll) {
1501
- const updatedOffset = calculateOffsetWithOffsetPosition(
1502
- state,
1503
- calculateOffsetForIndex(ctx, state, initialScroll.index),
1504
- initialScroll
1505
- );
1506
- scrollState = updatedOffset;
1507
- }
1508
- const scrollAdjustPad = -previousScrollAdjust - topPad;
1509
- let scroll = scrollState + scrollExtra + scrollAdjustPad;
1510
- if (scroll + scrollLength > totalSize) {
1511
- scroll = totalSize - scrollLength;
1512
- }
1513
- if (ENABLE_DEBUG_VIEW) {
1514
- set$(ctx, "debugRawScroll", scrollState);
1515
- set$(ctx, "debugComputedScroll", scroll);
1516
- }
1517
- const scrollBuffer = state.props.scrollBuffer;
1518
- let scrollBufferTop = scrollBuffer;
1519
- let scrollBufferBottom = scrollBuffer;
1520
- if (speed > 0) {
1521
- scrollBufferTop = scrollBuffer * 0.5;
1522
- scrollBufferBottom = scrollBuffer * 1.5;
1523
- } else {
1524
- scrollBufferTop = scrollBuffer * 1.5;
1525
- scrollBufferBottom = scrollBuffer * 0.5;
1526
- }
1527
- const scrollTopBuffered = scroll - scrollBufferTop;
1528
- const scrollBottom = scroll + scrollLength;
1529
- const scrollBottomBuffered = scrollBottom + scrollBufferBottom;
1530
- if (scrollForNextCalculateItemsInView) {
1531
- const { top, bottom } = scrollForNextCalculateItemsInView;
1532
- if (scrollTopBuffered > top && scrollBottomBuffered < bottom) {
1474
+ unstable_batchedUpdates(() => {
1475
+ var _a, _b, _c, _d, _e, _f, _g, _h;
1476
+ const {
1477
+ scrollLength,
1478
+ startBufferedId: startBufferedIdOrig,
1479
+ positions,
1480
+ columns,
1481
+ containerItemKeys,
1482
+ idCache,
1483
+ sizes,
1484
+ indexByKey,
1485
+ scrollForNextCalculateItemsInView,
1486
+ enableScrollForNextCalculateItemsInView,
1487
+ minIndexSizeChanged
1488
+ } = state;
1489
+ const data = state.props.data;
1490
+ const prevNumContainers = peek$(ctx, "numContainers");
1491
+ if (!data || scrollLength === 0 || !prevNumContainers) {
1533
1492
  return;
1534
1493
  }
1535
- }
1536
- let startNoBuffer = null;
1537
- let startBuffered = null;
1538
- let startBufferedId = null;
1539
- let endNoBuffer = null;
1540
- let endBuffered = null;
1541
- let loopStart = startBufferedIdOrig ? indexByKey.get(startBufferedIdOrig) || 0 : 0;
1542
- if (minIndexSizeChanged !== void 0) {
1543
- loopStart = Math.min(minIndexSizeChanged, loopStart);
1544
- state.minIndexSizeChanged = void 0;
1545
- }
1546
- for (let i = loopStart; i >= 0; i--) {
1547
- const id = (_a = idCache.get(i)) != null ? _a : getId(state, i);
1548
- const top = positions.get(id);
1549
- const size = (_b = sizes.get(id)) != null ? _b : getItemSize(state, id, i, data[i]);
1550
- const bottom = top + size;
1551
- if (bottom > scroll - scrollBuffer) {
1552
- loopStart = i;
1494
+ const totalSize = peek$(ctx, "totalSize");
1495
+ const topPad = peek$(ctx, "stylePaddingTop") + peek$(ctx, "headerSize");
1496
+ const numColumns = peek$(ctx, "numColumns");
1497
+ const previousScrollAdjust = 0;
1498
+ const { dataChanged, doMVCP } = params;
1499
+ const speed = getScrollVelocity(state);
1500
+ if (doMVCP || dataChanged) {
1501
+ const checkMVCP = doMVCP ? prepareMVCP(ctx, state) : void 0;
1502
+ updateAllPositions(ctx, state, dataChanged);
1503
+ checkMVCP == null ? void 0 : checkMVCP();
1504
+ }
1505
+ const scrollExtra = 0;
1506
+ const { queuedInitialLayout } = state;
1507
+ let { scroll: scrollState } = state;
1508
+ const initialScroll = state.props.initialScroll;
1509
+ if (!queuedInitialLayout && initialScroll) {
1510
+ const updatedOffset = calculateOffsetWithOffsetPosition(
1511
+ state,
1512
+ calculateOffsetForIndex(ctx, state, initialScroll.index),
1513
+ initialScroll
1514
+ );
1515
+ scrollState = updatedOffset;
1516
+ }
1517
+ const scrollAdjustPad = -previousScrollAdjust - topPad;
1518
+ let scroll = scrollState + scrollExtra + scrollAdjustPad;
1519
+ if (scroll + scrollLength > totalSize) {
1520
+ scroll = totalSize - scrollLength;
1521
+ }
1522
+ if (ENABLE_DEBUG_VIEW) {
1523
+ set$(ctx, "debugRawScroll", scrollState);
1524
+ set$(ctx, "debugComputedScroll", scroll);
1525
+ }
1526
+ const scrollBuffer = state.props.scrollBuffer;
1527
+ let scrollBufferTop = scrollBuffer;
1528
+ let scrollBufferBottom = scrollBuffer;
1529
+ if (speed > 0) {
1530
+ scrollBufferTop = scrollBuffer * 0.5;
1531
+ scrollBufferBottom = scrollBuffer * 1.5;
1553
1532
  } else {
1554
- break;
1555
- }
1556
- }
1557
- const loopStartMod = loopStart % numColumns;
1558
- if (loopStartMod > 0) {
1559
- loopStart -= loopStartMod;
1560
- }
1561
- let foundEnd = false;
1562
- let nextTop;
1563
- let nextBottom;
1564
- let maxIndexRendered = 0;
1565
- for (let i = 0; i < prevNumContainers; i++) {
1566
- const key = peek$(ctx, `containerItemKey${i}`);
1567
- if (key !== void 0) {
1568
- const index = indexByKey.get(key);
1569
- maxIndexRendered = Math.max(maxIndexRendered, index);
1570
- }
1571
- }
1572
- let firstFullyOnScreenIndex;
1573
- const dataLength = data.length;
1574
- for (let i = Math.max(0, loopStart); i < dataLength && (!foundEnd || i <= maxIndexRendered); i++) {
1575
- const id = (_c = idCache.get(i)) != null ? _c : getId(state, i);
1576
- const size = (_d = sizes.get(id)) != null ? _d : getItemSize(state, id, i, data[i]);
1577
- const top = positions.get(id);
1578
- if (!foundEnd) {
1579
- if (startNoBuffer === null && top + size > scroll) {
1580
- startNoBuffer = i;
1581
- }
1582
- if (firstFullyOnScreenIndex === void 0 && top >= scroll - 10) {
1583
- firstFullyOnScreenIndex = i;
1584
- }
1585
- if (startBuffered === null && top + size > scrollTopBuffered) {
1586
- startBuffered = i;
1587
- startBufferedId = id;
1588
- nextTop = top;
1589
- }
1590
- if (startNoBuffer !== null) {
1591
- if (top <= scrollBottom) {
1592
- endNoBuffer = i;
1593
- }
1594
- if (top <= scrollBottomBuffered) {
1595
- endBuffered = i;
1596
- nextBottom = top + size;
1597
- } else {
1598
- foundEnd = true;
1599
- }
1533
+ scrollBufferTop = scrollBuffer * 1.5;
1534
+ scrollBufferBottom = scrollBuffer * 0.5;
1535
+ }
1536
+ const scrollTopBuffered = scroll - scrollBufferTop;
1537
+ const scrollBottom = scroll + scrollLength;
1538
+ const scrollBottomBuffered = scrollBottom + scrollBufferBottom;
1539
+ if (scrollForNextCalculateItemsInView) {
1540
+ const { top, bottom } = scrollForNextCalculateItemsInView;
1541
+ if (scrollTopBuffered > top && scrollBottomBuffered < bottom) {
1542
+ return;
1600
1543
  }
1601
1544
  }
1602
- }
1603
- const idsInView = [];
1604
- for (let i = firstFullyOnScreenIndex; i <= endNoBuffer; i++) {
1605
- const id = (_e = idCache.get(i)) != null ? _e : getId(state, i);
1606
- idsInView.push(id);
1607
- }
1608
- Object.assign(state, {
1609
- endBuffered,
1610
- endNoBuffer,
1611
- firstFullyOnScreenIndex,
1612
- idsInView,
1613
- startBuffered,
1614
- startBufferedId,
1615
- startNoBuffer
1616
- });
1617
- if (enableScrollForNextCalculateItemsInView && nextTop !== void 0 && nextBottom !== void 0) {
1618
- state.scrollForNextCalculateItemsInView = nextTop !== void 0 && nextBottom !== void 0 ? {
1619
- bottom: nextBottom,
1620
- top: nextTop
1621
- } : void 0;
1622
- }
1623
- const numContainers = peek$(ctx, "numContainers");
1624
- const pendingRemoval = [];
1625
- if (dataChanged) {
1626
- for (let i = 0; i < numContainers; i++) {
1627
- const itemKey = peek$(ctx, `containerItemKey${i}`);
1628
- if (!state.props.keyExtractor || itemKey && indexByKey.get(itemKey) === void 0) {
1629
- pendingRemoval.push(i);
1545
+ let startNoBuffer = null;
1546
+ let startBuffered = null;
1547
+ let startBufferedId = null;
1548
+ let endNoBuffer = null;
1549
+ let endBuffered = null;
1550
+ let loopStart = startBufferedIdOrig ? indexByKey.get(startBufferedIdOrig) || 0 : 0;
1551
+ if (minIndexSizeChanged !== void 0) {
1552
+ loopStart = Math.min(minIndexSizeChanged, loopStart);
1553
+ state.minIndexSizeChanged = void 0;
1554
+ }
1555
+ for (let i = loopStart; i >= 0; i--) {
1556
+ const id = (_a = idCache.get(i)) != null ? _a : getId(state, i);
1557
+ const top = positions.get(id);
1558
+ const size = (_b = sizes.get(id)) != null ? _b : getItemSize(state, id, i, data[i]);
1559
+ const bottom = top + size;
1560
+ if (bottom > scroll - scrollBuffer) {
1561
+ loopStart = i;
1562
+ } else {
1563
+ break;
1630
1564
  }
1631
1565
  }
1632
- }
1633
- if (startBuffered !== null && endBuffered !== null) {
1634
- let numContainers2 = prevNumContainers;
1635
- const needNewContainers = [];
1636
- for (let i = startBuffered; i <= endBuffered; i++) {
1637
- const id = (_f = idCache.get(i)) != null ? _f : getId(state, i);
1638
- if (!containerItemKeys.has(id)) {
1639
- needNewContainers.push(i);
1566
+ const loopStartMod = loopStart % numColumns;
1567
+ if (loopStartMod > 0) {
1568
+ loopStart -= loopStartMod;
1569
+ }
1570
+ let foundEnd = false;
1571
+ let nextTop;
1572
+ let nextBottom;
1573
+ let maxIndexRendered = 0;
1574
+ for (let i = 0; i < prevNumContainers; i++) {
1575
+ const key = peek$(ctx, `containerItemKey${i}`);
1576
+ if (key !== void 0) {
1577
+ const index = indexByKey.get(key);
1578
+ maxIndexRendered = Math.max(maxIndexRendered, index);
1640
1579
  }
1641
1580
  }
1642
- if (needNewContainers.length > 0) {
1643
- const availableContainers = findAvailableContainers(
1644
- ctx,
1645
- state,
1646
- needNewContainers.length,
1647
- startBuffered,
1648
- endBuffered,
1649
- pendingRemoval
1650
- );
1651
- for (let idx = 0; idx < needNewContainers.length; idx++) {
1652
- const i = needNewContainers[idx];
1653
- const containerIndex = availableContainers[idx];
1654
- const id = (_g = idCache.get(i)) != null ? _g : getId(state, i);
1655
- const oldKey = peek$(ctx, `containerItemKey${containerIndex}`);
1656
- if (oldKey && oldKey !== id) {
1657
- containerItemKeys.delete(oldKey);
1581
+ let firstFullyOnScreenIndex;
1582
+ const dataLength = data.length;
1583
+ for (let i = Math.max(0, loopStart); i < dataLength && (!foundEnd || i <= maxIndexRendered); i++) {
1584
+ const id = (_c = idCache.get(i)) != null ? _c : getId(state, i);
1585
+ const size = (_d = sizes.get(id)) != null ? _d : getItemSize(state, id, i, data[i]);
1586
+ const top = positions.get(id);
1587
+ if (!foundEnd) {
1588
+ if (startNoBuffer === null && top + size > scroll) {
1589
+ startNoBuffer = i;
1590
+ }
1591
+ if (firstFullyOnScreenIndex === void 0 && top >= scroll - 10) {
1592
+ firstFullyOnScreenIndex = i;
1593
+ }
1594
+ if (startBuffered === null && top + size > scrollTopBuffered) {
1595
+ startBuffered = i;
1596
+ startBufferedId = id;
1597
+ nextTop = top;
1658
1598
  }
1659
- set$(ctx, `containerItemKey${containerIndex}`, id);
1660
- set$(ctx, `containerItemData${containerIndex}`, data[i]);
1661
- containerItemKeys.add(id);
1662
- if (containerIndex >= numContainers2) {
1663
- numContainers2 = containerIndex + 1;
1599
+ if (startNoBuffer !== null) {
1600
+ if (top <= scrollBottom) {
1601
+ endNoBuffer = i;
1602
+ }
1603
+ if (top <= scrollBottomBuffered) {
1604
+ endBuffered = i;
1605
+ nextBottom = top + size;
1606
+ } else {
1607
+ foundEnd = true;
1608
+ }
1664
1609
  }
1665
1610
  }
1666
- if (numContainers2 !== prevNumContainers) {
1667
- set$(ctx, "numContainers", numContainers2);
1668
- if (numContainers2 > peek$(ctx, "numContainersPooled")) {
1669
- set$(ctx, "numContainersPooled", Math.ceil(numContainers2 * 1.5));
1611
+ }
1612
+ const idsInView = [];
1613
+ for (let i = firstFullyOnScreenIndex; i <= endNoBuffer; i++) {
1614
+ const id = (_e = idCache.get(i)) != null ? _e : getId(state, i);
1615
+ idsInView.push(id);
1616
+ }
1617
+ Object.assign(state, {
1618
+ endBuffered,
1619
+ endNoBuffer,
1620
+ firstFullyOnScreenIndex,
1621
+ idsInView,
1622
+ startBuffered,
1623
+ startBufferedId,
1624
+ startNoBuffer
1625
+ });
1626
+ if (enableScrollForNextCalculateItemsInView && nextTop !== void 0 && nextBottom !== void 0) {
1627
+ state.scrollForNextCalculateItemsInView = nextTop !== void 0 && nextBottom !== void 0 ? {
1628
+ bottom: nextBottom,
1629
+ top: nextTop
1630
+ } : void 0;
1631
+ }
1632
+ const numContainers = peek$(ctx, "numContainers");
1633
+ const pendingRemoval = [];
1634
+ if (dataChanged) {
1635
+ for (let i = 0; i < numContainers; i++) {
1636
+ const itemKey = peek$(ctx, `containerItemKey${i}`);
1637
+ if (!state.props.keyExtractor || itemKey && indexByKey.get(itemKey) === void 0) {
1638
+ pendingRemoval.push(i);
1670
1639
  }
1671
1640
  }
1672
1641
  }
1673
- }
1674
- for (let i = 0; i < numContainers; i++) {
1675
- const itemKey = peek$(ctx, `containerItemKey${i}`);
1676
- if (pendingRemoval.includes(i)) {
1677
- if (itemKey) {
1678
- containerItemKeys.delete(itemKey);
1642
+ if (startBuffered !== null && endBuffered !== null) {
1643
+ let numContainers2 = prevNumContainers;
1644
+ const needNewContainers = [];
1645
+ for (let i = startBuffered; i <= endBuffered; i++) {
1646
+ const id = (_f = idCache.get(i)) != null ? _f : getId(state, i);
1647
+ if (!containerItemKeys.has(id)) {
1648
+ needNewContainers.push(i);
1649
+ }
1679
1650
  }
1680
- set$(ctx, `containerItemKey${i}`, void 0);
1681
- set$(ctx, `containerItemData${i}`, void 0);
1682
- set$(ctx, `containerPosition${i}`, POSITION_OUT_OF_VIEW);
1683
- set$(ctx, `containerColumn${i}`, -1);
1684
- } else {
1685
- const itemIndex = indexByKey.get(itemKey);
1686
- const item = data[itemIndex];
1687
- if (item !== void 0) {
1688
- const id = (_h = idCache.get(itemIndex)) != null ? _h : getId(state, itemIndex);
1689
- const position = positions.get(id);
1690
- if (position === void 0) {
1691
- set$(ctx, `containerPosition${i}`, POSITION_OUT_OF_VIEW);
1692
- } else {
1693
- const column = columns.get(id) || 1;
1694
- const prevPos = peek$(ctx, `containerPosition${i}`);
1695
- const prevColumn = peek$(ctx, `containerColumn${i}`);
1696
- const prevData = peek$(ctx, `containerItemData${i}`);
1697
- if (position > POSITION_OUT_OF_VIEW && position !== prevPos) {
1698
- set$(ctx, `containerPosition${i}`, position);
1651
+ if (needNewContainers.length > 0) {
1652
+ const availableContainers = findAvailableContainers(
1653
+ ctx,
1654
+ state,
1655
+ needNewContainers.length,
1656
+ startBuffered,
1657
+ endBuffered,
1658
+ pendingRemoval
1659
+ );
1660
+ for (let idx = 0; idx < needNewContainers.length; idx++) {
1661
+ const i = needNewContainers[idx];
1662
+ const containerIndex = availableContainers[idx];
1663
+ const id = (_g = idCache.get(i)) != null ? _g : getId(state, i);
1664
+ const oldKey = peek$(ctx, `containerItemKey${containerIndex}`);
1665
+ if (oldKey && oldKey !== id) {
1666
+ containerItemKeys.delete(oldKey);
1699
1667
  }
1700
- if (column >= 0 && column !== prevColumn) {
1701
- set$(ctx, `containerColumn${i}`, column);
1668
+ set$(ctx, `containerItemKey${containerIndex}`, id);
1669
+ set$(ctx, `containerItemData${containerIndex}`, data[i]);
1670
+ containerItemKeys.add(id);
1671
+ if (containerIndex >= numContainers2) {
1672
+ numContainers2 = containerIndex + 1;
1702
1673
  }
1703
- if (prevData !== item) {
1704
- set$(ctx, `containerItemData${i}`, data[itemIndex]);
1674
+ }
1675
+ if (numContainers2 !== prevNumContainers) {
1676
+ set$(ctx, "numContainers", numContainers2);
1677
+ if (numContainers2 > peek$(ctx, "numContainersPooled")) {
1678
+ set$(ctx, "numContainersPooled", Math.ceil(numContainers2 * 1.5));
1705
1679
  }
1706
1680
  }
1707
1681
  }
1708
1682
  }
1709
- }
1710
- if (!queuedInitialLayout && endBuffered !== null) {
1711
- if (checkAllSizesKnown(state)) {
1712
- setDidLayout(ctx, state);
1683
+ for (let i = 0; i < numContainers; i++) {
1684
+ const itemKey = peek$(ctx, `containerItemKey${i}`);
1685
+ if (pendingRemoval.includes(i)) {
1686
+ if (itemKey) {
1687
+ containerItemKeys.delete(itemKey);
1688
+ }
1689
+ set$(ctx, `containerItemKey${i}`, void 0);
1690
+ set$(ctx, `containerItemData${i}`, void 0);
1691
+ set$(ctx, `containerPosition${i}`, POSITION_OUT_OF_VIEW);
1692
+ set$(ctx, `containerColumn${i}`, -1);
1693
+ } else {
1694
+ const itemIndex = indexByKey.get(itemKey);
1695
+ const item = data[itemIndex];
1696
+ if (item !== void 0) {
1697
+ const id = (_h = idCache.get(itemIndex)) != null ? _h : getId(state, itemIndex);
1698
+ const position = positions.get(id);
1699
+ if (position === void 0) {
1700
+ set$(ctx, `containerPosition${i}`, POSITION_OUT_OF_VIEW);
1701
+ } else {
1702
+ const column = columns.get(id) || 1;
1703
+ const prevPos = peek$(ctx, `containerPosition${i}`);
1704
+ const prevColumn = peek$(ctx, `containerColumn${i}`);
1705
+ const prevData = peek$(ctx, `containerItemData${i}`);
1706
+ if (position > POSITION_OUT_OF_VIEW && position !== prevPos) {
1707
+ set$(ctx, `containerPosition${i}`, position);
1708
+ }
1709
+ if (column >= 0 && column !== prevColumn) {
1710
+ set$(ctx, `containerColumn${i}`, column);
1711
+ }
1712
+ if (prevData !== item) {
1713
+ set$(ctx, `containerItemData${i}`, data[itemIndex]);
1714
+ }
1715
+ }
1716
+ }
1717
+ }
1713
1718
  }
1714
- }
1715
- if (state.props.viewabilityConfigCallbackPairs) {
1716
- updateViewableItems(
1717
- state,
1718
- ctx,
1719
- state.props.viewabilityConfigCallbackPairs,
1720
- scrollLength,
1721
- startNoBuffer,
1722
- endNoBuffer
1723
- );
1724
- }
1719
+ if (!queuedInitialLayout && endBuffered !== null) {
1720
+ if (checkAllSizesKnown(state)) {
1721
+ setDidLayout(ctx, state);
1722
+ }
1723
+ }
1724
+ if (state.props.viewabilityConfigCallbackPairs) {
1725
+ updateViewableItems(
1726
+ state,
1727
+ ctx,
1728
+ state.props.viewabilityConfigCallbackPairs,
1729
+ scrollLength,
1730
+ startNoBuffer,
1731
+ endNoBuffer
1732
+ );
1733
+ }
1734
+ });
1725
1735
  }
1726
1736
 
1727
1737
  // src/core/doInitialAllocateContainers.ts
@@ -1995,32 +2005,20 @@ function updateItemSizes(ctx, state, itemUpdates) {
1995
2005
  }
1996
2006
  }
1997
2007
  function updateItemSize(ctx, state, itemKey, sizeObj) {
1998
- if (IsNewArchitecture) {
1999
- const { sizesKnown } = state;
2000
- const numContainers = peek$(ctx, "numContainers");
2001
- const changes = [];
2002
- for (let i = 0; i < numContainers; i++) {
2003
- const containerItemKey = peek$(ctx, `containerItemKey${i}`);
2004
- if (itemKey === containerItemKey) {
2005
- changes.push({ itemKey, sizeObj });
2006
- } else if (!sizesKnown.has(containerItemKey) && containerItemKey !== void 0) {
2007
- const containerRef = ctx.viewRefs.get(i);
2008
- if (containerRef == null ? void 0 : containerRef.current) {
2009
- let measured;
2010
- containerRef.current.measure((x, y, width, height) => {
2011
- measured = { height, width, x, y };
2012
- });
2013
- if (measured) {
2014
- changes.push({ itemKey: containerItemKey, sizeObj: measured });
2015
- }
2016
- }
2017
- }
2018
- }
2019
- if (changes.length > 0) {
2020
- updateItemSizes(ctx, state, changes);
2008
+ const { queuedItemSizeUpdates, queuedItemSizeUpdatesWaiting } = state;
2009
+ const containersDidLayout = peek$(ctx, "containersDidLayout");
2010
+ if (!containersDidLayout || !queuedItemSizeUpdatesWaiting) {
2011
+ updateItemSizes(ctx, state, [{ itemKey, sizeObj }]);
2012
+ if (containersDidLayout) {
2013
+ state.queuedItemSizeUpdatesWaiting = true;
2014
+ requestAnimationFrame(() => {
2015
+ state.queuedItemSizeUpdatesWaiting = false;
2016
+ updateItemSizes(ctx, state, queuedItemSizeUpdates);
2017
+ queuedItemSizeUpdates.length = 0;
2018
+ });
2021
2019
  }
2022
2020
  } else {
2023
- updateItemSizes(ctx, state, [{ itemKey, sizeObj }]);
2021
+ queuedItemSizeUpdates.push({ itemKey, sizeObj });
2024
2022
  }
2025
2023
  }
2026
2024
  function updateOneItemSize(state, itemKey, sizeObj) {
@@ -2201,6 +2199,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
2201
2199
  positions: /* @__PURE__ */ new Map(),
2202
2200
  props: {},
2203
2201
  queuedCalculateItemsInView: 0,
2202
+ queuedItemSizeUpdates: [],
2204
2203
  refScroller: void 0,
2205
2204
  scroll: 0,
2206
2205
  scrollAdjustHandler: new ScrollAdjustHandler(ctx),
@@ -2285,10 +2284,13 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
2285
2284
  set$(ctx, "lastItemKeys", memoizedLastItemKeys);
2286
2285
  set$(ctx, "numColumns", numColumnsProp);
2287
2286
  const prevPaddingTop = peek$(ctx, "stylePaddingTop");
2288
- setPaddingTop(ctx, { stylePaddingTop: stylePaddingTopState });
2287
+ setPaddingTop(ctx, state, { stylePaddingTop: stylePaddingTopState });
2289
2288
  refState.current.props.stylePaddingBottom = stylePaddingBottomState;
2290
- const paddingDiff = stylePaddingTopState - prevPaddingTop;
2289
+ let paddingDiff = stylePaddingTopState - prevPaddingTop;
2291
2290
  if (maintainVisibleContentPosition && paddingDiff && prevPaddingTop !== void 0 && Platform.OS === "ios") {
2291
+ if (state.scroll < 0) {
2292
+ paddingDiff += state.scroll;
2293
+ }
2292
2294
  requestAdjust(ctx, state, paddingDiff);
2293
2295
  }
2294
2296
  };