@legendapp/list 2.0.0-next.24 → 2.0.0-next.25

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 (4) hide show
  1. package/index.js +59 -43
  2. package/index.mjs +59 -43
  3. package/package.json +1 -1
  4. package/.DS_Store +0 -0
package/index.js CHANGED
@@ -863,7 +863,7 @@ function calculateOffsetForIndex(ctx, state, index) {
863
863
  }
864
864
 
865
865
  // src/utils/getItemSize.ts
866
- function getItemSize(state, key, index, data, useAverageSize, defaultAverageSize) {
866
+ function getItemSize(state, key, index, data, useAverageSize, defaultAverageSize, preferRenderedCache) {
867
867
  var _a, _b;
868
868
  const {
869
869
  sizesKnown,
@@ -884,7 +884,11 @@ function getItemSize(state, key, index, data, useAverageSize, defaultAverageSize
884
884
  sizesKnown.set(key, size);
885
885
  }
886
886
  }
887
- if (size === void 0 && useAverageSize && sizeKnown === void 0 && !scrollingTo) {
887
+ const renderedSize = sizes.get(key);
888
+ if (size === void 0 && preferRenderedCache && renderedSize !== void 0) {
889
+ return renderedSize;
890
+ }
891
+ if (size === void 0 && useAverageSize && !scrollingTo) {
888
892
  if (itemType === "") {
889
893
  size = defaultAverageSize;
890
894
  } else {
@@ -894,11 +898,8 @@ function getItemSize(state, key, index, data, useAverageSize, defaultAverageSize
894
898
  }
895
899
  }
896
900
  }
897
- if (size === void 0) {
898
- size = sizes.get(key);
899
- if (size !== void 0) {
900
- return size;
901
- }
901
+ if (size === void 0 && renderedSize !== void 0) {
902
+ return renderedSize;
902
903
  }
903
904
  if (size === void 0) {
904
905
  size = getEstimatedItemSize ? getEstimatedItemSize(index, data, itemType) : estimatedItemSize;
@@ -1058,10 +1059,10 @@ function setPaddingTop(ctx, state, { stylePaddingTop, alignItemsPaddingTop }) {
1058
1059
  if (stylePaddingTop !== void 0) {
1059
1060
  const prevStylePaddingTop = peek$(ctx, "stylePaddingTop") || 0;
1060
1061
  if (stylePaddingTop < prevStylePaddingTop) {
1061
- let prevTotalSize = peek$(ctx, "totalSize");
1062
+ let prevTotalSize = peek$(ctx, "totalSize") || 0;
1062
1063
  set$(ctx, "totalSize", prevTotalSize + prevStylePaddingTop);
1063
1064
  state.timeoutSetPaddingTop = setTimeout(() => {
1064
- prevTotalSize = peek$(ctx, "totalSize");
1065
+ prevTotalSize = peek$(ctx, "totalSize") || 0;
1065
1066
  set$(ctx, "totalSize", prevTotalSize - prevStylePaddingTop);
1066
1067
  }, 16);
1067
1068
  }
@@ -1195,7 +1196,7 @@ function updateAllPositions(ctx, state, dataChanged) {
1195
1196
  const numColumns = peek$(ctx, "numColumns");
1196
1197
  const indexByKeyForChecking = __DEV__ ? /* @__PURE__ */ new Map() : void 0;
1197
1198
  const scrollVelocity = getScrollVelocity(state);
1198
- const useAverageSize = false;
1199
+ const useAverageSize = !getEstimatedItemSize;
1199
1200
  const itemType = "";
1200
1201
  let averageSize = (_a = averageSizes[itemType]) == null ? void 0 : _a.avg;
1201
1202
  if (averageSize !== void 0) {
@@ -1211,7 +1212,16 @@ function updateAllPositions(ctx, state, dataChanged) {
1211
1212
  let bailout = false;
1212
1213
  for (let i = firstFullyOnScreenIndex - 1; i >= 0; i--) {
1213
1214
  const id = (_b = idCache.get(i)) != null ? _b : getId(state, i);
1214
- const size = (_c = sizesKnown.get(id)) != null ? _c : getItemSize(state, id, i, data[i], useAverageSize, averageSize);
1215
+ const size = (_c = sizesKnown.get(id)) != null ? _c : getItemSize(
1216
+ state,
1217
+ id,
1218
+ i,
1219
+ data[i],
1220
+ useAverageSize,
1221
+ averageSize,
1222
+ /*preferRenderedCache*/
1223
+ !!dataChanged
1224
+ );
1215
1225
  const itemColumn = columns.get(id);
1216
1226
  maxSizeInRow2 = Math.max(maxSizeInRow2, size);
1217
1227
  if (itemColumn === 1) {
@@ -1238,7 +1248,16 @@ function updateAllPositions(ctx, state, dataChanged) {
1238
1248
  const dataLength = data.length;
1239
1249
  for (let i = 0; i < dataLength; i++) {
1240
1250
  const id = (_d = idCache.get(i)) != null ? _d : getId(state, i);
1241
- const size = (_e = sizesKnown.get(id)) != null ? _e : getItemSize(state, id, i, data[i], useAverageSize, averageSize);
1251
+ const size = (_e = sizesKnown.get(id)) != null ? _e : getItemSize(
1252
+ state,
1253
+ id,
1254
+ i,
1255
+ data[i],
1256
+ useAverageSize,
1257
+ averageSize,
1258
+ /*preferRenderedCache*/
1259
+ !!dataChanged
1260
+ );
1242
1261
  if (__DEV__ && needsIndexByKey) {
1243
1262
  if (indexByKeyForChecking.has(id)) {
1244
1263
  console.error(
@@ -1479,14 +1498,14 @@ function checkAllSizesKnown(state) {
1479
1498
  // src/utils/findAvailableContainers.ts
1480
1499
  function findAvailableContainers(ctx, state, numNeeded, startBuffered, endBuffered, pendingRemoval, requiredItemTypes, needNewContainers) {
1481
1500
  const numContainers = peek$(ctx, "numContainers");
1482
- const { stickyIndicesSet } = state.props;
1501
+ const { stickyContainerPool, containerItemTypes } = state;
1483
1502
  const result = [];
1484
1503
  const availableContainers = [];
1504
+ const stickyIndicesSet = state.props.stickyIndicesSet;
1485
1505
  const stickyItemIndices = (needNewContainers == null ? void 0 : needNewContainers.filter((index) => stickyIndicesSet.has(index))) || [];
1486
- const nonStickyItemIndices = (needNewContainers == null ? void 0 : needNewContainers.filter((index) => !stickyIndicesSet.has(index))) || [];
1487
1506
  const canReuseContainer = (containerIndex, requiredType) => {
1488
1507
  if (!requiredType) return true;
1489
- const existingType = state.containerItemTypes.get(containerIndex);
1508
+ const existingType = containerItemTypes.get(containerIndex);
1490
1509
  if (!existingType) return true;
1491
1510
  return existingType === requiredType;
1492
1511
  };
@@ -1495,7 +1514,7 @@ function findAvailableContainers(ctx, state, numNeeded, startBuffered, endBuffer
1495
1514
  for (let i = 0; i < stickyItemIndices.length; i++) {
1496
1515
  const requiredType = neededTypes[typeIndex];
1497
1516
  let foundContainer = false;
1498
- for (const containerIndex of state.stickyContainerPool) {
1517
+ for (const containerIndex of stickyContainerPool) {
1499
1518
  const key = peek$(ctx, `containerItemKey${containerIndex}`);
1500
1519
  const isPendingRemoval = pendingRemoval.includes(containerIndex);
1501
1520
  if ((key === void 0 || isPendingRemoval) && canReuseContainer(containerIndex, requiredType)) {
@@ -1512,38 +1531,33 @@ function findAvailableContainers(ctx, state, numNeeded, startBuffered, endBuffer
1512
1531
  if (!foundContainer) {
1513
1532
  const newContainerIndex = numContainers + result.filter((index) => index >= numContainers).length;
1514
1533
  result.push(newContainerIndex);
1515
- state.stickyContainerPool.add(newContainerIndex);
1534
+ stickyContainerPool.add(newContainerIndex);
1516
1535
  if (requiredItemTypes) typeIndex++;
1517
1536
  }
1518
1537
  }
1519
- if (nonStickyItemIndices.length > 0) {
1520
- for (let u = 0; u < numContainers; u++) {
1521
- if (state.stickyContainerPool.has(u)) {
1522
- continue;
1523
- }
1524
- const key = peek$(ctx, `containerItemKey${u}`);
1525
- let isOk = key === void 0;
1526
- if (!isOk) {
1527
- const index = pendingRemoval.indexOf(u);
1528
- if (index !== -1) {
1529
- pendingRemoval.splice(index, 1);
1530
- const requiredType = neededTypes[typeIndex];
1531
- isOk = canReuseContainer(u, requiredType);
1532
- }
1538
+ for (let u = 0; u < numContainers && result.length < numNeeded; u++) {
1539
+ if (stickyContainerPool.has(u)) {
1540
+ continue;
1541
+ }
1542
+ const key = peek$(ctx, `containerItemKey${u}`);
1543
+ let isOk = key === void 0;
1544
+ if (!isOk) {
1545
+ const index = pendingRemoval.indexOf(u);
1546
+ if (index !== -1) {
1547
+ pendingRemoval.splice(index, 1);
1548
+ const requiredType = neededTypes[typeIndex];
1549
+ isOk = canReuseContainer(u, requiredType);
1533
1550
  }
1534
- if (isOk) {
1535
- result.push(u);
1536
- if (requiredItemTypes) {
1537
- typeIndex++;
1538
- }
1539
- if (result.length >= numNeeded) {
1540
- return result;
1541
- }
1551
+ }
1552
+ if (isOk) {
1553
+ result.push(u);
1554
+ if (requiredItemTypes) {
1555
+ typeIndex++;
1542
1556
  }
1543
1557
  }
1544
1558
  }
1545
- for (let u = 0; u < numContainers; u++) {
1546
- if (state.stickyContainerPool.has(u)) {
1559
+ for (let u = 0; u < numContainers && result.length < numNeeded; u++) {
1560
+ if (stickyContainerPool.has(u)) {
1547
1561
  continue;
1548
1562
  }
1549
1563
  const key = peek$(ctx, `containerItemKey${u}`);
@@ -1788,7 +1802,9 @@ function calculateItemsInView(ctx, state, params = {}) {
1788
1802
  viewabilityConfigCallbackPairs,
1789
1803
  props: { getItemType, initialScroll, itemsAreEqual, keyExtractor, scrollBuffer }
1790
1804
  } = state;
1791
- const { data, stickyIndicesArr, stickyIndicesSet } = state.props;
1805
+ const { data } = state.props;
1806
+ const stickyIndicesArr = state.props.stickyIndicesArr || [];
1807
+ const stickyIndicesSet = state.props.stickyIndicesSet || /* @__PURE__ */ new Set();
1792
1808
  const prevNumContainers = peek$(ctx, "numContainers");
1793
1809
  if (!data || scrollLength === 0 || !prevNumContainers) {
1794
1810
  return;
@@ -2202,7 +2218,7 @@ function handleLayout(ctx, state, layout, setCanRender) {
2202
2218
  // src/core/onScroll.ts
2203
2219
  function onScroll(ctx, state, event) {
2204
2220
  var _a, _b, _c, _d, _e;
2205
- if (!state.scrollProcessingEnabled) {
2221
+ if (state.scrollProcessingEnabled === false) {
2206
2222
  return;
2207
2223
  }
2208
2224
  if (((_b = (_a = event.nativeEvent) == null ? void 0 : _a.contentSize) == null ? void 0 : _b.height) === 0 && ((_c = event.nativeEvent.contentSize) == null ? void 0 : _c.width) === 0) {
package/index.mjs CHANGED
@@ -842,7 +842,7 @@ function calculateOffsetForIndex(ctx, state, index) {
842
842
  }
843
843
 
844
844
  // src/utils/getItemSize.ts
845
- function getItemSize(state, key, index, data, useAverageSize, defaultAverageSize) {
845
+ function getItemSize(state, key, index, data, useAverageSize, defaultAverageSize, preferRenderedCache) {
846
846
  var _a, _b;
847
847
  const {
848
848
  sizesKnown,
@@ -863,7 +863,11 @@ function getItemSize(state, key, index, data, useAverageSize, defaultAverageSize
863
863
  sizesKnown.set(key, size);
864
864
  }
865
865
  }
866
- if (size === void 0 && useAverageSize && sizeKnown === void 0 && !scrollingTo) {
866
+ const renderedSize = sizes.get(key);
867
+ if (size === void 0 && preferRenderedCache && renderedSize !== void 0) {
868
+ return renderedSize;
869
+ }
870
+ if (size === void 0 && useAverageSize && !scrollingTo) {
867
871
  if (itemType === "") {
868
872
  size = defaultAverageSize;
869
873
  } else {
@@ -873,11 +877,8 @@ function getItemSize(state, key, index, data, useAverageSize, defaultAverageSize
873
877
  }
874
878
  }
875
879
  }
876
- if (size === void 0) {
877
- size = sizes.get(key);
878
- if (size !== void 0) {
879
- return size;
880
- }
880
+ if (size === void 0 && renderedSize !== void 0) {
881
+ return renderedSize;
881
882
  }
882
883
  if (size === void 0) {
883
884
  size = getEstimatedItemSize ? getEstimatedItemSize(index, data, itemType) : estimatedItemSize;
@@ -1037,10 +1038,10 @@ function setPaddingTop(ctx, state, { stylePaddingTop, alignItemsPaddingTop }) {
1037
1038
  if (stylePaddingTop !== void 0) {
1038
1039
  const prevStylePaddingTop = peek$(ctx, "stylePaddingTop") || 0;
1039
1040
  if (stylePaddingTop < prevStylePaddingTop) {
1040
- let prevTotalSize = peek$(ctx, "totalSize");
1041
+ let prevTotalSize = peek$(ctx, "totalSize") || 0;
1041
1042
  set$(ctx, "totalSize", prevTotalSize + prevStylePaddingTop);
1042
1043
  state.timeoutSetPaddingTop = setTimeout(() => {
1043
- prevTotalSize = peek$(ctx, "totalSize");
1044
+ prevTotalSize = peek$(ctx, "totalSize") || 0;
1044
1045
  set$(ctx, "totalSize", prevTotalSize - prevStylePaddingTop);
1045
1046
  }, 16);
1046
1047
  }
@@ -1174,7 +1175,7 @@ function updateAllPositions(ctx, state, dataChanged) {
1174
1175
  const numColumns = peek$(ctx, "numColumns");
1175
1176
  const indexByKeyForChecking = __DEV__ ? /* @__PURE__ */ new Map() : void 0;
1176
1177
  const scrollVelocity = getScrollVelocity(state);
1177
- const useAverageSize = false;
1178
+ const useAverageSize = !getEstimatedItemSize;
1178
1179
  const itemType = "";
1179
1180
  let averageSize = (_a = averageSizes[itemType]) == null ? void 0 : _a.avg;
1180
1181
  if (averageSize !== void 0) {
@@ -1190,7 +1191,16 @@ function updateAllPositions(ctx, state, dataChanged) {
1190
1191
  let bailout = false;
1191
1192
  for (let i = firstFullyOnScreenIndex - 1; i >= 0; i--) {
1192
1193
  const id = (_b = idCache.get(i)) != null ? _b : getId(state, i);
1193
- const size = (_c = sizesKnown.get(id)) != null ? _c : getItemSize(state, id, i, data[i], useAverageSize, averageSize);
1194
+ const size = (_c = sizesKnown.get(id)) != null ? _c : getItemSize(
1195
+ state,
1196
+ id,
1197
+ i,
1198
+ data[i],
1199
+ useAverageSize,
1200
+ averageSize,
1201
+ /*preferRenderedCache*/
1202
+ !!dataChanged
1203
+ );
1194
1204
  const itemColumn = columns.get(id);
1195
1205
  maxSizeInRow2 = Math.max(maxSizeInRow2, size);
1196
1206
  if (itemColumn === 1) {
@@ -1217,7 +1227,16 @@ function updateAllPositions(ctx, state, dataChanged) {
1217
1227
  const dataLength = data.length;
1218
1228
  for (let i = 0; i < dataLength; i++) {
1219
1229
  const id = (_d = idCache.get(i)) != null ? _d : getId(state, i);
1220
- const size = (_e = sizesKnown.get(id)) != null ? _e : getItemSize(state, id, i, data[i], useAverageSize, averageSize);
1230
+ const size = (_e = sizesKnown.get(id)) != null ? _e : getItemSize(
1231
+ state,
1232
+ id,
1233
+ i,
1234
+ data[i],
1235
+ useAverageSize,
1236
+ averageSize,
1237
+ /*preferRenderedCache*/
1238
+ !!dataChanged
1239
+ );
1221
1240
  if (__DEV__ && needsIndexByKey) {
1222
1241
  if (indexByKeyForChecking.has(id)) {
1223
1242
  console.error(
@@ -1458,14 +1477,14 @@ function checkAllSizesKnown(state) {
1458
1477
  // src/utils/findAvailableContainers.ts
1459
1478
  function findAvailableContainers(ctx, state, numNeeded, startBuffered, endBuffered, pendingRemoval, requiredItemTypes, needNewContainers) {
1460
1479
  const numContainers = peek$(ctx, "numContainers");
1461
- const { stickyIndicesSet } = state.props;
1480
+ const { stickyContainerPool, containerItemTypes } = state;
1462
1481
  const result = [];
1463
1482
  const availableContainers = [];
1483
+ const stickyIndicesSet = state.props.stickyIndicesSet;
1464
1484
  const stickyItemIndices = (needNewContainers == null ? void 0 : needNewContainers.filter((index) => stickyIndicesSet.has(index))) || [];
1465
- const nonStickyItemIndices = (needNewContainers == null ? void 0 : needNewContainers.filter((index) => !stickyIndicesSet.has(index))) || [];
1466
1485
  const canReuseContainer = (containerIndex, requiredType) => {
1467
1486
  if (!requiredType) return true;
1468
- const existingType = state.containerItemTypes.get(containerIndex);
1487
+ const existingType = containerItemTypes.get(containerIndex);
1469
1488
  if (!existingType) return true;
1470
1489
  return existingType === requiredType;
1471
1490
  };
@@ -1474,7 +1493,7 @@ function findAvailableContainers(ctx, state, numNeeded, startBuffered, endBuffer
1474
1493
  for (let i = 0; i < stickyItemIndices.length; i++) {
1475
1494
  const requiredType = neededTypes[typeIndex];
1476
1495
  let foundContainer = false;
1477
- for (const containerIndex of state.stickyContainerPool) {
1496
+ for (const containerIndex of stickyContainerPool) {
1478
1497
  const key = peek$(ctx, `containerItemKey${containerIndex}`);
1479
1498
  const isPendingRemoval = pendingRemoval.includes(containerIndex);
1480
1499
  if ((key === void 0 || isPendingRemoval) && canReuseContainer(containerIndex, requiredType)) {
@@ -1491,38 +1510,33 @@ function findAvailableContainers(ctx, state, numNeeded, startBuffered, endBuffer
1491
1510
  if (!foundContainer) {
1492
1511
  const newContainerIndex = numContainers + result.filter((index) => index >= numContainers).length;
1493
1512
  result.push(newContainerIndex);
1494
- state.stickyContainerPool.add(newContainerIndex);
1513
+ stickyContainerPool.add(newContainerIndex);
1495
1514
  if (requiredItemTypes) typeIndex++;
1496
1515
  }
1497
1516
  }
1498
- if (nonStickyItemIndices.length > 0) {
1499
- for (let u = 0; u < numContainers; u++) {
1500
- if (state.stickyContainerPool.has(u)) {
1501
- continue;
1502
- }
1503
- const key = peek$(ctx, `containerItemKey${u}`);
1504
- let isOk = key === void 0;
1505
- if (!isOk) {
1506
- const index = pendingRemoval.indexOf(u);
1507
- if (index !== -1) {
1508
- pendingRemoval.splice(index, 1);
1509
- const requiredType = neededTypes[typeIndex];
1510
- isOk = canReuseContainer(u, requiredType);
1511
- }
1517
+ for (let u = 0; u < numContainers && result.length < numNeeded; u++) {
1518
+ if (stickyContainerPool.has(u)) {
1519
+ continue;
1520
+ }
1521
+ const key = peek$(ctx, `containerItemKey${u}`);
1522
+ let isOk = key === void 0;
1523
+ if (!isOk) {
1524
+ const index = pendingRemoval.indexOf(u);
1525
+ if (index !== -1) {
1526
+ pendingRemoval.splice(index, 1);
1527
+ const requiredType = neededTypes[typeIndex];
1528
+ isOk = canReuseContainer(u, requiredType);
1512
1529
  }
1513
- if (isOk) {
1514
- result.push(u);
1515
- if (requiredItemTypes) {
1516
- typeIndex++;
1517
- }
1518
- if (result.length >= numNeeded) {
1519
- return result;
1520
- }
1530
+ }
1531
+ if (isOk) {
1532
+ result.push(u);
1533
+ if (requiredItemTypes) {
1534
+ typeIndex++;
1521
1535
  }
1522
1536
  }
1523
1537
  }
1524
- for (let u = 0; u < numContainers; u++) {
1525
- if (state.stickyContainerPool.has(u)) {
1538
+ for (let u = 0; u < numContainers && result.length < numNeeded; u++) {
1539
+ if (stickyContainerPool.has(u)) {
1526
1540
  continue;
1527
1541
  }
1528
1542
  const key = peek$(ctx, `containerItemKey${u}`);
@@ -1767,7 +1781,9 @@ function calculateItemsInView(ctx, state, params = {}) {
1767
1781
  viewabilityConfigCallbackPairs,
1768
1782
  props: { getItemType, initialScroll, itemsAreEqual, keyExtractor, scrollBuffer }
1769
1783
  } = state;
1770
- const { data, stickyIndicesArr, stickyIndicesSet } = state.props;
1784
+ const { data } = state.props;
1785
+ const stickyIndicesArr = state.props.stickyIndicesArr || [];
1786
+ const stickyIndicesSet = state.props.stickyIndicesSet || /* @__PURE__ */ new Set();
1771
1787
  const prevNumContainers = peek$(ctx, "numContainers");
1772
1788
  if (!data || scrollLength === 0 || !prevNumContainers) {
1773
1789
  return;
@@ -2181,7 +2197,7 @@ function handleLayout(ctx, state, layout, setCanRender) {
2181
2197
  // src/core/onScroll.ts
2182
2198
  function onScroll(ctx, state, event) {
2183
2199
  var _a, _b, _c, _d, _e;
2184
- if (!state.scrollProcessingEnabled) {
2200
+ if (state.scrollProcessingEnabled === false) {
2185
2201
  return;
2186
2202
  }
2187
2203
  if (((_b = (_a = event.nativeEvent) == null ? void 0 : _a.contentSize) == null ? void 0 : _b.height) === 0 && ((_c = event.nativeEvent.contentSize) == null ? void 0 : _c.width) === 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legendapp/list",
3
- "version": "2.0.0-next.24",
3
+ "version": "2.0.0-next.25",
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,
package/.DS_Store DELETED
Binary file