@legendapp/list 1.0.0-beta.11 → 1.0.0-beta.13

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, Platform, Animated, ScrollView, Dimensions, StyleSheet, 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,10 +141,40 @@ 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 LeanViewComponent = React6.forwardRef((props, ref) => {
174
+ return React6.createElement("RCTView", { ...props, ref });
146
175
  });
147
- LeanView.displayName = "RCTView";
176
+ LeanViewComponent.displayName = "RCTView";
177
+ var LeanView = Platform.OS === "android" || Platform.OS === "ios" ? LeanViewComponent : View;
148
178
 
149
179
  // src/constants.ts
150
180
  var POSITION_OUT_OF_VIEW = -1e7;
@@ -153,6 +183,8 @@ var ANCHORED_POSITION_OUT_OF_VIEW = {
153
183
  relativeCoordinate: POSITION_OUT_OF_VIEW,
154
184
  top: POSITION_OUT_OF_VIEW
155
185
  };
186
+ var ENABLE_DEVMODE = __DEV__ && false;
187
+ var ENABLE_DEBUG_VIEW = __DEV__ && false;
156
188
 
157
189
  // src/Container.tsx
158
190
  var isNewArchitecture = global.nativeFabricUIManager != null;
@@ -164,7 +196,6 @@ var Container = ({
164
196
  updateItemSize,
165
197
  ItemSeparatorComponent
166
198
  }) => {
167
- useStateContext();
168
199
  const maintainVisibleContentPosition = use$("maintainVisibleContentPosition");
169
200
  const position = use$(`containerPosition${id}`) || ANCHORED_POSITION_OUT_OF_VIEW;
170
201
  const column = use$(`containerColumn${id}`) || 0;
@@ -223,16 +254,22 @@ var Container = ({
223
254
  () => ({ containerId: id, itemKey, index, value: data }),
224
255
  [id, itemKey, index, data]
225
256
  );
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));
257
+ 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
258
  if (maintainVisibleContentPosition) {
228
259
  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));
260
+ if (ENABLE_DEVMODE) {
261
+ anchorStyle.borderColor = position.type === "top" ? "red" : "blue";
262
+ anchorStyle.borderWidth = 1;
263
+ }
264
+ 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
265
  }
231
- return /* @__PURE__ */ React5__default.createElement(LeanView, { style, onLayout, ref }, contentFragment);
266
+ return /* @__PURE__ */ React6__default.createElement(LeanView, { style, onLayout, ref }, contentFragment);
232
267
  };
233
268
  var useAnimatedValue = useAnimatedValue$1 || ((initialValue) => {
234
269
  return useRef(new Animated.Value(initialValue)).current;
235
270
  });
