@legendapp/list 1.0.0-beta.11 → 1.0.0-beta.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,11 +1,11 @@
1
- import * as React5 from 'react';
2
- import React5__default, { createContext, useMemo, forwardRef, useRef, useCallback, useEffect, useImperativeHandle, useSyncExternalStore, useContext, useState, useLayoutEffect } from 'react';
3
- import { Animated, ScrollView, View, Dimensions, StyleSheet, Platform, useAnimatedValue as useAnimatedValue$1 } from 'react-native';
1
+ import * as React6 from 'react';
2
+ import React6__default, { createContext, memo, useReducer, useEffect, useMemo, useRef, useCallback, useImperativeHandle, useSyncExternalStore, useContext, useState, forwardRef, useLayoutEffect } from 'react';
3
+ import { View, Text, Animated, ScrollView, Dimensions, StyleSheet, Platform, useAnimatedValue as useAnimatedValue$1 } from 'react-native';
4
4
 
5
5
  // src/LegendList.tsx
6
- var ContextState = React5.createContext(null);
6
+ var ContextState = React6.createContext(null);
7
7
  function StateProvider({ children }) {
8
- const [value] = React5.useState(() => ({
8
+ const [value] = React6.useState(() => ({
9
9
  listeners: /* @__PURE__ */ new Map(),
10
10
  values: /* @__PURE__ */ new Map(),
11
11
  mapViewabilityCallbacks: /* @__PURE__ */ new Map(),
@@ -13,10 +13,10 @@ function StateProvider({ children }) {
13
13
  mapViewabilityAmountCallbacks: /* @__PURE__ */ new Map(),
14
14
  mapViewabilityAmountValues: /* @__PURE__ */ new Map()
15
15
  }));
16
- return /* @__PURE__ */ React5.createElement(ContextState.Provider, { value }, children);
16
+ return /* @__PURE__ */ React6.createElement(ContextState.Provider, { value }, children);
17
17
  }
18
18
  function useStateContext() {
19
- return React5.useContext(ContextState);
19
+ return React6.useContext(ContextState);
20
20
  }
21
21
  function createSelectorFunctions(ctx, signalName) {
22
22
  return {
@@ -25,8 +25,8 @@ function createSelectorFunctions(ctx, signalName) {
25
25
  };
26
26
  }
27
27
  function use$(signalName) {
28
- const ctx = React5.useContext(ContextState);
29
- const { subscribe, get } = React5.useMemo(() => createSelectorFunctions(ctx, signalName), []);
28
+ const ctx = React6.useContext(ContextState);
29
+ const { subscribe, get } = React6.useMemo(() => createSelectorFunctions(ctx, signalName), []);
30
30
  const value = useSyncExternalStore(subscribe, get);
31
31
  return value;
32
32
  }
@@ -141,8 +141,37 @@ function useRecyclingState(valueOrFun) {
141
141
  });
142
142
  return stateInfo;
143
143
  }
144
- var LeanView = React5.forwardRef((props, ref) => {
145
- return React5.createElement("RCTView", { ...props, ref });
144
+ var DebugView = memo(function DebugView2({ state }) {
145
+ const paddingTop = use$("paddingTop");
146
+ const [, forceUpdate] = useReducer((x) => x + 1, 0);
147
+ useInterval(() => {
148
+ forceUpdate();
149
+ }, 100);
150
+ return /* @__PURE__ */ React.createElement(
151
+ View,
152
+ {
153
+ style: {
154
+ position: "absolute",
155
+ top: 0,
156
+ right: 0,
157
+ paddingLeft: 4,
158
+ paddingBottom: 4,
159
+ // height: 100,
160
+ backgroundColor: "#FFFFFFCC"
161
+ }
162
+ },
163
+ /* @__PURE__ */ React.createElement(Text, null, "PaddingTop: ", paddingTop),
164
+ /* @__PURE__ */ React.createElement(Text, null, "At end: ", String(state.isAtBottom))
165
+ );
166
+ });
167
+ function useInterval(callback, delay) {
168
+ useEffect(() => {
169
+ const interval = setInterval(callback, delay);
170
+ return () => clearInterval(interval);
171
+ }, [delay]);
172
+ }
173
+ var LeanView = React6.forwardRef((props, ref) => {
174
+ return React6.createElement("RCTView", { ...props, ref });
146
175
  });
147
176
  LeanView.displayName = "RCTView";
148
177
 
@@ -153,6 +182,8 @@ var ANCHORED_POSITION_OUT_OF_VIEW = {
153
182
  relativeCoordinate: POSITION_OUT_OF_VIEW,
154
183
  top: POSITION_OUT_OF_VIEW
155
184
  };
185
+ var ENABLE_DEVMODE = __DEV__ && false;
186
+ var ENABLE_DEBUG_VIEW = __DEV__ && false;
156
187
 
157
188
  // src/Container.tsx
158
189
  var isNewArchitecture = global.nativeFabricUIManager != null;
@@ -164,7 +195,6 @@ var Container = ({
164
195
  updateItemSize,
165
196
  ItemSeparatorComponent
166
197
  }) => {
167
- useStateContext();
168
198
  const maintainVisibleContentPosition = use$("maintainVisibleContentPosition");
169
199
  const position = use$(`containerPosition${id}`) || ANCHORED_POSITION_OUT_OF_VIEW;
170
200
  const column = use$(`containerColumn${id}`) || 0;
@@ -223,12 +253,16 @@ var Container = ({
223
253
  () => ({ containerId: id, itemKey, index, value: data }),
224
254
  [id, itemKey, index, data]
225
255
  );
226
- const contentFragment = /* @__PURE__ */ React5__default.createElement(React5__default.Fragment, { key: recycleItems ? void 0 : itemKey }, /* @__PURE__ */ React5__default.createElement(ContextContainer.Provider, { value: contextValue }, renderedItem, renderedItem && ItemSeparatorComponent && itemKey !== lastItemKey && ItemSeparatorComponent));
256
+ const contentFragment = /* @__PURE__ */ React6__default.createElement(React6__default.Fragment, { key: recycleItems ? void 0 : itemKey }, /* @__PURE__ */ React6__default.createElement(ContextContainer.Provider, { value: contextValue }, renderedItem, renderedItem && ItemSeparatorComponent && itemKey !== lastItemKey && ItemSeparatorComponent));
227
257
  if (maintainVisibleContentPosition) {
228
258
  const anchorStyle = position.type === "top" ? { position: "absolute", top: 0, left: 0, right: 0 } : { position: "absolute", bottom: 0, left: 0, right: 0 };
229
- return /* @__PURE__ */ React5__default.createElement(LeanView, { style }, /* @__PURE__ */ React5__default.createElement(LeanView, { style: anchorStyle, onLayout, ref }, contentFragment));
259
+ if (ENABLE_DEVMODE) {
260
+ anchorStyle.borderColor = position.type === "top" ? "red" : "blue";
261
+ anchorStyle.borderWidth = 1;
262
+ }
263
+ return /* @__PURE__ */ React6__default.createElement(LeanView, { style }, /* @__PURE__ */ React6__default.createElement(LeanView, { style: anchorStyle, onLayout, ref }, contentFragment, ENABLE_DEVMODE && /* @__PURE__ */ React6__default.createElement(Text, { style: { position: "absolute", top: 0, left: 0, zIndex: 1e3 } }, position.top)));
230
264
  }
231
- return /* @__PURE__ */ React5__default.createElement(LeanView, { style, onLayout, ref }, contentFragment);
265
+ return /* @__PURE__ */ React6__default.createElement(LeanView, { style, onLayout, ref }, contentFragment);
232
266
  };
233
267
  var useAnimatedValue = useAnimatedValue$1 || ((initialValue) => {
234
268
  return useRef(new Animated.Value(initialValue)).current;
@@ -256,7 +290,7 @@ function useValue$(key, getValue, useMicrotask) {
256
290
  }
257
291
 
258
292
  // src/Containers.tsx
259
- var Containers = React5.memo(function Containers2({
293
+ var Containers = React6.memo(function Containers2({
260
294
  horizontal,
261
295
  recycleItems,
262
296
  ItemSeparatorComponent,
@@ -275,7 +309,7 @@ var Containers = React5.memo(function Containers2({
275
309
  const containers = [];
276
310
  for (let i = 0; i < numContainers; i++) {
277
311
  containers.push(
278
- /* @__PURE__ */ React5.createElement(
312
+ /* @__PURE__ */ React6.createElement(
279
313
  Container,
280
314
  {
281
315
  id: i,
@@ -290,20 +324,71 @@ var Containers = React5.memo(function Containers2({
290
324
  );
291
325
  }
292
326
  const style = horizontal ? { width: animSize, opacity: animOpacity } : { height: animSize, opacity: animOpacity };
293
- return /* @__PURE__ */ React5.createElement(Animated.View, { style }, containers);
327
+ return /* @__PURE__ */ React6.createElement(Animated.View, { style }, containers);
294
328
  });
295
329
 
296
330
  // src/ListComponent.tsx
297
331
  var getComponent = (Component) => {
298
- if (React5.isValidElement(Component)) {
332
+ if (React6.isValidElement(Component)) {
299
333
  return Component;
300
334
  }
301
335
  if (Component) {
302
- return /* @__PURE__ */ React5.createElement(Component, null);
336
+ return /* @__PURE__ */ React6.createElement(Component, null);
303
337
  }
304
338
  return null;
305
339
  };
306
- var ListComponent = React5.memo(function ListComponent2({
340
+ var PaddingAndAdjust = () => {
341
+ const animPaddingTop = useValue$("paddingTop", (v) => v, true);
342
+ const animScrollAdjust = useValue$("scrollAdjust", (v) => v, true);
343
+ const additionalSize = { marginTop: animScrollAdjust, paddingTop: animPaddingTop };
344
+ return /* @__PURE__ */ React6.createElement(Animated.View, { style: additionalSize });
345
+ };
346
+ var PaddingAndAdjustDevMode = () => {
347
+ const animPaddingTop = useValue$("paddingTop", (v) => v, true);
348
+ const animScrollAdjust = useValue$("scrollAdjust", (v) => v, true);
349
+ return /* @__PURE__ */ React6.createElement(React6.Fragment, null, /* @__PURE__ */ React6.createElement(Animated.View, { style: { marginTop: animScrollAdjust } }), /* @__PURE__ */ React6.createElement(Animated.View, { style: { paddingTop: animPaddingTop } }), /* @__PURE__ */ React6.createElement(
350
+ Animated.View,
351
+ {
352
+ style: {
353
+ position: "absolute",
354
+ top: Animated.add(animScrollAdjust, Animated.multiply(animScrollAdjust, -1)),
355
+ height: animPaddingTop,
356
+ left: 0,
357
+ right: 0,
358
+ backgroundColor: "green"
359
+ }
360
+ }
361
+ ), /* @__PURE__ */ React6.createElement(
362
+ Animated.View,
363
+ {
364
+ style: {
365
+ position: "absolute",
366
+ top: animPaddingTop,
367
+ height: animScrollAdjust,
368
+ left: -16,
369
+ right: -16,
370
+ backgroundColor: "lightblue"
371
+ }
372
+ }
373
+ ), /* @__PURE__ */ React6.createElement(
374
+ Animated.View,
375
+ {
376
+ style: {
377
+ position: "absolute",
378
+ top: animPaddingTop,
379
+ height: Animated.multiply(animScrollAdjust, -1),
380
+ width: 8,
381
+ right: 4,
382
+ borderStyle: "dashed",
383
+ borderColor: "blue",
384
+ borderWidth: 1,
385
+ backgroundColor: "lightblue"
386
+ //backgroundColor: "blue",
387
+ }
388
+ }
389
+ ));
390
+ };
391
+ var ListComponent = React6.memo(function ListComponent2({
307
392
  style,
308
393
  contentContainerStyle,
309
394
  horizontal,
@@ -327,14 +412,11 @@ var ListComponent = React5.memo(function ListComponent2({
327
412
  ...rest
328
413
  }) {
329
414
  const ctx = useStateContext();
330
- const animPaddingTop = useValue$("paddingTop");
331
- const animScrollAdjust = useValue$("scrollAdjust");
332
415
  const ScrollComponent = renderScrollComponent ? useMemo(
333
- () => React5.forwardRef((props, ref) => renderScrollComponent({ ...props, ref })),
416
+ () => React6.forwardRef((props, ref) => renderScrollComponent({ ...props, ref })),
334
417
  [renderScrollComponent]
335
418
  ) : ScrollView;
336
- const additionalSize = { marginTop: animScrollAdjust, paddingTop: animPaddingTop };
337
- return /* @__PURE__ */ React5.createElement(
419
+ return /* @__PURE__ */ React6.createElement(
338
420
  ScrollComponent,
339
421
  {
340
422
  ...rest,
@@ -352,8 +434,8 @@ var ListComponent = React5.memo(function ListComponent2({
352
434
  contentOffset: initialContentOffset ? horizontal ? { x: initialContentOffset, y: 0 } : { x: 0, y: initialContentOffset } : void 0,
353
435
  ref: refScrollView
354
436
  },
355
- /* @__PURE__ */ React5.createElement(Animated.View, { style: additionalSize }),
356
- ListHeaderComponent && /* @__PURE__ */ React5.createElement(
437
+ ENABLE_DEVMODE ? /* @__PURE__ */ React6.createElement(PaddingAndAdjustDevMode, null) : /* @__PURE__ */ React6.createElement(PaddingAndAdjust, null),
438
+ ListHeaderComponent && /* @__PURE__ */ React6.createElement(
357
439
  Animated.View,
358
440
  {
359
441
  style: ListHeaderComponentStyle,
@@ -368,7 +450,7 @@ var ListComponent = React5.memo(function ListComponent2({
368
450
  getComponent(ListHeaderComponent)
369
451
  ),
370
452
  ListEmptyComponent && getComponent(ListEmptyComponent),
371
- /* @__PURE__ */ React5.createElement(
453
+ /* @__PURE__ */ React6.createElement(
372
454
  Containers,
373
455
  {
374
456
  horizontal,
@@ -379,7 +461,7 @@ var ListComponent = React5.memo(function ListComponent2({
379
461
  updateItemSize
380
462
  }
381
463
  ),
382
- ListFooterComponent && /* @__PURE__ */ React5.createElement(View, { style: ListFooterComponentStyle }, getComponent(ListFooterComponent))
464
+ ListFooterComponent && /* @__PURE__ */ React6.createElement(View, { style: ListFooterComponentStyle }, getComponent(ListFooterComponent))
383
465
  );
384
466
  });
385
467
 
@@ -390,7 +472,6 @@ var ScrollAdjustHandler = class {
390
472
  this.appliedAdjust = 0;
391
473
  this.pendingAdjust = 0;
392
474
  this.busy = false;
393
- this.firstAdjust = true;
394
475
  this.context = ctx;
395
476
  }
396
477
  requestAdjust(adjust, onAdjusted) {
@@ -407,18 +488,14 @@ var ScrollAdjustHandler = class {
407
488
  };
408
489
  if (!this.busy) {
409
490
  this.busy = true;
410
- if (this.firstAdjust) {
411
- this.firstAdjust = false;
412
- setTimeout(doAjdust, 50);
413
- } else {
414
- doAjdust();
415
- }
491
+ doAjdust();
416
492
  }
417
493
  }
418
494
  getAppliedAdjust() {
419
495
  return this.appliedAdjust;
420
496
  }
421
497
  };
498
+ var typedForwardRef = forwardRef;
422
499
  var useCombinedRef = (...refs) => {
423
500
  const callback = useCallback((element) => {
424
501
  for (const ref of refs) {
@@ -585,13 +662,13 @@ function maybeUpdateViewabilityCallback(ctx, configId, viewToken) {
585
662
  // src/LegendList.tsx
586
663
  var DEFAULT_DRAW_DISTANCE = 250;
587
664
  var DEFAULT_ITEM_SIZE = 100;
588
- var LegendList = forwardRef(function LegendList2(props, forwardedRef) {
589
- return /* @__PURE__ */ React5.createElement(StateProvider, null, /* @__PURE__ */ React5.createElement(LegendListInner, { ...props, ref: forwardedRef }));
665
+ var LegendList = typedForwardRef(function LegendList2(props, forwardedRef) {
666
+ return /* @__PURE__ */ React6.createElement(StateProvider, null, /* @__PURE__ */ React6.createElement(LegendListInner, { ...props, ref: forwardedRef }));
590
667
  });
591
- var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef) {
668
+ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwardedRef) {
592
669
  var _a, _b, _c, _d, _e, _f, _g;
593
670
  const {
594
- data,
671
+ data: dataProp,
595
672
  initialScrollIndex,
596
673
  initialScrollOffset,
597
674
  horizontal,
@@ -633,24 +710,25 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
633
710
  const refState = useRef();
634
711
  const getId = (index) => {
635
712
  var _a2;
636
- const data2 = (_a2 = refState.current) == null ? void 0 : _a2.data;
637
- if (!data2) {
713
+ const data = (_a2 = refState.current) == null ? void 0 : _a2.data;
714
+ if (!data) {
638
715
  return "";
639
716
  }
640
- const ret = index < data2.length ? keyExtractor ? keyExtractor(data2[index], index) : index : null;
717
+ const ret = index < data.length ? keyExtractor ? keyExtractor(data[index], index) : index : null;
641
718
  return `${ret}`;
642
719
  };
643
- const getItemSize = (key, index, data2) => {
720
+ const getItemSize = (key, index, data) => {
644
721
  var _a2;
645
722
  const sizeKnown = refState.current.sizes.get(key);
646
723
  if (sizeKnown !== void 0) {
647
724
  return sizeKnown;
648
725
  }
649
- const size = (_a2 = getEstimatedItemSize ? getEstimatedItemSize(index, data2) : estimatedItemSize) != null ? _a2 : DEFAULT_ITEM_SIZE;
726
+ const size = (_a2 = getEstimatedItemSize ? getEstimatedItemSize(index, data) : estimatedItemSize) != null ? _a2 : DEFAULT_ITEM_SIZE;
650
727
  refState.current.sizes.set(key, size);
651
728
  return size;
652
729
  };
653
730
  const calculateInitialOffset = (index = initialScrollIndex) => {
731
+ const data = dataProp;
654
732
  if (index) {
655
733
  let offset = 0;
656
734
  if (getEstimatedItemSize) {
@@ -677,7 +755,7 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
677
755
  isEndReached: false,
678
756
  isAtBottom: false,
679
757
  isAtTop: false,
680
- data,
758
+ data: dataProp,
681
759
  idsInFirstRender: void 0,
682
760
  hasScrolled: false,
683
761
  scrollLength: initialScrollLength,
@@ -709,14 +787,14 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
709
787
  enableScrollForNextCalculateItemsInView: true,
710
788
  minIndexSizeChanged: 0
711
789
  };
712
- refState.current.idsInFirstRender = new Set(data.map((_, i) => getId(i)));
790
+ refState.current.idsInFirstRender = new Set(dataProp.map((_, i) => getId(i)));
713
791
  if (maintainVisibleContentPosition) {
714
792
  if (initialScrollIndex) {
715
793
  refState.current.anchorElement = {
716
794
  coordinate: initialContentOffset,
717
795
  id: getId(initialScrollIndex)
718
796
  };
719
- } else if (data.length) {
797
+ } else if (dataProp.length) {
720
798
  refState.current.anchorElement = {
721
799
  coordinate: initialContentOffset,
722
800
  id: getId(0)
@@ -739,7 +817,7 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
739
817
  };
740
818
  const addTotalSize = useCallback((key, add, totalSizeBelowAnchor) => {
741
819
  const state = refState.current;
742
- const { scrollLength, indexByKey, anchorElement } = state;
820
+ const { indexByKey, anchorElement } = state;
743
821
  const index = key === null ? 0 : indexByKey.get(key);
744
822
  let isAboveAnchor = false;
745
823
  if (maintainVisibleContentPosition) {
@@ -756,10 +834,9 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
756
834
  state.totalSizeBelowAnchor += add;
757
835
  }
758
836
  }
759
- let applyAdjustValue = void 0;
760
- const totalSize = state.totalSize;
761
- let resultSize = totalSize;
762
- if (maintainVisibleContentPosition) {
837
+ let applyAdjustValue = 0;
838
+ let resultSize = state.totalSize;
839
+ if (maintainVisibleContentPosition && anchorElement !== void 0) {
763
840
  const newAdjust = anchorElement.coordinate - state.totalSizeBelowAnchor;
764
841
  applyAdjustValue = -newAdjust;
765
842
  state.belowAnchorElementPositions = buildElementPositionsBelowAnchor();
@@ -777,7 +854,7 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
777
854
  }
778
855
  }, []);
779
856
  const getRowHeight = (n) => {
780
- const { rowHeights } = refState.current;
857
+ const { rowHeights, data } = refState.current;
781
858
  if (numColumnsProp === 1) {
782
859
  const id = getId(n);
783
860
  return getItemSize(id, n, data[n]);
@@ -830,7 +907,7 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
830
907
  const calculateItemsInView = useCallback((speed) => {
831
908
  const state = refState.current;
832
909
  const {
833
- data: data2,
910
+ data,
834
911
  scrollLength,
835
912
  scroll: scrollState,
836
913
  startBufferedId: startBufferedIdOrig,
@@ -841,7 +918,7 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
841
918
  if (state.waitingForMicrotask) {
842
919
  state.waitingForMicrotask = false;
843
920
  }
844
- if (!data2) {
921
+ if (!data) {
845
922
  return;
846
923
  }
847
924
  const topPad = (peek$(ctx, "stylePaddingTop") || 0) + (peek$(ctx, "headerSize") || 0);
@@ -887,7 +964,7 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
887
964
  }
888
965
  const top2 = newPosition || positions.get(id);
889
966
  if (top2 !== void 0) {
890
- const size = getItemSize(id, i, data2[i]);
967
+ const size = getItemSize(id, i, data[i]);
891
968
  const bottom = top2 + size;
892
969
  if (bottom > scroll - scrollBuffer) {
893
970
  loopStart = i;
@@ -916,9 +993,9 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
916
993
  }
917
994
  return topOffset;
918
995
  };
919
- for (let i = loopStart; i < data2.length; i++) {
996
+ for (let i = loopStart; i < data.length; i++) {
920
997
  const id = getId(i);
921
- const size = getItemSize(id, i, data2[i]);
998
+ const size = getItemSize(id, i, data[i]);
922
999
  maxSizeInRow = Math.max(maxSizeInRow, size);
923
1000
  if (top === void 0) {
924
1001
  top = getInitialTop(i);
@@ -1006,13 +1083,13 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
1006
1083
  if (furthestIndex >= 0) {
1007
1084
  set$(ctx, `containerItemKey${furthestIndex}`, id);
1008
1085
  const index = state.indexByKey.get(id);
1009
- set$(ctx, `containerItemData${furthestIndex}`, data2[index]);
1086
+ set$(ctx, `containerItemData${furthestIndex}`, data[index]);
1010
1087
  } else {
1011
1088
  const containerId = numContainers;
1012
1089
  numContainers++;
1013
1090
  set$(ctx, `containerItemKey${containerId}`, id);
1014
1091
  const index = state.indexByKey.get(id);
1015
- set$(ctx, `containerItemData${containerId}`, data2[index]);
1092
+ set$(ctx, `containerItemData${containerId}`, data[index]);
1016
1093
  set$(ctx, `containerPosition${containerId}`, ANCHORED_POSITION_OUT_OF_VIEW);
1017
1094
  set$(ctx, `containerColumn${containerId}`, -1);
1018
1095
  if (__DEV__ && numContainers > peek$(ctx, "numContainersPooled")) {
@@ -1033,13 +1110,13 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
1033
1110
  for (let i = 0; i < numContainers; i++) {
1034
1111
  const itemKey = peek$(ctx, `containerItemKey${i}`);
1035
1112
  const itemIndex = state.indexByKey.get(itemKey);
1036
- const item = data2[itemIndex];
1113
+ const item = data[itemIndex];
1037
1114
  if (item) {
1038
1115
  const id = getId(itemIndex);
1039
1116
  if (itemKey !== id || itemIndex < startBuffered || itemIndex > endBuffered) {
1040
1117
  const prevPos = peek$(ctx, `containerPosition${i}`).top;
1041
1118
  const pos = positions.get(id) || 0;
1042
- const size = getItemSize(id, itemIndex, data2[i]);
1119
+ const size = getItemSize(id, itemIndex, data[i]);
1043
1120
  if (pos + size >= scroll && pos <= scrollBottom || prevPos + size >= scroll && prevPos <= scrollBottom) {
1044
1121
  set$(ctx, `containerPosition${i}`, ANCHORED_POSITION_OUT_OF_VIEW);
1045
1122
  }
@@ -1053,7 +1130,7 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
1053
1130
  if (maintainVisibleContentPosition && itemIndex < anchorElementIndex) {
1054
1131
  const currentRow = Math.floor(itemIndex / numColumnsProp);
1055
1132
  const rowHeight = getRowHeight(currentRow);
1056
- const elementHeight = getItemSize(id, itemIndex, data2[i]);
1133
+ const elementHeight = getItemSize(id, itemIndex, data[i]);
1057
1134
  const diff = rowHeight - elementHeight;
1058
1135
  pos.relativeCoordinate = pos.top + getRowHeight(currentRow) - diff;
1059
1136
  pos.type = "bottom";
@@ -1068,7 +1145,7 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
1068
1145
  set$(ctx, `containerColumn${i}`, column2);
1069
1146
  }
1070
1147
  if (prevData !== item) {
1071
- set$(ctx, `containerItemData${i}`, data2[itemIndex]);
1148
+ set$(ctx, `containerItemData${i}`, data[itemIndex]);
1072
1149
  }
1073
1150
  }
1074
1151
  }
@@ -1098,7 +1175,10 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
1098
1175
  const doMaintainScrollAtEnd = (animated) => {
1099
1176
  const state = refState.current;
1100
1177
  if ((state == null ? void 0 : state.isAtBottom) && maintainScrollAtEnd) {
1101
- state.scroll = state.totalSize - state.scrollLength + peek$(ctx, "paddingTop");
1178
+ const paddingTop = peek$(ctx, "paddingTop") || 0;
1179
+ if (paddingTop > 0) {
1180
+ state.scroll = 0;
1181
+ }
1102
1182
  requestAnimationFrame(() => {
1103
1183
  var _a2;
1104
1184
  (_a2 = refScroller.current) == null ? void 0 : _a2.scrollToEnd({
@@ -1114,21 +1194,19 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
1114
1194
  }
1115
1195
  const { scrollLength, scroll, totalSize } = refState.current;
1116
1196
  if (totalSize > 0) {
1117
- const distanceFromEnd = totalSize - scroll - scrollLength;
1197
+ const distanceFromEnd = totalSize - scroll - scrollLength + (peek$(ctx, "paddingTop") || 0);
1118
1198
  if (refState.current) {
1119
1199
  refState.current.isAtBottom = distanceFromEnd < scrollLength * maintainScrollAtEndThreshold;
1120
1200
  }
1121
- const { onEndReached } = callbacks.current;
1122
- if (onEndReached) {
1123
- if (!refState.current.isEndReached) {
1124
- if (distanceFromEnd < onEndReachedThreshold * scrollLength) {
1125
- refState.current.isEndReached = true;
1126
- onEndReached({ distanceFromEnd });
1127
- }
1128
- } else {
1129
- if (distanceFromEnd >= onEndReachedThreshold * scrollLength) {
1130
- refState.current.isEndReached = false;
1131
- }
1201
+ if (!refState.current.isEndReached) {
1202
+ if (distanceFromEnd < onEndReachedThreshold * scrollLength) {
1203
+ refState.current.isEndReached = true;
1204
+ const { onEndReached } = callbacks.current;
1205
+ onEndReached == null ? void 0 : onEndReached({ distanceFromEnd });
1206
+ }
1207
+ } else {
1208
+ if (distanceFromEnd >= onEndReachedThreshold * scrollLength) {
1209
+ refState.current.isEndReached = false;
1132
1210
  }
1133
1211
  }
1134
1212
  }
@@ -1140,29 +1218,27 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
1140
1218
  const { scrollLength, scroll } = refState.current;
1141
1219
  const distanceFromTop = scroll;
1142
1220
  refState.current.isAtTop = distanceFromTop < 0;
1143
- const { onStartReached } = callbacks.current;
1144
- if (onStartReached) {
1145
- if (!refState.current.isStartReached && !refState.current.startReachedBlockedByTimer) {
1146
- if (distanceFromTop < onStartReachedThreshold * scrollLength) {
1147
- refState.current.isStartReached = true;
1148
- onStartReached({ distanceFromStart: scroll });
1149
- refState.current.startReachedBlockedByTimer = true;
1150
- setTimeout(() => {
1151
- refState.current.startReachedBlockedByTimer = false;
1152
- }, 700);
1153
- }
1154
- } else {
1155
- if (distanceFromTop >= 1.3 * onStartReachedThreshold * scrollLength) {
1156
- refState.current.isStartReached = false;
1157
- }
1221
+ if (!refState.current.isStartReached && !refState.current.startReachedBlockedByTimer) {
1222
+ if (distanceFromTop < onStartReachedThreshold * scrollLength) {
1223
+ refState.current.isStartReached = true;
1224
+ const { onStartReached } = callbacks.current;
1225
+ onStartReached == null ? void 0 : onStartReached({ distanceFromStart: scroll });
1226
+ refState.current.startReachedBlockedByTimer = true;
1227
+ setTimeout(() => {
1228
+ refState.current.startReachedBlockedByTimer = false;
1229
+ }, 700);
1230
+ }
1231
+ } else {
1232
+ if (distanceFromTop >= 1.3 * onStartReachedThreshold * scrollLength) {
1233
+ refState.current.isStartReached = false;
1158
1234
  }
1159
1235
  }
1160
1236
  };
1161
- const checkResetContainers = (reset) => {
1237
+ const checkResetContainers = (isFirst2) => {
1162
1238
  const state = refState.current;
1163
1239
  if (state) {
1164
- state.data = data;
1165
- if (reset) {
1240
+ state.data = dataProp;
1241
+ if (!isFirst2) {
1166
1242
  refState.current.scrollForNextCalculateItemsInView = void 0;
1167
1243
  const numContainers = peek$(ctx, "numContainers");
1168
1244
  for (let i = 0; i < numContainers; i++) {
@@ -1178,28 +1254,28 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
1178
1254
  state.positions.clear();
1179
1255
  }
1180
1256
  calculateItemsInView(state.scrollVelocity);
1257
+ const didMaintainScrollAtEnd = doMaintainScrollAtEnd(false);
1258
+ if (!didMaintainScrollAtEnd && dataProp.length > state.data.length) {
1259
+ state.isEndReached = false;
1260
+ }
1261
+ checkAtTop();
1262
+ checkAtBottom();
1181
1263
  }
1182
- const didMaintainScrollAtEnd = doMaintainScrollAtEnd(false);
1183
- if (!didMaintainScrollAtEnd && data.length > state.data.length) {
1184
- state.isEndReached = false;
1185
- }
1186
- checkAtTop();
1187
- checkAtBottom();
1188
1264
  }
1189
1265
  };
1190
1266
  const isFirst = !refState.current.renderItem;
1191
- if (isFirst || data !== refState.current.data || numColumnsProp !== peek$(ctx, "numColumns")) {
1192
- if (!keyExtractorProp && !isFirst && data !== refState.current.data) {
1267
+ if (isFirst || dataProp !== refState.current.data || numColumnsProp !== peek$(ctx, "numColumns")) {
1268
+ if (!keyExtractorProp && !isFirst && dataProp !== refState.current.data) {
1193
1269
  refState.current.positions.clear();
1194
1270
  }
1195
- refState.current.data = data;
1271
+ refState.current.data = dataProp;
1196
1272
  let totalSize = 0;
1197
1273
  let totalSizeBelowIndex = 0;
1198
1274
  const indexByKey = /* @__PURE__ */ new Map();
1199
1275
  const newPositions = /* @__PURE__ */ new Map();
1200
1276
  let column = 1;
1201
1277
  let maxSizeInRow = 0;
1202
- for (let i = 0; i < data.length; i++) {
1278
+ for (let i = 0; i < dataProp.length; i++) {
1203
1279
  const key = getId(i);
1204
1280
  if (__DEV__) {
1205
1281
  if (indexByKey.has(key)) {
@@ -1218,7 +1294,7 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
1218
1294
  if (!isFirst) {
1219
1295
  if (maintainVisibleContentPosition) {
1220
1296
  if (refState.current.anchorElement == null || indexByKey.get(refState.current.anchorElement.id) == null) {
1221
- if (data.length) {
1297
+ if (dataProp.length) {
1222
1298
  const newAnchorElement = {
1223
1299
  coordinate: 0,
1224
1300
  id: getId(0)
@@ -1235,7 +1311,7 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
1235
1311
  }
1236
1312
  } else {
1237
1313
  if (refState.current.startBufferedId != null && newPositions.get(refState.current.startBufferedId) == null) {
1238
- if (data.length) {
1314
+ if (dataProp.length) {
1239
1315
  refState.current.startBufferedId = getId(0);
1240
1316
  } else {
1241
1317
  refState.current.startBufferedId = void 0;
@@ -1248,9 +1324,9 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
1248
1324
  }
1249
1325
  }
1250
1326
  const anchorElementIndex = getAnchorElementIndex();
1251
- for (let i = 0; i < data.length; i++) {
1327
+ for (let i = 0; i < dataProp.length; i++) {
1252
1328
  const key = getId(i);
1253
- const size = getItemSize(key, i, data[i]);
1329
+ const size = getItemSize(key, i, dataProp[i]);
1254
1330
  maxSizeInRow = Math.max(maxSizeInRow, size);
1255
1331
  column++;
1256
1332
  if (column > numColumnsProp) {
@@ -1269,15 +1345,15 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
1269
1345
  }
1270
1346
  useEffect(() => {
1271
1347
  checkResetContainers(
1272
- /*reset*/
1273
- !isFirst
1348
+ /*isFirst*/
1349
+ isFirst
1274
1350
  );
1275
- }, [isFirst, data, numColumnsProp]);
1351
+ }, [isFirst, dataProp, numColumnsProp]);
1276
1352
  useEffect(() => {
1277
1353
  set$(ctx, "extraData", extraData);
1278
1354
  }, [extraData]);
1279
1355
  refState.current.renderItem = renderItem;
1280
- const lastItemKey = data.length > 0 ? getId(data.length - 1) : void 0;
1356
+ const lastItemKey = dataProp.length > 0 ? getId(dataProp.length - 1) : void 0;
1281
1357
  const stylePaddingTop = (_g = (_f = (_d = StyleSheet.flatten(style)) == null ? void 0 : _d.paddingTop) != null ? _f : (_e = StyleSheet.flatten(contentContainerStyle)) == null ? void 0 : _e.paddingTop) != null ? _g : 0;
1282
1358
  const initalizeStateVars = () => {
1283
1359
  set$(ctx, "lastItemKey", lastItemKey);
@@ -1294,7 +1370,7 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
1294
1370
  if (!state) {
1295
1371
  return null;
1296
1372
  }
1297
- const { data: data2, indexByKey } = state;
1373
+ const { data, indexByKey } = state;
1298
1374
  const index = indexByKey.get(key);
1299
1375
  if (index === void 0) {
1300
1376
  return null;
@@ -1312,7 +1388,7 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
1312
1388
  return useRecyclingState(valueOrFun);
1313
1389
  };
1314
1390
  const renderedItem = (_b2 = (_a2 = refState.current).renderItem) == null ? void 0 : _b2.call(_a2, {
1315
- item: data2[index],
1391
+ item: data[index],
1316
1392
  index,
1317
1393
  useViewability: useViewability2,
1318
1394
  useViewabilityAmount: useViewabilityAmount2,
@@ -1328,7 +1404,7 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
1328
1404
  state.viewabilityConfigCallbackPairs = viewability;
1329
1405
  state.enableScrollForNextCalculateItemsInView = !viewability;
1330
1406
  const scrollLength = state.scrollLength;
1331
- const averageItemSize = (_a2 = estimatedItemSize != null ? estimatedItemSize : getEstimatedItemSize == null ? void 0 : getEstimatedItemSize(0, data[0])) != null ? _a2 : DEFAULT_ITEM_SIZE;
1407
+ const averageItemSize = (_a2 = estimatedItemSize != null ? estimatedItemSize : getEstimatedItemSize == null ? void 0 : getEstimatedItemSize(0, dataProp[0])) != null ? _a2 : DEFAULT_ITEM_SIZE;
1332
1408
  const numContainers = Math.ceil((scrollLength + scrollBuffer * 2) / averageItemSize) * numColumnsProp;
1333
1409
  for (let i = 0; i < numContainers; i++) {
1334
1410
  set$(ctx, `containerPosition${i}`, ANCHORED_POSITION_OUT_OF_VIEW);
@@ -1336,31 +1412,33 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
1336
1412
  }
1337
1413
  set$(ctx, "numContainers", numContainers);
1338
1414
  set$(ctx, "numContainersPooled", numContainers * 2);
1339
- calculateItemsInView(state.scrollVelocity);
1415
+ if (initialScrollIndex) {
1416
+ requestAnimationFrame(() => {
1417
+ calculateItemsInView(state.scrollVelocity);
1418
+ });
1419
+ } else {
1420
+ calculateItemsInView(state.scrollVelocity);
1421
+ }
1340
1422
  });
1341
1423
  const updateItemSize = useCallback((containerId, itemKey, size) => {
1342
1424
  const state = refState.current;
1343
- const { sizes, indexByKey, columns, sizesLaidOut, data: data2 } = state;
1344
- if (!data2) {
1425
+ const { sizes, indexByKey, columns, sizesLaidOut, data, rowHeights } = state;
1426
+ if (!data) {
1345
1427
  return;
1346
1428
  }
1347
1429
  const index = indexByKey.get(itemKey);
1348
1430
  const numColumns = peek$(ctx, "numColumns");
1349
1431
  state.minIndexSizeChanged = state.minIndexSizeChanged !== void 0 ? Math.min(state.minIndexSizeChanged, index) : index;
1350
- const prevSize = getItemSize(itemKey, index, data2);
1432
+ const prevSize = getItemSize(itemKey, index, data);
1351
1433
  if (!prevSize || Math.abs(prevSize - size) > 0.5) {
1352
1434
  let diff;
1353
1435
  if (numColumns > 1) {
1436
+ const rowNumber = Math.floor(index / numColumnsProp);
1437
+ const prevSizeInRow = getRowHeight(rowNumber);
1354
1438
  sizes.set(itemKey, size);
1355
- const column = columns.get(itemKey);
1356
- const loopStart = index - (column - 1);
1357
- let nextMaxSizeInRow = 0;
1358
- for (let i = loopStart; i < loopStart + numColumns && i < data2.length; i++) {
1359
- const id = getId(i);
1360
- const size2 = getItemSize(id, i, data2[i]);
1361
- nextMaxSizeInRow = Math.max(nextMaxSizeInRow, size2);
1362
- }
1363
- diff = nextMaxSizeInRow - prevSize;
1439
+ rowHeights.delete(rowNumber);
1440
+ const sizeInRow = getRowHeight(rowNumber);
1441
+ diff = sizeInRow - prevSizeInRow;
1364
1442
  } else {
1365
1443
  sizes.set(itemKey, size);
1366
1444
  diff = size - prevSize;
@@ -1402,7 +1480,7 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
1402
1480
  }
1403
1481
  }
1404
1482
  if (onItemSizeChanged) {
1405
- onItemSizeChanged({ size, previous: prevSize, index, itemKey, itemData: data2[index] });
1483
+ onItemSizeChanged({ size, previous: prevSize, index, itemKey, itemData: data[index] });
1406
1484
  }
1407
1485
  }
1408
1486
  }, []);
@@ -1496,6 +1574,7 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
1496
1574
  refScroller.current.scrollTo({ ...offsetObj, animated });
1497
1575
  },
1498
1576
  scrollToItem: ({ item, animated }) => {
1577
+ const { data } = refState.current;
1499
1578
  const index = data.indexOf(item);
1500
1579
  if (index !== -1) {
1501
1580
  scrollToIndex({ index, animated });
@@ -1506,7 +1585,7 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
1506
1585
  },
1507
1586
  []
1508
1587
  );
1509
- return /* @__PURE__ */ React5.createElement(
1588
+ return /* @__PURE__ */ React6.createElement(React6.Fragment, null, /* @__PURE__ */ React6.createElement(
1510
1589
  ListComponent,
1511
1590
  {
1512
1591
  ...rest,
@@ -1519,13 +1598,13 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
1519
1598
  onLayout,
1520
1599
  recycleItems,
1521
1600
  alignItemsAtEnd,
1522
- ListEmptyComponent: data.length === 0 ? ListEmptyComponent : void 0,
1601
+ ListEmptyComponent: dataProp.length === 0 ? ListEmptyComponent : void 0,
1523
1602
  maintainVisibleContentPosition,
1524
1603
  scrollEventThrottle: scrollEventThrottle != null ? scrollEventThrottle : Platform.OS === "web" ? 16 : void 0,
1525
1604
  waitForInitialLayout,
1526
1605
  style
1527
1606
  }
1528
- );
1607
+ ), __DEV__ && ENABLE_DEBUG_VIEW && /* @__PURE__ */ React6.createElement(DebugView, { state: refState.current }));
1529
1608
  });
1530
1609
 
1531
1610
  export { LegendList, useRecyclingEffect, useRecyclingState, useViewability, useViewabilityAmount };