@legendapp/list 0.5.0 → 0.5.2

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
@@ -63,6 +63,10 @@ interface InternalState {
63
63
  timeouts: Set<number>;
64
64
  nativeMarginTop: number;
65
65
  indexByKey: Map<string, number>;
66
+ contentSize: {
67
+ width: number;
68
+ height: number;
69
+ };
66
70
  viewabilityConfigCallbackPairs: ViewabilityConfigCallbackPairs | undefined;
67
71
  renderItem: (props: LegendListRenderItemProps<any>) => ReactNode;
68
72
  scrollHistory: Array<{
package/index.d.ts CHANGED
@@ -63,6 +63,10 @@ interface InternalState {
63
63
  timeouts: Set<number>;
64
64
  nativeMarginTop: number;
65
65
  indexByKey: Map<string, number>;
66
+ contentSize: {
67
+ width: number;
68
+ height: number;
69
+ };
66
70
  viewabilityConfigCallbackPairs: ViewabilityConfigCallbackPairs | undefined;
67
71
  renderItem: (props: LegendListRenderItemProps<any>) => ReactNode;
68
72
  scrollHistory: Array<{
package/index.js CHANGED
@@ -470,7 +470,7 @@ var LegendList = React7.forwardRef(function LegendList2(props, forwardedRef) {
470
470
  return /* @__PURE__ */ React7__namespace.createElement(StateProvider, null, /* @__PURE__ */ React7__namespace.createElement(LegendListInner, { ...props, ref: forwardedRef }));
471
471
  });
472
472
  var LegendListInner = React7.forwardRef(function LegendListInner2(props, forwardedRef) {
473
- var _a, _b, _c, _d, _e, _f;
473
+ var _a, _b, _c, _d, _e;
474
474
  const {
475
475
  data,
476
476
  initialScrollIndex,
@@ -565,7 +565,8 @@ var LegendListInner = React7.forwardRef(function LegendListInner2(props, forward
565
565
  scrollTime: 0,
566
566
  indexByKey: /* @__PURE__ */ new Map(),
567
567
  scrollHistory: [],
568
- scrollVelocity: 0
568
+ scrollVelocity: 0,
569
+ contentSize: { width: 0, height: 0 }
569
570
  };
570
571
  refState.current.idsInFirstRender = new Set(data.map((_, i) => getId(i)));
571
572
  set$(ctx, "scrollAdjust", refState.current.scrollAdjustPending);
@@ -775,40 +776,48 @@ var LegendListInner = React7.forwardRef(function LegendListInner2(props, forward
775
776
  }
776
777
  };
777
778
  const checkAtBottom = () => {
778
- var _a2;
779
- const { scrollLength, scroll } = refState.current;
780
- const totalSize = peek$(ctx, "totalSize");
781
- const distanceFromEnd = totalSize - scroll - scrollLength;
779
+ if (!refState.current) {
780
+ return;
781
+ }
782
+ const { scrollLength, scroll, contentSize } = refState.current;
783
+ const distanceFromEnd = contentSize[horizontal ? "width" : "height"] - scroll - scrollLength;
782
784
  if (refState.current) {
783
785
  refState.current.isAtBottom = distanceFromEnd < scrollLength * maintainScrollAtEndThreshold;
784
786
  }
785
- if (onEndReached && !((_a2 = refState.current) == null ? void 0 : _a2.isEndReached)) {
786
- if (distanceFromEnd < onEndReachedThreshold * scrollLength) {
787
- if (refState.current) {
787
+ if (onEndReached) {
788
+ if (!refState.current.isEndReached) {
789
+ if (distanceFromEnd < onEndReachedThreshold * scrollLength) {
788
790
  refState.current.isEndReached = true;
791
+ onEndReached({ distanceFromEnd });
792
+ }
793
+ } else {
794
+ if (distanceFromEnd >= onEndReachedThreshold * scrollLength) {
795
+ refState.current.isEndReached = false;
789
796
  }
790
- onEndReached({ distanceFromEnd });
791
797
  }
792
798
  }
793
799
  };
794
800
  const checkAtTop = () => {
795
- var _a2;
796
- const { scrollLength, scroll } = refState.current;
797
- if (refState.current) {
798
- refState.current.isAtTop = scroll === 0;
801
+ if (!refState.current) {
802
+ return;
799
803
  }
800
- if (onStartReached && !((_a2 = refState.current) == null ? void 0 : _a2.isStartReached)) {
801
- if (scroll < onStartReachedThreshold * scrollLength) {
802
- if (refState.current) {
804
+ const { scrollLength, scroll } = refState.current;
805
+ refState.current.isAtTop = scroll === 0;
806
+ if (onStartReached) {
807
+ if (!refState.current.isStartReached) {
808
+ if (scroll < onStartReachedThreshold * scrollLength) {
803
809
  refState.current.isStartReached = true;
810
+ onStartReached({ distanceFromStart: scroll });
811
+ }
812
+ } else {
813
+ if (scroll >= onStartReachedThreshold * scrollLength) {
814
+ refState.current.isStartReached = false;
804
815
  }
805
- onStartReached({ distanceFromStart: scroll });
806
816
  }
807
817
  }
808
818
  };
809
819
  const isFirst = !refState.current.renderItem;
810
820
  if (isFirst || data !== refState.current.data) {
811
- (data == null ? void 0 : data.length) > ((_a = refState.current.data) == null ? void 0 : _a.length);
812
821
  refState.current.data = data;
813
822
  let totalSize = 0;
814
823
  const indexByKey = /* @__PURE__ */ new Map();
@@ -825,7 +834,7 @@ var LegendListInner = React7.forwardRef(function LegendListInner2(props, forward
825
834
  if (maintainVisibleContentPosition) {
826
835
  for (const [key, index] of refState.current.indexByKey) {
827
836
  if (index < refState.current.startNoBuffer && !indexByKey.has(key)) {
828
- const size = (_b = refState.current.sizes.get(key)) != null ? _b : 0;
837
+ const size = (_a = refState.current.sizes.get(key)) != null ? _a : 0;
829
838
  if (size) {
830
839
  adjustScroll(-size);
831
840
  }
@@ -842,16 +851,16 @@ var LegendListInner = React7.forwardRef(function LegendListInner2(props, forward
842
851
  }
843
852
  calculateItemsInView();
844
853
  doMaintainScrollAtEnd(false);
854
+ checkAtTop();
855
+ checkAtBottom();
845
856
  }
846
- checkAtBottom();
847
- checkAtTop();
848
857
  }
849
858
  refState.current.renderItem = renderItem;
850
859
  set$(ctx, "lastItemKey", getId(data[data.length - 1]));
851
860
  set$(
852
861
  ctx,
853
862
  "stylePaddingTop",
854
- (_f = (_e = (_c = reactNative.StyleSheet.flatten(style)) == null ? void 0 : _c.paddingTop) != null ? _e : (_d = reactNative.StyleSheet.flatten(contentContainerStyle)) == null ? void 0 : _d.paddingTop) != null ? _f : 0
863
+ (_e = (_d = (_b = reactNative.StyleSheet.flatten(style)) == null ? void 0 : _b.paddingTop) != null ? _d : (_c = reactNative.StyleSheet.flatten(contentContainerStyle)) == null ? void 0 : _c.paddingTop) != null ? _e : 0
855
864
  );
856
865
  const getRenderedItem = React7.useCallback((key, containerId) => {
857
866
  var _a2, _b2;
@@ -998,10 +1007,12 @@ var LegendListInner = React7.forwardRef(function LegendListInner2(props, forward
998
1007
  scrollLength += event.nativeEvent.layout[horizontal ? "x" : "y"];
999
1008
  }
1000
1009
  refState.current.scrollLength = scrollLength;
1001
- doMaintainScrollAtEnd(false);
1002
- doUpdatePaddingTop();
1003
- checkAtBottom();
1004
- checkAtTop();
1010
+ if (refState.current.hasScrolled) {
1011
+ doMaintainScrollAtEnd(false);
1012
+ doUpdatePaddingTop();
1013
+ checkAtBottom();
1014
+ checkAtTop();
1015
+ }
1005
1016
  if (__DEV__) {
1006
1017
  const isWidthZero = event.nativeEvent.layout.width === 0;
1007
1018
  const isHeightZero = event.nativeEvent.layout.height === 0;
@@ -1020,6 +1031,7 @@ var LegendListInner = React7.forwardRef(function LegendListInner2(props, forward
1020
1031
  }
1021
1032
  const state = refState.current;
1022
1033
  state.hasScrolled = true;
1034
+ state.contentSize = event.nativeEvent.contentSize;
1023
1035
  const currentTime = performance.now();
1024
1036
  const newScroll = event.nativeEvent.contentOffset[horizontal ? "x" : "y"];
1025
1037
  state.scrollHistory.push({ scroll: newScroll, time: currentTime });
package/index.mjs CHANGED
@@ -449,7 +449,7 @@ var LegendList = forwardRef(function LegendList2(props, forwardedRef) {
449
449
  return /* @__PURE__ */ React7.createElement(StateProvider, null, /* @__PURE__ */ React7.createElement(LegendListInner, { ...props, ref: forwardedRef }));
450
450
  });
451
451
  var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef) {
452
- var _a, _b, _c, _d, _e, _f;
452
+ var _a, _b, _c, _d, _e;
453
453
  const {
454
454
  data,
455
455
  initialScrollIndex,
@@ -544,7 +544,8 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
544
544
  scrollTime: 0,
545
545
  indexByKey: /* @__PURE__ */ new Map(),
546
546
  scrollHistory: [],
547
- scrollVelocity: 0
547
+ scrollVelocity: 0,
548
+ contentSize: { width: 0, height: 0 }
548
549
  };
549
550
  refState.current.idsInFirstRender = new Set(data.map((_, i) => getId(i)));
550
551
  set$(ctx, "scrollAdjust", refState.current.scrollAdjustPending);
@@ -754,40 +755,48 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
754
755
  }
755
756
  };
756
757
  const checkAtBottom = () => {
757
- var _a2;
758
- const { scrollLength, scroll } = refState.current;
759
- const totalSize = peek$(ctx, "totalSize");
760
- const distanceFromEnd = totalSize - scroll - scrollLength;
758
+ if (!refState.current) {
759
+ return;
760
+ }
761
+ const { scrollLength, scroll, contentSize } = refState.current;
762
+ const distanceFromEnd = contentSize[horizontal ? "width" : "height"] - scroll - scrollLength;
761
763
  if (refState.current) {
762
764
  refState.current.isAtBottom = distanceFromEnd < scrollLength * maintainScrollAtEndThreshold;
763
765
  }
764
- if (onEndReached && !((_a2 = refState.current) == null ? void 0 : _a2.isEndReached)) {
765
- if (distanceFromEnd < onEndReachedThreshold * scrollLength) {
766
- if (refState.current) {
766
+ if (onEndReached) {
767
+ if (!refState.current.isEndReached) {
768
+ if (distanceFromEnd < onEndReachedThreshold * scrollLength) {
767
769
  refState.current.isEndReached = true;
770
+ onEndReached({ distanceFromEnd });
771
+ }
772
+ } else {
773
+ if (distanceFromEnd >= onEndReachedThreshold * scrollLength) {
774
+ refState.current.isEndReached = false;
768
775
  }
769
- onEndReached({ distanceFromEnd });
770
776
  }
771
777
  }
772
778
  };
773
779
  const checkAtTop = () => {
774
- var _a2;
775
- const { scrollLength, scroll } = refState.current;
776
- if (refState.current) {
777
- refState.current.isAtTop = scroll === 0;
780
+ if (!refState.current) {
781
+ return;
778
782
  }
779
- if (onStartReached && !((_a2 = refState.current) == null ? void 0 : _a2.isStartReached)) {
780
- if (scroll < onStartReachedThreshold * scrollLength) {
781
- if (refState.current) {
783
+ const { scrollLength, scroll } = refState.current;
784
+ refState.current.isAtTop = scroll === 0;
785
+ if (onStartReached) {
786
+ if (!refState.current.isStartReached) {
787
+ if (scroll < onStartReachedThreshold * scrollLength) {
782
788
  refState.current.isStartReached = true;
789
+ onStartReached({ distanceFromStart: scroll });
790
+ }
791
+ } else {
792
+ if (scroll >= onStartReachedThreshold * scrollLength) {
793
+ refState.current.isStartReached = false;
783
794
  }
784
- onStartReached({ distanceFromStart: scroll });
785
795
  }
786
796
  }
787
797
  };
788
798
  const isFirst = !refState.current.renderItem;
789
799
  if (isFirst || data !== refState.current.data) {
790
- (data == null ? void 0 : data.length) > ((_a = refState.current.data) == null ? void 0 : _a.length);
791
800
  refState.current.data = data;
792
801
  let totalSize = 0;
793
802
  const indexByKey = /* @__PURE__ */ new Map();
@@ -804,7 +813,7 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
804
813
  if (maintainVisibleContentPosition) {
805
814
  for (const [key, index] of refState.current.indexByKey) {
806
815
  if (index < refState.current.startNoBuffer && !indexByKey.has(key)) {
807
- const size = (_b = refState.current.sizes.get(key)) != null ? _b : 0;
816
+ const size = (_a = refState.current.sizes.get(key)) != null ? _a : 0;
808
817
  if (size) {
809
818
  adjustScroll(-size);
810
819
  }
@@ -821,16 +830,16 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
821
830
  }
822
831
  calculateItemsInView();
823
832
  doMaintainScrollAtEnd(false);
833
+ checkAtTop();
834
+ checkAtBottom();
824
835
  }
825
- checkAtBottom();
826
- checkAtTop();
827
836
  }
828
837
  refState.current.renderItem = renderItem;
829
838
  set$(ctx, "lastItemKey", getId(data[data.length - 1]));
830
839
  set$(
831
840
  ctx,
832
841
  "stylePaddingTop",
833
- (_f = (_e = (_c = StyleSheet.flatten(style)) == null ? void 0 : _c.paddingTop) != null ? _e : (_d = StyleSheet.flatten(contentContainerStyle)) == null ? void 0 : _d.paddingTop) != null ? _f : 0
842
+ (_e = (_d = (_b = StyleSheet.flatten(style)) == null ? void 0 : _b.paddingTop) != null ? _d : (_c = StyleSheet.flatten(contentContainerStyle)) == null ? void 0 : _c.paddingTop) != null ? _e : 0
834
843
  );
835
844
  const getRenderedItem = useCallback((key, containerId) => {
836
845
  var _a2, _b2;
@@ -977,10 +986,12 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
977
986
  scrollLength += event.nativeEvent.layout[horizontal ? "x" : "y"];
978
987
  }
979
988
  refState.current.scrollLength = scrollLength;
980
- doMaintainScrollAtEnd(false);
981
- doUpdatePaddingTop();
982
- checkAtBottom();
983
- checkAtTop();
989
+ if (refState.current.hasScrolled) {
990
+ doMaintainScrollAtEnd(false);
991
+ doUpdatePaddingTop();
992
+ checkAtBottom();
993
+ checkAtTop();
994
+ }
984
995
  if (__DEV__) {
985
996
  const isWidthZero = event.nativeEvent.layout.width === 0;
986
997
  const isHeightZero = event.nativeEvent.layout.height === 0;
@@ -999,6 +1010,7 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
999
1010
  }
1000
1011
  const state = refState.current;
1001
1012
  state.hasScrolled = true;
1013
+ state.contentSize = event.nativeEvent.contentSize;
1002
1014
  const currentTime = performance.now();
1003
1015
  const newScroll = event.nativeEvent.contentOffset[horizontal ? "x" : "y"];
1004
1016
  state.scrollHistory.push({ scroll: newScroll, time: currentTime });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legendapp/list",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
4
4
  "description": "legend-list",
5
5
  "sideEffects": false,
6
6
  "private": false,