@legendapp/list 1.0.4 → 1.0.6

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 +63 -46
  2. package/index.mjs +63 -46
  3. package/package.json +1 -1
package/index.js CHANGED
@@ -919,7 +919,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
919
919
  columnWrapperStyle,
920
920
  keyExtractor: keyExtractorProp,
921
921
  renderItem,
922
- estimatedItemSize,
922
+ estimatedItemSize: estimatedItemSizeProp,
923
923
  getEstimatedItemSize,
924
924
  suggestEstimatedItemSize,
925
925
  ListEmptyComponent,
@@ -959,6 +959,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
959
959
  ctx.columnWrapperStyle = columnWrapperStyle || (contentContainerStyle ? createColumnWrapperStyle(contentContainerStyle) : void 0);
960
960
  const refScroller = React2.useRef(null);
961
961
  const combinedRef = useCombinedRef(refScroller, refScrollView);
962
+ const estimatedItemSize = estimatedItemSizeProp != null ? estimatedItemSizeProp : DEFAULT_ITEM_SIZE;
962
963
  const scrollBuffer = (drawDistance != null ? drawDistance : DEFAULT_DRAW_DISTANCE) || 1;
963
964
  const keyExtractor = keyExtractorProp != null ? keyExtractorProp : (item, index) => index.toString();
964
965
  const refState = React2.useRef();
@@ -972,7 +973,6 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
972
973
  return `${ret}`;
973
974
  };
974
975
  const getItemSize = (key, index, data, useAverageSize = false) => {
975
- var _a;
976
976
  const state = refState.current;
977
977
  const sizeKnown = state.sizesKnown.get(key);
978
978
  const sizePrevious = state.sizes.get(key);
@@ -992,7 +992,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
992
992
  return sizePrevious;
993
993
  }
994
994
  if (size === void 0) {
995
- size = (_a = getEstimatedItemSize ? getEstimatedItemSize(index, data) : estimatedItemSize) != null ? _a : DEFAULT_ITEM_SIZE;
995
+ size = getEstimatedItemSize ? getEstimatedItemSize(index, data) : estimatedItemSize;
996
996
  }
997
997
  state.sizes.set(key, size);
998
998
  return size;
@@ -1013,7 +1013,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1013
1013
  for (let i = 0; i < index; i++) {
1014
1014
  offset += sizeFn(i);
1015
1015
  }
1016
- } else if (estimatedItemSize) {
1016
+ } else {
1017
1017
  offset = index * estimatedItemSize;
1018
1018
  }
1019
1019
  const adjust = peek$(ctx, "containersDidLayout") ? ((_a = refState.current) == null ? void 0 : _a.scrollAdjustHandler.getAppliedAdjust()) || 0 : 0;
@@ -1110,6 +1110,11 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1110
1110
  }) => {
1111
1111
  var _a;
1112
1112
  const state = refState.current;
1113
+ if (index >= state.data.length) {
1114
+ index = state.data.length - 1;
1115
+ } else if (index < 0) {
1116
+ index = 0;
1117
+ }
1113
1118
  const firstIndexOffset = calculateOffsetForIndex(index);
1114
1119
  let firstIndexScrollPostion = firstIndexOffset - viewOffset;
1115
1120
  const diff = Math.abs(state.scroll - firstIndexScrollPostion);
@@ -1128,15 +1133,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1128
1133
  if (viewPosition) {
1129
1134
  firstIndexScrollPostion -= viewPosition * (state.scrollLength - getItemSize(getId(index), index, state.data[index]));
1130
1135
  }
1131
- state.scrollAdjustHandler.setDisableAdjust(true);
1132
- state.scrollingToOffset = firstIndexScrollPostion;
1133
1136
  scrollTo(firstIndexScrollPostion, animated);
1134
- if (!animated) {
1135
- requestAnimationFrame(() => {
1136
- state.scrollingToOffset = void 0;
1137
- state.scrollAdjustHandler.setDisableAdjust(false);
1138
- });
1139
- }
1140
1137
  };
1141
1138
  const setDidLayout = () => {
1142
1139
  refState.current.queuedInitialLayout = true;
@@ -1240,10 +1237,12 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1240
1237
  };
