@legendapp/list 2.0.7 → 2.0.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/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 2.0.8
2
+ - Fix: Data changing sometimes left blank spaces because it was ignoring scroll
3
+ - Fix: Toggling between empty and non-empty causing maintainVisibleContentPosition issues
4
+
1
5
  ## 2.0.7
2
6
  - Fix: Layout not working on react-native-macos because of transform instead of position
3
7
 
package/index.d.mts CHANGED
@@ -331,6 +331,7 @@ interface InternalState {
331
331
  minIndexSizeChanged: number | undefined;
332
332
  queuedInitialLayout?: boolean | undefined;
333
333
  queuedCalculateItemsInView: number | undefined;
334
+ dataChangeNeedsScrollUpdate: boolean;
334
335
  lastBatchingAction: number;
335
336
  ignoreScrollFromMVCP?: {
336
337
  lt?: number;
package/index.d.ts CHANGED
@@ -331,6 +331,7 @@ interface InternalState {
331
331
  minIndexSizeChanged: number | undefined;
332
332
  queuedInitialLayout?: boolean | undefined;
333
333
  queuedCalculateItemsInView: number | undefined;
334
+ dataChangeNeedsScrollUpdate: boolean;
334
335
  lastBatchingAction: number;
335
336
  ignoreScrollFromMVCP?: {
336
337
  lt?: number;
package/index.js CHANGED
@@ -820,7 +820,7 @@ var ListComponent = typedMemo(function ListComponent2({
820
820
  ],
821
821
  contentOffset: initialContentOffset ? horizontal ? { x: initialContentOffset, y: 0 } : { x: 0, y: initialContentOffset } : void 0,
822
822
  horizontal,
823
- maintainVisibleContentPosition: maintainVisibleContentPosition && !ListEmptyComponent ? { minIndexForVisible: 0 } : void 0,
823
+ maintainVisibleContentPosition: maintainVisibleContentPosition ? { minIndexForVisible: 0 } : void 0,
824
824
  onLayout,
825
825
  onScroll: onScroll2,
826
826
  ref: refScrollView,
@@ -831,7 +831,7 @@ var ListComponent = typedMemo(function ListComponent2({
831
831
  ENABLE_DEVMODE ? /* @__PURE__ */ React2__namespace.createElement(PaddingDevMode, null) : /* @__PURE__ */ React2__namespace.createElement(Padding, null),
832
832
  ListHeaderComponent && /* @__PURE__ */ React2__namespace.createElement(reactNative.View, { onLayout: onLayoutHeaderSync, ref: refHeader, style: ListHeaderComponentStyle }, getComponent(ListHeaderComponent)),
833
833
  ListEmptyComponent && getComponent(ListEmptyComponent),
834
- canRender && /* @__PURE__ */ React2__namespace.createElement(
834
+ canRender && !ListEmptyComponent && /* @__PURE__ */ React2__namespace.createElement(
835
835
  Containers,
836
836
  {
837
837
  getRenderedItem: getRenderedItem2,
@@ -1865,7 +1865,7 @@ function calculateItemsInView(ctx, state, params = {}) {
1865
1865
  const scrollTopBuffered = scroll - scrollBufferTop;
1866
1866
  const scrollBottom = scroll + scrollLength + (scroll < 0 ? -scroll : 0);
1867
1867
  const scrollBottomBuffered = scrollBottom + scrollBufferBottom;
1868
- if (scrollForNextCalculateItemsInView) {
1868
+ if (!dataChanged && scrollForNextCalculateItemsInView) {
1869
1869
  const { top, bottom } = scrollForNextCalculateItemsInView;
1870
1870
  if (scrollTopBuffered > top && scrollBottomBuffered < bottom) {
1871
1871
  return;
@@ -1888,7 +1888,7 @@ function calculateItemsInView(ctx, state, params = {}) {
1888
1888
  let startBufferedId = null;
1889
1889
  let endNoBuffer = null;
1890
1890
  let endBuffered = null;
1891
- let loopStart = startBufferedIdOrig ? indexByKey.get(startBufferedIdOrig) || 0 : 0;
1891
+ let loopStart = !dataChanged && startBufferedIdOrig ? indexByKey.get(startBufferedIdOrig) || 0 : 0;
1892
1892
  for (let i = loopStart; i >= 0; i--) {
1893
1893
  const id = (_b = idCache.get(i)) != null ? _b : getId(state, i);
1894
1894
  const top = positions.get(id);
@@ -2367,10 +2367,11 @@ function updateScroll(ctx, state, newScroll) {
2367
2367
  state.scrollPrevTime = state.scrollTime;
2368
2368
  state.scroll = newScroll;
2369
2369
  state.scrollTime = currentTime;
2370
- if (Math.abs(state.scroll - state.scrollPrev) > 2) {
2370
+ if (state.dataChangeNeedsScrollUpdate || Math.abs(state.scroll - state.scrollPrev) > 2) {
2371
2371
  calculateItemsInView(ctx, state);
2372
2372
  checkAtBottom(ctx, state);
2373
2373
  checkAtTop(state);
2374
+ state.dataChangeNeedsScrollUpdate = false;
2374
2375
  }
2375
2376
  }
2376
2377
 
@@ -2691,6 +2692,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
2691
2692
  columns: /* @__PURE__ */ new Map(),
2692
2693
  containerItemKeys: /* @__PURE__ */ new Set(),
2693
2694
  containerItemTypes: /* @__PURE__ */ new Map(),
2695
+ dataChangeNeedsScrollUpdate: false,
2694
2696
  enableScrollForNextCalculateItemsInView: true,
2695
2697
  endBuffered: -1,
2696
2698
  endNoBuffer: -1,
@@ -2741,6 +2743,9 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
2741
2743
  const state = refState.current;
2742
2744
  const isFirst = !state.props.renderItem;
2743
2745
  const didDataChange = state.props.data !== dataProp;
2746
+ if (didDataChange) {
2747
+ state.dataChangeNeedsScrollUpdate = true;
2748
+ }
2744
2749
  const throttleScrollFn = scrollEventThrottle && onScrollProp ? useThrottledOnScroll(onScrollProp, scrollEventThrottle) : onScrollProp;
2745
2750
  state.props = {
2746
2751
  alignItemsAtEnd,
package/index.mjs CHANGED
@@ -799,7 +799,7 @@ var ListComponent = typedMemo(function ListComponent2({
799
799
  ],
800
800
  contentOffset: initialContentOffset ? horizontal ? { x: initialContentOffset, y: 0 } : { x: 0, y: initialContentOffset } : void 0,
801
801
  horizontal,
802
- maintainVisibleContentPosition: maintainVisibleContentPosition && !ListEmptyComponent ? { minIndexForVisible: 0 } : void 0,
802
+ maintainVisibleContentPosition: maintainVisibleContentPosition ? { minIndexForVisible: 0 } : void 0,
803
803
  onLayout,
804
804
  onScroll: onScroll2,
805
805
  ref: refScrollView,
@@ -810,7 +810,7 @@ var ListComponent = typedMemo(function ListComponent2({
810
810
  ENABLE_DEVMODE ? /* @__PURE__ */ React2.createElement(PaddingDevMode, null) : /* @__PURE__ */ React2.createElement(Padding, null),
811
811
  ListHeaderComponent && /* @__PURE__ */ React2.createElement(View, { onLayout: onLayoutHeaderSync, ref: refHeader, style: ListHeaderComponentStyle }, getComponent(ListHeaderComponent)),
812
812
  ListEmptyComponent && getComponent(ListEmptyComponent),
813
- canRender && /* @__PURE__ */ React2.createElement(
813
+ canRender && !ListEmptyComponent && /* @__PURE__ */ React2.createElement(
814
814
  Containers,
815
815
  {
816
816
  getRenderedItem: getRenderedItem2,
@@ -1844,7 +1844,7 @@ function calculateItemsInView(ctx, state, params = {}) {
1844
1844
  const scrollTopBuffered = scroll - scrollBufferTop;
1845
1845
  const scrollBottom = scroll + scrollLength + (scroll < 0 ? -scroll : 0);
1846
1846
  const scrollBottomBuffered = scrollBottom + scrollBufferBottom;
1847
- if (scrollForNextCalculateItemsInView) {
1847
+ if (!dataChanged && scrollForNextCalculateItemsInView) {
1848
1848
  const { top, bottom } = scrollForNextCalculateItemsInView;
1849
1849
  if (scrollTopBuffered > top && scrollBottomBuffered < bottom) {
1850
1850
  return;
@@ -1867,7 +1867,7 @@ function calculateItemsInView(ctx, state, params = {}) {
1867
1867
  let startBufferedId = null;
1868
1868
  let endNoBuffer = null;
1869
1869
  let endBuffered = null;
1870
- let loopStart = startBufferedIdOrig ? indexByKey.get(startBufferedIdOrig) || 0 : 0;
1870
+ let loopStart = !dataChanged && startBufferedIdOrig ? indexByKey.get(startBufferedIdOrig) || 0 : 0;
1871
1871
  for (let i = loopStart; i >= 0; i--) {
1872
1872
  const id = (_b = idCache.get(i)) != null ? _b : getId(state, i);
1873
1873
  const top = positions.get(id);
@@ -2346,10 +2346,11 @@ function updateScroll(ctx, state, newScroll) {
2346
2346
  state.scrollPrevTime = state.scrollTime;
2347
2347
  state.scroll = newScroll;
2348
2348
  state.scrollTime = currentTime;
2349
- if (Math.abs(state.scroll - state.scrollPrev) > 2) {
2349
+ if (state.dataChangeNeedsScrollUpdate || Math.abs(state.scroll - state.scrollPrev) > 2) {
2350
2350
  calculateItemsInView(ctx, state);
2351
2351
  checkAtBottom(ctx, state);
2352
2352
  checkAtTop(state);
2353
+ state.dataChangeNeedsScrollUpdate = false;
2353
2354
  }
2354
2355
  }
2355
2356
 
@@ -2670,6 +2671,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
2670
2671
  columns: /* @__PURE__ */ new Map(),
2671
2672
  containerItemKeys: /* @__PURE__ */ new Set(),
2672
2673
  containerItemTypes: /* @__PURE__ */ new Map(),
2674
+ dataChangeNeedsScrollUpdate: false,
2673
2675
  enableScrollForNextCalculateItemsInView: true,
2674
2676
  endBuffered: -1,
2675
2677
  endNoBuffer: -1,
@@ -2720,6 +2722,9 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
2720
2722
  const state = refState.current;
2721
2723
  const isFirst = !state.props.renderItem;
2722
2724
  const didDataChange = state.props.data !== dataProp;
2725
+ if (didDataChange) {
2726
+ state.dataChangeNeedsScrollUpdate = true;
2727
+ }
2723
2728
  const throttleScrollFn = scrollEventThrottle && onScrollProp ? useThrottledOnScroll(onScrollProp, scrollEventThrottle) : onScrollProp;
2724
2729
  state.props = {
2725
2730
  alignItemsAtEnd,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legendapp/list",
3
- "version": "2.0.7",
3
+ "version": "2.0.8",
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,