@legendapp/list 0.5.0 → 0.5.1

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);
@@ -776,9 +777,8 @@ var LegendListInner = React7.forwardRef(function LegendListInner2(props, forward
776
777
  };
777
778
  const checkAtBottom = () => {
778
779
  var _a2;
779
- const { scrollLength, scroll } = refState.current;
780
- const totalSize = peek$(ctx, "totalSize");
781
- const distanceFromEnd = totalSize - scroll - scrollLength;
780
+ const { scrollLength, scroll, contentSize } = refState.current;
781
+ const distanceFromEnd = contentSize[horizontal ? "width" : "height"] - scroll - scrollLength;
782
782
  if (refState.current) {
783
783
  refState.current.isAtBottom = distanceFromEnd < scrollLength * maintainScrollAtEndThreshold;
784
784
  }
@@ -808,7 +808,6 @@ var LegendListInner = React7.forwardRef(function LegendListInner2(props, forward
808
808
  };
809
809
  const isFirst = !refState.current.renderItem;
810
810
  if (isFirst || data !== refState.current.data) {
811
- (data == null ? void 0 : data.length) > ((_a = refState.current.data) == null ? void 0 : _a.length);
812
811
  refState.current.data = data;
813
812
  let totalSize = 0;
814
813
  const indexByKey = /* @__PURE__ */ new Map();
@@ -825,7 +824,7 @@ var LegendListInner = React7.forwardRef(function LegendListInner2(props, forward
825
824
  if (maintainVisibleContentPosition) {
826
825
  for (const [key, index] of refState.current.indexByKey) {
827
826
  if (index < refState.current.startNoBuffer && !indexByKey.has(key)) {
828
- const size = (_b = refState.current.sizes.get(key)) != null ? _b : 0;
827
+ const size = (_a = refState.current.sizes.get(key)) != null ? _a : 0;
829
828
  if (size) {
830
829
  adjustScroll(-size);
831
830
  }
@@ -842,16 +841,16 @@ var LegendListInner = React7.forwardRef(function LegendListInner2(props, forward
842
841
  }
843
842
  calculateItemsInView();
844
843
  doMaintainScrollAtEnd(false);
844
+ checkAtTop();
845
+ checkAtBottom();
845
846
  }
846
- checkAtBottom();
847
- checkAtTop();
848
847
  }
849
848
  refState.current.renderItem = renderItem;
850
849
  set$(ctx, "lastItemKey", getId(data[data.length - 1]));
851
850
  set$(
852
851
  ctx,
853
852
  "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
853
+ (_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
854
  );
856
855
  const getRenderedItem = React7.useCallback((key, containerId) => {
857
856
  var _a2, _b2;
@@ -998,10 +997,12 @@ var LegendListInner = React7.forwardRef(function LegendListInner2(props, forward
998
997
  scrollLength += event.nativeEvent.layout[horizontal ? "x" : "y"];
999
998
  }
1000
999
  refState.current.scrollLength = scrollLength;
1001
- doMaintainScrollAtEnd(false);
1002
- doUpdatePaddingTop();
1003
- checkAtBottom();
1004
- checkAtTop();
1000
+ if (refState.current.hasScrolled) {
1001
+ doMaintainScrollAtEnd(false);
1002
+ doUpdatePaddingTop();
1003
+ checkAtBottom();
1004
+ checkAtTop();
1005
+ }
1005
1006
  if (__DEV__) {
1006
1007
  const isWidthZero = event.nativeEvent.layout.width === 0;
1007
1008
  const isHeightZero = event.nativeEvent.layout.height === 0;
@@ -1020,6 +1021,7 @@ var LegendListInner = React7.forwardRef(function LegendListInner2(props, forward
1020
1021
  }
1021
1022
  const state = refState.current;
1022
1023
  state.hasScrolled = true;
1024
+ state.contentSize = event.nativeEvent.contentSize;
1023
1025
  const currentTime = performance.now();
1024
1026
  const newScroll = event.nativeEvent.contentOffset[horizontal ? "x" : "y"];
1025
1027
  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);
@@ -755,9 +756,8 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
755
756
  };
756
757
  const checkAtBottom = () => {
757
758
  var _a2;
758
- const { scrollLength, scroll } = refState.current;
759
- const totalSize = peek$(ctx, "totalSize");
760
- const distanceFromEnd = totalSize - scroll - scrollLength;
759
+ const { scrollLength, scroll, contentSize } = refState.current;
760
+ const distanceFromEnd = contentSize[horizontal ? "width" : "height"] - scroll - scrollLength;
761
761
  if (refState.current) {
762
762
  refState.current.isAtBottom = distanceFromEnd < scrollLength * maintainScrollAtEndThreshold;
763
763
  }
@@ -787,7 +787,6 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
787
787
  };
788
788
  const isFirst = !refState.current.renderItem;
789
789
  if (isFirst || data !== refState.current.data) {
790
- (data == null ? void 0 : data.length) > ((_a = refState.current.data) == null ? void 0 : _a.length);
791
790
  refState.current.data = data;
792
791
  let totalSize = 0;
793
792
  const indexByKey = /* @__PURE__ */ new Map();
@@ -804,7 +803,7 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
804
803
  if (maintainVisibleContentPosition) {
805
804
  for (const [key, index] of refState.current.indexByKey) {
806
805
  if (index < refState.current.startNoBuffer && !indexByKey.has(key)) {
807
- const size = (_b = refState.current.sizes.get(key)) != null ? _b : 0;
806
+ const size = (_a = refState.current.sizes.get(key)) != null ? _a : 0;
808
807
  if (size) {
809
808
  adjustScroll(-size);
810
809
  }
@@ -821,16 +820,16 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
821
820
  }
822
821
  calculateItemsInView();
823
822
  doMaintainScrollAtEnd(false);
823
+ checkAtTop();
824
+ checkAtBottom();
824
825
  }
825
- checkAtBottom();
826
- checkAtTop();
827
826
  }
828
827
  refState.current.renderItem = renderItem;
829
828
  set$(ctx, "lastItemKey", getId(data[data.length - 1]));
830
829
  set$(
831
830
  ctx,
832
831
  "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
832
+ (_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
833
  );
835
834
  const getRenderedItem = useCallback((key, containerId) => {
836
835
  var _a2, _b2;
@@ -977,10 +976,12 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
977
976
  scrollLength += event.nativeEvent.layout[horizontal ? "x" : "y"];
978
977
  }
979
978
  refState.current.scrollLength = scrollLength;
980
- doMaintainScrollAtEnd(false);
981
- doUpdatePaddingTop();
982
- checkAtBottom();
983
- checkAtTop();
979
+ if (refState.current.hasScrolled) {
980
+ doMaintainScrollAtEnd(false);
981
+ doUpdatePaddingTop();
982
+ checkAtBottom();
983
+ checkAtTop();
984
+ }
984
985
  if (__DEV__) {
985
986
  const isWidthZero = event.nativeEvent.layout.width === 0;
986
987
  const isHeightZero = event.nativeEvent.layout.height === 0;
@@ -999,6 +1000,7 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
999
1000
  }
1000
1001
  const state = refState.current;
1001
1002
  state.hasScrolled = true;
1003
+ state.contentSize = event.nativeEvent.contentSize;
1002
1004
  const currentTime = performance.now();
1003
1005
  const newScroll = event.nativeEvent.contentOffset[horizontal ? "x" : "y"];
1004
1006
  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.1",
4
4
  "description": "legend-list",
5
5
  "sideEffects": false,
6
6
  "private": false,