1241
1238
  const disableScrollJumps = (timeout) => {
1242
1239
  const state = refState.current;
1243
- state.disableScrollJumpsFrom = state.scroll - state.scrollAdjustHandler.getAppliedAdjust();
1244
- setTimeout(() => {
1245
- state.disableScrollJumpsFrom = void 0;
1246
- }, timeout);
1240
+ if (state.scrollingToOffset === void 0) {
1241
+ state.disableScrollJumpsFrom = state.scroll - state.scrollAdjustHandler.getAppliedAdjust();
1242
+ setTimeout(() => {
1243
+ state.disableScrollJumpsFrom = void 0;
1244
+ }, timeout);
1245
+ }
1247
1246
  };
1248
1247
  const getElementPositionBelowAchor = (id) => {
1249
1248
  var _a;
@@ -1356,7 +1355,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1356
1355
  const previousScrollAdjust = scrollAdjustHandler.getAppliedAdjust();
1357
1356
  const scrollExtra = Math.max(-16, Math.min(16, speed)) * 16;
1358
1357
  let scrollState = state.scroll;
1359
- const useAverageSize = !state.disableScrollJumpsFrom;
1358
+ const useAverageSize = !state.disableScrollJumpsFrom && speed >= 0 && peek$(ctx, "containersDidLayout");
1360
1359
  if (!state.queuedInitialLayout && initialScrollIndex) {
1361
1360
  const updatedOffset = calculateOffsetForIndex(initialScrollIndex);
1362
1361
  scrollState = updatedOffset;
@@ -1437,7 +1436,8 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1437
1436
  }
1438
1437
  return topOffset;
1439
1438
  };
1440
- for (let i = Math.max(0, loopStart); i < data.length; i++) {
1439
+ let foundEnd = false;
1440
+ for (let i = Math.max(0, loopStart); i < data.length && (!foundEnd || i <= prevEndBuffered); i++) {
1441
1441
  const id = getId(i);
1442
1442
  const size = getItemSize(id, i, data[i], useAverageSize);
1443
1443
  maxSizeInRow = Math.max(maxSizeInRow, size);
@@ -1450,21 +1450,23 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1450
1450
  if (columns.get(id) !== column) {
1451
1451
  columns.set(id, column);
1452
1452
  }
1453
- if (startNoBuffer === null && top + size > scroll) {
1454
- startNoBuffer = i;
1455
- }
1456
- if (startBuffered === null && top + size > scroll - scrollBufferTop) {
1457
- startBuffered = i;
1458
- startBufferedId = id;
1459
- }
1460
- if (startNoBuffer !== null) {
1461
- if (top <= scrollBottom) {
1462
- endNoBuffer = i;
1453
+ if (!foundEnd) {
1454
+ if (startNoBuffer === null && top + size > scroll) {
1455
+ startNoBuffer = i;
1463
1456
  }
1464
- if (top <= scrollBottom + scrollBufferBottom) {
1465
- endBuffered = i;
1466
- } else {
1467
- break;
1457
+ if (startBuffered === null && top + size > scroll - scrollBufferTop) {
1458
+ startBuffered = i;
1459
+ startBufferedId = id;
1460
+ }
1461
+ if (startNoBuffer !== null) {
1462
+ if (top <= scrollBottom) {
1463
+ endNoBuffer = i;
1464
+ }
1465
+ if (top <= scrollBottom + scrollBufferBottom) {
1466
+ endBuffered = i;
1467
+ } else {
1468
+ foundEnd = true;
1469
+ }
1468
1470
  }
1469
1471
  }
1470
1472
  column++;
@@ -1566,18 +1568,14 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1566
1568
  const item = data[itemIndex];
1567
1569
  if (item !== void 0) {
1568
1570
  const id = getId(itemIndex);
1569
- if (itemKey !== id || itemIndex < startBuffered || itemIndex > endBuffered) {
1570
- const prevPos = peek$(ctx, `containerPosition${i}`);
1571
- const pos = positions.get(id) || 0;
1572
- const size = getItemSize(id, itemIndex, data[i]);
1573
- if (pos + size >= scroll && pos <= scrollBottom || prevPos + size >= scroll && prevPos <= scrollBottom || endBuffered < prevEndBuffered) {
1574
- set$(ctx, `containerPosition${i}`, ANCHORED_POSITION_OUT_OF_VIEW);
1575
- }
1571
+ const position = positions.get(id);
1572
+ if (position === void 0) {
1573
+ set$(ctx, `containerPosition${i}`, ANCHORED_POSITION_OUT_OF_VIEW);
1576
1574
  } else {
1577
1575
  const pos = {
1578
1576
  type: "top",
1579
- relativeCoordinate: positions.get(id) || 0,
1580
- top: positions.get(id) || 0
1577
+ relativeCoordinate: positions.get(id),
1578
+ top: positions.get(id)
1581
1579
  };
1582
1580
  const column2 = columns.get(id) || 1;
1583
1581
  if (maintainVisibleContentPosition && itemIndex < anchorElementIndex) {
@@ -1653,13 +1651,27 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1653
1651
  setPaddingTop({ alignItemsPaddingTop: paddingTop });
1654
1652
  }
1655
1653
  };
1654
+ const finishScrollTo = () => {
1655
+ const state = refState.current;
1656
+ if (state) {
1657
+ state.scrollingToOffset = void 0;
1658
+ state.scrollAdjustHandler.setDisableAdjust(false);
1659
+ calculateItemsInView();
1660
+ }
1661
+ };
1656
1662
  const scrollTo = (offset, animated) => {
1657
1663
  var _a;
1664
+ const state = refState.current;
1665
+ state.scrollAdjustHandler.setDisableAdjust(true);
1666
+ state.scrollingToOffset = offset;
1658
1667
  (_a = refScroller.current) == null ? void 0 : _a.scrollTo({
1659
1668
  x: horizontal ? offset : 0,
1660
1669
  y: horizontal ? 0 : offset,
1661
1670
  animated: !!animated
1662
1671
  });
1672
+ if (!animated) {
1673
+ requestAnimationFrame(finishScrollTo);
1674
+ }
1663
1675
  };
1664
1676
  const doMaintainScrollAtEnd = (animated) => {
1665
1677
  const state = refState.current;
@@ -1912,7 +1924,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1912
1924
  isFirst
1913
1925
  );
1914
1926
  }
1915
- }, [isFirst, dataProp, numColumnsProp]);
1927
+ }, [dataProp, numColumnsProp]);
1916
1928
  React2.useEffect(() => {
1917
1929
  set$(ctx, "extraData", extraData);
1918
1930
  }, [extraData]);
@@ -1937,11 +1949,10 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1937
1949
  return { index, item: data[index], renderedItem };
1938
1950
  }, []);
