@legendapp/list 1.0.0-beta.10 → 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,29 @@ 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;
499
+ var useCombinedRef = (...refs) => {
500
+ const callback = useCallback((element) => {
501
+ for (const ref of refs) {
502
+ if (!ref) {
503
+ continue;
504
+ }
505
+ if (typeof ref === "function") {
506
+ ref(element);
507
+ } else {
508
+ ref.current = element;
509
+ }
510
+ }
511
+ }, refs);
512
+ return callback;
513
+ };
422
514
 
423
515
  // src/viewability.ts
424
516
  var mapViewabilityConfigCallbackPairs = /* @__PURE__ */ new Map();
@@ -570,13 +662,13 @@ function maybeUpdateViewabilityCallback(ctx, configId, viewToken) {
570
662
  // src/LegendList.tsx
571
663
  var DEFAULT_DRAW_DISTANCE = 250;
572
664
  var DEFAULT_ITEM_SIZE = 100;
573
- var LegendList = forwardRef(function LegendList2(props, forwardedRef) {
574
- 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 }));
575
667
  });
576
- var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef) {
668
+ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwardedRef) {
577
669
  var _a, _b, _c, _d, _e, _f, _g;
578
670
  const {
579
- data,
671
+ data: dataProp,
580
672
  initialScrollIndex,
581
673
  initialScrollOffset,
582
674
  horizontal,
@@ -612,29 +704,31 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
612
704
  callbacks.current.onEndReached = rest.onEndReached;
613
705
  const ctx = useStateContext();
614
706
  const refScroller = useRef(null);
707
+ const combinedRef = useCombinedRef(refScroller, refScrollView);
615
708
  const scrollBuffer = drawDistance != null ? drawDistance : DEFAULT_DRAW_DISTANCE;
616
709
  const keyExtractor = keyExtractorProp != null ? keyExtractorProp : (item, index) => index.toString();
617
710
  const refState = useRef();
618
711
  const getId = (index) => {
619
712
  var _a2;
620
- const data2 = (_a2 = refState.current) == null ? void 0 : _a2.data;
621
- if (!data2) {
713
+ const data = (_a2 = refState.current) == null ? void 0 : _a2.data;
714
+ if (!data) {
622
715
  return "";
623
716
  }
624
- 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;
625
718
  return `${ret}`;
626
719
  };
627
- const getItemSize = (key, index, data2) => {
720
+ const getItemSize = (key, index, data) => {
628
721
  var _a2;
629
722
  const sizeKnown = refState.current.sizes.get(key);
630
723
  if (sizeKnown !== void 0) {
631
724
  return sizeKnown;
632
725
  }
633
- 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;
634
727
  refState.current.sizes.set(key, size);
635
728
  return size;
636
729
  };
637
730
  const calculateInitialOffset = (index = initialScrollIndex) => {
731
+ const data = dataProp;
638
732
  if (index) {
639
733
  let offset = 0;
640
734
  if (getEstimatedItemSize) {
@@ -661,7 +755,7 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
661
755
  isEndReached: false,
662
756
  isAtBottom: false,
663
757
  isAtTop: false,
664
- data,
758
+ data: dataProp,
665
759
  idsInFirstRender: void 0,
666
760
  hasScrolled: false,
667
761
  scrollLength: initialScrollLength,
@@ -693,14 +787,14 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
693
787
  enableScrollForNextCalculateItemsInView: true,
694
788
  minIndexSizeChanged: 0
695
789
  };
696
- refState.current.idsInFirstRender = new Set(data.map((_, i) => getId(i)));
790
+ refState.current.idsInFirstRender = new Set(dataProp.map((_, i) => getId(i)));
697
791
  if (maintainVisibleContentPosition) {
698
792
  if (initialScrollIndex) {
699
793
  refState.current.anchorElement = {
700
794
  coordinate: initialContentOffset,
701
795
  id: getId(initialScrollIndex)
702
796
  };
703
- } else if (data.length) {
797
+ } else if (dataProp.length) {
704
798
  refState.current.anchorElement = {
705
799
  coordinate: initialContentOffset,
706
800
  id: getId(0)
@@ -723,7 +817,7 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
723
817
  };
724
818
  const addTotalSize = useCallback((key, add, totalSizeBelowAnchor) => {
725
819
  const state = refState.current;
726
- const { scrollLength, indexByKey, anchorElement } = state;
820
+ const { indexByKey, anchorElement } = state;
727
821
  const index = key === null ? 0 : indexByKey.get(key);
728
822
  let isAboveAnchor = false;
729
823
  if (maintainVisibleContentPosition) {
@@ -740,10 +834,9 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
740
834
  state.totalSizeBelowAnchor += add;
741
835
  }
742
836
  }
743
- let applyAdjustValue = void 0;
744
- const totalSize = state.totalSize;
745
- let resultSize = totalSize;
746
- if (maintainVisibleContentPosition && totalSize > scrollLength) {
837
+ let applyAdjustValue = 0;
838
+ let resultSize = state.totalSize;
839
+ if (maintainVisibleContentPosition && anchorElement !== void 0) {
747
840
  const newAdjust = anchorElement.coordinate - state.totalSizeBelowAnchor;
748
841
  applyAdjustValue = -newAdjust;
749
842
  state.belowAnchorElementPositions = buildElementPositionsBelowAnchor();
@@ -761,7 +854,7 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
761
854
  }
762
855
  }, []);
763
856
  const getRowHeight = (n) => {
764
- const { rowHeights } = refState.current;
857
+ const { rowHeights, data } = refState.current;
765
858
  if (numColumnsProp === 1) {
766
859
  const id = getId(n);
767
860
  return getItemSize(id, n, data[n]);
@@ -814,7 +907,7 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
814
907
  const calculateItemsInView = useCallback((speed) => {
815
908
  const state = refState.current;
816
909
  const {
817
- data: data2,
910
+ data,
818
911
  scrollLength,
819
912
  scroll: scrollState,
820
913
  startBufferedId: startBufferedIdOrig,
@@ -825,7 +918,7 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
825
918
  if (state.waitingForMicrotask) {
826
919
  state.waitingForMicrotask = false;
827
920
  }
828
- if (!data2) {
921
+ if (!data) {
829
922
  return;
830
923
  }
831
924
  const topPad = (peek$(ctx, "stylePaddingTop") || 0) + (peek$(ctx, "headerSize") || 0);
@@ -871,7 +964,7 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
871
964
  }
872
965
  const top2 = newPosition || positions.get(id);
873
966
  if (top2 !== void 0) {
874
- const size = getItemSize(id, i, data2[i]);
967
+ const size = getItemSize(id, i, data[i]);
875
968
  const bottom = top2 + size;
876
969
  if (bottom > scroll - scrollBuffer) {
877
970
  loopStart = i;
@@ -900,9 +993,9 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
900
993
  }
901
994
  return topOffset;
902
995
  };
903
- for (let i = loopStart; i < data2.length; i++) {
996
+ for (let i = loopStart; i < data.length; i++) {
904
997
  const id = getId(i);
905
- const size = getItemSize(id, i, data2[i]);
998
+ const size = getItemSize(id, i, data[i]);
906
999
  maxSizeInRow = Math.max(maxSizeInRow, size);
907
1000
  if (top === void 0) {
908
1001
  top = getInitialTop(i);
@@ -990,13 +1083,13 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
990
1083
  if (furthestIndex >= 0) {
991
1084
  set$(ctx, `containerItemKey${furthestIndex}`, id);
992
1085
  const index = state.indexByKey.get(id);
993
- set$(ctx, `containerItemData${furthestIndex}`, data2[index]);
1086
+ set$(ctx, `containerItemData${furthestIndex}`, data[index]);
994
1087
  } else {
995
1088
  const containerId = numContainers;
996
1089
  numContainers++;
997
1090
  set$(ctx, `containerItemKey${containerId}`, id);
998
1091
  const index = state.indexByKey.get(id);
999
- set$(ctx, `containerItemData${containerId}`, data2[index]);
1092
+ set$(ctx, `containerItemData${containerId}`, data[index]);
1000
1093
  set$(ctx, `containerPosition${containerId}`, ANCHORED_POSITION_OUT_OF_VIEW);
1001
1094
  set$(ctx, `containerColumn${containerId}`, -1);
1002
1095
  if (__DEV__ && numContainers > peek$(ctx, "numContainersPooled")) {
@@ -1017,13 +1110,13 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
1017
1110
  for (let i = 0; i < numContainers; i++) {
1018
1111
  const itemKey = peek$(ctx, `containerItemKey${i}`);
1019
1112
  const itemIndex = state.indexByKey.get(itemKey);
1020
- const item = data2[itemIndex];
1113
+ const item = data[itemIndex];
1021
1114
  if (item) {
1022
1115
  const id = getId(itemIndex);
1023
1116
  if (itemKey !== id || itemIndex < startBuffered || itemIndex > endBuffered) {
1024
1117
  const prevPos = peek$(ctx, `containerPosition${i}`).top;
1025
1118
  const pos = positions.get(id) || 0;
1026
- const size = getItemSize(id, itemIndex, data2[i]);
1119
+ const size = getItemSize(id, itemIndex, data[i]);
1027
1120
  if (pos + size >= scroll && pos <= scrollBottom || prevPos + size >= scroll && prevPos <= scrollBottom) {
1028
1121
  set$(ctx, `containerPosition${i}`, ANCHORED_POSITION_OUT_OF_VIEW);
1029
1122
  }
@@ -1037,7 +1130,7 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
1037
1130
  if (maintainVisibleContentPosition && itemIndex < anchorElementIndex) {
1038
1131
  const currentRow = Math.floor(itemIndex / numColumnsProp);
1039
1132
  const rowHeight = getRowHeight(currentRow);
1040
- const elementHeight = getItemSize(id, itemIndex, data2[i]);
1133
+ const elementHeight = getItemSize(id, itemIndex, data[i]);
1041
1134
  const diff = rowHeight - elementHeight;
1042
1135
  pos.relativeCoordinate = pos.top + getRowHeight(currentRow) - diff;
1043
1136
  pos.type = "bottom";
@@ -1052,7 +1145,7 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
1052
1145
  set$(ctx, `containerColumn${i}`, column2);
1053
1146
  }
1054
1147
  if (prevData !== item) {
1055
- set$(ctx, `containerItemData${i}`, data2[itemIndex]);
1148
+ set$(ctx, `containerItemData${i}`, data[itemIndex]);
1056
1149
  }
1057
1150
  }
1058
1151
  }
@@ -1082,7 +1175,10 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
1082
1175
  const doMaintainScrollAtEnd = (animated) => {
1083
1176
  const state = refState.current;
1084
1177
  if ((state == null ? void 0 : state.isAtBottom) && maintainScrollAtEnd) {
1085
- 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
+ }
1086
1182
  requestAnimationFrame(() => {
1087
1183
  var _a2;
1088
1184
  (_a2 = refScroller.current) == null ? void 0 : _a2.scrollToEnd({
@@ -1098,21 +1194,19 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
1098
1194
  }
1099
1195
  const { scrollLength, scroll, totalSize } = refState.current;
1100
1196
  if (totalSize > 0) {
1101
- const distanceFromEnd = totalSize - scroll - scrollLength;
1197
+ const distanceFromEnd = totalSize - scroll - scrollLength + (peek$(ctx, "paddingTop") || 0);
1102
1198
  if (refState.current) {
1103
1199
  refState.current.isAtBottom = distanceFromEnd < scrollLength * maintainScrollAtEndThreshold;
1104
1200
  }
1105
- const { onEndReached } = callbacks.current;
1106
- if (onEndReached) {
1107
- if (!refState.current.isEndReached) {
1108
- if (distanceFromEnd < onEndReachedThreshold * scrollLength) {
1109
- refState.current.isEndReached = true;
1110
- onEndReached({ distanceFromEnd });
1111
- }
1112
- } else {
1113
- if (distanceFromEnd >= onEndReachedThreshold * scrollLength) {
1114
- refState.current.isEndReached = false;
1115
- }
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;
1116
1210
  }
1117
1211
  }
1118
1212
  }
@@ -1124,29 +1218,27 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
1124
1218
  const { scrollLength, scroll } = refState.current;
1125
1219
  const distanceFromTop = scroll;
1126
1220
  refState.current.isAtTop = distanceFromTop < 0;
1127
- const { onStartReached } = callbacks.current;
1128
- if (onStartReached) {
1129
- if (!refState.current.isStartReached && !refState.current.startReachedBlockedByTimer) {
1130
- if (distanceFromTop < onStartReachedThreshold * scrollLength) {
1131
- refState.current.isStartReached = true;
1132
- onStartReached({ distanceFromStart: scroll });
1133
- refState.current.startReachedBlockedByTimer = true;
1134
- setTimeout(() => {
1135
- refState.current.startReachedBlockedByTimer = false;
1136
- }, 700);
1137
- }
1138
- } else {
1139
- if (distanceFromTop >= 1.3 * onStartReachedThreshold * scrollLength) {
1140
- refState.current.isStartReached = false;
1141
- }
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;
1142
1234
  }
1143
1235
  }
1144
1236
  };
1145
- const checkResetContainers = (reset) => {
1237
+ const checkResetContainers = (isFirst2) => {
1146
1238
  const state = refState.current;
1147
1239
  if (state) {
1148
- state.data = data;
1149
- if (reset) {
1240
+ state.data = dataProp;
1241
+ if (!isFirst2) {
1150
1242
  refState.current.scrollForNextCalculateItemsInView = void 0;
1151
1243
  const numContainers = peek$(ctx, "numContainers");
1152
1244
  for (let i = 0; i < numContainers; i++) {
@@ -1162,28 +1254,28 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
1162
1254
  state.positions.clear();
1163
1255
  }
1164
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();
1165
1263
  }
1166
- const didMaintainScrollAtEnd = doMaintainScrollAtEnd(false);
1167
- if (!didMaintainScrollAtEnd && data.length > state.data.length) {
1168
- state.isEndReached = false;
1169
- }
1170
- checkAtTop();
1171
- checkAtBottom();
1172
1264
  }
1173
1265
  };
1174
1266
  const isFirst = !refState.current.renderItem;
1175
- if (isFirst || data !== refState.current.data || numColumnsProp !== peek$(ctx, "numColumns")) {
1176
- 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) {
1177
1269
  refState.current.positions.clear();
1178
1270
  }
1179
- refState.current.data = data;
1271
+ refState.current.data = dataProp;
1180
1272
  let totalSize = 0;
1181
1273
  let totalSizeBelowIndex = 0;
1182
1274
  const indexByKey = /* @__PURE__ */ new Map();
1183
1275
  const newPositions = /* @__PURE__ */ new Map();
1184
1276
  let column = 1;
1185
1277
  let maxSizeInRow = 0;
1186
- for (let i = 0; i < data.length; i++) {
1278
+ for (let i = 0; i < dataProp.length; i++) {
1187
1279
  const key = getId(i);
1188
1280
  if (__DEV__) {
1189
1281
  if (indexByKey.has(key)) {
@@ -1202,7 +1294,7 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
1202
1294
  if (!isFirst) {
1203
1295
  if (maintainVisibleContentPosition) {
1204
1296
  if (refState.current.anchorElement == null || indexByKey.get(refState.current.anchorElement.id) == null) {
1205
- if (data.length) {
1297
+ if (dataProp.length) {
1206
1298
  const newAnchorElement = {
1207
1299
  coordinate: 0,
1208
1300
  id: getId(0)
@@ -1219,7 +1311,7 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
1219
1311
  }
1220
1312
  } else {
1221
1313
  if (refState.current.startBufferedId != null && newPositions.get(refState.current.startBufferedId) == null) {
1222
- if (data.length) {
1314
+ if (dataProp.length) {
1223
1315
  refState.current.startBufferedId = getId(0);
1224
1316
  } else {
1225
1317
  refState.current.startBufferedId = void 0;
@@ -1232,9 +1324,9 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
1232
1324
  }
1233
1325
  }
1234
1326
  const anchorElementIndex = getAnchorElementIndex();
1235
- for (let i = 0; i < data.length; i++) {
1327
+ for (let i = 0; i < dataProp.length; i++) {
1236
1328
  const key = getId(i);
1237
- const size = getItemSize(key, i, data[i]);
1329
+ const size = getItemSize(key, i, dataProp[i]);
1238
1330
  maxSizeInRow = Math.max(maxSizeInRow, size);
1239
1331
  column++;
1240
1332
  if (column > numColumnsProp) {
@@ -1253,15 +1345,15 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
1253
1345
  }
1254
1346
  useEffect(() => {
1255
1347
  checkResetContainers(
1256
- /*reset*/
1257
- !isFirst
1348
+ /*isFirst*/
1349
+ isFirst
1258
1350
  );
1259
- }, [isFirst, data, numColumnsProp]);
1351
+ }, [isFirst, dataProp, numColumnsProp]);
1260
1352
  useEffect(() => {
1261
1353
  set$(ctx, "extraData", extraData);
1262
1354
  }, [extraData]);
1263
1355
  refState.current.renderItem = renderItem;
1264
- const lastItemKey = data.length > 0 ? getId(data.length - 1) : void 0;
1356
+ const lastItemKey = dataProp.length > 0 ? getId(dataProp.length - 1) : void 0;
1265
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;
1266
1358
  const initalizeStateVars = () => {
1267
1359
  set$(ctx, "lastItemKey", lastItemKey);
@@ -1278,7 +1370,7 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
1278
1370
  if (!state) {
1279
1371
  return null;
1280
1372
  }
1281
- const { data: data2, indexByKey } = state;
1373
+ const { data, indexByKey } = state;
1282
1374
  const index = indexByKey.get(key);
1283
1375
  if (index === void 0) {
1284
1376
  return null;
@@ -1296,7 +1388,7 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
1296
1388
  return useRecyclingState(valueOrFun);
1297
1389
  };
1298
1390
  const renderedItem = (_b2 = (_a2 = refState.current).renderItem) == null ? void 0 : _b2.call(_a2, {
1299
- item: data2[index],
1391
+ item: data[index],
1300
1392
  index,
1301
1393
  useViewability: useViewability2,
1302
1394
  useViewabilityAmount: useViewabilityAmount2,
@@ -1312,7 +1404,7 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
1312
1404
  state.viewabilityConfigCallbackPairs = viewability;
1313
1405
  state.enableScrollForNextCalculateItemsInView = !viewability;
1314
1406
  const scrollLength = state.scrollLength;
1315
- 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;
1316
1408
  const numContainers = Math.ceil((scrollLength + scrollBuffer * 2) / averageItemSize) * numColumnsProp;
1317
1409
  for (let i = 0; i < numContainers; i++) {
1318
1410
  set$(ctx, `containerPosition${i}`, ANCHORED_POSITION_OUT_OF_VIEW);
@@ -1320,31 +1412,33 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
1320
1412
  }
1321
1413
  set$(ctx, "numContainers", numContainers);
1322
1414
  set$(ctx, "numContainersPooled", numContainers * 2);
1323
- calculateItemsInView(state.scrollVelocity);
1415
+ if (initialScrollIndex) {
1416
+ requestAnimationFrame(() => {
1417
+ calculateItemsInView(state.scrollVelocity);
1418
+ });
1419
+ } else {
1420
+ calculateItemsInView(state.scrollVelocity);
1421
+ }
1324
1422
  });
1325
1423
  const updateItemSize = useCallback((containerId, itemKey, size) => {
1326
1424
  const state = refState.current;
1327
- const { sizes, indexByKey, columns, sizesLaidOut, data: data2 } = state;
1328
- if (!data2) {
1425
+ const { sizes, indexByKey, columns, sizesLaidOut, data, rowHeights } = state;
1426
+ if (!data) {
1329
1427
  return;
1330
1428
  }
1331
1429
  const index = indexByKey.get(itemKey);
1332
1430
  const numColumns = peek$(ctx, "numColumns");
1333
1431
  state.minIndexSizeChanged = state.minIndexSizeChanged !== void 0 ? Math.min(state.minIndexSizeChanged, index) : index;
1334
- const prevSize = getItemSize(itemKey, index, data2);
1432
+ const prevSize = getItemSize(itemKey, index, data);
1335
1433
  if (!prevSize || Math.abs(prevSize - size) > 0.5) {
1336
1434
  let diff;
1337
1435
  if (numColumns > 1) {
1436
+ const rowNumber = Math.floor(index / numColumnsProp);
1437
+ const prevSizeInRow = getRowHeight(rowNumber);
1338
1438
  sizes.set(itemKey, size);
1339
- const column = columns.get(itemKey);
1340
- const loopStart = index - (column - 1);
1341
- let nextMaxSizeInRow = 0;
1342
- for (let i = loopStart; i < loopStart + numColumns && i < data2.length; i++) {
1343
- const id = getId(i);
1344
- const size2 = getItemSize(id, i, data2[i]);
1345
- nextMaxSizeInRow = Math.max(nextMaxSizeInRow, size2);
1346
- }
1347
- diff = nextMaxSizeInRow - prevSize;
1439
+ rowHeights.delete(rowNumber);
1440
+ const sizeInRow = getRowHeight(rowNumber);
1441
+ diff = sizeInRow - prevSizeInRow;
1348
1442
  } else {
1349
1443
  sizes.set(itemKey, size);
1350
1444
  diff = size - prevSize;
@@ -1386,7 +1480,7 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
1386
1480
  }
1387
1481
  }
1388
1482
  if (onItemSizeChanged) {
1389
- onItemSizeChanged({ size, previous: prevSize, index, itemKey, itemData: data2[index] });
1483
+ onItemSizeChanged({ size, previous: prevSize, index, itemKey, itemData: data[index] });
1390
1484
  }
1391
1485
  }
1392
1486
  }, []);
@@ -1480,6 +1574,7 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
1480
1574
  refScroller.current.scrollTo({ ...offsetObj, animated });
1481
1575
  },
1482
1576
  scrollToItem: ({ item, animated }) => {
1577
+ const { data } = refState.current;
1483
1578
  const index = data.indexOf(item);
1484
1579
  if (index !== -1) {
1485
1580
  scrollToIndex({ index, animated });
@@ -1490,21 +1585,12 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
1490
1585
  },
1491
1586
  []
1492
1587
  );
1493
- return /* @__PURE__ */ React5.createElement(
1588
+ return /* @__PURE__ */ React6.createElement(React6.Fragment, null, /* @__PURE__ */ React6.createElement(
1494
1589
  ListComponent,
1495
1590
  {
1496
1591
  ...rest,
1497
1592
  horizontal,
1498
- refScrollView: (r) => {
1499
- refScroller.current = r;
1500
- if (refScrollView) {
1501
- if (typeof refScrollView === "function") {
1502
- refScrollView(r);
1503
- } else {
1504
- refScrollView.current = r;
1505
- }
1506
- }
1507
- },
1593
+ refScrollView: combinedRef,
1508
1594
  initialContentOffset,
1509
1595
  getRenderedItem,
1510
1596
  updateItemSize,
@@ -1512,13 +1598,13 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
1512
1598
  onLayout,
1513
1599
  recycleItems,
1514
1600
  alignItemsAtEnd,
1515
- ListEmptyComponent: data.length === 0 ? ListEmptyComponent : void 0,
1601
+ ListEmptyComponent: dataProp.length === 0 ? ListEmptyComponent : void 0,
1516
1602
  maintainVisibleContentPosition,
1517
1603
  scrollEventThrottle: scrollEventThrottle != null ? scrollEventThrottle : Platform.OS === "web" ? 16 : void 0,
1518
1604
  waitForInitialLayout,
1519
1605
  style
1520
1606
  }
1521
- );
1607
+ ), __DEV__ && ENABLE_DEBUG_VIEW && /* @__PURE__ */ React6.createElement(DebugView, { state: refState.current }));
1522
1608
  });
1523
1609
 
1524
1610
  export { LegendList, useRecyclingEffect, useRecyclingState, useViewability, useViewabilityAmount };