@legendapp/list 2.0.0-next.18 → 2.0.0-next.19

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.d.mts CHANGED
@@ -276,7 +276,6 @@ interface InternalState {
276
276
  endBuffered: number;
277
277
  endNoBuffer: number;
278
278
  firstFullyOnScreenIndex: number;
279
- idsInView: string[];
280
279
  scrollPending: number;
281
280
  scroll: number;
282
281
  scrollTime: number;
package/index.d.ts CHANGED
@@ -276,7 +276,6 @@ interface InternalState {
276
276
  endBuffered: number;
277
277
  endNoBuffer: number;
278
278
  firstFullyOnScreenIndex: number;
279
- idsInView: string[];
280
279
  scrollPending: number;
281
280
  scroll: number;
282
281
  scrollTime: number;
package/index.js CHANGED
@@ -920,6 +920,18 @@ 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
+
923
935
  // src/core/finishScrollTo.ts
924
936
  var finishScrollTo = (state) => {
925
937
  if (state) {
@@ -984,32 +996,46 @@ function requestAdjust(ctx, state, positionDiff) {
984
996
  }
985
997
 
986
998
  // src/core/prepareMVCP.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
+ }
987
1018
  function prepareMVCP(ctx, state, dataChanged) {
1019
+ var _a;
988
1020
  const {
989
- idsInView,
990
1021
  positions,
991
1022
  scrollingTo,
992
1023
  props: { maintainVisibleContentPosition }
993
1024
  } = state;
994
1025
  let prevPosition;
995
1026
  let targetId;
996
- const idsInViewWithPositions = [];
1027
+ let idsInViewWithPositions;
997
1028
  const scrollTarget = scrollingTo == null ? void 0 : scrollingTo.index;
998
1029
  if (maintainVisibleContentPosition) {
999
1030
  const indexByKey = state.indexByKey;
1000
1031
  if (scrollTarget !== void 0) {
1032
+ console.log("scrollTarget", scrollTarget);
1001
1033
  targetId = getId(state, scrollTarget);
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);
1034
+ } else if (peek$(ctx, "containersDidLayout")) {
1035
+ idsInViewWithPositions = getItemsInView(ctx, state);
1036
+ if (!dataChanged) {
1037
+ targetId = (_a = idsInViewWithPositions.find(({ id }) => indexByKey.get(id) !== void 0)) == null ? void 0 : _a.id;
1038
+ console.log("targetId in view", targetId);
1013
1039
  }
1014
1040
  }
1015
1041
  if (targetId !== void 0) {
@@ -1018,12 +1044,13 @@ function prepareMVCP(ctx, state, dataChanged) {
1018
1044
  }
1019
1045
  return () => {
1020
1046
  let positionDiff;
1021
- if (dataChanged && targetId === void 0) {
1047
+ if (dataChanged && idsInViewWithPositions && targetId === void 0) {
1022
1048
  for (let i = 0; i < idsInViewWithPositions.length; i++) {
1023
1049
  const { id, position } = idsInViewWithPositions[i];
1024
1050
  const newPosition = positions.get(id);
1025
1051
  if (newPosition !== void 0) {
1026
1052
  positionDiff = newPosition - position;
1053
+ console.log("positionDiff", positionDiff, id);
1027
1054
  break;
1028
1055
  }
1029
1056
  }
@@ -1032,6 +1059,7 @@ function prepareMVCP(ctx, state, dataChanged) {
1032
1059
  const newPosition = positions.get(targetId);
1033
1060
  if (newPosition !== void 0) {
1034
1061
  positionDiff = newPosition - prevPosition;
1062
+ console.log("positionDiff targetId", positionDiff, targetId);
1035
1063
  }
1036
1064
  }
1037
1065
  if (positionDiff !== void 0 && Math.abs(positionDiff) > 0.1) {
@@ -1126,6 +1154,7 @@ var getScrollVelocity = (state) => {
1126
1154
  const newest = scrollHistory[scrollHistory.length - 1];
1127
1155
  let oldest;
1128
1156
  let start = 0;
1157
+ const now = Date.now();
1129
1158
  for (let i = 0; i < scrollHistory.length - 1; i++) {
1130
1159
  const entry = scrollHistory[i];
1131
1160
  const nextEntry = scrollHistory[i + 1];
@@ -1141,12 +1170,12 @@ var getScrollVelocity = (state) => {
1141
1170
  }
1142
1171
  for (let i = start; i < scrollHistory.length - 1; i++) {
1143
1172
  const entry = scrollHistory[i];
1144
- if (newest.time - entry.time <= 1e3) {
1173
+ if (now - entry.time <= 1e3) {
1145
1174
  oldest = entry;
1146
1175
  break;
1147
1176
  }
1148
1177
  }
1149
- if (oldest) {
1178
+ if (oldest && oldest !== newest) {
1150
1179
  const scrollDiff = newest.scroll - oldest.scroll;
1151
1180
  const timeDiff = newest.time - oldest.time;
1152
1181
  velocity = timeDiff > 0 ? scrollDiff / timeDiff : 0;
@@ -1764,7 +1793,7 @@ function handleStickyRecycling(ctx, state, stickyArray, scroll, scrollBuffer, pe
1764
1793
  }
1765
1794
  function calculateItemsInView(ctx, state, params = {}) {
1766
1795
  reactNative.unstable_batchedUpdates(() => {
1767
- var _a, _b, _c, _d, _e, _f, _g, _h;
1796
+ var _a, _b, _c, _d, _e, _f, _g;
1768
1797
  const {
1769
1798
  columns,
1770
1799
  containerItemKeys,
@@ -1785,10 +1814,7 @@ function calculateItemsInView(ctx, state, params = {}) {
1785
1814
  if (!data || scrollLength === 0 || !prevNumContainers) {
1786
1815
  return;
1787
1816
  }
1788
- const totalSize = peek$(ctx, "totalSize");
1789
- const topPad = peek$(ctx, "stylePaddingTop") + peek$(ctx, "headerSize");
1790
1817
  const numColumns = peek$(ctx, "numColumns");
1791
- const previousScrollAdjust = 0;
1792
1818
  const { dataChanged, doMVCP } = params;
1793
1819
  const speed = getScrollVelocity(state);
1794
1820
  if (doMVCP || dataChanged) {
@@ -1801,7 +1827,6 @@ function calculateItemsInView(ctx, state, params = {}) {
1801
1827
  updateAllPositions(ctx, state, dataChanged);
1802
1828
  checkMVCP == null ? void 0 : checkMVCP();
1803
1829
  }
1804
- const scrollExtra = 0;
1805
1830
  const { queuedInitialLayout } = state;
1806
1831
  let { scroll: scrollState } = state;
1807
1832
  if (!queuedInitialLayout && initialScroll) {
@@ -1811,12 +1836,9 @@ function calculateItemsInView(ctx, state, params = {}) {
1811
1836
  initialScroll
1812
1837
  );
1813
1838
  scrollState = updatedOffset;
1839
+ state.scroll = scrollState;
1814
1840
  }
1815
- const scrollAdjustPad = -previousScrollAdjust - topPad;
1816
- let scroll = scrollState + scrollExtra + scrollAdjustPad;
1817
- if (scroll + scrollLength > totalSize) {
1818
- scroll = Math.max(0, totalSize - scrollLength);
1819
- }
1841
+ const scroll = getEffectiveScroll(ctx, state);
1820
1842
  if (ENABLE_DEBUG_VIEW) {
1821
1843
  set$(ctx, "debugRawScroll", scrollState);
1822
1844
  set$(ctx, "debugComputedScroll", scroll);
@@ -1906,16 +1928,10 @@ function calculateItemsInView(ctx, state, params = {}) {
1906
1928
  }
1907
1929
  }
1908
1930
  }
1909
- const idsInView = [];
1910
- for (let i = firstFullyOnScreenIndex; i <= endNoBuffer; i++) {
1911
- const id = (_e = idCache.get(i)) != null ? _e : getId(state, i);
1912
- idsInView.push(id);
1913
- }
1914
1931
  Object.assign(state, {
1915
1932
  endBuffered,
1916
1933
  endNoBuffer,
1917
1934
  firstFullyOnScreenIndex,
1918
- idsInView,
1919
1935
  startBuffered,
1920
1936
  startBufferedId,
1921
1937
  startNoBuffer
@@ -1940,7 +1956,7 @@ function calculateItemsInView(ctx, state, params = {}) {
1940
1956
  let numContainers2 = prevNumContainers;
1941
1957
  const needNewContainers = [];
1942
1958
  for (let i = startBuffered; i <= endBuffered; i++) {
1943
- const id = (_f = idCache.get(i)) != null ? _f : getId(state, i);
1959
+ const id = (_e = idCache.get(i)) != null ? _e : getId(state, i);
1944
1960
  if (!containerItemKeys.has(id)) {
1945
1961
  needNewContainers.push(i);
1946
1962
  }
@@ -1975,7 +1991,7 @@ function calculateItemsInView(ctx, state, params = {}) {
1975
1991
  for (let idx = 0; idx < needNewContainers.length; idx++) {
1976
1992
  const i = needNewContainers[idx];
1977
1993
  const containerIndex = availableContainers[idx];
1978
- const id = (_g = idCache.get(i)) != null ? _g : getId(state, i);
1994
+ const id = (_f = idCache.get(i)) != null ? _f : getId(state, i);
1979
1995
  const oldKey = peek$(ctx, `containerItemKey${containerIndex}`);
1980
1996
  if (oldKey && oldKey !== id) {
1981
1997
  containerItemKeys.delete(oldKey);
@@ -2029,7 +2045,7 @@ function calculateItemsInView(ctx, state, params = {}) {
2029
2045
  const itemIndex = indexByKey.get(itemKey);
2030
2046
  const item = data[itemIndex];
2031
2047
  if (item !== void 0) {
2032
- const id = (_h = idCache.get(itemIndex)) != null ? _h : getId(state, itemIndex);
2048
+ const id = (_g = idCache.get(itemIndex)) != null ? _g : getId(state, itemIndex);
2033
2049
  const position = positions.get(id);
2034
2050
  if (position === void 0) {
2035
2051
  set$(ctx, `containerPosition${i}`, POSITION_OUT_OF_VIEW);
@@ -2605,7 +2621,6 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
2605
2621
  endReachedBlockedByTimer: false,
2606
2622
  firstFullyOnScreenIndex: -1,
2607
2623
  idCache: /* @__PURE__ */ new Map(),
2608
- idsInView: [],
2609
2624
  indexByKey: /* @__PURE__ */ new Map(),
2610
2625
  initialScroll,
2611
2626
  isAtEnd: false,
package/index.mjs CHANGED
@@ -899,6 +899,18 @@ 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
+
902
914
  // src/core/finishScrollTo.ts
903
915
  var finishScrollTo = (state) => {
904
916
  if (state) {
@@ -963,32 +975,46 @@ function requestAdjust(ctx, state, positionDiff) {
963
975
  }
964
976
 
965
977
  // src/core/prepareMVCP.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
+ }
966
997
  function prepareMVCP(ctx, state, dataChanged) {
998
+ var _a;
967
999
  const {
968
- idsInView,
969
1000
  positions,
970
1001
  scrollingTo,
971
1002
  props: { maintainVisibleContentPosition }
972
1003
  } = state;
973
1004
  let prevPosition;
974
1005
  let targetId;
975
- const idsInViewWithPositions = [];
1006
+ let idsInViewWithPositions;
976
1007
  const scrollTarget = scrollingTo == null ? void 0 : scrollingTo.index;
977
1008
  if (maintainVisibleContentPosition) {
978
1009
  const indexByKey = state.indexByKey;
979
1010
  if (scrollTarget !== void 0) {
1011
+ console.log("scrollTarget", scrollTarget);
980
1012
  targetId = getId(state, scrollTarget);
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);
1013
+ } else if (peek$(ctx, "containersDidLayout")) {
1014
+ idsInViewWithPositions = getItemsInView(ctx, state);
1015
+ if (!dataChanged) {
1016
+ targetId = (_a = idsInViewWithPositions.find(({ id }) => indexByKey.get(id) !== void 0)) == null ? void 0 : _a.id;
1017
+ console.log("targetId in view", targetId);
992
1018
  }
993
1019
  }
994
1020
  if (targetId !== void 0) {
@@ -997,12 +1023,13 @@ function prepareMVCP(ctx, state, dataChanged) {
997
1023
  }
998
1024
  return () => {
999
1025
  let positionDiff;
1000
- if (dataChanged && targetId === void 0) {
1026
+ if (dataChanged && idsInViewWithPositions && targetId === void 0) {
1001
1027
  for (let i = 0; i < idsInViewWithPositions.length; i++) {
1002
1028
  const { id, position } = idsInViewWithPositions[i];
1003
1029
  const newPosition = positions.get(id);
1004
1030
  if (newPosition !== void 0) {
1005
1031
  positionDiff = newPosition - position;
1032
+ console.log("positionDiff", positionDiff, id);
1006
1033
  break;
1007
1034
  }
1008
1035
  }
@@ -1011,6 +1038,7 @@ function prepareMVCP(ctx, state, dataChanged) {
1011
1038
  const newPosition = positions.get(targetId);
1012
1039
  if (newPosition !== void 0) {
1013
1040
  positionDiff = newPosition - prevPosition;
1041
+ console.log("positionDiff targetId", positionDiff, targetId);
1014
1042
  }
1015
1043
  }
1016
1044
  if (positionDiff !== void 0 && Math.abs(positionDiff) > 0.1) {
@@ -1105,6 +1133,7 @@ var getScrollVelocity = (state) => {
1105
1133
  const newest = scrollHistory[scrollHistory.length - 1];
1106
1134
  let oldest;
1107
1135
  let start = 0;
1136
+ const now = Date.now();
1108
1137
  for (let i = 0; i < scrollHistory.length - 1; i++) {
1109
1138
  const entry = scrollHistory[i];
1110
1139
  const nextEntry = scrollHistory[i + 1];
@@ -1120,12 +1149,12 @@ var getScrollVelocity = (state) => {
1120
1149
  }
1121
1150
  for (let i = start; i < scrollHistory.length - 1; i++) {
1122
1151
  const entry = scrollHistory[i];
1123
- if (newest.time - entry.time <= 1e3) {
1152
+ if (now - entry.time <= 1e3) {
1124
1153
  oldest = entry;
1125
1154
  break;
1126
1155
  }
1127
1156
  }
1128
- if (oldest) {
1157
+ if (oldest && oldest !== newest) {
1129
1158
  const scrollDiff = newest.scroll - oldest.scroll;
1130
1159
  const timeDiff = newest.time - oldest.time;
1131
1160
  velocity = timeDiff > 0 ? scrollDiff / timeDiff : 0;
@@ -1743,7 +1772,7 @@ function handleStickyRecycling(ctx, state, stickyArray, scroll, scrollBuffer, pe
1743
1772
  }
1744
1773
  function calculateItemsInView(ctx, state, params = {}) {
1745
1774
  unstable_batchedUpdates(() => {
1746
- var _a, _b, _c, _d, _e, _f, _g, _h;
1775
+ var _a, _b, _c, _d, _e, _f, _g;
1747
1776
  const {
1748
1777
  columns,
1749
1778
  containerItemKeys,
@@ -1764,10 +1793,7 @@ function calculateItemsInView(ctx, state, params = {}) {
1764
1793
  if (!data || scrollLength === 0 || !prevNumContainers) {
1765
1794
  return;
1766
1795
  }
1767
- const totalSize = peek$(ctx, "totalSize");
1768
- const topPad = peek$(ctx, "stylePaddingTop") + peek$(ctx, "headerSize");
1769
1796
  const numColumns = peek$(ctx, "numColumns");
1770
- const previousScrollAdjust = 0;
1771
1797
  const { dataChanged, doMVCP } = params;
1772
1798
  const speed = getScrollVelocity(state);
1773
1799
  if (doMVCP || dataChanged) {
@@ -1780,7 +1806,6 @@ function calculateItemsInView(ctx, state, params = {}) {
1780
1806
  updateAllPositions(ctx, state, dataChanged);
1781
1807
  checkMVCP == null ? void 0 : checkMVCP();
1782
1808
  }
1783
- const scrollExtra = 0;
1784
1809
  const { queuedInitialLayout } = state;
1785
1810
  let { scroll: scrollState } = state;
1786
1811
  if (!queuedInitialLayout && initialScroll) {
@@ -1790,12 +1815,9 @@ function calculateItemsInView(ctx, state, params = {}) {
1790
1815
  initialScroll
1791
1816
  );
1792
1817
  scrollState = updatedOffset;
1818
+ state.scroll = scrollState;
1793
1819
  }
1794
- const scrollAdjustPad = -previousScrollAdjust - topPad;
1795
- let scroll = scrollState + scrollExtra + scrollAdjustPad;
1796
- if (scroll + scrollLength > totalSize) {
1797
- scroll = Math.max(0, totalSize - scrollLength);
1798
- }
1820
+ const scroll = getEffectiveScroll(ctx, state);
1799
1821
  if (ENABLE_DEBUG_VIEW) {
1800
1822
  set$(ctx, "debugRawScroll", scrollState);
1801
1823
  set$(ctx, "debugComputedScroll", scroll);
@@ -1885,16 +1907,10 @@ function calculateItemsInView(ctx, state, params = {}) {
1885
1907
  }
1886
1908
  }
1887
1909
  }
1888
- const idsInView = [];
1889
- for (let i = firstFullyOnScreenIndex; i <= endNoBuffer; i++) {
1890
- const id = (_e = idCache.get(i)) != null ? _e : getId(state, i);
1891
- idsInView.push(id);
1892
- }
1893
1910
  Object.assign(state, {
1894
1911
  endBuffered,
1895
1912
  endNoBuffer,
1896
1913
  firstFullyOnScreenIndex,
1897
- idsInView,
1898
1914
  startBuffered,
1899
1915
  startBufferedId,
1900
1916
  startNoBuffer
@@ -1919,7 +1935,7 @@ function calculateItemsInView(ctx, state, params = {}) {
1919
1935
  let numContainers2 = prevNumContainers;
1920
1936
  const needNewContainers = [];
1921
1937
  for (let i = startBuffered; i <= endBuffered; i++) {
1922
- const id = (_f = idCache.get(i)) != null ? _f : getId(state, i);
1938
+ const id = (_e = idCache.get(i)) != null ? _e : getId(state, i);
1923
1939
  if (!containerItemKeys.has(id)) {
1924
1940
  needNewContainers.push(i);
1925
1941
  }
@@ -1954,7 +1970,7 @@ function calculateItemsInView(ctx, state, params = {}) {
1954
1970
  for (let idx = 0; idx < needNewContainers.length; idx++) {
1955
1971
  const i = needNewContainers[idx];
1956
1972
  const containerIndex = availableContainers[idx];
1957
- const id = (_g = idCache.get(i)) != null ? _g : getId(state, i);
1973
+ const id = (_f = idCache.get(i)) != null ? _f : getId(state, i);
1958
1974
  const oldKey = peek$(ctx, `containerItemKey${containerIndex}`);
1959
1975
  if (oldKey && oldKey !== id) {
1960
1976
  containerItemKeys.delete(oldKey);
@@ -2008,7 +2024,7 @@ function calculateItemsInView(ctx, state, params = {}) {
2008
2024
  const itemIndex = indexByKey.get(itemKey);
2009
2025
  const item = data[itemIndex];
2010
2026
  if (item !== void 0) {
2011
- const id = (_h = idCache.get(itemIndex)) != null ? _h : getId(state, itemIndex);
2027
+ const id = (_g = idCache.get(itemIndex)) != null ? _g : getId(state, itemIndex);
2012
2028
  const position = positions.get(id);
2013
2029
  if (position === void 0) {
2014
2030
  set$(ctx, `containerPosition${i}`, POSITION_OUT_OF_VIEW);
@@ -2584,7 +2600,6 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
2584
2600
  endReachedBlockedByTimer: false,
2585
2601
  firstFullyOnScreenIndex: -1,
2586
2602
  idCache: /* @__PURE__ */ new Map(),
2587
- idsInView: [],
2588
2603
  indexByKey: /* @__PURE__ */ new Map(),
2589
2604
  initialScroll,
2590
2605
  isAtEnd: false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legendapp/list",
3
- "version": "2.0.0-next.18",
3
+ "version": "2.0.0-next.19",
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,