@legendapp/list 2.0.0-next.21 → 2.0.0-next.23

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/.DS_Store ADDED
Binary file
package/index.d.mts CHANGED
@@ -277,6 +277,7 @@ interface InternalState {
277
277
  endBuffered: number;
278
278
  endNoBuffer: number;
279
279
  firstFullyOnScreenIndex: number;
280
+ idsInView: string[];
280
281
  scrollPending: number;
281
282
  scroll: number;
282
283
  scrollTime: number;
package/index.d.ts CHANGED
@@ -277,6 +277,7 @@ interface InternalState {
277
277
  endBuffered: number;
278
278
  endNoBuffer: number;
279
279
  firstFullyOnScreenIndex: number;
280
+ idsInView: string[];
280
281
  scrollPending: number;
281
282
  scroll: number;
282
283
  scrollTime: number;
package/index.js CHANGED
@@ -850,14 +850,14 @@ function calculateOffsetForIndex(ctx, state, index) {
850
850
  let position = 0;
851
851
  if (index !== void 0) {
852
852
  position = (state == null ? void 0 : state.positions.get(getId(state, index))) || 0;
853
- }
854
- const paddingTop = peek$(ctx, "stylePaddingTop");
855
- if (paddingTop) {
856
- position += paddingTop;
857
- }
858
- const headerSize = peek$(ctx, "headerSize");
859
- if (headerSize) {
860
- position += headerSize;
853
+ const paddingTop = peek$(ctx, "stylePaddingTop");
854
+ if (paddingTop) {
855
+ position += paddingTop;
856
+ }
857
+ const headerSize = peek$(ctx, "headerSize");
858
+ if (headerSize) {
859
+ position += headerSize;
860
+ }
861
861
  }
862
862
  return position;
863
863
  }
@@ -920,18 +920,6 @@ function calculateOffsetWithOffsetPosition(state, offsetParam, params) {
920
920
  return offset;
921
921
  }
922
922
 
923
- // src/core/getEffectiveScroll.ts
924
- function getEffectiveScroll(ctx, state) {
925
- const { scroll: scrollState, scrollLength } = state;
926
- const topPad = peek$(ctx, "stylePaddingTop") + peek$(ctx, "headerSize");
927
- const totalSize = peek$(ctx, "totalSize");
928
- let scroll = scrollState - topPad;
929
- if (scroll + scrollLength > totalSize) {
930
- scroll = Math.max(0, totalSize - scrollLength);
931
- }
932
- return scroll;
933
- }
934
-
935
923
  // src/core/finishScrollTo.ts
936
924
  var finishScrollTo = (state) => {
937
925
  if (state) {
@@ -996,44 +984,32 @@ function requestAdjust(ctx, state, positionDiff) {
996
984
  }
997
985
 
998
986
  // src/core/mvcp.ts
999
- function getItemsInView(ctx, state) {
1000
- const { startNoBuffer, endNoBuffer, positions, scrollLength } = state;
1001
- const idsInViewWithPositions = [];
1002
- const scroll = getEffectiveScroll(ctx, state);
1003
- if (startNoBuffer !== null && endNoBuffer !== null) {
1004
- for (let i = startNoBuffer; i <= endNoBuffer; i++) {
1005
- const id = getId(state, i);
1006
- if (id) {
1007
- const position = positions.get(id);
1008
- if (position === void 0 || position > scroll + scrollLength) {
1009
- break;
1010
- } else if (position >= scroll) {
1011
- idsInViewWithPositions.push({ id, position });
1012
- }
1013
- }
1014
- }
1015
- }
1016
- return idsInViewWithPositions;
1017
- }
1018
987
  function prepareMVCP(ctx, state, dataChanged) {
1019
- var _a;
1020
988
  const {
989
+ idsInView,
1021
990
  positions,
1022
991
  scrollingTo,
1023
992
  props: { maintainVisibleContentPosition }
1024
993
  } = state;
1025
994
  let prevPosition;
1026
995
  let targetId;
1027
- let idsInViewWithPositions;
996
+ const idsInViewWithPositions = [];
1028
997
  const scrollTarget = scrollingTo == null ? void 0 : scrollingTo.index;
1029
998
  if (maintainVisibleContentPosition) {
1030
999
  const indexByKey = state.indexByKey;
1031
1000
  if (scrollTarget !== void 0) {
1032
1001
  targetId = getId(state, scrollTarget);
1033
- } else if (peek$(ctx, "containersDidLayout")) {
1034
- idsInViewWithPositions = getItemsInView(ctx, state);
1035
- if (!dataChanged) {
1036
- targetId = (_a = idsInViewWithPositions.find(({ id }) => indexByKey.get(id) !== void 0)) == null ? void 0 : _a.id;
1002
+ } else if (idsInView.length > 0 && peek$(ctx, "containersDidLayout")) {
1003
+ if (dataChanged) {
1004
+ for (let i = 0; i < idsInView.length; i++) {
1005
+ const id = idsInView[i];
1006
+ const index = indexByKey.get(id);
1007
+ if (index !== void 0) {
1008
+ idsInViewWithPositions.push({ id, position: positions.get(id) });
1009
+ }
1010
+ }
1011
+ } else {
1012
+ targetId = state.idsInView.find((id) => indexByKey.get(id) !== void 0);
1037
1013
  }
1038
1014
  }
1039
1015
  if (targetId !== void 0) {
@@ -1042,7 +1018,7 @@ function prepareMVCP(ctx, state, dataChanged) {
1042
1018
  }
1043
1019
  return () => {
1044
1020
  let positionDiff;
1045
- if (dataChanged && idsInViewWithPositions && targetId === void 0) {
1021
+ if (dataChanged && targetId === void 0) {
1046
1022
  for (let i = 0; i < idsInViewWithPositions.length; i++) {
1047
1023
  const { id, position } = idsInViewWithPositions[i];
1048
1024
  const newPosition = positions.get(id);
@@ -1789,7 +1765,7 @@ function handleStickyRecycling(ctx, state, stickyArray, scroll, scrollBuffer, pe
1789
1765
  }
1790
1766
  function calculateItemsInView(ctx, state, params = {}) {
1791
1767
  reactNative.unstable_batchedUpdates(() => {
1792
- var _a, _b, _c, _d, _e, _f, _g;
1768
+ var _a, _b, _c, _d, _e, _f, _g, _h;
1793
1769
  const {
1794
1770
  columns,
1795
1771
  containerItemKeys,
@@ -1810,7 +1786,10 @@ function calculateItemsInView(ctx, state, params = {}) {
1810
1786
  if (!data || scrollLength === 0 || !prevNumContainers) {
1811
1787
  return;
1812
1788
  }
1789
+ const totalSize = peek$(ctx, "totalSize");
1790
+ const topPad = peek$(ctx, "stylePaddingTop") + peek$(ctx, "headerSize");
1813
1791
  const numColumns = peek$(ctx, "numColumns");
1792
+ const previousScrollAdjust = 0;
1814
1793
  const { dataChanged, doMVCP } = params;
1815
1794
  const speed = getScrollVelocity(state);
1816
1795
  if (doMVCP || dataChanged) {
@@ -1823,6 +1802,7 @@ function calculateItemsInView(ctx, state, params = {}) {
1823
1802
  updateAllPositions(ctx, state, dataChanged);
1824
1803
  checkMVCP == null ? void 0 : checkMVCP();
1825
1804
  }
1805
+ const scrollExtra = 0;
1826
1806
  const { queuedInitialLayout } = state;
1827
1807
  let { scroll: scrollState } = state;
1828
1808
  if (!queuedInitialLayout && initialScroll) {
@@ -1832,9 +1812,12 @@ function calculateItemsInView(ctx, state, params = {}) {
1832
1812
  initialScroll
1833
1813
  );
1834
1814
  scrollState = updatedOffset;
1835
- state.scroll = scrollState;
1836
1815
  }
1837
- const scroll = getEffectiveScroll(ctx, state);
1816
+ const scrollAdjustPad = -previousScrollAdjust - topPad;
1817
+ let scroll = scrollState + scrollExtra + scrollAdjustPad;
1818
+ if (scroll + scrollLength > totalSize) {
1819
+ scroll = Math.max(0, totalSize - scrollLength);
1820
+ }
1838
1821
  if (ENABLE_DEBUG_VIEW) {
1839
1822
  set$(ctx, "debugRawScroll", scrollState);
1840
1823
  set$(ctx, "debugComputedScroll", scroll);
@@ -1924,10 +1907,16 @@ function calculateItemsInView(ctx, state, params = {}) {
1924
1907
  }
1925
1908
  }
1926
1909
  }
1910
+ const idsInView = [];
1911
+ for (let i = firstFullyOnScreenIndex; i <= endNoBuffer; i++) {
1912
+ const id = (_e = idCache.get(i)) != null ? _e : getId(state, i);
1913
+ idsInView.push(id);
1914
+ }
1927
1915
  Object.assign(state, {
1928
1916
  endBuffered,
1929
1917
  endNoBuffer,
1930
1918
  firstFullyOnScreenIndex,
1919
+ idsInView,
1931
1920
  startBuffered,
1932
1921
  startBufferedId,
1933
1922
  startNoBuffer
@@ -1952,7 +1941,7 @@ function calculateItemsInView(ctx, state, params = {}) {
1952
1941
  let numContainers2 = prevNumContainers;
1953
1942
  const needNewContainers = [];
1954
1943
  for (let i = startBuffered; i <= endBuffered; i++) {
1955
- const id = (_e = idCache.get(i)) != null ? _e : getId(state, i);
1944
+ const id = (_f = idCache.get(i)) != null ? _f : getId(state, i);
1956
1945
  if (!containerItemKeys.has(id)) {
1957
1946
  needNewContainers.push(i);
1958
1947
  }
@@ -1987,7 +1976,7 @@ function calculateItemsInView(ctx, state, params = {}) {
1987
1976
  for (let idx = 0; idx < needNewContainers.length; idx++) {
1988
1977
  const i = needNewContainers[idx];
1989
1978
  const containerIndex = availableContainers[idx];
1990
- const id = (_f = idCache.get(i)) != null ? _f : getId(state, i);
1979
+ const id = (_g = idCache.get(i)) != null ? _g : getId(state, i);
1991
1980
  const oldKey = peek$(ctx, `containerItemKey${containerIndex}`);
1992
1981
  if (oldKey && oldKey !== id) {
1993
1982
  containerItemKeys.delete(oldKey);
@@ -2041,7 +2030,7 @@ function calculateItemsInView(ctx, state, params = {}) {
2041
2030
  const itemIndex = indexByKey.get(itemKey);
2042
2031
  const item = data[itemIndex];
2043
2032
  if (item !== void 0) {
2044
- const id = (_g = idCache.get(itemIndex)) != null ? _g : getId(state, itemIndex);
2033
+ const id = (_h = idCache.get(itemIndex)) != null ? _h : getId(state, itemIndex);
2045
2034
  const position = positions.get(id);
2046
2035
  if (position === void 0) {
2047
2036
  set$(ctx, `containerPosition${i}`, POSITION_OUT_OF_VIEW);
@@ -2619,6 +2608,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
2619
2608
  endReachedBlockedByTimer: false,
2620
2609
  firstFullyOnScreenIndex: -1,
2621
2610
  idCache: /* @__PURE__ */ new Map(),
2611
+ idsInView: [],
2622
2612
  indexByKey: /* @__PURE__ */ new Map(),
2623
2613
  initialScroll,
2624
2614
  isAtEnd: false,
package/index.mjs CHANGED
@@ -829,14 +829,14 @@ function calculateOffsetForIndex(ctx, state, index) {
829
829
  let position = 0;
830
830
  if (index !== void 0) {
831
831
  position = (state == null ? void 0 : state.positions.get(getId(state, index))) || 0;
832
- }
833
- const paddingTop = peek$(ctx, "stylePaddingTop");
834
- if (paddingTop) {
835
- position += paddingTop;
836
- }
837
- const headerSize = peek$(ctx, "headerSize");
838
- if (headerSize) {
839
- position += headerSize;
832
+ const paddingTop = peek$(ctx, "stylePaddingTop");
833
+ if (paddingTop) {
834
+ position += paddingTop;
835
+ }
836
+ const headerSize = peek$(ctx, "headerSize");
837
+ if (headerSize) {
838
+ position += headerSize;
839
+ }
840
840
  }
841
841
  return position;
842
842
  }
@@ -899,18 +899,6 @@ function calculateOffsetWithOffsetPosition(state, offsetParam, params) {
899
899
  return offset;
900
900
  }
901
901
 
902
- // src/core/getEffectiveScroll.ts
903
- function getEffectiveScroll(ctx, state) {
904
- const { scroll: scrollState, scrollLength } = state;
905
- const topPad = peek$(ctx, "stylePaddingTop") + peek$(ctx, "headerSize");
906
- const totalSize = peek$(ctx, "totalSize");
907
- let scroll = scrollState - topPad;
908
- if (scroll + scrollLength > totalSize) {
909
- scroll = Math.max(0, totalSize - scrollLength);
910
- }
911
- return scroll;
912
- }
913
-
914
902
  // src/core/finishScrollTo.ts
915
903
  var finishScrollTo = (state) => {
916
904
  if (state) {
@@ -975,44 +963,32 @@ function requestAdjust(ctx, state, positionDiff) {
975
963
  }
976
964
 
977
965
  // src/core/mvcp.ts
978
- function getItemsInView(ctx, state) {
979
- const { startNoBuffer, endNoBuffer, positions, scrollLength } = state;
980
- const idsInViewWithPositions = [];
981
- const scroll = getEffectiveScroll(ctx, state);
982
- if (startNoBuffer !== null && endNoBuffer !== null) {
983
- for (let i = startNoBuffer; i <= endNoBuffer; i++) {
984
- const id = getId(state, i);
985
- if (id) {
986
- const position = positions.get(id);
987
- if (position === void 0 || position > scroll + scrollLength) {
988
- break;
989
- } else if (position >= scroll) {
990
- idsInViewWithPositions.push({ id, position });
991
- }
992
- }
993
- }
994
- }
995
- return idsInViewWithPositions;
996
- }
997
966
  function prepareMVCP(ctx, state, dataChanged) {
998
- var _a;
999
967
  const {
968
+ idsInView,
1000
969
  positions,
1001
970
  scrollingTo,
1002
971
  props: { maintainVisibleContentPosition }
1003
972
  } = state;
1004
973
  let prevPosition;
1005
974
  let targetId;
1006
- let idsInViewWithPositions;
975
+ const idsInViewWithPositions = [];
1007
976
  const scrollTarget = scrollingTo == null ? void 0 : scrollingTo.index;
1008
977
  if (maintainVisibleContentPosition) {
1009
978
  const indexByKey = state.indexByKey;
1010
979
  if (scrollTarget !== void 0) {
1011
980
  targetId = getId(state, scrollTarget);
1012
- } else if (peek$(ctx, "containersDidLayout")) {
1013
- idsInViewWithPositions = getItemsInView(ctx, state);
1014
- if (!dataChanged) {
1015
- targetId = (_a = idsInViewWithPositions.find(({ id }) => indexByKey.get(id) !== void 0)) == null ? void 0 : _a.id;
981
+ } else if (idsInView.length > 0 && peek$(ctx, "containersDidLayout")) {
982
+ if (dataChanged) {
983
+ for (let i = 0; i < idsInView.length; i++) {
984
+ const id = idsInView[i];
985
+ const index = indexByKey.get(id);
986
+ if (index !== void 0) {
987
+ idsInViewWithPositions.push({ id, position: positions.get(id) });
988
+ }
989
+ }
990
+ } else {
991
+ targetId = state.idsInView.find((id) => indexByKey.get(id) !== void 0);
1016
992
  }
1017
993
  }
1018
994
  if (targetId !== void 0) {
@@ -1021,7 +997,7 @@ function prepareMVCP(ctx, state, dataChanged) {
1021
997
  }
1022
998
  return () => {
1023
999
  let positionDiff;
1024
- if (dataChanged && idsInViewWithPositions && targetId === void 0) {
1000
+ if (dataChanged && targetId === void 0) {
1025
1001
  for (let i = 0; i < idsInViewWithPositions.length; i++) {
1026
1002
  const { id, position } = idsInViewWithPositions[i];
1027
1003
  const newPosition = positions.get(id);
@@ -1768,7 +1744,7 @@ function handleStickyRecycling(ctx, state, stickyArray, scroll, scrollBuffer, pe
1768
1744
  }
1769
1745
  function calculateItemsInView(ctx, state, params = {}) {
1770
1746
  unstable_batchedUpdates(() => {
1771
- var _a, _b, _c, _d, _e, _f, _g;
1747
+ var _a, _b, _c, _d, _e, _f, _g, _h;
1772
1748
  const {
1773
1749
  columns,
1774
1750
  containerItemKeys,
@@ -1789,7 +1765,10 @@ function calculateItemsInView(ctx, state, params = {}) {
1789
1765
  if (!data || scrollLength === 0 || !prevNumContainers) {
1790
1766
  return;
1791
1767
  }
1768
+ const totalSize = peek$(ctx, "totalSize");
1769
+ const topPad = peek$(ctx, "stylePaddingTop") + peek$(ctx, "headerSize");
1792
1770
  const numColumns = peek$(ctx, "numColumns");
1771
+ const previousScrollAdjust = 0;
1793
1772
  const { dataChanged, doMVCP } = params;
1794
1773
  const speed = getScrollVelocity(state);
1795
1774
  if (doMVCP || dataChanged) {
@@ -1802,6 +1781,7 @@ function calculateItemsInView(ctx, state, params = {}) {
1802
1781
  updateAllPositions(ctx, state, dataChanged);
1803
1782
  checkMVCP == null ? void 0 : checkMVCP();
1804
1783
  }
1784
+ const scrollExtra = 0;
1805
1785
  const { queuedInitialLayout } = state;
1806
1786
  let { scroll: scrollState } = state;
1807
1787
  if (!queuedInitialLayout && initialScroll) {
@@ -1811,9 +1791,12 @@ function calculateItemsInView(ctx, state, params = {}) {
1811
1791
  initialScroll
1812
1792
  );
1813
1793
  scrollState = updatedOffset;
1814
- state.scroll = scrollState;
1815
1794
  }
1816
- const scroll = getEffectiveScroll(ctx, state);
1795
+ const scrollAdjustPad = -previousScrollAdjust - topPad;
1796
+ let scroll = scrollState + scrollExtra + scrollAdjustPad;
1797
+ if (scroll + scrollLength > totalSize) {
1798
+ scroll = Math.max(0, totalSize - scrollLength);
1799
+ }
1817
1800
  if (ENABLE_DEBUG_VIEW) {
1818
1801
  set$(ctx, "debugRawScroll", scrollState);
1819
1802
  set$(ctx, "debugComputedScroll", scroll);
@@ -1903,10 +1886,16 @@ function calculateItemsInView(ctx, state, params = {}) {
1903
1886
  }
1904
1887
  }
1905
1888
  }
1889
+ const idsInView = [];
1890
+ for (let i = firstFullyOnScreenIndex; i <= endNoBuffer; i++) {
1891
+ const id = (_e = idCache.get(i)) != null ? _e : getId(state, i);
1892
+ idsInView.push(id);
1893
+ }
1906
1894
  Object.assign(state, {
1907
1895
  endBuffered,
1908
1896
  endNoBuffer,
1909
1897
  firstFullyOnScreenIndex,
1898
+ idsInView,
1910
1899
  startBuffered,
1911
1900
  startBufferedId,
1912
1901
  startNoBuffer
@@ -1931,7 +1920,7 @@ function calculateItemsInView(ctx, state, params = {}) {
1931
1920
  let numContainers2 = prevNumContainers;
1932
1921
  const needNewContainers = [];
1933
1922
  for (let i = startBuffered; i <= endBuffered; i++) {
1934
- const id = (_e = idCache.get(i)) != null ? _e : getId(state, i);
1923
+ const id = (_f = idCache.get(i)) != null ? _f : getId(state, i);
1935
1924
  if (!containerItemKeys.has(id)) {
1936
1925
  needNewContainers.push(i);
1937
1926
  }
@@ -1966,7 +1955,7 @@ function calculateItemsInView(ctx, state, params = {}) {
1966
1955
  for (let idx = 0; idx < needNewContainers.length; idx++) {
1967
1956
  const i = needNewContainers[idx];
1968
1957
  const containerIndex = availableContainers[idx];
1969
- const id = (_f = idCache.get(i)) != null ? _f : getId(state, i);
1958
+ const id = (_g = idCache.get(i)) != null ? _g : getId(state, i);
1970
1959
  const oldKey = peek$(ctx, `containerItemKey${containerIndex}`);
1971
1960
  if (oldKey && oldKey !== id) {
1972
1961
  containerItemKeys.delete(oldKey);
@@ -2020,7 +2009,7 @@ function calculateItemsInView(ctx, state, params = {}) {
2020
2009
  const itemIndex = indexByKey.get(itemKey);
2021
2010
  const item = data[itemIndex];
2022
2011
  if (item !== void 0) {
2023
- const id = (_g = idCache.get(itemIndex)) != null ? _g : getId(state, itemIndex);
2012
+ const id = (_h = idCache.get(itemIndex)) != null ? _h : getId(state, itemIndex);
2024
2013
  const position = positions.get(id);
2025
2014
  if (position === void 0) {
2026
2015
  set$(ctx, `containerPosition${i}`, POSITION_OUT_OF_VIEW);
@@ -2598,6 +2587,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
2598
2587
  endReachedBlockedByTimer: false,
2599
2588
  firstFullyOnScreenIndex: -1,
2600
2589
  idCache: /* @__PURE__ */ new Map(),
2590
+ idsInView: [],
2601
2591
  indexByKey: /* @__PURE__ */ new Map(),
2602
2592
  initialScroll,
2603
2593
  isAtEnd: false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legendapp/list",
3
- "version": "2.0.0-next.21",
3
+ "version": "2.0.0-next.23",
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,