1939
1951
  const doInitialAllocateContainers = () => {
1940
- var _a;
1941
1952
  const state = refState.current;
1942
1953
  const { scrollLength, data } = state;
1943
1954
  if (scrollLength > 0 && data.length > 0 && !peek$(ctx, "numContainers")) {
1944
- const averageItemSize = (_a = estimatedItemSize != null ? estimatedItemSize : getEstimatedItemSize == null ? void 0 : getEstimatedItemSize(0, data[0])) != null ? _a : DEFAULT_ITEM_SIZE;
1955
+ const averageItemSize = getEstimatedItemSize ? getEstimatedItemSize(0, data[0]) : estimatedItemSize;
1945
1956
  const numContainers = Math.ceil((scrollLength + scrollBuffer * 2) / averageItemSize) * numColumnsProp;
1946
1957
  for (let i = 0; i < numContainers; i++) {
1947
1958
  set$(ctx, `containerPosition${i}`, ANCHORED_POSITION_OUT_OF_VIEW);
@@ -1992,6 +2003,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1992
2003
  const numColumns = peek$(ctx, "numColumns");
1993
2004
  state.minIndexSizeChanged = state.minIndexSizeChanged !== void 0 ? Math.min(state.minIndexSizeChanged, index) : index;
1994
2005
  const prevSize = getItemSize(itemKey, index, data);
2006
+ const prevSizeKnown = sizesKnown.get(itemKey);
1995
2007
  let needsCalculate = false;
1996
2008
  let needsUpdateContainersDidLayout = false;
1997
2009
  sizesKnown.set(itemKey, size);
@@ -2034,7 +2046,9 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
2034
2046
  }
2035
2047
  state.scrollForNextCalculateItemsInView = void 0;
2036
2048
  addTotalSize(itemKey, diff, 0);
2037
- doMaintainScrollAtEnd(false);
2049
+ if (prevSizeKnown !== void 0 && Math.abs(prevSizeKnown - size) > 5) {
2050
+ doMaintainScrollAtEnd(false);
2051
+ }
2038
2052
  if (onItemSizeChanged) {
2039
2053
  onItemSizeChanged({
2040
2054
  size,
@@ -2052,7 +2066,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
2052
2066
  if (needsUpdateContainersDidLayout || !fromFixGaps && needsCalculate && (isInView || !queuedInitialLayout)) {
2053
2067
  const scrollVelocity = state.scrollVelocity;
2054
2068
  let didCalculate = false;
2055
- if ((Number.isNaN(scrollVelocity) || Math.abs(scrollVelocity) < 1) && (!waitForInitialLayout || needsUpdateContainersDidLayout || queuedInitialLayout)) {
2069
+ if ((Number.isNaN(scrollVelocity) || Math.abs(scrollVelocity) < 1 || state.scrollingToOffset !== void 0) && (!waitForInitialLayout || needsUpdateContainersDidLayout || queuedInitialLayout)) {
2056
2070
  if (Date.now() - state.lastBatchingAction < 500) {
2057
2071
  if (!state.queuedCalculateItemsInView) {
2058
2072
  state.queuedCalculateItemsInView = requestAnimationFrame(() => {
@@ -2110,6 +2124,9 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
2110
2124
  if (state.ignoreScrollFromCalcTotal && newScroll !== 0) {
2111
2125
  return;
2112
2126
  }
2127
+ if (state.scrollingToOffset !== void 0 && Math.abs(newScroll - state.scrollingToOffset) < 10) {
2128
+ finishScrollTo();
2129
+ }
2113
2130
  if (state.disableScrollJumpsFrom !== void 0) {
2114
2131
  const scrollMinusAdjust = newScroll - state.scrollAdjustHandler.getAppliedAdjust();
2115
2132
  if (Math.abs(scrollMinusAdjust - state.disableScrollJumpsFrom) > 200) {
package/index.mjs CHANGED
@@ -898,7 +898,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
898
898
  columnWrapperStyle,
899
899
  keyExtractor: keyExtractorProp,
900
900
  renderItem,
901
- estimatedItemSize,
901
+ estimatedItemSize: estimatedItemSizeProp,
902
902
  getEstimatedItemSize,
903
903
  suggestEstimatedItemSize,
904
904
  ListEmptyComponent,
@@ -938,6 +938,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
938
938
  ctx.columnWrapperStyle = columnWrapperStyle || (contentContainerStyle ? createColumnWrapperStyle(contentContainerStyle) : void 0);
939
939
  const refScroller = useRef(null);
940
940
  const combinedRef = useCombinedRef(refScroller, refScrollView);
941
+ const estimatedItemSize = estimatedItemSizeProp != null ? estimatedItemSizeProp : DEFAULT_ITEM_SIZE;
941
942
  const scrollBuffer = (drawDistance != null ? drawDistance : DEFAULT_DRAW_DISTANCE) || 1;
942
943
  const keyExtractor = keyExtractorProp != null ? keyExtractorProp : (item, index) => index.toString();
943
944
  const refState = useRef();
@@ -951,7 +952,6 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
951
952
  return `${ret}`;
952
953
  };
953
954
  const getItemSize = (key, index, data, useAverageSize = false) => {
954
- var _a;
955
955
  const state = refState.current;
956
956
  const sizeKnown = state.sizesKnown.get(key);
957
957
  const sizePrevious = state.sizes.get(key);
@@ -971,7 +971,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
971
971
  return sizePrevious;
972
972
  }
973
973
  if (size === void 0) {
974
- size = (_a = getEstimatedItemSize ? getEstimatedItemSize(index, data) : estimatedItemSize) != null ? _a : DEFAULT_ITEM_SIZE;
974
+ size = getEstimatedItemSize ? getEstimatedItemSize(index, data) : estimatedItemSize;
975
975
  }
976
976
  state.sizes.set(key, size);
977
977
  return size;
@@ -992,7 +992,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
992
992
  for (let i = 0; i < index; i++) {
993
993
  offset += sizeFn(i);
994
994
  }
995
- } else if (estimatedItemSize) {
995
+ } else {
996
996
  offset = index * estimatedItemSize;
997
997
  }
998
998
  const adjust = peek$(ctx, "containersDidLayout") ? ((_a = refState.current) == null ? void 0 : _a.scrollAdjustHandler.getAppliedAdjust()) || 0 : 0;
@@ -1089,6 +1089,11 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1089
1089
  }) => {
1090
1090
  var _a;
1091
1091
  const state = refState.current;
1092
+ if (index >= state.data.length) {
1093
+ index = state.data.length - 1;
1094
+ } else if (index < 0) {
1095
+ index = 0;
1096
+ }
1092
1097
  const firstIndexOffset = calculateOffsetForIndex(index);
1093
1098
  let firstIndexScrollPostion = firstIndexOffset - viewOffset;
1094
1099
  const diff = Math.abs(state.scroll - firstIndexScrollPostion);
@@ -1107,15 +1112,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1107
1112
  if (viewPosition) {
1108
1113
  firstIndexScrollPostion -= viewPosition * (state.scrollLength - getItemSize(getId(index), index, state.data[index]));
1109
1114
  }
1110
- state.scrollAdjustHandler.setDisableAdjust(true);
1111
- state.scrollingToOffset = firstIndexScrollPostion;
1112
1115
  scrollTo(firstIndexScrollPostion, animated);
1113
- if (!animated) {
1114
- requestAnimationFrame(() => {
1115
- state.scrollingToOffset = void 0;
1116
- state.scrollAdjustHandler.setDisableAdjust(false);
1117
- });
1118
- }
1119
1116
  };
1120
1117
  const setDidLayout = () => {
1121
1118
  refState.current.queuedInitialLayout = true;
@@ -1219,10 +1216,12 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1219
1216
  };
1220
1217
  const disableScrollJumps = (timeout) => {
1221
1218
  const state = refState.current;
1222
- state.disableScrollJumpsFrom = state.scroll - state.scrollAdjustHandler.getAppliedAdjust();
1223
- setTimeout(() => {
1224
- state.disableScrollJumpsFrom = void 0;
1225
- }, timeout);
1219
+ if (state.scrollingToOffset === void 0) {
1220
+ state.disableScrollJumpsFrom = state.scroll - state.scrollAdjustHandler.getAppliedAdjust();
1221
+ setTimeout(() => {
1222
+ state.disableScrollJumpsFrom = void 0;
1223
+ }, timeout);
1224
+ }
1226
1225
  };
1227
1226
  const getElementPositionBelowAchor = (id) => {
1228
1227
  var _a;
@@ -1335,7 +1334,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1335
1334
  const previousScrollAdjust = scrollAdjustHandler.getAppliedAdjust();
1336
1335
  const scrollExtra = Math.max(-16, Math.min(16, speed)) * 16;
1337
1336
  let scrollState = state.scroll;
1338
- const useAverageSize = !state.disableScrollJumpsFrom;
1337
+ const useAverageSize = !state.disableScrollJumpsFrom && speed >= 0 && peek$(ctx, "containersDidLayout");
1339
1338
  if (!state.queuedInitialLayout && initialScrollIndex) {
1340
1339
  const updatedOffset = calculateOffsetForIndex(initialScrollIndex);
1341
1340
  scrollState = updatedOffset;
@@ -1416,7 +1415,8 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1416
1415
  }
1417
1416
  return topOffset;
1418
1417
  };
1419
- for (let i = Math.max(0, loopStart); i < data.length; i++) {
1418
+ let foundEnd = false;
1419
+ for (let i = Math.max(0, loopStart); i < data.length && (!foundEnd || i <= prevEndBuffered); i++) {
1420
1420
  const id = getId(i);
1421
1421
  const size = getItemSize(id, i, data[i], useAverageSize);
1422
1422
  maxSizeInRow = Math.max(maxSizeInRow, size);
@@ -1429,21 +1429,23 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1429
1429
  if (columns.get(id) !== column) {
1430
1430
  columns.set(id, column);
1431
1431
  }
1432
- if (startNoBuffer === null && top + size > scroll) {
1433
- startNoBuffer = i;
1434
- }
1435
- if (startBuffered === null && top + size > scroll - scrollBufferTop) {
1436
- startBuffered = i;
1437
- startBufferedId = id;
1438
- }
1439
- if (startNoBuffer !== null) {
1440
- if (top <= scrollBottom) {
1441
- endNoBuffer = i;
1432
+ if (!foundEnd) {
1433
+ if (startNoBuffer === null && top + size > scroll) {
1434
+ startNoBuffer = i;
1442
1435
  }
1443
- if (top <= scrollBottom + scrollBufferBottom) {
1444
- endBuffered = i;
1445
- } else {
1446
- break;
1436
+ if (startBuffered === null && top + size > scroll - scrollBufferTop) {
1437
+ startBuffered = i;
1438
+ startBufferedId = id;
1439
+ }
1440
+ if (startNoBuffer !== null) {
1441
+ if (top <= scrollBottom) {
1442
+ endNoBuffer = i;
1443
+ }
1444
+ if (top <= scrollBottom + scrollBufferBottom) {
1445
+ endBuffered = i;
1446
+ } else {
1447
+ foundEnd = true;
1448
+ }
1447
1449
  }
1448
1450
  }
1449
1451
  column++;
@@ -1545,18 +1547,14 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1545
1547
  const item = data[itemIndex];
1546
1548
  if (item !== void 0) {
1547
1549
  const id = getId(itemIndex);
1548
- if (itemKey !== id || itemIndex < startBuffered || itemIndex > endBuffered) {
1549
- const prevPos = peek$(ctx, `containerPosition${i}`);
1550
- const pos = positions.get(id) || 0;
1551
- const size = getItemSize(id, itemIndex, data[i]);
1552
- if (pos + size >= scroll && pos <= scrollBottom || prevPos + size >= scroll && prevPos <= scrollBottom || endBuffered < prevEndBuffered) {
1553
- set$(ctx, `containerPosition${i}`, ANCHORED_POSITION_OUT_OF_VIEW);
1554
- }
1550
+ const position = positions.get(id);
1551
+ if (position === void 0) {
1552
+ set$(ctx, `containerPosition${i}`, ANCHORED_POSITION_OUT_OF_VIEW);
1555
1553
  } else {
1556
1554
  const pos = {
1557
1555
  type: "top",
1558
- relativeCoordinate: positions.get(id) || 0,
1559
- top: positions.get(id) || 0
1556
+ relativeCoordinate: positions.get(id),
1557
+ top: positions.get(id)
1560
1558
  };
1561
1559
  const column2 = columns.get(id) || 1;
1562
1560
  if (maintainVisibleContentPosition && itemIndex < anchorElementIndex) {
@@ -1632,13 +1630,27 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1632
1630
  setPaddingTop({ alignItemsPaddingTop: paddingTop });
1633
1631
  }
1634
1632
  };
1633
+ const finishScrollTo = () => {
1634
+ const state = refState.current;
1635
+ if (state) {
1636
+ state.scrollingToOffset = void 0;
1637
+ state.scrollAdjustHandler.setDisableAdjust(false);
1638
+ calculateItemsInView();
1639
+ }
1640
+ };
1635
1641
  const scrollTo = (offset, animated) => {
1636
1642
  var _a;
1643
+ const state = refState.current;
1644
+ state.scrollAdjustHandler.setDisableAdjust(true);
1645
+ state.scrollingToOffset = offset;
1637
1646
  (_a = refScroller.current) == null ? void 0 : _a.scrollTo({
1638
1647
  x: horizontal ? offset : 0,
1639
1648
  y: horizontal ? 0 : offset,
1640
1649
  animated: !!animated
1641
1650
  });
1651
+ if (!animated) {
1652
+ requestAnimationFrame(finishScrollTo);
1653
+ }
1642
1654
  };
1643
1655
  const doMaintainScrollAtEnd = (animated) => {
1644
1656
  const state = refState.current;
@@ -1891,7 +1903,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1891
1903
  isFirst
1892
1904
  );
1893
1905
  }
1894
- }, [isFirst, dataProp, numColumnsProp]);
1906
+ }, [dataProp, numColumnsProp]);
1895
1907
  useEffect(() => {
1896
1908
  set$(ctx, "extraData", extraData);
1897
1909
  }, [extraData]);
@@ -1916,11 +1928,10 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1916
1928
  return { index, item: data[index], renderedItem };
1917
1929
  }, []);
1918
1930
  const doInitialAllocateContainers = () => {
1919
- var _a;
1920
1931
  const state = refState.current;
1921
1932
  const { scrollLength, data } = state;
1922
1933
  if (scrollLength > 0 && data.length > 0 && !peek$(ctx, "numContainers")) {
1923
- const averageItemSize = (_a = estimatedItemSize != null ? estimatedItemSize : getEstimatedItemSize == null ? void 0 : getEstimatedItemSize(0, data[0])) != null ? _a : DEFAULT_ITEM_SIZE;
1934
+ const averageItemSize = getEstimatedItemSize ? getEstimatedItemSize(0, data[0]) : estimatedItemSize;
1924
1935
  const numContainers = Math.ceil((scrollLength + scrollBuffer * 2) / averageItemSize) * numColumnsProp;
1925
1936
  for (let i = 0; i < numContainers; i++) {
1926
1937
  set$(ctx, `containerPosition${i}`, ANCHORED_POSITION_OUT_OF_VIEW);
@@ -1971,6 +1982,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1971
1982
  const numColumns = peek$(ctx, "numColumns");
1972
1983
  state.minIndexSizeChanged = state.minIndexSizeChanged !== void 0 ? Math.min(state.minIndexSizeChanged, index) : index;
1973
1984
  const prevSize = getItemSize(itemKey, index, data);
1985
+ const prevSizeKnown = sizesKnown.get(itemKey);
1974
1986
  let needsCalculate = false;
1975
1987
  let needsUpdateContainersDidLayout = false;
1976
1988
  sizesKnown.set(itemKey, size);
@@ -2013,7 +2025,9 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
2013
2025
  }
2014
2026
  state.scrollForNextCalculateItemsInView = void 0;
2015
2027
  addTotalSize(itemKey, diff, 0);
2016
- doMaintainScrollAtEnd(false);
2028
+ if (prevSizeKnown !== void 0 && Math.abs(prevSizeKnown - size) > 5) {
2029
+ doMaintainScrollAtEnd(false);
2030
+ }
2017
2031
  if (onItemSizeChanged) {
2018
2032
  onItemSizeChanged({
2019
2033
  size,
@@ -2031,7 +2045,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
2031
2045
  if (needsUpdateContainersDidLayout || !fromFixGaps && needsCalculate && (isInView || !queuedInitialLayout)) {
2032
2046
  const scrollVelocity = state.scrollVelocity;
2033
2047
  let didCalculate = false;
2034
- if ((Number.isNaN(scrollVelocity) || Math.abs(scrollVelocity) < 1) && (!waitForInitialLayout || needsUpdateContainersDidLayout || queuedInitialLayout)) {
2048
+ if ((Number.isNaN(scrollVelocity) || Math.abs(scrollVelocity) < 1 || state.scrollingToOffset !== void 0) && (!waitForInitialLayout || needsUpdateContainersDidLayout || queuedInitialLayout)) {
2035
2049
  if (Date.now() - state.lastBatchingAction < 500) {
2036
2050
  if (!state.queuedCalculateItemsInView) {
2037
2051
  state.queuedCalculateItemsInView = requestAnimationFrame(() => {
@@ -2089,6 +2103,9 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
2089
2103
  if (state.ignoreScrollFromCalcTotal && newScroll !== 0) {
2090
2104
  return;
2091
2105
  }
2106
+ if (state.scrollingToOffset !== void 0 && Math.abs(newScroll - state.scrollingToOffset) < 10) {
2107
+ finishScrollTo();
2108
+ }
2092
2109
  if (state.disableScrollJumpsFrom !== void 0) {
2093
2110
  const scrollMinusAdjust = newScroll - state.scrollAdjustHandler.getAppliedAdjust();
2094
2111
  if (Math.abs(scrollMinusAdjust - state.disableScrollJumpsFrom) > 200) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legendapp/list",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
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,