@legendapp/list 1.0.10 → 1.0.12

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.mjs CHANGED
@@ -1,12 +1,12 @@
1
- import * as React2 from 'react';
2
- import React2__default, { useReducer, useEffect, createContext, useMemo, useRef, useCallback, useImperativeHandle, useContext, useState, forwardRef, memo, useLayoutEffect } from 'react';
1
+ import * as React3 from 'react';
2
+ import React3__default, { useReducer, useEffect, createContext, useMemo, useRef, useCallback, useImperativeHandle, useContext, useState, forwardRef, memo, useLayoutEffect } from 'react';
3
3
  import { View, Text, Platform, Animated, ScrollView, StyleSheet, Dimensions, RefreshControl } from 'react-native';
4
4
  import { useSyncExternalStore } from 'use-sync-external-store/shim';
5
5
 
6
6
  // src/LegendList.tsx
7
- var ContextState = React2.createContext(null);
7
+ var ContextState = React3.createContext(null);
8
8
  function StateProvider({ children }) {
9
- const [value] = React2.useState(() => ({
9
+ const [value] = React3.useState(() => ({
10
10
  listeners: /* @__PURE__ */ new Map(),
11
11
  values: /* @__PURE__ */ new Map([
12
12
  ["paddingTop", 0],
@@ -21,10 +21,10 @@ function StateProvider({ children }) {
21
21
  columnWrapperStyle: void 0,
22
22
  viewRefs: /* @__PURE__ */ new Map()
23
23
  }));
24
- return /* @__PURE__ */ React2.createElement(ContextState.Provider, { value }, children);
24
+ return /* @__PURE__ */ React3.createElement(ContextState.Provider, { value }, children);
25
25
  }
26
26
  function useStateContext() {
27
- return React2.useContext(ContextState);
27
+ return React3.useContext(ContextState);
28
28
  }
29
29
  function createSelectorFunctionsArr(ctx, signalNames) {
30
30
  let lastValues = [];
@@ -94,17 +94,17 @@ function getContentSize(ctx) {
94
94
  return headerSize + footerSize + totalSize + stylePaddingTop;
95
95
  }
96
96
  function useArr$(signalNames) {
97
- const ctx = React2.useContext(ContextState);
98
- const { subscribe, get } = React2.useMemo(() => createSelectorFunctionsArr(ctx, signalNames), [ctx, signalNames]);
97
+ const ctx = React3.useContext(ContextState);
98
+ const { subscribe, get } = React3.useMemo(() => createSelectorFunctionsArr(ctx, signalNames), [ctx, signalNames]);
99
99
  const value = useSyncExternalStore(subscribe, get);
100
100
  return value;
101
101
  }
102
102
 
103
103
  // src/DebugView.tsx
104
104
  var DebugRow = ({ children }) => {
105
- return /* @__PURE__ */ React2.createElement(View, { style: { flexDirection: "row", alignItems: "center", justifyContent: "space-between" } }, children);
105
+ return /* @__PURE__ */ React3.createElement(View, { style: { flexDirection: "row", alignItems: "center", justifyContent: "space-between" } }, children);
106
106
  };
107
- var DebugView = React2.memo(function DebugView2({ state }) {
107
+ var DebugView = React3.memo(function DebugView2({ state }) {
108
108
  const ctx = useStateContext();
109
109
  const [
110
110
  totalSize = 0,
@@ -128,7 +128,7 @@ var DebugView = React2.memo(function DebugView2({ state }) {
128
128
  useInterval(() => {
129
129
  forceUpdate();
130
130
  }, 100);
131
- return /* @__PURE__ */ React2.createElement(
131
+ return /* @__PURE__ */ React3.createElement(
132
132
  View,
133
133
  {
134
134
  style: {
@@ -144,15 +144,15 @@ var DebugView = React2.memo(function DebugView2({ state }) {
144
144
  },
145
145
  pointerEvents: "none"
146
146
  },
147
- /* @__PURE__ */ React2.createElement(DebugRow, null, /* @__PURE__ */ React2.createElement(Text, null, "TotalSize:"), /* @__PURE__ */ React2.createElement(Text, null, totalSize.toFixed(2))),
148
- /* @__PURE__ */ React2.createElement(DebugRow, null, /* @__PURE__ */ React2.createElement(Text, null, "ContentSize:"), /* @__PURE__ */ React2.createElement(Text, null, contentSize.toFixed(2))),
149
- /* @__PURE__ */ React2.createElement(DebugRow, null, /* @__PURE__ */ React2.createElement(Text, null, "At end:"), /* @__PURE__ */ React2.createElement(Text, null, String(state.isAtBottom))),
150
- /* @__PURE__ */ React2.createElement(Text, null),
151
- /* @__PURE__ */ React2.createElement(DebugRow, null, /* @__PURE__ */ React2.createElement(Text, null, "ScrollAdjust:"), /* @__PURE__ */ React2.createElement(Text, null, scrollAdjust.toFixed(2))),
152
- /* @__PURE__ */ React2.createElement(DebugRow, null, /* @__PURE__ */ React2.createElement(Text, null, "TotalSizeReal: "), /* @__PURE__ */ React2.createElement(Text, null, totalSizeWithScrollAdjust.toFixed(2))),
153
- /* @__PURE__ */ React2.createElement(Text, null),
154
- /* @__PURE__ */ React2.createElement(DebugRow, null, /* @__PURE__ */ React2.createElement(Text, null, "RawScroll: "), /* @__PURE__ */ React2.createElement(Text, null, rawScroll.toFixed(2))),
155
- /* @__PURE__ */ React2.createElement(DebugRow, null, /* @__PURE__ */ React2.createElement(Text, null, "ComputedScroll: "), /* @__PURE__ */ React2.createElement(Text, null, scroll.toFixed(2)))
147
+ /* @__PURE__ */ React3.createElement(DebugRow, null, /* @__PURE__ */ React3.createElement(Text, null, "TotalSize:"), /* @__PURE__ */ React3.createElement(Text, null, totalSize.toFixed(2))),
148
+ /* @__PURE__ */ React3.createElement(DebugRow, null, /* @__PURE__ */ React3.createElement(Text, null, "ContentSize:"), /* @__PURE__ */ React3.createElement(Text, null, contentSize.toFixed(2))),
149
+ /* @__PURE__ */ React3.createElement(DebugRow, null, /* @__PURE__ */ React3.createElement(Text, null, "At end:"), /* @__PURE__ */ React3.createElement(Text, null, String(state.isAtBottom))),
150
+ /* @__PURE__ */ React3.createElement(Text, null),
151
+ /* @__PURE__ */ React3.createElement(DebugRow, null, /* @__PURE__ */ React3.createElement(Text, null, "ScrollAdjust:"), /* @__PURE__ */ React3.createElement(Text, null, scrollAdjust.toFixed(2))),
152
+ /* @__PURE__ */ React3.createElement(DebugRow, null, /* @__PURE__ */ React3.createElement(Text, null, "TotalSizeReal: "), /* @__PURE__ */ React3.createElement(Text, null, totalSizeWithScrollAdjust.toFixed(2))),
153
+ /* @__PURE__ */ React3.createElement(Text, null),
154
+ /* @__PURE__ */ React3.createElement(DebugRow, null, /* @__PURE__ */ React3.createElement(Text, null, "RawScroll: "), /* @__PURE__ */ React3.createElement(Text, null, rawScroll.toFixed(2))),
155
+ /* @__PURE__ */ React3.createElement(DebugRow, null, /* @__PURE__ */ React3.createElement(Text, null, "ComputedScroll: "), /* @__PURE__ */ React3.createElement(Text, null, scroll.toFixed(2)))
156
156
  );
157
157
  });
158
158
  function useInterval(callback, delay) {
@@ -280,8 +280,8 @@ function useRecyclingState(valueOrFun) {
280
280
  );
281
281
  return [refState.current.value, setState];
282
282
  }
283
- var LeanViewComponent = React2.forwardRef((props, ref) => {
284
- return React2.createElement("RCTView", { ...props, ref });
283
+ var LeanViewComponent = React3.forwardRef((props, ref) => {
284
+ return React3.createElement("RCTView", { ...props, ref });
285
285
  });
286
286
  LeanViewComponent.displayName = "RCTView";
287
287
  var LeanView = Platform.OS === "android" || Platform.OS === "ios" ? LeanViewComponent : View;
@@ -421,16 +421,16 @@ var Container = ({
421
421
  ctx.viewRefs.set(id, ref);
422
422
  return { containerId: id, itemKey, index, value: data, triggerLayout };
423
423
  }, [id, itemKey, index, data]);
424
- const contentFragment = /* @__PURE__ */ React2__default.createElement(React2__default.Fragment, { key: recycleItems ? void 0 : itemKey }, /* @__PURE__ */ React2__default.createElement(ContextContainer.Provider, { value: contextValue }, renderedItem, renderedItemInfo && ItemSeparatorComponent && !lastItemKeys.includes(itemKey) && /* @__PURE__ */ React2__default.createElement(ItemSeparatorComponent, { leadingItem: renderedItemInfo.item })));
424
+ const contentFragment = /* @__PURE__ */ React3__default.createElement(React3__default.Fragment, { key: recycleItems ? void 0 : itemKey }, /* @__PURE__ */ React3__default.createElement(ContextContainer.Provider, { value: contextValue }, renderedItem, renderedItemInfo && ItemSeparatorComponent && !lastItemKeys.includes(itemKey) && /* @__PURE__ */ React3__default.createElement(ItemSeparatorComponent, { leadingItem: renderedItemInfo.item })));
425
425
  if (maintainVisibleContentPosition) {
426
426
  const anchorStyle = position.type === "top" ? { position: "absolute", top: 0, left: 0, right: 0 } : { position: "absolute", bottom: 0, left: 0, right: 0 };
427
427
  if (__DEV__ && ENABLE_DEVMODE) {
428
428
  anchorStyle.borderColor = position.type === "top" ? "red" : "blue";
429
429
  anchorStyle.borderWidth = 1;
430
430
  }
431
- return /* @__PURE__ */ React2__default.createElement(LeanView, { style }, /* @__PURE__ */ React2__default.createElement(LeanView, { style: anchorStyle, onLayout, ref }, contentFragment, __DEV__ && ENABLE_DEVMODE && /* @__PURE__ */ React2__default.createElement(Text, { style: { position: "absolute", top: 0, left: 0, zIndex: 1e3 } }, position.top)));
431
+ return /* @__PURE__ */ React3__default.createElement(LeanView, { style }, /* @__PURE__ */ React3__default.createElement(LeanView, { style: [anchorStyle, paddingStyles], onLayout, ref }, contentFragment, __DEV__ && ENABLE_DEVMODE && /* @__PURE__ */ React3__default.createElement(Text, { style: { position: "absolute", top: 0, left: 0, zIndex: 1e3 } }, position.top)));
432
432
  }
433
- return /* @__PURE__ */ React2__default.createElement(LeanView, { style, onLayout, ref }, contentFragment);
433
+ return /* @__PURE__ */ React3__default.createElement(LeanView, { style, onLayout, ref }, contentFragment);
434
434
  };
435
435
  var typedForwardRef = forwardRef;
436
436
  var typedMemo = memo;
@@ -483,7 +483,7 @@ var Containers = typedMemo(function Containers2({
483
483
  const containers = [];
484
484
  for (let i = 0; i < numContainers; i++) {
485
485
  containers.push(
486
- /* @__PURE__ */ React2.createElement(
486
+ /* @__PURE__ */ React3.createElement(
487
487
  Container,
488
488
  {
489
489
  id: i,
@@ -512,16 +512,41 @@ var Containers = typedMemo(function Containers2({
512
512
  }
513
513
  }
514
514
  }
515
- return /* @__PURE__ */ React2.createElement(Animated.View, { style }, containers);
515
+ return /* @__PURE__ */ React3.createElement(Animated.View, { style }, containers);
516
516
  });
517
+ function ListHeaderComponentContainer({
518
+ children,
519
+ style,
520
+ ctx,
521
+ horizontal,
522
+ waitForInitialLayout
523
+ }) {
524
+ const scrollAdjust = useValue$("scrollAdjust", (v) => v, true);
525
+ const animOpacity = waitForInitialLayout ? useValue$("containersDidLayout", (value) => value ? 1 : 0) : void 0;
526
+ const additionalSize = {
527
+ transform: [{ translateY: Animated.multiply(scrollAdjust, -1) }],
528
+ opacity: animOpacity
529
+ };
530
+ return /* @__PURE__ */ React.createElement(
531
+ Animated.View,
532
+ {
533
+ style: [style, additionalSize],
534
+ onLayout: (event) => {
535
+ const size = event.nativeEvent.layout[horizontal ? "width" : "height"];
536
+ set$(ctx, "headerSize", size);
537
+ }
538
+ },
539
+ children
540
+ );
541
+ }
517
542
 
518
543
  // src/ListComponent.tsx
519
544
  var getComponent = (Component) => {
520
- if (React2.isValidElement(Component)) {
545
+ if (React3.isValidElement(Component)) {
521
546
  return Component;
522
547
  }
523
548
  if (Component) {
524
- return /* @__PURE__ */ React2.createElement(Component, null);
549
+ return /* @__PURE__ */ React3.createElement(Component, null);
525
550
  }
526
551
  return null;
527
552
  };
@@ -529,12 +554,12 @@ var PaddingAndAdjust = () => {
529
554
  const animPaddingTop = useValue$("paddingTop", (v) => v, true);
530
555
  const animScrollAdjust = useValue$("scrollAdjust", (v) => v, true);
531
556
  const additionalSize = { marginTop: animScrollAdjust, paddingTop: animPaddingTop };
532
- return /* @__PURE__ */ React2.createElement(Animated.View, { style: additionalSize });
557
+ return /* @__PURE__ */ React3.createElement(Animated.View, { style: additionalSize });
533
558
  };
534
559
  var PaddingAndAdjustDevMode = () => {
535
560
  const animPaddingTop = useValue$("paddingTop", (v) => v, true);
536
561
  const animScrollAdjust = useValue$("scrollAdjust", (v) => v, true);
537
- return /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement(Animated.View, { style: { marginTop: animScrollAdjust } }), /* @__PURE__ */ React2.createElement(Animated.View, { style: { paddingTop: animPaddingTop } }), /* @__PURE__ */ React2.createElement(
562
+ return /* @__PURE__ */ React3.createElement(React3.Fragment, null, /* @__PURE__ */ React3.createElement(Animated.View, { style: { marginTop: animScrollAdjust } }), /* @__PURE__ */ React3.createElement(Animated.View, { style: { paddingTop: animPaddingTop } }), /* @__PURE__ */ React3.createElement(
538
563
  Animated.View,
539
564
  {
540
565
  style: {
@@ -546,7 +571,7 @@ var PaddingAndAdjustDevMode = () => {
546
571
  backgroundColor: "green"
547
572
  }
548
573
  }
549
- ), /* @__PURE__ */ React2.createElement(
574
+ ), /* @__PURE__ */ React3.createElement(
550
575
  Animated.View,
551
576
  {
552
577
  style: {
@@ -558,7 +583,7 @@ var PaddingAndAdjustDevMode = () => {
558
583
  backgroundColor: "lightblue"
559
584
  }
560
585
  }
561
- ), /* @__PURE__ */ React2.createElement(
586
+ ), /* @__PURE__ */ React3.createElement(
562
587
  Animated.View,
563
588
  {
564
589
  style: {
@@ -604,10 +629,10 @@ var ListComponent = typedMemo(function ListComponent2({
604
629
  }) {
605
630
  const ctx = useStateContext();
606
631
  const ScrollComponent = renderScrollComponent ? useMemo(
607
- () => React2.forwardRef((props, ref) => renderScrollComponent({ ...props, ref })),
632
+ () => React3.forwardRef((props, ref) => renderScrollComponent({ ...props, ref })),
608
633
  [renderScrollComponent]
609
634
  ) : ScrollView;
610
- return /* @__PURE__ */ React2.createElement(
635
+ return /* @__PURE__ */ React3.createElement(
611
636
  ScrollComponent,
612
637
  {
613
638
  ...rest,
@@ -625,20 +650,19 @@ var ListComponent = typedMemo(function ListComponent2({
625
650
  contentOffset: initialContentOffset ? horizontal ? { x: initialContentOffset, y: 0 } : { x: 0, y: initialContentOffset } : void 0,
626
651
  ref: refScrollView
627
652
  },
628
- !ListEmptyComponent && (ENABLE_DEVMODE ? /* @__PURE__ */ React2.createElement(PaddingAndAdjustDevMode, null) : /* @__PURE__ */ React2.createElement(PaddingAndAdjust, null)),
629
- ListHeaderComponent && /* @__PURE__ */ React2.createElement(
630
- View,
653
+ !ListEmptyComponent && (ENABLE_DEVMODE ? /* @__PURE__ */ React3.createElement(PaddingAndAdjustDevMode, null) : /* @__PURE__ */ React3.createElement(PaddingAndAdjust, null)),
654
+ ListHeaderComponent && /* @__PURE__ */ React3.createElement(
655
+ ListHeaderComponentContainer,
631
656
  {
632
657
  style: ListHeaderComponentStyle,
633
- onLayout: (event) => {
634
- const size = event.nativeEvent.layout[horizontal ? "width" : "height"];
635
- set$(ctx, "headerSize", size);
636
- }
658
+ ctx,
659
+ horizontal,
660
+ waitForInitialLayout
637
661
  },
638
662
  getComponent(ListHeaderComponent)
639
663
  ),
640
664
  ListEmptyComponent && getComponent(ListEmptyComponent),
641
- /* @__PURE__ */ React2.createElement(
665
+ /* @__PURE__ */ React3.createElement(
642
666
  Containers,
643
667
  {
644
668
  horizontal,
@@ -649,7 +673,7 @@ var ListComponent = typedMemo(function ListComponent2({
649
673
  updateItemSize
650
674
  }
651
675
  ),
652
- ListFooterComponent && /* @__PURE__ */ React2.createElement(
676
+ ListFooterComponent && /* @__PURE__ */ React3.createElement(
653
677
  View,
654
678
  {
655
679
  style: ListFooterComponentStyle,
@@ -931,7 +955,7 @@ function createColumnWrapperStyle(contentContainerStyle) {
931
955
  }
932
956
  }
933
957
  var LegendList = typedForwardRef(function LegendList2(props, forwardedRef) {
934
- return /* @__PURE__ */ React2.createElement(StateProvider, null, /* @__PURE__ */ React2.createElement(LegendListInner, { ...props, ref: forwardedRef }));
958
+ return /* @__PURE__ */ React3.createElement(StateProvider, null, /* @__PURE__ */ React3.createElement(LegendListInner, { ...props, ref: forwardedRef }));
935
959
  });
936
960
  var LegendListInner = typedForwardRef(function LegendListInner2(props, forwardedRef) {
937
961
  const {
@@ -1051,7 +1075,8 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1051
1075
  offset = index * estimatedItemSize;
1052
1076
  }
1053
1077
  const adjust = peek$(ctx, "containersDidLayout") ? ((_a = refState.current) == null ? void 0 : _a.scrollAdjustHandler.getAppliedAdjust()) || 0 : 0;
1054
- return offset / numColumnsProp - adjust;
1078
+ const topPad = peek$(ctx, "stylePaddingTop") + peek$(ctx, "headerSize");
1079
+ return offset / numColumnsProp - adjust + topPad;
1055
1080
  }
1056
1081
  return 0;
1057
1082
  };
@@ -1084,6 +1109,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1084
1109
  scrollPrev: 0,
1085
1110
  scrollPrevTime: 0,
1086
1111
  scrollTime: 0,
1112
+ scrollPending: 0,
1087
1113
  indexByKey: /* @__PURE__ */ new Map(),
1088
1114
  scrollHistory: [],
1089
1115
  scrollVelocity: 0,
@@ -1152,11 +1178,12 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1152
1178
  const firstIndexOffset = calculateOffsetForIndex(index);
1153
1179
  let firstIndexScrollPostion = firstIndexOffset - viewOffset;
1154
1180
  const diff = Math.abs(state.scroll - firstIndexScrollPostion);
1181
+ const topPad = peek$(ctx, "stylePaddingTop") + peek$(ctx, "headerSize");
1155
1182
  const needsReanchoring = maintainVisibleContentPosition && diff > 100;
1156
1183
  state.scrollForNextCalculateItemsInView = void 0;
1157
1184
  if (needsReanchoring) {
1158
1185
  const id = getId(index);
1159
- state.anchorElement = { id, coordinate: firstIndexOffset };
1186
+ state.anchorElement = { id, coordinate: firstIndexOffset - topPad };
1160
1187
  (_a = state.belowAnchorElementPositions) == null ? void 0 : _a.clear();
1161
1188
  state.positions.clear();
1162
1189
  calcTotalSizesAndPositions({ forgetPositions: true });
@@ -1276,6 +1303,9 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1276
1303
  state.scrollHistory.length = 0;
1277
1304
  setTimeout(() => {
1278
1305
  state.disableScrollJumpsFrom = void 0;
1306
+ if (state.scrollPending !== void 0 && state.scrollPending !== state.scroll) {
1307
+ updateScroll(state.scrollPending);
1308
+ }
1279
1309
  }, timeout);
1280
1310
  }
1281
1311
  };
@@ -1389,7 +1419,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1389
1419
  const numColumns = peek$(ctx, "numColumns");
1390
1420
  const previousScrollAdjust = scrollAdjustHandler.getAppliedAdjust();
1391
1421
  let scrollState = state.scroll;
1392
- const scrollExtra = Math.max(-16, Math.min(16, speed)) * 24;
1422
+ const scrollExtra = 0;
1393
1423
  const useAverageSize = !state.disableScrollJumpsFrom && speed >= 0 && peek$(ctx, "containersDidLayout");
1394
1424
  if (!state.queuedInitialLayout && initialScrollIndex) {
1395
1425
  const updatedOffset = calculateOffsetForIndex(initialScrollIndex);
@@ -1672,6 +1702,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1672
1702
  if (state) {
1673
1703
  state.scrollingToOffset = void 0;
1674
1704
  state.scrollAdjustHandler.setDisableAdjust(false);
1705
+ state.scrollHistory.length = 0;
1675
1706
  calculateItemsInView();
1676
1707
  }
1677
1708
  };
@@ -1697,6 +1728,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1697
1728
  if (paddingTop > 0) {
1698
1729
  state.scroll = 0;
1699
1730
  }
1731
+ state.disableScrollJumpsFrom = void 0;
1700
1732
  requestAnimationFrame(() => {
1701
1733
  var _a;
1702
1734
  state.maintainingScrollAtEnd = true;
@@ -1786,8 +1818,13 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1786
1818
  if (state) {
1787
1819
  state.data = dataProp;
1788
1820
  if (!isFirst2) {
1789
- disableScrollJumps(2e3);
1790
- refState.current.scrollForNextCalculateItemsInView = void 0;
1821
+ const totalSizeBefore = state.previousTotalSize;
1822
+ const totalSizeAfter = state.totalSize;
1823
+ const scrollDiff = state.scroll - state.scrollPrev;
1824
+ const sizeDiff = totalSizeAfter - totalSizeBefore;
1825
+ if (Math.abs(scrollDiff - sizeDiff) < 10) {
1826
+ disableScrollJumps(1e3);
1827
+ }
1791
1828
  const numContainers = peek$(ctx, "numContainers");
1792
1829
  for (let i = 0; i < numContainers; i++) {
1793
1830
  const itemKey = peek$(ctx, `containerItemKey${i}`);
@@ -1998,6 +2035,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1998
2035
  refState.current.sizes.clear();
1999
2036
  refState.current.positions.clear();
2000
2037
  }
2038
+ refState.current.previousTotalSize = peek$(ctx, "totalSize");
2001
2039
  calcTotalSizesAndPositions({ forgetPositions: false });
2002
2040
  }
2003
2041
  useEffect(() => {
@@ -2205,63 +2243,76 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
2205
2243
  }
2206
2244
  }, []);
2207
2245
  const handleScroll = useCallback(
2208
- (event, fromSelf) => {
2246
+ (event) => {
2209
2247
  var _a, _b, _c, _d;
2210
2248
  if (((_b = (_a = event.nativeEvent) == null ? void 0 : _a.contentSize) == null ? void 0 : _b.height) === 0 && ((_c = event.nativeEvent.contentSize) == null ? void 0 : _c.width) === 0) {
2211
2249
  return;
2212
2250
  }
2213
2251
  const state = refState.current;
2214
2252
  const newScroll = event.nativeEvent.contentOffset[horizontal ? "x" : "y"];
2253
+ state.scrollPending = newScroll;
2215
2254
  if (state.ignoreScrollFromCalcTotal && newScroll !== 0) {
2216
2255
  return;
2217
2256
  }
2218
- if (state.scrollingToOffset !== void 0 && Math.abs(newScroll - state.scrollingToOffset) < 10) {
2219
- finishScrollTo();
2257
+ updateScroll(newScroll);
2258
+ (_d = state.onScroll) == null ? void 0 : _d.call(state, event);
2259
+ },
2260
+ []
2261
+ );
2262
+ const updateScroll = useCallback((newScroll) => {
2263
+ const state = refState.current;
2264
+ const scrollingToOffset = state.scrollingToOffset;
2265
+ if (scrollingToOffset !== void 0 && Math.abs(newScroll - scrollingToOffset) < 10) {
2266
+ finishScrollTo();
2267
+ }
2268
+ if (state.disableScrollJumpsFrom !== void 0) {
2269
+ const scrollMinusAdjust = newScroll - state.scrollAdjustHandler.getAppliedAdjust();
2270
+ if (Math.abs(scrollMinusAdjust - state.disableScrollJumpsFrom) > 200) {
2271
+ return;
2220
2272
  }
2221
- if (state.disableScrollJumpsFrom !== void 0) {
2222
- const scrollMinusAdjust = newScroll - state.scrollAdjustHandler.getAppliedAdjust();
2223
- if (Math.abs(scrollMinusAdjust - state.disableScrollJumpsFrom) > 200) {
2224
- return;
2273
+ state.disableScrollJumpsFrom = void 0;
2274
+ }
2275
+ state.hasScrolled = true;
2276
+ state.lastBatchingAction = Date.now();
2277
+ const currentTime = performance.now();
2278
+ if (scrollingToOffset === void 0 && !(state.scrollHistory.length === 0 && newScroll === initialContentOffset)) {
2279
+ state.scrollHistory.push({ scroll: newScroll, time: currentTime });
2280
+ }
2281
+ if (state.scrollHistory.length > 5) {
2282
+ state.scrollHistory.shift();
2283
+ }
2284
+ if (state.scrollTimer !== void 0) {
2285
+ clearTimeout(state.scrollTimer);
2286
+ }
2287
+ state.scrollTimer = setTimeout(() => {
2288
+ state.scrollVelocity = 0;
2289
+ }, 500);
2290
+ let velocity = 0;
2291
+ if (state.scrollHistory.length >= 2) {
2292
+ const newest = state.scrollHistory[state.scrollHistory.length - 1];
2293
+ let oldest;
2294
+ for (let i = 0; i < state.scrollHistory.length - 1; i++) {
2295
+ const entry = state.scrollHistory[i];
2296
+ if (newest.time - entry.time <= 100) {
2297
+ oldest = entry;
2298
+ break;
2225
2299
  }
2226
- state.disableScrollJumpsFrom = void 0;
2227
2300
  }
2228
- state.hasScrolled = true;
2229
- state.lastBatchingAction = Date.now();
2230
- const currentTime = performance.now();
2231
- if (!(state.scrollHistory.length === 0 && newScroll === initialContentOffset)) {
2232
- state.scrollHistory.push({ scroll: newScroll, time: currentTime });
2233
- }
2234
- if (state.scrollHistory.length > 5) {
2235
- state.scrollHistory.shift();
2236
- }
2237
- if (state.scrollTimer !== void 0) {
2238
- clearTimeout(state.scrollTimer);
2239
- }
2240
- state.scrollTimer = setTimeout(() => {
2241
- state.scrollVelocity = 0;
2242
- }, 500);
2243
- let velocity = 0;
2244
- if (state.scrollHistory.length >= 2) {
2245
- const newest = state.scrollHistory[state.scrollHistory.length - 1];
2246
- const oldest = state.scrollHistory[0];
2301
+ if (oldest) {
2247
2302
  const scrollDiff = newest.scroll - oldest.scroll;
2248
2303
  const timeDiff = newest.time - oldest.time;
2249
2304
  velocity = timeDiff > 0 ? scrollDiff / timeDiff : 0;
2250
2305
  }
2251
- state.scrollPrev = state.scroll;
2252
- state.scrollPrevTime = state.scrollTime;
2253
- state.scroll = newScroll;
2254
- state.scrollTime = currentTime;
2255
- state.scrollVelocity = velocity;
2256
- calculateItemsInView();
2257
- checkAtBottom();
2258
- checkAtTop();
2259
- if (!fromSelf) {
2260
- (_d = state.onScroll) == null ? void 0 : _d.call(state, event);
2261
- }
2262
- },
2263
- []
2264
- );
2306
+ }
2307
+ state.scrollPrev = state.scroll;
2308
+ state.scrollPrevTime = state.scrollTime;
2309
+ state.scroll = newScroll;
2310
+ state.scrollTime = currentTime;
2311
+ state.scrollVelocity = velocity;
2312
+ calculateItemsInView();
2313
+ checkAtBottom();
2314
+ checkAtTop();
2315
+ }, []);
2265
2316
  useImperativeHandle(
2266
2317
  forwardedRef,
2267
2318
  () => {
@@ -2335,7 +2386,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
2335
2386
  }
2336
2387
  }, []);
2337
2388
  }
2338
- return /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement(
2389
+ return /* @__PURE__ */ React3.createElement(React3.Fragment, null, /* @__PURE__ */ React3.createElement(
2339
2390
  ListComponent,
2340
2391
  {
2341
2392
  ...rest,
@@ -2374,7 +2425,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
2374
2425
  maintainVisibleContentPosition,
2375
2426
  scrollEventThrottle: Platform.OS === "web" ? 16 : void 0,
2376
2427
  waitForInitialLayout,
2377
- refreshControl: refreshControl != null ? refreshControl : onRefresh && /* @__PURE__ */ React2.createElement(
2428
+ refreshControl: refreshControl != null ? refreshControl : onRefresh && /* @__PURE__ */ React3.createElement(
2378
2429
  RefreshControl,
2379
2430
  {
2380
2431
  refreshing: !!refreshing,
@@ -2385,7 +2436,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
2385
2436
  style,
2386
2437
  contentContainerStyle
2387
2438
  }
2388
- ), __DEV__ && ENABLE_DEBUG_VIEW && /* @__PURE__ */ React2.createElement(DebugView, { state: refState.current }));
2439
+ ), __DEV__ && ENABLE_DEBUG_VIEW && /* @__PURE__ */ React3.createElement(DebugView, { state: refState.current }));
2389
2440
  });
2390
2441
 
2391
2442
  export { LegendList, useRecyclingEffect, useRecyclingState, useViewability, useViewabilityAmount };