@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.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var React5 = require('react');
3
+ var React6 = require('react');
4
4
  var reactNative = require('react-native');
5
5
 
6
6
  function _interopNamespace(e) {
@@ -21,12 +21,12 @@ function _interopNamespace(e) {
21
21
  return Object.freeze(n);
22
22
  }
23
23
 
24
- var React5__namespace = /*#__PURE__*/_interopNamespace(React5);
24
+ var React6__namespace = /*#__PURE__*/_interopNamespace(React6);
25
25
 
26
26
  // src/LegendList.tsx
27
- var ContextState = React5__namespace.createContext(null);
27
+ var ContextState = React6__namespace.createContext(null);
28
28
  function StateProvider({ children }) {
29
- const [value] = React5__namespace.useState(() => ({
29
+ const [value] = React6__namespace.useState(() => ({
30
30
  listeners: /* @__PURE__ */ new Map(),
31
31
  values: /* @__PURE__ */ new Map(),
32
32
  mapViewabilityCallbacks: /* @__PURE__ */ new Map(),
@@ -34,10 +34,10 @@ function StateProvider({ children }) {
34
34
  mapViewabilityAmountCallbacks: /* @__PURE__ */ new Map(),
35
35
  mapViewabilityAmountValues: /* @__PURE__ */ new Map()
36
36
  }));
37
- return /* @__PURE__ */ React5__namespace.createElement(ContextState.Provider, { value }, children);
37
+ return /* @__PURE__ */ React6__namespace.createElement(ContextState.Provider, { value }, children);
38
38
  }
39
39
  function useStateContext() {
40
- return React5__namespace.useContext(ContextState);
40
+ return React6__namespace.useContext(ContextState);
41
41
  }
42
42
  function createSelectorFunctions(ctx, signalName) {
43
43
  return {
@@ -46,9 +46,9 @@ function createSelectorFunctions(ctx, signalName) {
46
46
  };
47
47
  }
48
48
  function use$(signalName) {
49
- const ctx = React5__namespace.useContext(ContextState);
50
- const { subscribe, get } = React5__namespace.useMemo(() => createSelectorFunctions(ctx, signalName), []);
51
- const value = React5.useSyncExternalStore(subscribe, get);
49
+ const ctx = React6__namespace.useContext(ContextState);
50
+ const { subscribe, get } = React6__namespace.useMemo(() => createSelectorFunctions(ctx, signalName), []);
51
+ const value = React6.useSyncExternalStore(subscribe, get);
52
52
  return value;
53
53
  }
54
54
  function listen$(ctx, signalName, cb) {
@@ -79,7 +79,7 @@ function set$(ctx, signalName, value) {
79
79
  }
80
80
  var symbolFirst = Symbol();
81
81
  function useInit(cb) {
82
- const refValue = React5.useRef(symbolFirst);
82
+ const refValue = React6.useRef(symbolFirst);
83
83
  if (refValue.current === symbolFirst) {
84
84
  refValue.current = cb();
85
85
  }
@@ -87,10 +87,10 @@ function useInit(cb) {
87
87
  }
88
88
 
89
89
  // src/ContextContainer.ts
90
- var ContextContainer = React5.createContext(null);
90
+ var ContextContainer = React6.createContext(null);
91
91
  function useViewability(configId, callback) {
92
92
  const ctx = useStateContext();
93
- const { containerId } = React5.useContext(ContextContainer);
93
+ const { containerId } = React6.useContext(ContextContainer);
94
94
  const key = containerId + configId;
95
95
  useInit(() => {
96
96
  const value = ctx.mapViewabilityValues.get(key);
@@ -99,7 +99,7 @@ function useViewability(configId, callback) {
99
99
  }
100
100
  });
101
101
  ctx.mapViewabilityCallbacks.set(key, callback);
102
- React5.useEffect(
102
+ React6.useEffect(
103
103
  () => () => {
104
104
  ctx.mapViewabilityCallbacks.delete(key);
105
105
  },
@@ -108,7 +108,7 @@ function useViewability(configId, callback) {
108
108
  }
109
109
  function useViewabilityAmount(callback) {
110
110
  const ctx = useStateContext();
111
- const { containerId } = React5.useContext(ContextContainer);
111
+ const { containerId } = React6.useContext(ContextContainer);
112
112
  useInit(() => {
113
113
  const value = ctx.mapViewabilityAmountValues.get(containerId);
114
114
  if (value) {
@@ -116,7 +116,7 @@ function useViewabilityAmount(callback) {
116
116
  }
117
117
  });
118
118
  ctx.mapViewabilityAmountCallbacks.set(containerId, callback);
119
- React5.useEffect(
119
+ React6.useEffect(
120
120
  () => () => {
121
121
  ctx.mapViewabilityAmountCallbacks.delete(containerId);
122
122
  },
@@ -124,12 +124,12 @@ function useViewabilityAmount(callback) {
124
124
  );
125
125
  }
126
126
  function useRecyclingEffect(effect) {
127
- const { index, value } = React5.useContext(ContextContainer);
128
- const prevValues = React5.useRef({
127
+ const { index, value } = React6.useContext(ContextContainer);
128
+ const prevValues = React6.useRef({
129
129
  prevIndex: void 0,
130
130
  prevItem: void 0
131
131
  });
132
- React5.useEffect(() => {
132
+ React6.useEffect(() => {
133
133
  let ret = void 0;
134
134
  if (prevValues.current.prevIndex !== void 0 && prevValues.current.prevItem !== void 0) {
135
135
  ret = effect({
@@ -147,8 +147,8 @@ function useRecyclingEffect(effect) {
147
147
  }, [index, value]);
148
148
  }
149
149
  function useRecyclingState(valueOrFun) {
150
- const { index, value } = React5.useContext(ContextContainer);
151
- const stateInfo = React5.useState(
150
+ const { index, value } = React6.useContext(ContextContainer);
151
+ const stateInfo = React6.useState(
152
152
  () => typeof valueOrFun === "function" ? valueOrFun({
153
153
  index,
154
154
  item: value,
@@ -162,8 +162,37 @@ function useRecyclingState(valueOrFun) {
162
162
  });
163
163
  return stateInfo;
164
164
  }
165
- var LeanView = React5__namespace.forwardRef((props, ref) => {
166
- return React5__namespace.createElement("RCTView", { ...props, ref });
165
+ var DebugView = React6.memo(function DebugView2({ state }) {
166
+ const paddingTop = use$("paddingTop");
167
+ const [, forceUpdate] = React6.useReducer((x) => x + 1, 0);
168
+ useInterval(() => {
169
+ forceUpdate();
170
+ }, 100);
171
+ return /* @__PURE__ */ React.createElement(
172
+ reactNative.View,
173
+ {
174
+ style: {
175
+ position: "absolute",
176
+ top: 0,
177
+ right: 0,
178
+ paddingLeft: 4,
179
+ paddingBottom: 4,
180
+ // height: 100,
181
+ backgroundColor: "#FFFFFFCC"
182
+ }
183
+ },
184
+ /* @__PURE__ */ React.createElement(reactNative.Text, null, "PaddingTop: ", paddingTop),
185
+ /* @__PURE__ */ React.createElement(reactNative.Text, null, "At end: ", String(state.isAtBottom))
186
+ );
187
+ });
188
+ function useInterval(callback, delay) {
189
+ React6.useEffect(() => {
190
+ const interval = setInterval(callback, delay);
191
+ return () => clearInterval(interval);
192
+ }, [delay]);
193
+ }
194
+ var LeanView = React6__namespace.forwardRef((props, ref) => {
195
+ return React6__namespace.createElement("RCTView", { ...props, ref });
167
196
  });
168
197
  LeanView.displayName = "RCTView";
169
198
 
@@ -174,6 +203,8 @@ var ANCHORED_POSITION_OUT_OF_VIEW = {
174
203
  relativeCoordinate: POSITION_OUT_OF_VIEW,
175
204
  top: POSITION_OUT_OF_VIEW
176
205
  };
206
+ var ENABLE_DEVMODE = __DEV__ && false;
207
+ var ENABLE_DEBUG_VIEW = __DEV__ && false;
177
208
 
178
209
  // src/Container.tsx
179
210
  var isNewArchitecture = global.nativeFabricUIManager != null;
@@ -185,7 +216,6 @@ var Container = ({
185
216
  updateItemSize,
186
217
  ItemSeparatorComponent
187
218
  }) => {
188
- useStateContext();
189
219
  const maintainVisibleContentPosition = use$("maintainVisibleContentPosition");
190
220
  const position = use$(`containerPosition${id}`) || ANCHORED_POSITION_OUT_OF_VIEW;
191
221
  const column = use$(`containerColumn${id}`) || 0;
@@ -210,7 +240,7 @@ var Container = ({
210
240
  const itemKey = use$(`containerItemKey${id}`);
211
241
  const data = use$(`containerItemData${id}`);
212
242
  const extraData = use$("extraData");
213
- const renderedItemInfo = React5.useMemo(
243
+ const renderedItemInfo = React6.useMemo(
214
244
  () => itemKey !== void 0 && getRenderedItem(itemKey),
215
245
  [itemKey, data, extraData]
216
246
  );
@@ -225,9 +255,9 @@ var Container = ({
225
255
  updateItemSize(id, itemKey, size);
226
256
  }
227
257
  };
228
- const ref = React5.useRef(null);
258
+ const ref = React6.useRef(null);
229
259
  if (isNewArchitecture) {
230
- React5.useLayoutEffect(() => {
260
+ React6.useLayoutEffect(() => {
231
261
  var _a, _b;
232
262
  if (itemKey !== void 0) {
233
263
  const measured = (_b = (_a = ref.current) == null ? void 0 : _a.unstable_getBoundingClientRect) == null ? void 0 : _b.call(_a);
@@ -240,25 +270,29 @@ var Container = ({
240
270
  }
241
271
  }, [itemKey]);
242
272
  }
243
- const contextValue = React5.useMemo(
273
+ const contextValue = React6.useMemo(
244
274
  () => ({ containerId: id, itemKey, index, value: data }),
245
275
  [id, itemKey, index, data]
246
276
  );
247
- const contentFragment = /* @__PURE__ */ React5__namespace.default.createElement(React5__namespace.default.Fragment, { key: recycleItems ? void 0 : itemKey }, /* @__PURE__ */ React5__namespace.default.createElement(ContextContainer.Provider, { value: contextValue }, renderedItem, renderedItem && ItemSeparatorComponent && itemKey !== lastItemKey && ItemSeparatorComponent));
277
+ const contentFragment = /* @__PURE__ */ React6__namespace.default.createElement(React6__namespace.default.Fragment, { key: recycleItems ? void 0 : itemKey }, /* @__PURE__ */ React6__namespace.default.createElement(ContextContainer.Provider, { value: contextValue }, renderedItem, renderedItem && ItemSeparatorComponent && itemKey !== lastItemKey && ItemSeparatorComponent));
248
278
  if (maintainVisibleContentPosition) {
249
279
  const anchorStyle = position.type === "top" ? { position: "absolute", top: 0, left: 0, right: 0 } : { position: "absolute", bottom: 0, left: 0, right: 0 };
250
- return /* @__PURE__ */ React5__namespace.default.createElement(LeanView, { style }, /* @__PURE__ */ React5__namespace.default.createElement(LeanView, { style: anchorStyle, onLayout, ref }, contentFragment));
280
+ if (ENABLE_DEVMODE) {
281
+ anchorStyle.borderColor = position.type === "top" ? "red" : "blue";
282
+ anchorStyle.borderWidth = 1;
283
+ }
284
+ return /* @__PURE__ */ React6__namespace.default.createElement(LeanView, { style }, /* @__PURE__ */ React6__namespace.default.createElement(LeanView, { style: anchorStyle, onLayout, ref }, contentFragment, ENABLE_DEVMODE && /* @__PURE__ */ React6__namespace.default.createElement(reactNative.Text, { style: { position: "absolute", top: 0, left: 0, zIndex: 1e3 } }, position.top)));
251
285
  }
252
- return /* @__PURE__ */ React5__namespace.default.createElement(LeanView, { style, onLayout, ref }, contentFragment);
286
+ return /* @__PURE__ */ React6__namespace.default.createElement(LeanView, { style, onLayout, ref }, contentFragment);
253
287
  };
254
288
  var useAnimatedValue = reactNative.useAnimatedValue || ((initialValue) => {
255
- return React5.useRef(new reactNative.Animated.Value(initialValue)).current;
289
+ return React6.useRef(new reactNative.Animated.Value(initialValue)).current;
256
290
  });
257
291
  function useValue$(key, getValue, useMicrotask) {
258
292
  var _a;
259
293
  const ctx = useStateContext();
260
294
  const animValue = useAnimatedValue((_a = getValue ? getValue(peek$(ctx, key)) : peek$(ctx, key)) != null ? _a : 0);
261
- React5.useMemo(() => {
295
+ React6.useMemo(() => {
262
296
  let newValue = void 0;
263
297
  listen$(ctx, key, (v) => {
264
298
  if (useMicrotask && newValue === void 0) {
@@ -277,7 +311,7 @@ function useValue$(key, getValue, useMicrotask) {
277
311
  }
278
312
 
279
313
  // src/Containers.tsx
280
- var Containers = React5__namespace.memo(function Containers2({
314
+ var Containers = React6__namespace.memo(function Containers2({
281
315
  horizontal,
282
316
  recycleItems,
283
317
  ItemSeparatorComponent,
@@ -296,7 +330,7 @@ var Containers = React5__namespace.memo(function Containers2({
296
330
  const containers = [];
297
331
  for (let i = 0; i < numContainers; i++) {
298
332
  containers.push(
299
- /* @__PURE__ */ React5__namespace.createElement(
333
+ /* @__PURE__ */ React6__namespace.createElement(
300
334
  Container,
301
335
  {
302
336
  id: i,
@@ -311,20 +345,71 @@ var Containers = React5__namespace.memo(function Containers2({
311
345
  );
312
346
  }
313
347
  const style = horizontal ? { width: animSize, opacity: animOpacity } : { height: animSize, opacity: animOpacity };
314
- return /* @__PURE__ */ React5__namespace.createElement(reactNative.Animated.View, { style }, containers);
348
+ return /* @__PURE__ */ React6__namespace.createElement(reactNative.Animated.View, { style }, containers);
315
349
  });
316
350
 
317
351
  // src/ListComponent.tsx
318
352
  var getComponent = (Component) => {
319
- if (React5__namespace.isValidElement(Component)) {
353
+ if (React6__namespace.isValidElement(Component)) {
320
354
  return Component;
321
355
  }
322
356
  if (Component) {
323
- return /* @__PURE__ */ React5__namespace.createElement(Component, null);
357
+ return /* @__PURE__ */ React6__namespace.createElement(Component, null);
324
358
  }
325
359
  return null;
326
360
  };
327
- var ListComponent = React5__namespace.memo(function ListComponent2({
361
+ var PaddingAndAdjust = () => {
362
+ const animPaddingTop = useValue$("paddingTop", (v) => v, true);
363
+ const animScrollAdjust = useValue$("scrollAdjust", (v) => v, true);
364
+ const additionalSize = { marginTop: animScrollAdjust, paddingTop: animPaddingTop };
365
+ return /* @__PURE__ */ React6__namespace.createElement(reactNative.Animated.View, { style: additionalSize });
366
+ };
367
+ var PaddingAndAdjustDevMode = () => {
368
+ const animPaddingTop = useValue$("paddingTop", (v) => v, true);
369
+ const animScrollAdjust = useValue$("scrollAdjust", (v) => v, true);
370
+ return /* @__PURE__ */ React6__namespace.createElement(React6__namespace.Fragment, null, /* @__PURE__ */ React6__namespace.createElement(reactNative.Animated.View, { style: { marginTop: animScrollAdjust } }), /* @__PURE__ */ React6__namespace.createElement(reactNative.Animated.View, { style: { paddingTop: animPaddingTop } }), /* @__PURE__ */ React6__namespace.createElement(
371
+ reactNative.Animated.View,
372
+ {
373
+ style: {
374
+ position: "absolute",
375
+ top: reactNative.Animated.add(animScrollAdjust, reactNative.Animated.multiply(animScrollAdjust, -1)),
376
+ height: animPaddingTop,
377
+ left: 0,
378
+ right: 0,
379
+ backgroundColor: "green"
380
+ }
381
+ }
382
+ ), /* @__PURE__ */ React6__namespace.createElement(
383
+ reactNative.Animated.View,
384
+ {
385
+ style: {
386
+ position: "absolute",
387
+ top: animPaddingTop,
388
+ height: animScrollAdjust,
389
+ left: -16,
390
+ right: -16,
391
+ backgroundColor: "lightblue"
392
+ }
393
+ }
394
+ ), /* @__PURE__ */ React6__namespace.createElement(
395
+ reactNative.Animated.View,
396
+ {
397
+ style: {
398
+ position: "absolute",
399
+ top: animPaddingTop,
400
+ height: reactNative.Animated.multiply(animScrollAdjust, -1),
401
+ width: 8,
402
+ right: 4,
403
+ borderStyle: "dashed",
404
+ borderColor: "blue",
405
+ borderWidth: 1,
406
+ backgroundColor: "lightblue"
407
+ //backgroundColor: "blue",
408
+ }
409
+ }
410
+ ));
411
+ };
412
+ var ListComponent = React6__namespace.memo(function ListComponent2({
328
413
  style,
329
414
  contentContainerStyle,
330
415
  horizontal,
@@ -348,14 +433,11 @@ var ListComponent = React5__namespace.memo(function ListComponent2({
348
433
  ...rest
349
434
  }) {
350
435
  const ctx = useStateContext();
351
- const animPaddingTop = useValue$("paddingTop");
352
- const animScrollAdjust = useValue$("scrollAdjust");
353
- const ScrollComponent = renderScrollComponent ? React5.useMemo(
354
- () => React5__namespace.forwardRef((props, ref) => renderScrollComponent({ ...props, ref })),
436
+ const ScrollComponent = renderScrollComponent ? React6.useMemo(
437
+ () => React6__namespace.forwardRef((props, ref) => renderScrollComponent({ ...props, ref })),
355
438
  [renderScrollComponent]
356
439
  ) : reactNative.ScrollView;
357
- const additionalSize = { marginTop: animScrollAdjust, paddingTop: animPaddingTop };
358
- return /* @__PURE__ */ React5__namespace.createElement(
440
+ return /* @__PURE__ */ React6__namespace.createElement(
359
441
  ScrollComponent,
360
442
  {
361
443
  ...rest,
@@ -373,8 +455,8 @@ var ListComponent = React5__namespace.memo(function ListComponent2({
373
455
  contentOffset: initialContentOffset ? horizontal ? { x: initialContentOffset, y: 0 } : { x: 0, y: initialContentOffset } : void 0,
374
456
  ref: refScrollView
375
457
  },
376
- /* @__PURE__ */ React5__namespace.createElement(reactNative.Animated.View, { style: additionalSize }),
377
- ListHeaderComponent && /* @__PURE__ */ React5__namespace.createElement(
458
+ ENABLE_DEVMODE ? /* @__PURE__ */ React6__namespace.createElement(PaddingAndAdjustDevMode, null) : /* @__PURE__ */ React6__namespace.createElement(PaddingAndAdjust, null),
459
+ ListHeaderComponent && /* @__PURE__ */ React6__namespace.createElement(
378
460
  reactNative.Animated.View,
379
461
  {
380
462
  style: ListHeaderComponentStyle,
@@ -389,7 +471,7 @@ var ListComponent = React5__namespace.memo(function ListComponent2({
389
471
  getComponent(ListHeaderComponent)
390
472
  ),
391
473
  ListEmptyComponent && getComponent(ListEmptyComponent),
392
- /* @__PURE__ */ React5__namespace.createElement(
474
+ /* @__PURE__ */ React6__namespace.createElement(
393
475
  Containers,
394
476
  {
395
477
  horizontal,
@@ -400,7 +482,7 @@ var ListComponent = React5__namespace.memo(function ListComponent2({
400
482
  updateItemSize
401
483
  }
402
484
  ),
403
- ListFooterComponent && /* @__PURE__ */ React5__namespace.createElement(reactNative.View, { style: ListFooterComponentStyle }, getComponent(ListFooterComponent))
485
+ ListFooterComponent && /* @__PURE__ */ React6__namespace.createElement(reactNative.View, { style: ListFooterComponentStyle }, getComponent(ListFooterComponent))
404
486
  );
405
487
  });
406
488
 
@@ -411,7 +493,6 @@ var ScrollAdjustHandler = class {
411
493
  this.appliedAdjust = 0;
412
494
  this.pendingAdjust = 0;
413
495
  this.busy = false;
414
- this.firstAdjust = true;
415
496
  this.context = ctx;
416
497
  }
417
498
  requestAdjust(adjust, onAdjusted) {
@@ -428,18 +509,29 @@ var ScrollAdjustHandler = class {
428
509
  };
429
510
  if (!this.busy) {
430
511
  this.busy = true;
431
- if (this.firstAdjust) {
432
- this.firstAdjust = false;
433
- setTimeout(doAjdust, 50);
434
- } else {
435
- doAjdust();
436
- }
512
+ doAjdust();
437
513
  }
438
514
  }
439
515
  getAppliedAdjust() {
440
516
  return this.appliedAdjust;
441
517
  }
442
518
  };
519
+ var typedForwardRef = React6.forwardRef;
520
+ var useCombinedRef = (...refs) => {
521
+ const callback = React6.useCallback((element) => {
522
+ for (const ref of refs) {
523
+ if (!ref) {
524
+ continue;
525
+ }
526
+ if (typeof ref === "function") {
527
+ ref(element);
528
+ } else {
529
+ ref.current = element;
530
+ }
531
+ }
532
+ }, refs);
533
+ return callback;
534
+ };
443
535
 
444
536
  // src/viewability.ts
445
537
  var mapViewabilityConfigCallbackPairs = /* @__PURE__ */ new Map();
@@ -591,13 +683,13 @@ function maybeUpdateViewabilityCallback(ctx, configId, viewToken) {
591
683
  // src/LegendList.tsx
592
684
  var DEFAULT_DRAW_DISTANCE = 250;
593
685
  var DEFAULT_ITEM_SIZE = 100;
594
- var LegendList = React5.forwardRef(function LegendList2(props, forwardedRef) {
595
- return /* @__PURE__ */ React5__namespace.createElement(StateProvider, null, /* @__PURE__ */ React5__namespace.createElement(LegendListInner, { ...props, ref: forwardedRef }));
686
+ var LegendList = typedForwardRef(function LegendList2(props, forwardedRef) {
687
+ return /* @__PURE__ */ React6__namespace.createElement(StateProvider, null, /* @__PURE__ */ React6__namespace.createElement(LegendListInner, { ...props, ref: forwardedRef }));
596
688
  });
597
- var LegendListInner = React5.forwardRef(function LegendListInner2(props, forwardedRef) {
689
+ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwardedRef) {
598
690
  var _a, _b, _c, _d, _e, _f, _g;
599
691
  const {
600
- data,
692
+ data: dataProp,
601
693
  initialScrollIndex,
602
694
  initialScrollOffset,
603
695
  horizontal,
@@ -625,37 +717,39 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
625
717
  ...rest
626
718
  } = props;
627
719
  const { style, contentContainerStyle } = props;
628
- const callbacks = React5.useRef({
720
+ const callbacks = React6.useRef({
629
721
  onStartReached: rest.onStartReached,
630
722
  onEndReached: rest.onEndReached
631
723
  });
632
724
  callbacks.current.onStartReached = rest.onStartReached;
633
725
  callbacks.current.onEndReached = rest.onEndReached;
634
726
  const ctx = useStateContext();
635
- const refScroller = React5.useRef(null);
727
+ const refScroller = React6.useRef(null);
728
+ const combinedRef = useCombinedRef(refScroller, refScrollView);
636
729
  const scrollBuffer = drawDistance != null ? drawDistance : DEFAULT_DRAW_DISTANCE;
637
730
  const keyExtractor = keyExtractorProp != null ? keyExtractorProp : (item, index) => index.toString();
638
- const refState = React5.useRef();
731
+ const refState = React6.useRef();
639
732
  const getId = (index) => {
640
733
  var _a2;
641
- const data2 = (_a2 = refState.current) == null ? void 0 : _a2.data;
642
- if (!data2) {
734
+ const data = (_a2 = refState.current) == null ? void 0 : _a2.data;
735
+ if (!data) {
643
736
  return "";
644
737
  }
645
- const ret = index < data2.length ? keyExtractor ? keyExtractor(data2[index], index) : index : null;
738
+ const ret = index < data.length ? keyExtractor ? keyExtractor(data[index], index) : index : null;
646
739
  return `${ret}`;
647
740
  };
648
- const getItemSize = (key, index, data2) => {
741
+ const getItemSize = (key, index, data) => {
649
742
  var _a2;
650
743
  const sizeKnown = refState.current.sizes.get(key);
651
744
  if (sizeKnown !== void 0) {
652
745
  return sizeKnown;
653
746
  }
654
- const size = (_a2 = getEstimatedItemSize ? getEstimatedItemSize(index, data2) : estimatedItemSize) != null ? _a2 : DEFAULT_ITEM_SIZE;
747
+ const size = (_a2 = getEstimatedItemSize ? getEstimatedItemSize(index, data) : estimatedItemSize) != null ? _a2 : DEFAULT_ITEM_SIZE;
655
748
  refState.current.sizes.set(key, size);
656
749
  return size;
657
750
  };
658
751
  const calculateInitialOffset = (index = initialScrollIndex) => {
752
+ const data = dataProp;
659
753
  if (index) {
660
754
  let offset = 0;
661
755
  if (getEstimatedItemSize) {
@@ -669,7 +763,7 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
669
763
  }
670
764
  return 0;
671
765
  };
672
- const initialContentOffset = initialScrollOffset != null ? initialScrollOffset : React5.useMemo(calculateInitialOffset, []);
766
+ const initialContentOffset = initialScrollOffset != null ? initialScrollOffset : React6.useMemo(calculateInitialOffset, []);
673
767
  if (!refState.current) {
674
768
  const initialScrollLength = reactNative.Dimensions.get("window")[horizontal ? "width" : "height"];
675
769
  refState.current = {
@@ -682,7 +776,7 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
682
776
  isEndReached: false,
683
777
  isAtBottom: false,
684
778
  isAtTop: false,
685
- data,
779
+ data: dataProp,
686
780
  idsInFirstRender: void 0,
687
781
  hasScrolled: false,
688
782
  scrollLength: initialScrollLength,
@@ -714,14 +808,14 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
714
808
  enableScrollForNextCalculateItemsInView: true,
715
809
  minIndexSizeChanged: 0
716
810
  };
717
- refState.current.idsInFirstRender = new Set(data.map((_, i) => getId(i)));
811
+ refState.current.idsInFirstRender = new Set(dataProp.map((_, i) => getId(i)));
718
812
  if (maintainVisibleContentPosition) {
719
813
  if (initialScrollIndex) {
720
814
  refState.current.anchorElement = {
721
815
  coordinate: initialContentOffset,
722
816
  id: getId(initialScrollIndex)
723
817
  };
724
- } else if (data.length) {
818
+ } else if (dataProp.length) {
725
819
  refState.current.anchorElement = {
726
820
  coordinate: initialContentOffset,
727
821
  id: getId(0)
@@ -742,9 +836,9 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
742
836
  }
743
837
  return void 0;
744
838
  };
745
- const addTotalSize = React5.useCallback((key, add, totalSizeBelowAnchor) => {
839
+ const addTotalSize = React6.useCallback((key, add, totalSizeBelowAnchor) => {
746
840
  const state = refState.current;
747
- const { scrollLength, indexByKey, anchorElement } = state;
841
+ const { indexByKey, anchorElement } = state;
748
842
  const index = key === null ? 0 : indexByKey.get(key);
749
843
  let isAboveAnchor = false;
750
844
  if (maintainVisibleContentPosition) {
@@ -761,10 +855,9 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
761
855
  state.totalSizeBelowAnchor += add;
762
856
  }
763
857
  }
764
- let applyAdjustValue = void 0;
765
- const totalSize = state.totalSize;
766
- let resultSize = totalSize;
767
- if (maintainVisibleContentPosition && totalSize > scrollLength) {
858
+ let applyAdjustValue = 0;
859
+ let resultSize = state.totalSize;
860
+ if (maintainVisibleContentPosition && anchorElement !== void 0) {
768
861
  const newAdjust = anchorElement.coordinate - state.totalSizeBelowAnchor;
769
862
  applyAdjustValue = -newAdjust;
770
863
  state.belowAnchorElementPositions = buildElementPositionsBelowAnchor();
@@ -782,7 +875,7 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
782
875
  }
783
876
  }, []);
784
877
  const getRowHeight = (n) => {
785
- const { rowHeights } = refState.current;
878
+ const { rowHeights, data } = refState.current;
786
879
  if (numColumnsProp === 1) {
787
880
  const id = getId(n);
788
881
  return getItemSize(id, n, data[n]);
@@ -832,10 +925,10 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
832
925
  }
833
926
  return res;
834
927
  };
835
- const calculateItemsInView = React5.useCallback((speed) => {
928
+ const calculateItemsInView = React6.useCallback((speed) => {
836
929
  const state = refState.current;
837
930
  const {
838
- data: data2,
931
+ data,
839
932
  scrollLength,
840
933
  scroll: scrollState,
841
934
  startBufferedId: startBufferedIdOrig,
@@ -846,7 +939,7 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
846
939
  if (state.waitingForMicrotask) {
847
940
  state.waitingForMicrotask = false;
848
941
  }
849
- if (!data2) {
942
+ if (!data) {
850
943
  return;
851
944
  }
852
945
  const topPad = (peek$(ctx, "stylePaddingTop") || 0) + (peek$(ctx, "headerSize") || 0);
@@ -892,7 +985,7 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
892
985
  }
893
986
  const top2 = newPosition || positions.get(id);
894
987
  if (top2 !== void 0) {
895
- const size = getItemSize(id, i, data2[i]);
988
+ const size = getItemSize(id, i, data[i]);
896
989
  const bottom = top2 + size;
897
990
  if (bottom > scroll - scrollBuffer) {
898
991
  loopStart = i;
@@ -921,9 +1014,9 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
921
1014
  }
922
1015
  return topOffset;
923
1016
  };
924
- for (let i = loopStart; i < data2.length; i++) {
1017
+ for (let i = loopStart; i < data.length; i++) {
925
1018
  const id = getId(i);
926
- const size = getItemSize(id, i, data2[i]);
1019
+ const size = getItemSize(id, i, data[i]);
927
1020
  maxSizeInRow = Math.max(maxSizeInRow, size);
928
1021
  if (top === void 0) {
929
1022
  top = getInitialTop(i);
@@ -1011,13 +1104,13 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
1011
1104
  if (furthestIndex >= 0) {
1012
1105
  set$(ctx, `containerItemKey${furthestIndex}`, id);
1013
1106
  const index = state.indexByKey.get(id);
1014
- set$(ctx, `containerItemData${furthestIndex}`, data2[index]);
1107
+ set$(ctx, `containerItemData${furthestIndex}`, data[index]);
1015
1108
  } else {
1016
1109
  const containerId = numContainers;
1017
1110
  numContainers++;
1018
1111
  set$(ctx, `containerItemKey${containerId}`, id);
1019
1112
  const index = state.indexByKey.get(id);
1020
- set$(ctx, `containerItemData${containerId}`, data2[index]);
1113
+ set$(ctx, `containerItemData${containerId}`, data[index]);
1021
1114
  set$(ctx, `containerPosition${containerId}`, ANCHORED_POSITION_OUT_OF_VIEW);
1022
1115
  set$(ctx, `containerColumn${containerId}`, -1);
1023
1116
  if (__DEV__ && numContainers > peek$(ctx, "numContainersPooled")) {
@@ -1038,13 +1131,13 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
1038
1131
  for (let i = 0; i < numContainers; i++) {
1039
1132
  const itemKey = peek$(ctx, `containerItemKey${i}`);
1040
1133
  const itemIndex = state.indexByKey.get(itemKey);
1041
- const item = data2[itemIndex];
1134
+ const item = data[itemIndex];
1042
1135
  if (item) {
1043
1136
  const id = getId(itemIndex);
1044
1137
  if (itemKey !== id || itemIndex < startBuffered || itemIndex > endBuffered) {
1045
1138
  const prevPos = peek$(ctx, `containerPosition${i}`).top;
1046
1139
  const pos = positions.get(id) || 0;
1047
- const size = getItemSize(id, itemIndex, data2[i]);
1140
+ const size = getItemSize(id, itemIndex, data[i]);
1048
1141
  if (pos + size >= scroll && pos <= scrollBottom || prevPos + size >= scroll && prevPos <= scrollBottom) {
1049
1142
  set$(ctx, `containerPosition${i}`, ANCHORED_POSITION_OUT_OF_VIEW);
1050
1143
  }
@@ -1058,7 +1151,7 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
1058
1151
  if (maintainVisibleContentPosition && itemIndex < anchorElementIndex) {
1059
1152
  const currentRow = Math.floor(itemIndex / numColumnsProp);
1060
1153
  const rowHeight = getRowHeight(currentRow);
1061
- const elementHeight = getItemSize(id, itemIndex, data2[i]);
1154
+ const elementHeight = getItemSize(id, itemIndex, data[i]);
1062
1155
  const diff = rowHeight - elementHeight;
1063
1156
  pos.relativeCoordinate = pos.top + getRowHeight(currentRow) - diff;
1064
1157
  pos.type = "bottom";
@@ -1073,7 +1166,7 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
1073
1166
  set$(ctx, `containerColumn${i}`, column2);
1074
1167
  }
1075
1168
  if (prevData !== item) {
1076
- set$(ctx, `containerItemData${i}`, data2[itemIndex]);
1169
+ set$(ctx, `containerItemData${i}`, data[itemIndex]);
1077
1170
  }
1078
1171
  }
1079
1172
  }
@@ -1103,7 +1196,10 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
1103
1196
  const doMaintainScrollAtEnd = (animated) => {
1104
1197
  const state = refState.current;
1105
1198
  if ((state == null ? void 0 : state.isAtBottom) && maintainScrollAtEnd) {
1106
- state.scroll = state.totalSize - state.scrollLength + peek$(ctx, "paddingTop");
1199
+ const paddingTop = peek$(ctx, "paddingTop") || 0;
1200
+ if (paddingTop > 0) {
1201
+ state.scroll = 0;
1202
+ }
1107
1203
  requestAnimationFrame(() => {
1108
1204
  var _a2;
1109
1205
  (_a2 = refScroller.current) == null ? void 0 : _a2.scrollToEnd({
@@ -1119,21 +1215,19 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
1119
1215
  }
1120
1216
  const { scrollLength, scroll, totalSize } = refState.current;
1121
1217
  if (totalSize > 0) {
1122
- const distanceFromEnd = totalSize - scroll - scrollLength;
1218
+ const distanceFromEnd = totalSize - scroll - scrollLength + (peek$(ctx, "paddingTop") || 0);
1123
1219
  if (refState.current) {
1124
1220
  refState.current.isAtBottom = distanceFromEnd < scrollLength * maintainScrollAtEndThreshold;
1125
1221
  }
1126
- const { onEndReached } = callbacks.current;
1127
- if (onEndReached) {
1128
- if (!refState.current.isEndReached) {
1129
- if (distanceFromEnd < onEndReachedThreshold * scrollLength) {
1130
- refState.current.isEndReached = true;
1131
- onEndReached({ distanceFromEnd });
1132
- }
1133
- } else {
1134
- if (distanceFromEnd >= onEndReachedThreshold * scrollLength) {
1135
- refState.current.isEndReached = false;
1136
- }
1222
+ if (!refState.current.isEndReached) {
1223
+ if (distanceFromEnd < onEndReachedThreshold * scrollLength) {
1224
+ refState.current.isEndReached = true;
1225
+ const { onEndReached } = callbacks.current;
1226
+ onEndReached == null ? void 0 : onEndReached({ distanceFromEnd });
1227
+ }
1228
+ } else {
1229
+ if (distanceFromEnd >= onEndReachedThreshold * scrollLength) {
1230
+ refState.current.isEndReached = false;
1137
1231
  }
1138
1232
  }
1139
1233
  }
@@ -1145,29 +1239,27 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
1145
1239
  const { scrollLength, scroll } = refState.current;
1146
1240
  const distanceFromTop = scroll;
1147
1241
  refState.current.isAtTop = distanceFromTop < 0;
1148
- const { onStartReached } = callbacks.current;
1149
- if (onStartReached) {
1150
- if (!refState.current.isStartReached && !refState.current.startReachedBlockedByTimer) {
1151
- if (distanceFromTop < onStartReachedThreshold * scrollLength) {
1152
- refState.current.isStartReached = true;
1153
- onStartReached({ distanceFromStart: scroll });
1154
- refState.current.startReachedBlockedByTimer = true;
1155
- setTimeout(() => {
1156
- refState.current.startReachedBlockedByTimer = false;
1157
- }, 700);
1158
- }
1159
- } else {
1160
- if (distanceFromTop >= 1.3 * onStartReachedThreshold * scrollLength) {
1161
- refState.current.isStartReached = false;
1162
- }
1242
+ if (!refState.current.isStartReached && !refState.current.startReachedBlockedByTimer) {
1243
+ if (distanceFromTop < onStartReachedThreshold * scrollLength) {
1244
+ refState.current.isStartReached = true;
1245
+ const { onStartReached } = callbacks.current;
1246
+ onStartReached == null ? void 0 : onStartReached({ distanceFromStart: scroll });
1247
+ refState.current.startReachedBlockedByTimer = true;
1248
+ setTimeout(() => {
1249
+ refState.current.startReachedBlockedByTimer = false;
1250
+ }, 700);
1251
+ }
1252
+ } else {
1253
+ if (distanceFromTop >= 1.3 * onStartReachedThreshold * scrollLength) {
1254
+ refState.current.isStartReached = false;
1163
1255
  }
1164
1256
  }
1165
1257
  };
1166
- const checkResetContainers = (reset) => {
1258
+ const checkResetContainers = (isFirst2) => {
1167
1259
  const state = refState.current;
1168
1260
  if (state) {
1169
- state.data = data;
1170
- if (reset) {
1261
+ state.data = dataProp;
1262
+ if (!isFirst2) {
1171
1263
  refState.current.scrollForNextCalculateItemsInView = void 0;
1172
1264
  const numContainers = peek$(ctx, "numContainers");
1173
1265
  for (let i = 0; i < numContainers; i++) {
@@ -1183,28 +1275,28 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
1183
1275
  state.positions.clear();
1184
1276
  }
1185
1277
  calculateItemsInView(state.scrollVelocity);
1278
+ const didMaintainScrollAtEnd = doMaintainScrollAtEnd(false);
1279
+ if (!didMaintainScrollAtEnd && dataProp.length > state.data.length) {
1280
+ state.isEndReached = false;
1281
+ }
1282
+ checkAtTop();
1283
+ checkAtBottom();
1186
1284
  }
1187
- const didMaintainScrollAtEnd = doMaintainScrollAtEnd(false);
1188
- if (!didMaintainScrollAtEnd && data.length > state.data.length) {
1189
- state.isEndReached = false;
1190
- }
1191
- checkAtTop();
1192
- checkAtBottom();
1193
1285
  }
1194
1286
  };
1195
1287
  const isFirst = !refState.current.renderItem;
1196
- if (isFirst || data !== refState.current.data || numColumnsProp !== peek$(ctx, "numColumns")) {
1197
- if (!keyExtractorProp && !isFirst && data !== refState.current.data) {
1288
+ if (isFirst || dataProp !== refState.current.data || numColumnsProp !== peek$(ctx, "numColumns")) {
1289
+ if (!keyExtractorProp && !isFirst && dataProp !== refState.current.data) {
1198
1290
  refState.current.positions.clear();
1199
1291
  }
1200
- refState.current.data = data;
1292
+ refState.current.data = dataProp;
1201
1293
  let totalSize = 0;
1202
1294
  let totalSizeBelowIndex = 0;
1203
1295
  const indexByKey = /* @__PURE__ */ new Map();
1204
1296
  const newPositions = /* @__PURE__ */ new Map();
1205
1297
  let column = 1;
1206
1298
  let maxSizeInRow = 0;
1207
- for (let i = 0; i < data.length; i++) {
1299
+ for (let i = 0; i < dataProp.length; i++) {
1208
1300
  const key = getId(i);
1209
1301
  if (__DEV__) {
1210
1302
  if (indexByKey.has(key)) {
@@ -1223,7 +1315,7 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
1223
1315
  if (!isFirst) {
1224
1316
  if (maintainVisibleContentPosition) {
1225
1317
  if (refState.current.anchorElement == null || indexByKey.get(refState.current.anchorElement.id) == null) {
1226
- if (data.length) {
1318
+ if (dataProp.length) {
1227
1319
  const newAnchorElement = {
1228
1320
  coordinate: 0,
1229
1321
  id: getId(0)
@@ -1240,7 +1332,7 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
1240
1332
  }
1241
1333
  } else {
1242
1334
  if (refState.current.startBufferedId != null && newPositions.get(refState.current.startBufferedId) == null) {
1243
- if (data.length) {
1335
+ if (dataProp.length) {
1244
1336
  refState.current.startBufferedId = getId(0);
1245
1337
  } else {
1246
1338
  refState.current.startBufferedId = void 0;
@@ -1253,9 +1345,9 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
1253
1345
  }
1254
1346
  }
1255
1347
  const anchorElementIndex = getAnchorElementIndex();
1256
- for (let i = 0; i < data.length; i++) {
1348
+ for (let i = 0; i < dataProp.length; i++) {
1257
1349
  const key = getId(i);
1258
- const size = getItemSize(key, i, data[i]);
1350
+ const size = getItemSize(key, i, dataProp[i]);
1259
1351
  maxSizeInRow = Math.max(maxSizeInRow, size);
1260
1352
  column++;
1261
1353
  if (column > numColumnsProp) {
@@ -1272,17 +1364,17 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
1272
1364
  }
1273
1365
  addTotalSize(null, totalSize, totalSizeBelowIndex);
1274
1366
  }
1275
- React5.useEffect(() => {
1367
+ React6.useEffect(() => {
1276
1368
  checkResetContainers(
1277
- /*reset*/
1278
- !isFirst
1369
+ /*isFirst*/
1370
+ isFirst
1279
1371
  );
1280
- }, [isFirst, data, numColumnsProp]);
1281
- React5.useEffect(() => {
1372
+ }, [isFirst, dataProp, numColumnsProp]);
1373
+ React6.useEffect(() => {
1282
1374
  set$(ctx, "extraData", extraData);
1283
1375
  }, [extraData]);
1284
1376
  refState.current.renderItem = renderItem;
1285
- const lastItemKey = data.length > 0 ? getId(data.length - 1) : void 0;
1377
+ const lastItemKey = dataProp.length > 0 ? getId(dataProp.length - 1) : void 0;
1286
1378
  const stylePaddingTop = (_g = (_f = (_d = reactNative.StyleSheet.flatten(style)) == null ? void 0 : _d.paddingTop) != null ? _f : (_e = reactNative.StyleSheet.flatten(contentContainerStyle)) == null ? void 0 : _e.paddingTop) != null ? _g : 0;
1287
1379
  const initalizeStateVars = () => {
1288
1380
  set$(ctx, "lastItemKey", lastItemKey);
@@ -1292,14 +1384,14 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
1292
1384
  if (isFirst) {
1293
1385
  initalizeStateVars();
1294
1386
  }
1295
- React5.useEffect(initalizeStateVars, [lastItemKey, numColumnsProp, stylePaddingTop]);
1296
- const getRenderedItem = React5.useCallback((key) => {
1387
+ React6.useEffect(initalizeStateVars, [lastItemKey, numColumnsProp, stylePaddingTop]);
1388
+ const getRenderedItem = React6.useCallback((key) => {
1297
1389
  var _a2, _b2;
1298
1390
  const state = refState.current;
1299
1391
  if (!state) {
1300
1392
  return null;
1301
1393
  }
1302
- const { data: data2, indexByKey } = state;
1394
+ const { data, indexByKey } = state;
1303
1395
  const index = indexByKey.get(key);
1304
1396
  if (index === void 0) {
1305
1397
  return null;
@@ -1317,7 +1409,7 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
1317
1409
  return useRecyclingState(valueOrFun);
1318
1410
  };
1319
1411
  const renderedItem = (_b2 = (_a2 = refState.current).renderItem) == null ? void 0 : _b2.call(_a2, {
1320
- item: data2[index],
1412
+ item: data[index],
1321
1413
  index,
1322
1414
  useViewability: useViewability2,
1323
1415
  useViewabilityAmount: useViewabilityAmount2,
@@ -1333,7 +1425,7 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
1333
1425
  state.viewabilityConfigCallbackPairs = viewability;
1334
1426
  state.enableScrollForNextCalculateItemsInView = !viewability;
1335
1427
  const scrollLength = state.scrollLength;
1336
- const averageItemSize = (_a2 = estimatedItemSize != null ? estimatedItemSize : getEstimatedItemSize == null ? void 0 : getEstimatedItemSize(0, data[0])) != null ? _a2 : DEFAULT_ITEM_SIZE;
1428
+ const averageItemSize = (_a2 = estimatedItemSize != null ? estimatedItemSize : getEstimatedItemSize == null ? void 0 : getEstimatedItemSize(0, dataProp[0])) != null ? _a2 : DEFAULT_ITEM_SIZE;
1337
1429
  const numContainers = Math.ceil((scrollLength + scrollBuffer * 2) / averageItemSize) * numColumnsProp;
1338
1430
  for (let i = 0; i < numContainers; i++) {
1339
1431
  set$(ctx, `containerPosition${i}`, ANCHORED_POSITION_OUT_OF_VIEW);
@@ -1341,31 +1433,33 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
1341
1433
  }
1342
1434
  set$(ctx, "numContainers", numContainers);
1343
1435
  set$(ctx, "numContainersPooled", numContainers * 2);
1344
- calculateItemsInView(state.scrollVelocity);
1436
+ if (initialScrollIndex) {
1437
+ requestAnimationFrame(() => {
1438
+ calculateItemsInView(state.scrollVelocity);
1439
+ });
1440
+ } else {
1441
+ calculateItemsInView(state.scrollVelocity);
1442
+ }
1345
1443
  });
1346
- const updateItemSize = React5.useCallback((containerId, itemKey, size) => {
1444
+ const updateItemSize = React6.useCallback((containerId, itemKey, size) => {
1347
1445
  const state = refState.current;
1348
- const { sizes, indexByKey, columns, sizesLaidOut, data: data2 } = state;
1349
- if (!data2) {
1446
+ const { sizes, indexByKey, columns, sizesLaidOut, data, rowHeights } = state;
1447
+ if (!data) {
1350
1448
  return;
1351
1449
  }
1352
1450
  const index = indexByKey.get(itemKey);
1353
1451
  const numColumns = peek$(ctx, "numColumns");
1354
1452
  state.minIndexSizeChanged = state.minIndexSizeChanged !== void 0 ? Math.min(state.minIndexSizeChanged, index) : index;
1355
- const prevSize = getItemSize(itemKey, index, data2);
1453
+ const prevSize = getItemSize(itemKey, index, data);
1356
1454
  if (!prevSize || Math.abs(prevSize - size) > 0.5) {
1357
1455
  let diff;
1358
1456
  if (numColumns > 1) {
1457
+ const rowNumber = Math.floor(index / numColumnsProp);
1458
+ const prevSizeInRow = getRowHeight(rowNumber);
1359
1459
  sizes.set(itemKey, size);
1360
- const column = columns.get(itemKey);
1361
- const loopStart = index - (column - 1);
1362
- let nextMaxSizeInRow = 0;
1363
- for (let i = loopStart; i < loopStart + numColumns && i < data2.length; i++) {
1364
- const id = getId(i);
1365
- const size2 = getItemSize(id, i, data2[i]);
1366
- nextMaxSizeInRow = Math.max(nextMaxSizeInRow, size2);
1367
- }
1368
- diff = nextMaxSizeInRow - prevSize;
1460
+ rowHeights.delete(rowNumber);
1461
+ const sizeInRow = getRowHeight(rowNumber);
1462
+ diff = sizeInRow - prevSizeInRow;
1369
1463
  } else {
1370
1464
  sizes.set(itemKey, size);
1371
1465
  diff = size - prevSize;
@@ -1407,16 +1501,16 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
1407
1501
  }
1408
1502
  }
1409
1503
  if (onItemSizeChanged) {
1410
- onItemSizeChanged({ size, previous: prevSize, index, itemKey, itemData: data2[index] });
1504
+ onItemSizeChanged({ size, previous: prevSize, index, itemKey, itemData: data[index] });
1411
1505
  }
1412
1506
  }
1413
1507
  }, []);
1414
- const handleScrollDebounced = React5.useCallback((velocity) => {
1508
+ const handleScrollDebounced = React6.useCallback((velocity) => {
1415
1509
  calculateItemsInView(velocity);
1416
1510
  checkAtBottom();
1417
1511
  checkAtTop();
1418
1512
  }, []);
1419
- const onLayout = React5.useCallback((event) => {
1513
+ const onLayout = React6.useCallback((event) => {
1420
1514
  const scrollLength = event.nativeEvent.layout[horizontal ? "width" : "height"];
1421
1515
  const didChange = scrollLength !== refState.current.scrollLength;
1422
1516
  refState.current.scrollLength = scrollLength;
@@ -1440,7 +1534,7 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
1440
1534
  onLayoutProp(event);
1441
1535
  }
1442
1536
  }, []);
1443
- const handleScroll = React5.useCallback(
1537
+ const handleScroll = React6.useCallback(
1444
1538
  (event, fromSelf) => {
1445
1539
  var _a2, _b2, _c2;
1446
1540
  if (((_b2 = (_a2 = event.nativeEvent) == null ? void 0 : _a2.contentSize) == null ? void 0 : _b2.height) === 0 && ((_c2 = event.nativeEvent.contentSize) == null ? void 0 : _c2.width) === 0) {
@@ -1482,7 +1576,7 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
1482
1576
  },
1483
1577
  []
1484
1578
  );
1485
- React5.useImperativeHandle(
1579
+ React6.useImperativeHandle(
1486
1580
  forwardedRef,
1487
1581
  () => {
1488
1582
  const scrollToIndex = ({ index, animated }) => {
@@ -1501,6 +1595,7 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
1501
1595
  refScroller.current.scrollTo({ ...offsetObj, animated });
1502
1596
  },
1503
1597
  scrollToItem: ({ item, animated }) => {
1598
+ const { data } = refState.current;
1504
1599
  const index = data.indexOf(item);
1505
1600
  if (index !== -1) {
1506
1601
  scrollToIndex({ index, animated });
@@ -1511,21 +1606,12 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
1511
1606
  },
1512
1607
  []
1513
1608
  );
1514
- return /* @__PURE__ */ React5__namespace.createElement(
1609
+ return /* @__PURE__ */ React6__namespace.createElement(React6__namespace.Fragment, null, /* @__PURE__ */ React6__namespace.createElement(
1515
1610
  ListComponent,
1516
1611
  {
1517
1612
  ...rest,
1518
1613
  horizontal,
1519
- refScrollView: (r) => {
1520
- refScroller.current = r;
1521
- if (refScrollView) {
1522
- if (typeof refScrollView === "function") {
1523
- refScrollView(r);
1524
- } else {
1525
- refScrollView.current = r;
1526
- }
1527
- }
1528
- },
1614
+ refScrollView: combinedRef,
1529
1615
  initialContentOffset,
1530
1616
  getRenderedItem,
1531
1617
  updateItemSize,
@@ -1533,13 +1619,13 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
1533
1619
  onLayout,
1534
1620
  recycleItems,
1535
1621
  alignItemsAtEnd,
1536
- ListEmptyComponent: data.length === 0 ? ListEmptyComponent : void 0,
1622
+ ListEmptyComponent: dataProp.length === 0 ? ListEmptyComponent : void 0,
1537
1623
  maintainVisibleContentPosition,
1538
1624
  scrollEventThrottle: scrollEventThrottle != null ? scrollEventThrottle : reactNative.Platform.OS === "web" ? 16 : void 0,
1539
1625
  waitForInitialLayout,
1540
1626
  style
1541
1627
  }
1542
- );
1628
+ ), __DEV__ && ENABLE_DEBUG_VIEW && /* @__PURE__ */ React6__namespace.createElement(DebugView, { state: refState.current }));
1543
1629
  });
1544
1630
 
1545
1631
  exports.LegendList = LegendList;