271
+
272
+ // src/useValue$.ts
236
273
  function useValue$(key, getValue, useMicrotask) {
237
274
  var _a;
238
275
  const ctx = useStateContext();
@@ -256,7 +293,7 @@ function useValue$(key, getValue, useMicrotask) {
256
293
  }
257
294
 
258
295
  // src/Containers.tsx
259
- var Containers = React5.memo(function Containers2({
296
+ var Containers = React6.memo(function Containers2({
260
297
  horizontal,
261
298
  recycleItems,
262
299
  ItemSeparatorComponent,
@@ -275,7 +312,7 @@ var Containers = React5.memo(function Containers2({
275
312
  const containers = [];
276
313
  for (let i = 0; i < numContainers; i++) {
277
314
  containers.push(
278
- /* @__PURE__ */ React5.createElement(
315
+ /* @__PURE__ */ React6.createElement(
279
316
  Container,
280
317
  {
281
318
  id: i,
@@ -290,20 +327,71 @@ var Containers = React5.memo(function Containers2({
290
327
  );
291
328
  }
292
329
  const style = horizontal ? { width: animSize, opacity: animOpacity } : { height: animSize, opacity: animOpacity };
293
- return /* @__PURE__ */ React5.createElement(Animated.View, { style }, containers);
330
+ return /* @__PURE__ */ React6.createElement(Animated.View, { style }, containers);
294
331
  });
295
332
 
296
333
  // src/ListComponent.tsx
297
334
  var getComponent = (Component) => {
298
- if (React5.isValidElement(Component)) {
335
+ if (React6.isValidElement(Component)) {
299
336
  return Component;
300
337
  }
301
338
  if (Component) {
302
- return /* @__PURE__ */ React5.createElement(Component, null);
339
+ return /* @__PURE__ */ React6.createElement(Component, null);
303
340
  }
304
341
  return null;
305
342
  };
306
- var ListComponent = React5.memo(function ListComponent2({
343
+ var PaddingAndAdjust = () => {
344
+ const animPaddingTop = useValue$("paddingTop", (v) => v, true);
345
+ const animScrollAdjust = useValue$("scrollAdjust", (v) => v, true);
346
+ const additionalSize = { marginTop: animScrollAdjust, paddingTop: animPaddingTop };
347
+ return /* @__PURE__ */ React6.createElement(Animated.View, { style: additionalSize });
348
+ };
349
+ var PaddingAndAdjustDevMode = () => {
350
+ const animPaddingTop = useValue$("paddingTop", (v) => v, true);
351
+ const animScrollAdjust = useValue$("scrollAdjust", (v) => v, true);
352
+ 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(
353
+ Animated.View,
354
+ {
355
+ style: {
356
+ position: "absolute",
357
+ top: Animated.add(animScrollAdjust, Animated.multiply(animScrollAdjust, -1)),
358
+ height: animPaddingTop,
359
+ left: 0,
360
+ right: 0,
361
+ backgroundColor: "green"
362
+ }
363
+ }
364
+ ), /* @__PURE__ */ React6.createElement(
365
+ Animated.View,
366
+ {
367
+ style: {
368
+ position: "absolute",
369
+ top: animPaddingTop,
370
+ height: animScrollAdjust,
371
+ left: -16,
372
+ right: -16,
373
+ backgroundColor: "lightblue"
374
+ }
375
+ }
376
+ ), /* @__PURE__ */ React6.createElement(
377
+ Animated.View,
378
+ {
379
+ style: {
380
+ position: "absolute",
381
+ top: animPaddingTop,
382
+ height: Animated.multiply(animScrollAdjust, -1),
383
+ width: 8,
384
+ right: 4,
385
+ borderStyle: "dashed",
386
+ borderColor: "blue",
387
+ borderWidth: 1,
388
+ backgroundColor: "lightblue"
389
+ //backgroundColor: "blue",
390
+ }
391
+ }
392
+ ));
393
+ };
394
+ var ListComponent = React6.memo(function ListComponent2({
307
395
  style,
308
396
  contentContainerStyle,
309
397
  horizontal,
@@ -327,14 +415,11 @@ var ListComponent = React5.memo(function ListComponent2({
327
415
  ...rest
328
416
  }) {
329
417
  const ctx = useStateContext();
330
- const animPaddingTop = useValue$("paddingTop");
331
- const animScrollAdjust = useValue$("scrollAdjust");
332
418
  const ScrollComponent = renderScrollComponent ? useMemo(
333
- () => React5.forwardRef((props, ref) => renderScrollComponent({ ...props, ref })),
419
+ () => React6.forwardRef((props, ref) => renderScrollComponent({ ...props, ref })),
334
420
  [renderScrollComponent]
335
421
  ) : ScrollView;
336
- const additionalSize = { marginTop: animScrollAdjust, paddingTop: animPaddingTop };
337
- return /* @__PURE__ */ React5.createElement(
422
+ return /* @__PURE__ */ React6.createElement(
338
423
  ScrollComponent,
339
424
  {
340
425
  ...rest,
@@ -352,8 +437,8 @@ var ListComponent = React5.memo(function ListComponent2({
352
437
  contentOffset: initialContentOffset ? horizontal ? { x: initialContentOffset, y: 0 } : { x: 0, y: initialContentOffset } : void 0,
353
438
  ref: refScrollView
354
439
  },
355
- /* @__PURE__ */ React5.createElement(Animated.View, { style: additionalSize }),
356
- ListHeaderComponent && /* @__PURE__ */ React5.createElement(
440
+ ENABLE_DEVMODE ? /* @__PURE__ */ React6.createElement(PaddingAndAdjustDevMode, null) : /* @__PURE__ */ React6.createElement(PaddingAndAdjust, null),
441
+ ListHeaderComponent && /* @__PURE__ */ React6.createElement(
357
442
  Animated.View,
358
443
  {
359
444
  style: ListHeaderComponentStyle,
@@ -368,7 +453,7 @@ var ListComponent = React5.memo(function ListComponent2({
368
453
  getComponent(ListHeaderComponent)
369
454
  ),
370
455
  ListEmptyComponent && getComponent(ListEmptyComponent),
371
- /* @__PURE__ */ React5.createElement(
456
+ /* @__PURE__ */ React6.createElement(
372
457
  Containers,
373
458
  {
374
459
  horizontal,
@@ -379,7 +464,7 @@ var ListComponent = React5.memo(function ListComponent2({
379
464
  updateItemSize
380
465
  }
381
466
  ),
382
- ListFooterComponent && /* @__PURE__ */ React5.createElement(View, { style: ListFooterComponentStyle }, getComponent(ListFooterComponent))
467
+ ListFooterComponent && /* @__PURE__ */ React6.createElement(View, { style: ListFooterComponentStyle }, getComponent(ListFooterComponent))
383
468
  );
384
469
  });
385
470
 
@@ -390,7 +475,6 @@ var ScrollAdjustHandler = class {
390
475
  this.appliedAdjust = 0;
391
476
  this.pendingAdjust = 0;
392
477
  this.busy = false;
393
- this.firstAdjust = true;
394
478
  this.context = ctx;
395
479
  }
396
480
  requestAdjust(adjust, onAdjusted) {
@@ -407,18 +491,14 @@ var ScrollAdjustHandler = class {
407
491
  };
408
492
  if (!this.busy) {
409
493
  this.busy = true;
410
- if (this.firstAdjust) {
411
- this.firstAdjust = false;
412
- setTimeout(doAjdust, 50);
413
- } else {
414
- doAjdust();
415
- }
494
+ doAjdust();
416
495
  }
417
496
  }
418
497
  getAppliedAdjust() {
419
498
  return this.appliedAdjust;
420
499
  }
421
500
  };
501
+ var typedForwardRef = forwardRef;
422
502
  var useCombinedRef = (...refs) => {
423
503
  const callback = useCallback((element) => {
424
504
  for (const ref of refs) {
@@ -585,13 +665,13 @@ function maybeUpdateViewabilityCallback(ctx, configId, viewToken) {
585
665
  // src/LegendList.tsx
586
666
  var DEFAULT_DRAW_DISTANCE = 250;
587
667
  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 }));
668
+ var LegendList = typedForwardRef(function LegendList2(props, forwardedRef) {
669
+ return /* @__PURE__ */ React6.createElement(StateProvider, null, /* @__PURE__ */ React6.createElement(LegendListInner, { ...props, ref: forwardedRef }));
590
670
  });
591
- var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef) {
671
+ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwardedRef) {
592
672
  var _a, _b, _c, _d, _e, _f, _g;
593
673
  const {
594
- data,
674
+ data: dataProp,
595
675
  initialScrollIndex,
596
676
  initialScrollOffset,
597
677
  horizontal,
@@ -633,24 +713,25 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
633
713
  const refState = useRef();
634
714
  const getId = (index) => {
635
715
  var _a2;
636
- const data2 = (_a2 = refState.current) == null ? void 0 : _a2.data;
637
- if (!data2) {
716
+ const data = (_a2 = refState.current) == null ? void 0 : _a2.data;
717
+ if (!data) {
638
718
  return "";
639
719
  }
640
- const ret = index < data2.length ? keyExtractor ? keyExtractor(data2[index], index) : index : null;
720
+ const ret = index < data.length ? keyExtractor ? keyExtractor(data[index], index) : index : null;
641
721
  return `${ret}`;
642
722
  };
643
- const getItemSize = (key, index, data2) => {
723
+ const getItemSize = (key, index, data) => {
644
724
  var _a2;
645
725
  const sizeKnown = refState.current.sizes.get(key);
646
726
  if (sizeKnown !== void 0) {
647
727
  return sizeKnown;
648
728
  }
649
- const size = (_a2 = getEstimatedItemSize ? getEstimatedItemSize(index, data2) : estimatedItemSize) != null ? _a2 : DEFAULT_ITEM_SIZE;
729
+ const size = (_a2 = getEstimatedItemSize ? getEstimatedItemSize(index, data) : estimatedItemSize) != null ? _a2 : DEFAULT_ITEM_SIZE;
650
730
  refState.current.sizes.set(key, size);
651
731
  return size;
652
732
  };
653
733
  const calculateInitialOffset = (index = initialScrollIndex) => {
734
+ const data = dataProp;
654
735
  if (index) {
655
736
  let offset = 0;
656
737
  if (getEstimatedItemSize) {
@@ -677,7 +758,7 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
677
758
  isEndReached: false,
678
759
  isAtBottom: false,
679
760
  isAtTop: false,
680
- data,
761
+ data: dataProp,
681
762
  idsInFirstRender: void 0,
682
763
  hasScrolled: false,
683
764
  scrollLength: initialScrollLength,
@@ -709,14 +790,14 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
709
790
  enableScrollForNextCalculateItemsInView: true,
710
791
  minIndexSizeChanged: 0
711
792
  };
712
- refState.current.idsInFirstRender = new Set(data.map((_, i) => getId(i)));
793
+ refState.current.idsInFirstRender = new Set(dataProp.map((_, i) => getId(i)));
713
794
  if (maintainVisibleContentPosition) {
714
795
  if (initialScrollIndex) {
715
796
  refState.current.anchorElement = {
716
797
  coordinate: initialContentOffset,
717
798
  id: getId(initialScrollIndex)
718
799
  };
719
- } else if (data.length) {
800
+ } else if (dataProp.length) {
720
801
  refState.current.anchorElement = {
721
802
  coordinate: initialContentOffset,
722
803
  id: getId(0)
@@ -739,7 +820,7 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
739
820
  };
740
821
  const addTotalSize = useCallback((key, add, totalSizeBelowAnchor) => {
741
822
  const state = refState.current;
742
- const { scrollLength, indexByKey, anchorElement } = state;
823
+ const { indexByKey, anchorElement } = state;
743
824
  const index = key === null ? 0 : indexByKey.get(key);
744
825
  let isAboveAnchor = false;
745
826
  if (maintainVisibleContentPosition) {
@@ -756,10 +837,9 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
756
837
  state.totalSizeBelowAnchor += add;
757
838
  }
758
839
  }
759
- let applyAdjustValue = void 0;
760
- const totalSize = state.totalSize;
761
- let resultSize = totalSize;
762
- if (maintainVisibleContentPosition) {
840
+ let applyAdjustValue = 0;
841
+ let resultSize = state.totalSize;
842
+ if (maintainVisibleContentPosition && anchorElement !== void 0) {
763
843
  const newAdjust = anchorElement.coordinate - state.totalSizeBelowAnchor;
764
844
  applyAdjustValue = -newAdjust;
765
845
  state.belowAnchorElementPositions = buildElementPositionsBelowAnchor();
@@ -777,7 +857,7 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
777
857
  }
778
858
  }, []);
779
859
  const getRowHeight = (n) => {
780
- const { rowHeights } = refState.current;
860
+ const { rowHeights, data } = refState.current;
781
861
  if (numColumnsProp === 1) {
782
862
  const id = getId(n);
783
863
  return getItemSize(id, n, data[n]);
@@ -830,7 +910,7 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
830
910
  const calculateItemsInView = useCallback((speed) => {
831
911
  const state = refState.current;
832
912
  const {
833
- data: data2,
913
+ data,
834
914
  scrollLength,
835
915
  scroll: scrollState,
836
916
  startBufferedId: startBufferedIdOrig,
@@ -841,7 +921,7 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
841
921
  if (state.waitingForMicrotask) {
842
922
  state.waitingForMicrotask = false;
843
923
  }
844
- if (!data2) {
924
+ if (!data) {
845
925
  return;
846
926
  }
847
927
  const topPad = (peek$(ctx, "stylePaddingTop") || 0) + (peek$(ctx, "headerSize") || 0);
@@ -887,7 +967,7 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
887
967
  }
888
968
  const top2 = newPosition || positions.get(id);
889
969
  if (top2 !== void 0) {
890
- const size = getItemSize(id, i, data2[i]);
970
+ const size = getItemSize(id, i, data[i]);
891
971
  const bottom = top2 + size;
892
972
  if (bottom > scroll - scrollBuffer) {
893
973
  loopStart = i;
@@ -916,9 +996,9 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
916
996
  }
917
997
  return topOffset;
918
998
  };
919
- for (let i = loopStart; i < data2.length; i++) {
999
+ for (let i = loopStart; i < data.length; i++) {
920
1000
  const id = getId(i);
921
- const size = getItemSize(id, i, data2[i]);
1001
+ const size = getItemSize(id, i, data[i]);
922
1002
  maxSizeInRow = Math.max(maxSizeInRow, size);
923
1003
  if (top === void 0) {
924
1004
  top = getInitialTop(i);
@@ -1006,13 +1086,13 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
1006
1086
  if (furthestIndex >= 0) {
1007
1087
  set$(ctx, `containerItemKey${furthestIndex}`, id);
1008
1088
  const index = state.indexByKey.get(id);
1009
- set$(ctx, `containerItemData${furthestIndex}`, data2[index]);
1089
+ set$(ctx, `containerItemData${furthestIndex}`, data[index]);
1010
1090
  } else {
1011
1091
  const containerId = numContainers;
1012
1092
  numContainers++;
1013
1093
  set$(ctx, `containerItemKey${containerId}`, id);
1014
1094
  const index = state.indexByKey.get(id);
1015
- set$(ctx, `containerItemData${containerId}`, data2[index]);
1095
+ set$(ctx, `containerItemData${containerId}`, data[index]);
1016
1096
  set$(ctx, `containerPosition${containerId}`, ANCHORED_POSITION_OUT_OF_VIEW);
1017
1097
  set$(ctx, `containerColumn${containerId}`, -1);
1018
1098
  if (__DEV__ && numContainers > peek$(ctx, "numContainersPooled")) {
@@ -1033,13 +1113,13 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
1033
1113
  for (let i = 0; i < numContainers; i++) {
1034
1114
  const itemKey = peek$(ctx, `containerItemKey${i}`);
1035
1115
  const itemIndex = state.indexByKey.get(itemKey);
1036
- const item = data2[itemIndex];
1116
+ const item = data[itemIndex];
1037
1117
  if (item) {
1038
1118
  const id = getId(itemIndex);
1039
1119
  if (itemKey !== id || itemIndex < startBuffered || itemIndex > endBuffered) {
1040
1120
  const prevPos = peek$(ctx, `containerPosition${i}`).top;
1041
1121
  const pos = positions.get(id) || 0;
1042
- const size = getItemSize(id, itemIndex, data2[i]);
1122
+ const size = getItemSize(id, itemIndex, data[i]);
1043
1123
  if (pos + size >= scroll && pos <= scrollBottom || prevPos + size >= scroll && prevPos <= scrollBottom) {
1044
1124
  set$(ctx, `containerPosition${i}`, ANCHORED_POSITION_OUT_OF_VIEW);
1045
1125
  }
@@ -1053,7 +1133,7 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
1053
1133
  if (maintainVisibleContentPosition && itemIndex < anchorElementIndex) {
1054
1134
  const currentRow = Math.floor(itemIndex / numColumnsProp);
1055
1135
  const rowHeight = getRowHeight(currentRow);
1056
- const elementHeight = getItemSize(id, itemIndex, data2[i]);
1136
+ const elementHeight = getItemSize(id, itemIndex, data[i]);
1057
1137
  const diff = rowHeight - elementHeight;
1058
1138
  pos.relativeCoordinate = pos.top + getRowHeight(currentRow) - diff;
1059
1139
  pos.type = "bottom";
@@ -1068,7 +1148,7 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
1068
1148
  set$(ctx, `containerColumn${i}`, column2);
1069
1149
  }
1070
1150
  if (prevData !== item) {
1071
- set$(ctx, `containerItemData${i}`, data2[itemIndex]);
1151
+ set$(ctx, `containerItemData${i}`, data[itemIndex]);
1072
1152
  }
1073
1153
  }
1074
1154
  }
@@ -1098,7 +1178,10 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
1098
1178
  const doMaintainScrollAtEnd = (animated) => {
1099
1179
  const state = refState.current;
1100
1180
  if ((state == null ? void 0 : state.isAtBottom) && maintainScrollAtEnd) {
1101
- state.scroll = state.totalSize - state.scrollLength + peek$(ctx, "paddingTop");
1181
+ const paddingTop = peek$(ctx, "paddingTop") || 0;
1182
+ if (paddingTop > 0) {
1183
+ state.scroll = 0;
1184
+ }
1102
1185
  requestAnimationFrame(() => {
1103
1186
  var _a2;
1104
1187
  (_a2 = refScroller.current) == null ? void 0 : _a2.scrollToEnd({
@@ -1114,21 +1197,19 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
1114
1197
  }
1115
1198
  const { scrollLength, scroll, totalSize } = refState.current;
1116
1199
  if (totalSize > 0) {
1117
- const distanceFromEnd = totalSize - scroll - scrollLength;
1200
+ const distanceFromEnd = totalSize - scroll - scrollLength + (peek$(ctx, "paddingTop") || 0);
1118
1201
  if (refState.current) {
1119
1202
  refState.current.isAtBottom = distanceFromEnd < scrollLength * maintainScrollAtEndThreshold;
1120
1203
  }
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
- }
1204
+ if (!refState.current.isEndReached) {
1205
+ if (distanceFromEnd < onEndReachedThreshold * scrollLength) {
1206
+ refState.current.isEndReached = true;
1207
+ const { onEndReached } = callbacks.current;
1208
+ onEndReached == null ? void 0 : onEndReached({ distanceFromEnd });
1209
+ }
1210
+ } else {
1211
+ if (distanceFromEnd >= onEndReachedThreshold * scrollLength) {
1212
+ refState.current.isEndReached = false;
1132
1213
  }
1133
1214
  }
1134
1215
  }
@@ -1140,29 +1221,27 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
1140
1221
  const { scrollLength, scroll } = refState.current;
1141
1222
  const distanceFromTop = scroll;
1142
1223
  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
- }
1224
+ if (!refState.current.isStartReached && !refState.current.startReachedBlockedByTimer) {
1225
+ if (distanceFromTop < onStartReachedThreshold * scrollLength) {
1226
+ refState.current.isStartReached = true;
1227
+ const { onStartReached } = callbacks.current;
1228
+ onStartReached == null ? void 0 : onStartReached({ distanceFromStart: scroll });
1229
+ refState.current.startReachedBlockedByTimer = true;
1230
+ setTimeout(() => {
1231
+ refState.current.startReachedBlockedByTimer = false;
1232
+ }, 700);
1233
+ }
1234
+ } else {
1235
+ if (distanceFromTop >= 1.3 * onStartReachedThreshold * scrollLength) {
1236
+ refState.current.isStartReached = false;
1158
1237
  }
1159
1238
  }
1160
1239
  };
1161
- const checkResetContainers = (reset) => {
1240
+ const checkResetContainers = (isFirst2) => {
1162
1241
  const state = refState.current;
1163
1242
  if (state) {
1164
- state.data = data;
1165
- if (reset) {
1243
+ state.data = dataProp;
1244
+ if (!isFirst2) {
1166
1245
  refState.current.scrollForNextCalculateItemsInView = void 0;
1167
1246
  const numContainers = peek$(ctx, "numContainers");
1168
1247
  for (let i = 0; i < numContainers; i++) {
@@ -1178,28 +1257,28 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
1178
1257
  state.positions.clear();
1179
1258
  }
1180
1259
  calculateItemsInView(state.scrollVelocity);
1260
+ const didMaintainScrollAtEnd = doMaintainScrollAtEnd(false);
1261
+ if (!didMaintainScrollAtEnd && dataProp.length > state.data.length) {
1262
+ state.isEndReached = false;
1263
+ }
1264
+ checkAtTop();
1265
+ checkAtBottom();
1181
1266
  }
1182
- const didMaintainScrollAtEnd = doMaintainScrollAtEnd(false);
1183
- if (!didMaintainScrollAtEnd && data.length > state.data.length) {
1184
- state.isEndReached = false;
1185
- }
1186
- checkAtTop();
1187
- checkAtBottom();
1188
1267
  }
1189
1268
  };
1190
1269
  const isFirst = !refState.current.renderItem;
1191
- if (isFirst || data !== refState.current.data || numColumnsProp !== peek$(ctx, "numColumns")) {
1192
- if (!keyExtractorProp && !isFirst && data !== refState.current.data) {
1270
+ if (isFirst || dataProp !== refState.current.data || numColumnsProp !== peek$(ctx, "numColumns")) {
1271
+ if (!keyExtractorProp && !isFirst && dataProp !== refState.current.data) {
1193
1272
  refState.current.positions.clear();
1194
1273
  }
1195
- refState.current.data = data;
1274
+ refState.current.data = dataProp;
1196
1275
  let totalSize = 0;
1197
1276
  let totalSizeBelowIndex = 0;
1198
1277
  const indexByKey = /* @__PURE__ */ new Map();
1199
1278
  const newPositions = /* @__PURE__ */ new Map();
1200
1279
  let column = 1;
1201
1280
  let maxSizeInRow = 0;
1202
- for (let i = 0; i < data.length; i++) {
1281
+ for (let i = 0; i < dataProp.length; i++) {
1203
1282
  const key = getId(i);
1204
1283
  if (__DEV__) {
1205
1284
  if (indexByKey.has(key)) {
@@ -1218,7 +1297,7 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
1218
1297
  if (!isFirst) {
1219
1298
  if (maintainVisibleContentPosition) {
1220
1299
  if (refState.current.anchorElement == null || indexByKey.get(refState.current.anchorElement.id) == null) {
1221
- if (data.length) {
1300
+ if (dataProp.length) {
1222
1301
  const newAnchorElement = {
1223
1302
  coordinate: 0,
1224
1303
  id: getId(0)
@@ -1235,7 +1314,7 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
1235
1314
  }
1236
1315
  } else {
1237
1316
  if (refState.current.startBufferedId != null && newPositions.get(refState.current.startBufferedId) == null) {
1238
- if (data.length) {
1317
+ if (dataProp.length) {
1239
1318
  refState.current.startBufferedId = getId(0);
1240
1319
  } else {
1241
1320
  refState.current.startBufferedId = void 0;
@@ -1248,9 +1327,9 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
1248
1327
  }
1249
1328
  }
1250
1329
  const anchorElementIndex = getAnchorElementIndex();
1251
- for (let i = 0; i < data.length; i++) {
1330
+ for (let i = 0; i < dataProp.length; i++) {
1252
1331
  const key = getId(i);
1253
- const size = getItemSize(key, i, data[i]);
1332
+ const size = getItemSize(key, i, dataProp[i]);
1254
1333
  maxSizeInRow = Math.max(maxSizeInRow, size);
1255
1334
  column++;
1256
1335
  if (column > numColumnsProp) {
@@ -1269,15 +1348,15 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
1269
1348
  }
1270
1349
  useEffect(() => {
1271
1350
  checkResetContainers(
1272
- /*reset*/
1273
- !isFirst
1351
+ /*isFirst*/
1352
+ isFirst
1274
1353
  );
1275
- }, [isFirst, data, numColumnsProp]);
1354
+ }, [isFirst, dataProp, numColumnsProp]);
1276
1355
  useEffect(() => {
1277
1356
  set$(ctx, "extraData", extraData);
1278
1357
  }, [extraData]);
1279
1358
  refState.current.renderItem = renderItem;
1280
- const lastItemKey = data.length > 0 ? getId(data.length - 1) : void 0;
1359
+ const lastItemKey = dataProp.length > 0 ? getId(dataProp.length - 1) : void 0;
1281
1360
  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
1361
  const initalizeStateVars = () => {
1283
1362
  set$(ctx, "lastItemKey", lastItemKey);
@@ -1294,7 +1373,7 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
1294
1373
  if (!state) {
1295
1374
  return null;
1296
1375
  }
1297
- const { data: data2, indexByKey } = state;
1376
+ const { data, indexByKey } = state;
1298
1377
  const index = indexByKey.get(key);
1299
1378
  if (index === void 0) {
1300
1379
  return null;
@@ -1312,7 +1391,7 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
1312
1391
  return useRecyclingState(valueOrFun);
1313
1392
  };
1314
1393
  const renderedItem = (_b2 = (_a2 = refState.current).renderItem) == null ? void 0 : _b2.call(_a2, {
1315
- item: data2[index],
1394
+ item: data[index],
1316
1395
  index,
1317
1396
  useViewability: useViewability2,
1318
1397
  useViewabilityAmount: useViewabilityAmount2,
@@ -1328,7 +1407,7 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
1328
1407
  state.viewabilityConfigCallbackPairs = viewability;
1329
1408
  state.enableScrollForNextCalculateItemsInView = !viewability;
1330
1409
  const scrollLength = state.scrollLength;
1331
- const averageItemSize = (_a2 = estimatedItemSize != null ? estimatedItemSize : getEstimatedItemSize == null ? void 0 : getEstimatedItemSize(0, data[0])) != null ? _a2 : DEFAULT_ITEM_SIZE;
1410
+ const averageItemSize = (_a2 = estimatedItemSize != null ? estimatedItemSize : getEstimatedItemSize == null ? void 0 : getEstimatedItemSize(0, dataProp[0])) != null ? _a2 : DEFAULT_ITEM_SIZE;
1332
1411
  const numContainers = Math.ceil((scrollLength + scrollBuffer * 2) / averageItemSize) * numColumnsProp;
1333
1412
  for (let i = 0; i < numContainers; i++) {
1334
1413
  set$(ctx, `containerPosition${i}`, ANCHORED_POSITION_OUT_OF_VIEW);
@@ -1336,31 +1415,33 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
1336
1415
  }
1337
1416
  set$(ctx, "numContainers", numContainers);
1338
1417
  set$(ctx, "numContainersPooled", numContainers * 2);
1339
- calculateItemsInView(state.scrollVelocity);
1418
+ if (initialScrollIndex) {
1419
+ requestAnimationFrame(() => {
1420
+ calculateItemsInView(state.scrollVelocity);
1421
+ });
1422
+ } else {
1423
+ calculateItemsInView(state.scrollVelocity);
1424
+ }
1340
1425
  });
1341
1426
  const updateItemSize = useCallback((containerId, itemKey, size) => {
1342
1427
  const state = refState.current;
1343
- const { sizes, indexByKey, columns, sizesLaidOut, data: data2 } = state;
1344
- if (!data2) {
1428
+ const { sizes, indexByKey, columns, sizesLaidOut, data, rowHeights } = state;
1429
+ if (!data) {
1345
1430
  return;
1346
1431
  }
1347
1432
  const index = indexByKey.get(itemKey);
1348
1433
  const numColumns = peek$(ctx, "numColumns");
1349
1434
  state.minIndexSizeChanged = state.minIndexSizeChanged !== void 0 ? Math.min(state.minIndexSizeChanged, index) : index;
1350
- const prevSize = getItemSize(itemKey, index, data2);
1435
+ const prevSize = getItemSize(itemKey, index, data);
1351
1436
  if (!prevSize || Math.abs(prevSize - size) > 0.5) {
1352
1437
  let diff;
1353
1438
  if (numColumns > 1) {
1439
+ const rowNumber = Math.floor(index / numColumnsProp);
1440
+ const prevSizeInRow = getRowHeight(rowNumber);
1354
1441
  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;
1442
+ rowHeights.delete(rowNumber);
1443
+ const sizeInRow = getRowHeight(rowNumber);
1444
+ diff = sizeInRow - prevSizeInRow;
1364
1445
  } else {
1365
1446
  sizes.set(itemKey, size);
1366
1447
  diff = size - prevSize;
@@ -1402,7 +1483,7 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
1402
1483
  }
1403
1484
  }
1404
1485
  if (onItemSizeChanged) {
1405
- onItemSizeChanged({ size, previous: prevSize, index, itemKey, itemData: data2[index] });
1486
+ onItemSizeChanged({ size, previous: prevSize, index, itemKey, itemData: data[index] });
1406
1487
  }
1407
1488
  }
1408
1489
  }, []);
@@ -1496,6 +1577,7 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
1496
1577
  refScroller.current.scrollTo({ ...offsetObj, animated });
1497
1578
  },
1498
1579
  scrollToItem: ({ item, animated }) => {
1580
+ const { data } = refState.current;
1499
1581
  const index = data.indexOf(item);
1500
1582
  if (index !== -1) {
1501
1583
  scrollToIndex({ index, animated });
@@ -1506,7 +1588,7 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
1506
1588
  },
1507
1589
  []
1508
1590
  );
1509
- return /* @__PURE__ */ React5.createElement(
1591
+ return /* @__PURE__ */ React6.createElement(React6.Fragment, null, /* @__PURE__ */ React6.createElement(
1510
1592
  ListComponent,
1511
1593
  {
1512
1594
  ...rest,
@@ -1519,13 +1601,13 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
1519
1601
  onLayout,
1520
1602
  recycleItems,
1521
1603
  alignItemsAtEnd,
1522
- ListEmptyComponent: data.length === 0 ? ListEmptyComponent : void 0,
1604
+ ListEmptyComponent: dataProp.length === 0 ? ListEmptyComponent : void 0,
1523
1605
  maintainVisibleContentPosition,
1524
1606
  scrollEventThrottle: scrollEventThrottle != null ? scrollEventThrottle : Platform.OS === "web" ? 16 : void 0,
1525
1607
  waitForInitialLayout,
1526
1608
  style
1527
1609
  }
1528
- );
1610
+ ), __DEV__ && ENABLE_DEBUG_VIEW && /* @__PURE__ */ React6.createElement(DebugView, { state: refState.current }));
1529
1611
  });
1530
1612
 
1531
1613
  export { LegendList, useRecyclingEffect, useRecyclingState, useViewability, useViewabilityAmount };