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

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 React4 = require('react');
3
+ var React5 = 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 React4__namespace = /*#__PURE__*/_interopNamespace(React4);
24
+ var React5__namespace = /*#__PURE__*/_interopNamespace(React5);
25
25
 
26
26
  // src/LegendList.tsx
27
- var ContextState = React4__namespace.createContext(null);
27
+ var ContextState = React5__namespace.createContext(null);
28
28
  function StateProvider({ children }) {
29
- const [value] = React4__namespace.useState(() => ({
29
+ const [value] = React5__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__ */ React4__namespace.createElement(ContextState.Provider, { value }, children);
37
+ return /* @__PURE__ */ React5__namespace.createElement(ContextState.Provider, { value }, children);
38
38
  }
39
39
  function useStateContext() {
40
- return React4__namespace.useContext(ContextState);
40
+ return React5__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 = React4__namespace.useContext(ContextState);
50
- const { subscribe, get } = React4__namespace.useMemo(() => createSelectorFunctions(ctx, signalName), []);
51
- const value = React4.useSyncExternalStore(subscribe, get);
49
+ const ctx = React5__namespace.useContext(ContextState);
50
+ const { subscribe, get } = React5__namespace.useMemo(() => createSelectorFunctions(ctx, signalName), []);
51
+ const value = React5.useSyncExternalStore(subscribe, get);
52
52
  return value;
53
53
  }
54
54
  function listen$(ctx, signalName, cb) {
@@ -77,75 +77,207 @@ function set$(ctx, signalName, value) {
77
77
  }
78
78
  }
79
79
  }
80
+ var symbolFirst = Symbol();
81
+ function useInit(cb) {
82
+ const refValue = React5.useRef(symbolFirst);
83
+ if (refValue.current === symbolFirst) {
84
+ refValue.current = cb();
85
+ }
86
+ return refValue.current;
87
+ }
88
+
89
+ // src/ContextContainer.ts
90
+ var ContextContainer = React5.createContext(null);
91
+ function useViewability(configId, callback) {
92
+ const ctx = useStateContext();
93
+ const { containerId } = React5.useContext(ContextContainer);
94
+ const key = containerId + configId;
95
+ useInit(() => {
96
+ const value = ctx.mapViewabilityValues.get(key);
97
+ if (value) {
98
+ callback(value);
99
+ }
100
+ });
101
+ ctx.mapViewabilityCallbacks.set(key, callback);
102
+ React5.useEffect(
103
+ () => () => {
104
+ ctx.mapViewabilityCallbacks.delete(key);
105
+ },
106
+ []
107
+ );
108
+ }
109
+ function useViewabilityAmount(callback) {
110
+ const ctx = useStateContext();
111
+ const { containerId } = React5.useContext(ContextContainer);
112
+ useInit(() => {
113
+ const value = ctx.mapViewabilityAmountValues.get(containerId);
114
+ if (value) {
115
+ callback(value);
116
+ }
117
+ });
118
+ ctx.mapViewabilityAmountCallbacks.set(containerId, callback);
119
+ React5.useEffect(
120
+ () => () => {
121
+ ctx.mapViewabilityAmountCallbacks.delete(containerId);
122
+ },
123
+ []
124
+ );
125
+ }
126
+ function useRecyclingEffect(effect) {
127
+ const { index, value } = React5.useContext(ContextContainer);
128
+ const prevValues = React5.useRef({
129
+ prevIndex: void 0,
130
+ prevItem: void 0
131
+ });
132
+ React5.useEffect(() => {
133
+ let ret = void 0;
134
+ if (prevValues.current.prevIndex !== void 0 && prevValues.current.prevItem !== void 0) {
135
+ ret = effect({
136
+ index,
137
+ item: value,
138
+ prevIndex: prevValues.current.prevIndex,
139
+ prevItem: prevValues.current.prevItem
140
+ });
141
+ }
142
+ prevValues.current = {
143
+ prevIndex: index,
144
+ prevItem: value
145
+ };
146
+ return ret;
147
+ }, [index, value]);
148
+ }
149
+ function useRecyclingState(valueOrFun) {
150
+ const { index, value } = React5.useContext(ContextContainer);
151
+ const stateInfo = React5.useState(
152
+ () => typeof valueOrFun === "function" ? valueOrFun({
153
+ index,
154
+ item: value,
155
+ prevIndex: void 0,
156
+ prevItem: void 0
157
+ }) : valueOrFun
158
+ );
159
+ useRecyclingEffect((state) => {
160
+ const newState = typeof valueOrFun === "function" ? valueOrFun(state) : valueOrFun;
161
+ stateInfo[1](newState);
162
+ });
163
+ return stateInfo;
164
+ }
165
+ var LeanView = React5__namespace.forwardRef((props, ref) => {
166
+ return React5__namespace.createElement("RCTView", { ...props, ref });
167
+ });
168
+ LeanView.displayName = "RCTView";
169
+
170
+ // src/constants.ts
171
+ var POSITION_OUT_OF_VIEW = -1e7;
172
+ var ANCHORED_POSITION_OUT_OF_VIEW = {
173
+ type: "top",
174
+ relativeCoordinate: POSITION_OUT_OF_VIEW,
175
+ top: POSITION_OUT_OF_VIEW
176
+ };
80
177
 
81
178
  // src/Container.tsx
179
+ var isNewArchitecture = global.nativeFabricUIManager != null;
82
180
  var Container = ({
83
181
  id,
84
182
  recycleItems,
85
183
  horizontal,
86
- waitForInitialLayout,
87
184
  getRenderedItem,
88
185
  updateItemSize,
89
186
  ItemSeparatorComponent
90
187
  }) => {
91
- const ctx = useStateContext();
92
- const position = use$(`containerPosition${id}`);
188
+ useStateContext();
189
+ const maintainVisibleContentPosition = use$("maintainVisibleContentPosition");
190
+ const position = use$(`containerPosition${id}`) || ANCHORED_POSITION_OUT_OF_VIEW;
93
191
  const column = use$(`containerColumn${id}`) || 0;
94
192
  const numColumns = use$("numColumns");
95
193
  const otherAxisPos = numColumns > 1 ? `${(column - 1) / numColumns * 100}%` : 0;
96
194
  const otherAxisSize = numColumns > 1 ? `${1 / numColumns * 100}%` : void 0;
97
195
  const style = horizontal ? {
98
- flexDirection: "row",
196
+ flexDirection: ItemSeparatorComponent ? "row" : void 0,
99
197
  position: "absolute",
100
198
  top: otherAxisPos,
101
199
  bottom: numColumns > 1 ? null : 0,
102
200
  height: otherAxisSize,
103
- left: position
201
+ left: position.relativeCoordinate
104
202
  } : {
105
203
  position: "absolute",
106
204
  left: otherAxisPos,
107
205
  right: numColumns > 1 ? null : 0,
108
206
  width: otherAxisSize,
109
- top: position
207
+ top: position.relativeCoordinate
110
208
  };
111
- if (waitForInitialLayout) {
112
- const visible = use$(`containerDidLayout${id}`);
113
- style.opacity = visible ? 1 : 0;
114
- }
115
209
  const lastItemKey = use$("lastItemKey");
116
210
  const itemKey = use$(`containerItemKey${id}`);
117
211
  const data = use$(`containerItemData${id}`);
118
- const renderedItem = React4.useMemo(() => itemKey !== void 0 && getRenderedItem(itemKey, id), [itemKey, data]);
119
- return /* @__PURE__ */ React4__namespace.default.createElement(
120
- reactNative.View,
121
- {
122
- style,
123
- onLayout: (event) => {
124
- const key = peek$(ctx, `containerItemKey${id}`);
125
- if (key !== void 0) {
126
- const size = Math.floor(event.nativeEvent.layout[horizontal ? "width" : "height"] * 8) / 8;
127
- updateItemSize(id, key, size);
212
+ const extraData = use$("extraData");
213
+ const renderedItemInfo = React5.useMemo(
214
+ () => itemKey !== void 0 && getRenderedItem(itemKey),
215
+ [itemKey, data, extraData]
216
+ );
217
+ const { index, renderedItem } = renderedItemInfo || {};
218
+ const onLayout = (event) => {
219
+ if (itemKey !== void 0) {
220
+ const size = Math.floor(event.nativeEvent.layout[horizontal ? "width" : "height"] * 8) / 8;
221
+ if (size === 0) {
222
+ console.log("[WARN] Container 0 height reported, possible bug in LegendList", id, itemKey);
223
+ return;
224
+ }
225
+ updateItemSize(id, itemKey, size);
226
+ }
227
+ };
228
+ const ref = React5.useRef(null);
229
+ if (isNewArchitecture) {
230
+ React5.useLayoutEffect(() => {
231
+ var _a, _b;
232
+ if (itemKey !== void 0) {
233
+ const measured = (_b = (_a = ref.current) == null ? void 0 : _a.unstable_getBoundingClientRect) == null ? void 0 : _b.call(_a);
234
+ if (measured) {
235
+ const size = Math.floor(measured[horizontal ? "width" : "height"] * 8) / 8;
236
+ if (size) {
237
+ updateItemSize(id, itemKey, size);
238
+ }
128
239
  }
129
240
  }
130
- },
131
- /* @__PURE__ */ React4__namespace.default.createElement(React4__namespace.default.Fragment, { key: recycleItems ? void 0 : itemKey }, renderedItem, renderedItem && ItemSeparatorComponent && itemKey !== lastItemKey && ItemSeparatorComponent)
241
+ }, [itemKey]);
242
+ }
243
+ const contextValue = React5.useMemo(
244
+ () => ({ containerId: id, itemKey, index, value: data }),
245
+ [id, itemKey, index, data]
132
246
  );
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));
248
+ if (maintainVisibleContentPosition) {
249
+ 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));
251
+ }
252
+ return /* @__PURE__ */ React5__namespace.default.createElement(LeanView, { style, onLayout, ref }, contentFragment);
133
253
  };
134
254
  var useAnimatedValue = reactNative.useAnimatedValue || ((initialValue) => {
135
- return React4.useRef(new reactNative.Animated.Value(initialValue)).current;
255
+ return React5.useRef(new reactNative.Animated.Value(initialValue)).current;
136
256
  });
137
- function useValue$(key, getValue, key2) {
257
+ function useValue$(key, getValue, useMicrotask) {
138
258
  var _a;
139
259
  const ctx = useStateContext();
140
- const animValue = useAnimatedValue((_a = peek$(ctx, key)) != null ? _a : 0);
141
- React4.useMemo(() => {
142
- listen$(ctx, key, (v) => animValue.setValue(v));
260
+ const animValue = useAnimatedValue((_a = getValue ? getValue(peek$(ctx, key)) : peek$(ctx, key)) != null ? _a : 0);
261
+ React5.useMemo(() => {
262
+ let newValue = void 0;
263
+ listen$(ctx, key, (v) => {
264
+ if (useMicrotask && newValue === void 0) {
265
+ queueMicrotask(() => {
266
+ animValue.setValue(newValue);
267
+ newValue = void 0;
268
+ });
269
+ }
270
+ newValue = getValue ? getValue(v) : v;
271
+ if (!useMicrotask) {
272
+ animValue.setValue(newValue);
273
+ }
274
+ });
143
275
  }, []);
144
276
  return animValue;
145
277
  }
146
278
 
147
279
  // src/Containers.tsx
148
- var Containers = React4__namespace.memo(function Containers2({
280
+ var Containers = React5__namespace.memo(function Containers2({
149
281
  horizontal,
150
282
  recycleItems,
151
283
  ItemSeparatorComponent,
@@ -154,18 +286,23 @@ var Containers = React4__namespace.memo(function Containers2({
154
286
  getRenderedItem
155
287
  }) {
156
288
  const numContainers = use$("numContainersPooled");
157
- const animSize = useValue$("totalSize");
289
+ const animSize = useValue$(
290
+ "totalSize",
291
+ void 0,
292
+ /*useMicrotask*/
293
+ true
294
+ );
295
+ const animOpacity = waitForInitialLayout ? useValue$("containersDidLayout", (value) => value ? 1 : 0) : void 0;
158
296
  const containers = [];
159
297
  for (let i = 0; i < numContainers; i++) {
160
298
  containers.push(
161
- /* @__PURE__ */ React4__namespace.createElement(
299
+ /* @__PURE__ */ React5__namespace.createElement(
162
300
  Container,
163
301
  {
164
302
  id: i,
165
303
  key: i,
166
304
  recycleItems,
167
305
  horizontal,
168
- waitForInitialLayout,
169
306
  getRenderedItem,
170
307
  updateItemSize,
171
308
  ItemSeparatorComponent
@@ -173,21 +310,21 @@ var Containers = React4__namespace.memo(function Containers2({
173
310
  )
174
311
  );
175
312
  }
176
- const style = horizontal ? { width: animSize } : { height: animSize };
177
- return /* @__PURE__ */ React4__namespace.createElement(reactNative.Animated.View, { style }, containers);
313
+ const style = horizontal ? { width: animSize, opacity: animOpacity } : { height: animSize, opacity: animOpacity };
314
+ return /* @__PURE__ */ React5__namespace.createElement(reactNative.Animated.View, { style }, containers);
178
315
  });
179
316
 
180
317
  // src/ListComponent.tsx
181
318
  var getComponent = (Component) => {
182
- if (React4__namespace.isValidElement(Component)) {
319
+ if (React5__namespace.isValidElement(Component)) {
183
320
  return Component;
184
321
  }
185
322
  if (Component) {
186
- return /* @__PURE__ */ React4__namespace.createElement(Component, null);
323
+ return /* @__PURE__ */ React5__namespace.createElement(Component, null);
187
324
  }
188
325
  return null;
189
326
  };
190
- var ListComponent = React4__namespace.memo(function ListComponent2({
327
+ var ListComponent = React5__namespace.memo(function ListComponent2({
191
328
  style,
192
329
  contentContainerStyle,
193
330
  horizontal,
@@ -203,7 +340,6 @@ var ListComponent = React4__namespace.memo(function ListComponent2({
203
340
  ListFooterComponent,
204
341
  ListFooterComponentStyle,
205
342
  ListEmptyComponent,
206
- ListEmptyComponentStyle,
207
343
  getRenderedItem,
208
344
  updateItemSize,
209
345
  refScrollView,
@@ -214,17 +350,17 @@ var ListComponent = React4__namespace.memo(function ListComponent2({
214
350
  const ctx = useStateContext();
215
351
  const animPaddingTop = useValue$("paddingTop");
216
352
  const animScrollAdjust = useValue$("scrollAdjust");
217
- const ScrollComponent = renderScrollComponent ? React4.useMemo(
218
- () => React4__namespace.forwardRef((props, ref) => renderScrollComponent({ ...props, ref })),
353
+ const ScrollComponent = renderScrollComponent ? React5.useMemo(
354
+ () => React5__namespace.forwardRef((props, ref) => renderScrollComponent({ ...props, ref })),
219
355
  [renderScrollComponent]
220
356
  ) : reactNative.ScrollView;
221
357
  const additionalSize = { marginTop: animScrollAdjust, paddingTop: animPaddingTop };
222
- return /* @__PURE__ */ React4__namespace.createElement(
358
+ return /* @__PURE__ */ React5__namespace.createElement(
223
359
  ScrollComponent,
224
360
  {
225
361
  ...rest,
226
362
  style,
227
- maintainVisibleContentPosition: maintainVisibleContentPosition ? { minIndexForVisible: 0 } : void 0,
363
+ maintainVisibleContentPosition: maintainVisibleContentPosition && !ListEmptyComponent ? { minIndexForVisible: 0 } : void 0,
228
364
  contentContainerStyle: [
229
365
  contentContainerStyle,
230
366
  horizontal ? {
@@ -237,8 +373,8 @@ var ListComponent = React4__namespace.memo(function ListComponent2({
237
373
  contentOffset: initialContentOffset ? horizontal ? { x: initialContentOffset, y: 0 } : { x: 0, y: initialContentOffset } : void 0,
238
374
  ref: refScrollView
239
375
  },
240
- /* @__PURE__ */ React4__namespace.createElement(reactNative.Animated.View, { style: additionalSize }),
241
- ListHeaderComponent && /* @__PURE__ */ React4__namespace.createElement(
376
+ /* @__PURE__ */ React5__namespace.createElement(reactNative.Animated.View, { style: additionalSize }),
377
+ ListHeaderComponent && /* @__PURE__ */ React5__namespace.createElement(
242
378
  reactNative.Animated.View,
243
379
  {
244
380
  style: ListHeaderComponentStyle,
@@ -252,8 +388,8 @@ var ListComponent = React4__namespace.memo(function ListComponent2({
252
388
  },
253
389
  getComponent(ListHeaderComponent)
254
390
  ),
255
- ListEmptyComponent && /* @__PURE__ */ React4__namespace.createElement(reactNative.Animated.View, { style: ListEmptyComponentStyle }, getComponent(ListEmptyComponent)),
256
- /* @__PURE__ */ React4__namespace.createElement(
391
+ ListEmptyComponent && getComponent(ListEmptyComponent),
392
+ /* @__PURE__ */ React5__namespace.createElement(
257
393
  Containers,
258
394
  {
259
395
  horizontal,
@@ -264,7 +400,7 @@ var ListComponent = React4__namespace.memo(function ListComponent2({
264
400
  updateItemSize
265
401
  }
266
402
  ),
267
- ListFooterComponent && /* @__PURE__ */ React4__namespace.createElement(reactNative.View, { style: ListFooterComponentStyle }, getComponent(ListFooterComponent))
403
+ ListFooterComponent && /* @__PURE__ */ React5__namespace.createElement(reactNative.View, { style: ListFooterComponentStyle }, getComponent(ListFooterComponent))
268
404
  );
269
405
  });
270
406
 
@@ -304,14 +440,21 @@ var ScrollAdjustHandler = class {
304
440
  return this.appliedAdjust;
305
441
  }
306
442
  };
307
- var symbolFirst = Symbol();
308
- function useInit(cb) {
309
- const refValue = React4.useRef(symbolFirst);
310
- if (refValue.current === symbolFirst) {
311
- refValue.current = cb();
312
- }
313
- return refValue.current;
314
- }
443
+ var useCombinedRef = (...refs) => {
444
+ const callback = React5.useCallback((element) => {
445
+ for (const ref of refs) {
446
+ if (!ref) {
447
+ continue;
448
+ }
449
+ if (typeof ref === "function") {
450
+ ref(element);
451
+ } else {
452
+ ref.current = element;
453
+ }
454
+ }
455
+ }, refs);
456
+ return callback;
457
+ };
315
458
 
316
459
  // src/viewability.ts
317
460
  var mapViewabilityConfigCallbackPairs = /* @__PURE__ */ new Map();
@@ -462,13 +605,12 @@ function maybeUpdateViewabilityCallback(ctx, configId, viewToken) {
462
605
 
463
606
  // src/LegendList.tsx
464
607
  var DEFAULT_DRAW_DISTANCE = 250;
465
- var POSITION_OUT_OF_VIEW = -1e7;
466
608
  var DEFAULT_ITEM_SIZE = 100;
467
- var LegendList = React4.forwardRef(function LegendList2(props, forwardedRef) {
468
- return /* @__PURE__ */ React4__namespace.createElement(StateProvider, null, /* @__PURE__ */ React4__namespace.createElement(LegendListInner, { ...props, ref: forwardedRef }));
609
+ var LegendList = React5.forwardRef(function LegendList2(props, forwardedRef) {
610
+ return /* @__PURE__ */ React5__namespace.createElement(StateProvider, null, /* @__PURE__ */ React5__namespace.createElement(LegendListInner, { ...props, ref: forwardedRef }));
469
611
  });
470
- var LegendListInner = React4.forwardRef(function LegendListInner2(props, forwardedRef) {
471
- var _a, _b, _c, _d;
612
+ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forwardedRef) {
613
+ var _a, _b, _c, _d, _e, _f, _g;
472
614
  const {
473
615
  data,
474
616
  initialScrollIndex,
@@ -488,20 +630,28 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
488
630
  renderItem,
489
631
  estimatedItemSize,
490
632
  getEstimatedItemSize,
491
- onEndReached,
492
- onStartReached,
493
633
  ListEmptyComponent,
494
634
  onItemSizeChanged,
495
635
  scrollEventThrottle,
496
636
  refScrollView,
637
+ waitForInitialLayout = true,
638
+ extraData,
639
+ onLayout: onLayoutProp,
497
640
  ...rest
498
641
  } = props;
499
642
  const { style, contentContainerStyle } = props;
643
+ const callbacks = React5.useRef({
644
+ onStartReached: rest.onStartReached,
645
+ onEndReached: rest.onEndReached
646
+ });
647
+ callbacks.current.onStartReached = rest.onStartReached;
648
+ callbacks.current.onEndReached = rest.onEndReached;
500
649
  const ctx = useStateContext();
501
- const refScroller = React4.useRef(null);
650
+ const refScroller = React5.useRef(null);
651
+ const combinedRef = useCombinedRef(refScroller, refScrollView);
502
652
  const scrollBuffer = drawDistance != null ? drawDistance : DEFAULT_DRAW_DISTANCE;
503
653
  const keyExtractor = keyExtractorProp != null ? keyExtractorProp : (item, index) => index.toString();
504
- const refState = React4.useRef();
654
+ const refState = React5.useRef();
505
655
  const getId = (index) => {
506
656
  var _a2;
507
657
  const data2 = (_a2 = refState.current) == null ? void 0 : _a2.data;
@@ -535,7 +685,7 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
535
685
  }
536
686
  return 0;
537
687
  };
538
- const initialContentOffset = initialScrollOffset != null ? initialScrollOffset : React4.useMemo(calculateInitialOffset, []);
688
+ const initialContentOffset = initialScrollOffset != null ? initialScrollOffset : React5.useMemo(calculateInitialOffset, []);
539
689
  if (!refState.current) {
540
690
  const initialScrollLength = reactNative.Dimensions.get("window")[horizontal ? "width" : "height"];
541
691
  refState.current = {
@@ -543,7 +693,7 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
543
693
  positions: /* @__PURE__ */ new Map(),
544
694
  columns: /* @__PURE__ */ new Map(),
545
695
  pendingAdjust: 0,
546
- animFrameLayout: null,
696
+ waitingForMicrotask: false,
547
697
  isStartReached: initialContentOffset < initialScrollLength * onStartReachedThreshold,
548
698
  isEndReached: false,
549
699
  isAtBottom: false,
@@ -576,9 +726,9 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
576
726
  belowAnchorElementPositions: void 0,
577
727
  rowHeights: /* @__PURE__ */ new Map(),
578
728
  startReachedBlockedByTimer: false,
579
- layoutsPending: /* @__PURE__ */ new Set(),
580
729
  scrollForNextCalculateItemsInView: void 0,
581
- enableScrollForNextCalculateItemsInView: true
730
+ enableScrollForNextCalculateItemsInView: true,
731
+ minIndexSizeChanged: 0
582
732
  };
583
733
  refState.current.idsInFirstRender = new Set(data.map((_, i) => getId(i)));
584
734
  if (maintainVisibleContentPosition) {
@@ -597,6 +747,8 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
597
747
  }
598
748
  }
599
749
  set$(ctx, "scrollAdjust", 0);
750
+ set$(ctx, "maintainVisibleContentPosition", maintainVisibleContentPosition);
751
+ set$(ctx, "extraData", extraData);
600
752
  }
601
753
  const getAnchorElementIndex = () => {
602
754
  const state = refState.current;
@@ -606,16 +758,16 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
606
758
  }
607
759
  return void 0;
608
760
  };
609
- const addTotalSize = React4.useCallback((key, add, totalSizeBelowAnchor) => {
761
+ const addTotalSize = React5.useCallback((key, add, totalSizeBelowAnchor) => {
610
762
  const state = refState.current;
611
- const index = key === null ? 0 : state.indexByKey.get(key);
763
+ const { scrollLength, indexByKey, anchorElement } = state;
764
+ const index = key === null ? 0 : indexByKey.get(key);
612
765
  let isAboveAnchor = false;
613
766
  if (maintainVisibleContentPosition) {
614
- if (state.anchorElement && index < getAnchorElementIndex()) {
767
+ if (anchorElement && index < getAnchorElementIndex()) {
615
768
  isAboveAnchor = true;
616
769
  }
617
770
  }
618
- state.totalSize;
619
771
  if (key === null) {
620
772
  state.totalSize = add;
621
773
  state.totalSizeBelowAnchor = totalSizeBelowAnchor;
@@ -626,19 +778,19 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
626
778
  }
627
779
  }
628
780
  let applyAdjustValue = void 0;
781
+ const totalSize = state.totalSize;
782
+ let resultSize = totalSize;
629
783
  if (maintainVisibleContentPosition) {
630
- const newAdjust = state.anchorElement.coordinate - state.totalSizeBelowAnchor;
784
+ const newAdjust = anchorElement.coordinate - state.totalSizeBelowAnchor;
631
785
  applyAdjustValue = -newAdjust;
632
786
  state.belowAnchorElementPositions = buildElementPositionsBelowAnchor();
633
787
  state.rowHeights.clear();
634
- }
635
- const totalSize = state.totalSize;
636
- let resultSize = totalSize;
637
- if (applyAdjustValue !== void 0) {
638
- resultSize -= applyAdjustValue;
639
- refState.current.scrollAdjustHandler.requestAdjust(applyAdjustValue, (diff) => {
640
- state.scroll -= diff;
641
- });
788
+ if (applyAdjustValue !== void 0) {
789
+ resultSize -= applyAdjustValue;
790
+ refState.current.scrollAdjustHandler.requestAdjust(applyAdjustValue, (diff) => {
791
+ state.scroll -= diff;
792
+ });
793
+ }
642
794
  }
643
795
  set$(ctx, "totalSize", resultSize);
644
796
  if (alignItemsAtEnd) {
@@ -696,7 +848,7 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
696
848
  }
697
849
  return res;
698
850
  };
699
- const calculateItemsInView = React4.useCallback((speed) => {
851
+ const calculateItemsInView = React5.useCallback((speed) => {
700
852
  const state = refState.current;
701
853
  const {
702
854
  data: data2,
@@ -705,12 +857,10 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
705
857
  startBufferedId: startBufferedIdOrig,
706
858
  positions,
707
859
  columns,
708
- scrollAdjustHandler,
709
- layoutsPending
860
+ scrollAdjustHandler
710
861
  } = state;
711
- if (state.animFrameLayout) {
712
- cancelAnimationFrame(state.animFrameLayout);
713
- state.animFrameLayout = null;
862
+ if (state.waitingForMicrotask) {
863
+ state.waitingForMicrotask = false;
714
864
  }
715
865
  if (!data2) {
716
866
  return;
@@ -718,7 +868,17 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
718
868
  const topPad = (peek$(ctx, "stylePaddingTop") || 0) + (peek$(ctx, "headerSize") || 0);
719
869
  const previousScrollAdjust = scrollAdjustHandler.getAppliedAdjust();
720
870
  const scrollExtra = Math.max(-16, Math.min(16, speed)) * 16;
721
- const scroll = scrollState - previousScrollAdjust - topPad - scrollExtra;
871
+ const scroll = scrollState - previousScrollAdjust - topPad;
872
+ let scrollBufferTop = scrollBuffer;
873
+ let scrollBufferBottom = scrollBuffer;
874
+ if (scrollExtra > 8) {
875
+ scrollBufferTop = 0;
876
+ scrollBufferBottom = scrollBuffer + scrollExtra;
877
+ }
878
+ if (scrollExtra < -8) {
879
+ scrollBufferTop = scrollBuffer - scrollExtra;
880
+ scrollBufferBottom = 0;
881
+ }
722
882
  if (state.scrollForNextCalculateItemsInView) {
723
883
  const { top: top2, bottom } = state.scrollForNextCalculateItemsInView;
724
884
  if (scroll > top2 && scroll < bottom) {
@@ -731,8 +891,11 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
731
891
  let startBufferedId = null;
732
892
  let endNoBuffer = null;
733
893
  let endBuffered = null;
734
- const originalStartId = startBufferedIdOrig && state.indexByKey.get(startBufferedIdOrig);
735
- let loopStart = originalStartId || 0;
894
+ let loopStart = startBufferedIdOrig ? state.indexByKey.get(startBufferedIdOrig) || 0 : 0;
895
+ if (state.minIndexSizeChanged !== void 0) {
896
+ loopStart = Math.min(state.minIndexSizeChanged, loopStart);
897
+ state.minIndexSizeChanged = void 0;
898
+ }
736
899
  const anchorElementIndex = getAnchorElementIndex();
737
900
  for (let i = loopStart; i >= 0; i--) {
738
901
  const id = getId(i);
@@ -790,7 +953,7 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
790
953
  if (startNoBuffer === null && top + size > scroll) {
791
954
  startNoBuffer = i;
792
955
  }
793
- if (startBuffered === null && top + size > scroll - scrollBuffer) {
956
+ if (startBuffered === null && top + size > scroll - scrollBufferTop) {
794
957
  startBuffered = i;
795
958
  startBufferedId = id;
796
959
  }
@@ -798,7 +961,7 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
798
961
  if (top <= scrollBottom) {
799
962
  endNoBuffer = i;
800
963
  }
801
- if (top <= scrollBottom + scrollBuffer) {
964
+ if (top <= scrollBottom + scrollBufferBottom) {
802
965
  endBuffered = i;
803
966
  } else {
804
967
  break;
@@ -818,9 +981,9 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
818
981
  endBuffered,
819
982
  endNoBuffer
820
983
  });
821
- const nextTop = Math.ceil(startBuffered ? positions.get(startBufferedId) + scrollBuffer : 0);
984
+ const nextTop = Math.ceil(startBuffered !== null ? positions.get(startBufferedId) + scrollBuffer : 0);
822
985
  const nextBottom = Math.floor(
823
- endBuffered ? (positions.get(getId(endBuffered + 1)) || 0) - scrollLength - scrollBuffer : 0
986
+ endBuffered !== null ? (positions.get(getId(endBuffered + 1)) || 0) - scrollLength - scrollBuffer : 0
824
987
  );
825
988
  if (state.enableScrollForNextCalculateItemsInView) {
826
989
  state.scrollForNextCalculateItemsInView = nextTop >= 0 && nextBottom >= 0 ? {
@@ -852,7 +1015,7 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
852
1015
  break;
853
1016
  }
854
1017
  const index = state.indexByKey.get(key);
855
- const pos = peek$(ctx, `containerPosition${u}`);
1018
+ const pos = peek$(ctx, `containerPosition${u}`).top;
856
1019
  if (index < startBuffered || index > endBuffered) {
857
1020
  const distance = Math.abs(pos - top2);
858
1021
  if (index < 0 || distance > furthestDistance) {
@@ -871,7 +1034,7 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
871
1034
  set$(ctx, `containerItemKey${containerId}`, id);
872
1035
  const index = state.indexByKey.get(id);
873
1036
  set$(ctx, `containerItemData${containerId}`, data2[index]);
874
- set$(ctx, `containerPosition${containerId}`, POSITION_OUT_OF_VIEW);
1037
+ set$(ctx, `containerPosition${containerId}`, ANCHORED_POSITION_OUT_OF_VIEW);
875
1038
  set$(ctx, `containerColumn${containerId}`, -1);
876
1039
  if (__DEV__ && numContainers > peek$(ctx, "numContainersPooled")) {
877
1040
  console.warn(
@@ -895,19 +1058,31 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
895
1058
  if (item) {
896
1059
  const id = getId(itemIndex);
897
1060
  if (itemKey !== id || itemIndex < startBuffered || itemIndex > endBuffered) {
898
- const prevPos = peek$(ctx, `containerPosition${i}`);
1061
+ const prevPos = peek$(ctx, `containerPosition${i}`).top;
899
1062
  const pos = positions.get(id) || 0;
900
1063
  const size = getItemSize(id, itemIndex, data2[i]);
901
1064
  if (pos + size >= scroll && pos <= scrollBottom || prevPos + size >= scroll && prevPos <= scrollBottom) {
902
- set$(ctx, `containerPosition${i}`, POSITION_OUT_OF_VIEW);
1065
+ set$(ctx, `containerPosition${i}`, ANCHORED_POSITION_OUT_OF_VIEW);
903
1066
  }
904
1067
  } else {
905
- const pos = positions.get(id) || 0;
1068
+ const pos = {
1069
+ type: "top",
1070
+ relativeCoordinate: positions.get(id) || 0,
1071
+ top: positions.get(id) || 0
1072
+ };
906
1073
  const column2 = columns.get(id) || 1;
1074
+ if (maintainVisibleContentPosition && itemIndex < anchorElementIndex) {
1075
+ const currentRow = Math.floor(itemIndex / numColumnsProp);
1076
+ const rowHeight = getRowHeight(currentRow);
1077
+ const elementHeight = getItemSize(id, itemIndex, data2[i]);
1078
+ const diff = rowHeight - elementHeight;
1079
+ pos.relativeCoordinate = pos.top + getRowHeight(currentRow) - diff;
1080
+ pos.type = "bottom";
1081
+ }
907
1082
  const prevPos = peek$(ctx, `containerPosition${i}`);
908
1083
  const prevColumn = peek$(ctx, `containerColumn${i}`);
909
1084
  const prevData = peek$(ctx, `containerItemData${i}`);
910
- if (pos > POSITION_OUT_OF_VIEW && pos !== prevPos) {
1085
+ if (pos.relativeCoordinate > POSITION_OUT_OF_VIEW && pos.top !== prevPos.top) {
911
1086
  set$(ctx, `containerPosition${i}`, pos);
912
1087
  }
913
1088
  if (column2 >= 0 && column2 !== prevColumn) {
@@ -920,12 +1095,7 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
920
1095
  }
921
1096
  }
922
1097
  }
923
- if (layoutsPending.size > 0) {
924
- for (const containerId of layoutsPending) {
925
- set$(ctx, `containerDidLayout${containerId}`, true);
926
- }
927
- layoutsPending.clear();
928
- }
1098
+ set$(ctx, "containersDidLayout", true);
929
1099
  if (state.viewabilityConfigCallbackPairs) {
930
1100
  updateViewableItems(
931
1101
  state,
@@ -969,6 +1139,7 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
969
1139
  if (refState.current) {
970
1140
  refState.current.isAtBottom = distanceFromEnd < scrollLength * maintainScrollAtEndThreshold;
971
1141
  }
1142
+ const { onEndReached } = callbacks.current;
972
1143
  if (onEndReached) {
973
1144
  if (!refState.current.isEndReached) {
974
1145
  if (distanceFromEnd < onEndReachedThreshold * scrollLength) {
@@ -990,6 +1161,7 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
990
1161
  const { scrollLength, scroll } = refState.current;
991
1162
  const distanceFromTop = scroll;
992
1163
  refState.current.isAtTop = distanceFromTop < 0;
1164
+ const { onStartReached } = callbacks.current;
993
1165
  if (onStartReached) {
994
1166
  if (!refState.current.isStartReached && !refState.current.startReachedBlockedByTimer) {
995
1167
  if (distanceFromTop < onStartReachedThreshold * scrollLength) {
@@ -1018,13 +1190,13 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
1018
1190
  const itemKey = peek$(ctx, `containerItemKey${i}`);
1019
1191
  if (!keyExtractorProp || itemKey && state.indexByKey.get(itemKey) === void 0) {
1020
1192
  set$(ctx, `containerItemKey${i}`, void 0);
1021
- set$(ctx, `containerPosition${i}`, POSITION_OUT_OF_VIEW);
1193
+ set$(ctx, `containerItemData${i}`, void 0);
1194
+ set$(ctx, `containerPosition${i}`, ANCHORED_POSITION_OUT_OF_VIEW);
1022
1195
  set$(ctx, `containerColumn${i}`, -1);
1023
1196
  }
1024
1197
  }
1025
1198
  if (!keyExtractorProp) {
1026
- state.sizes.clear();
1027
- state.positions;
1199
+ state.positions.clear();
1028
1200
  }
1029
1201
  calculateItemsInView(state.scrollVelocity);
1030
1202
  }
@@ -1039,20 +1211,63 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
1039
1211
  const isFirst = !refState.current.renderItem;
1040
1212
  if (isFirst || data !== refState.current.data || numColumnsProp !== peek$(ctx, "numColumns")) {
1041
1213
  if (!keyExtractorProp && !isFirst && data !== refState.current.data) {
1042
- refState.current.sizes.clear();
1043
1214
  refState.current.positions.clear();
1044
1215
  }
1045
1216
  refState.current.data = data;
1046
1217
  let totalSize = 0;
1047
1218
  let totalSizeBelowIndex = 0;
1048
1219
  const indexByKey = /* @__PURE__ */ new Map();
1220
+ const newPositions = /* @__PURE__ */ new Map();
1049
1221
  let column = 1;
1050
1222
  let maxSizeInRow = 0;
1051
1223
  for (let i = 0; i < data.length; i++) {
1052
1224
  const key = getId(i);
1225
+ if (__DEV__) {
1226
+ if (indexByKey.has(key)) {
1227
+ console.error(
1228
+ `[legend-list] Error: Detected overlapping key (${key}) which causes missing items and gaps and other terrrible things. Check that keyExtractor returns unique values.`
1229
+ );
1230
+ }
1231
+ }
1053
1232
  indexByKey.set(key, i);
1233
+ if (refState.current.positions.get(key) != null && refState.current.indexByKey.get(key) === i) {
1234
+ newPositions.set(key, refState.current.positions.get(key));
1235
+ }
1054
1236
  }
1055
1237
  refState.current.indexByKey = indexByKey;
1238
+ refState.current.positions = newPositions;
1239
+ if (!isFirst) {
1240
+ if (maintainVisibleContentPosition) {
1241
+ if (refState.current.anchorElement == null || indexByKey.get(refState.current.anchorElement.id) == null) {
1242
+ if (data.length) {
1243
+ const newAnchorElement = {
1244
+ coordinate: 0,
1245
+ id: getId(0)
1246
+ };
1247
+ refState.current.anchorElement = newAnchorElement;
1248
+ (_a = refState.current.belowAnchorElementPositions) == null ? void 0 : _a.clear();
1249
+ (_b = refScroller.current) == null ? void 0 : _b.scrollTo({ x: 0, y: 0, animated: false });
1250
+ setTimeout(() => {
1251
+ calculateItemsInView(0);
1252
+ }, 0);
1253
+ } else {
1254
+ refState.current.startBufferedId = void 0;
1255
+ }
1256
+ }
1257
+ } else {
1258
+ if (refState.current.startBufferedId != null && newPositions.get(refState.current.startBufferedId) == null) {
1259
+ if (data.length) {
1260
+ refState.current.startBufferedId = getId(0);
1261
+ } else {
1262
+ refState.current.startBufferedId = void 0;
1263
+ }
1264
+ (_c = refScroller.current) == null ? void 0 : _c.scrollTo({ x: 0, y: 0, animated: false });
1265
+ setTimeout(() => {
1266
+ calculateItemsInView(0);
1267
+ }, 0);
1268
+ }
1269
+ }
1270
+ }
1056
1271
  const anchorElementIndex = getAnchorElementIndex();
1057
1272
  for (let i = 0; i < data.length; i++) {
1058
1273
  const key = getId(i);
@@ -1073,15 +1288,18 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
1073
1288
  }
1074
1289
  addTotalSize(null, totalSize, totalSizeBelowIndex);
1075
1290
  }
1076
- React4.useEffect(() => {
1291
+ React5.useEffect(() => {
1077
1292
  checkResetContainers(
1078
1293
  /*reset*/
1079
1294
  !isFirst
1080
1295
  );
1081
1296
  }, [isFirst, data, numColumnsProp]);
1297
+ React5.useEffect(() => {
1298
+ set$(ctx, "extraData", extraData);
1299
+ }, [extraData]);
1082
1300
  refState.current.renderItem = renderItem;
1083
- const lastItemKey = getId(data[data.length - 1]);
1084
- const stylePaddingTop = (_d = (_c = (_a = reactNative.StyleSheet.flatten(style)) == null ? void 0 : _a.paddingTop) != null ? _c : (_b = reactNative.StyleSheet.flatten(contentContainerStyle)) == null ? void 0 : _b.paddingTop) != null ? _d : 0;
1301
+ const lastItemKey = data.length > 0 ? getId(data.length - 1) : void 0;
1302
+ 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;
1085
1303
  const initalizeStateVars = () => {
1086
1304
  set$(ctx, "lastItemKey", lastItemKey);
1087
1305
  set$(ctx, "numColumns", numColumnsProp);
@@ -1090,8 +1308,8 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
1090
1308
  if (isFirst) {
1091
1309
  initalizeStateVars();
1092
1310
  }
1093
- React4.useEffect(initalizeStateVars, [lastItemKey, numColumnsProp, stylePaddingTop]);
1094
- const getRenderedItem = React4.useCallback((key, containerId) => {
1311
+ React5.useEffect(initalizeStateVars, [lastItemKey, numColumnsProp, stylePaddingTop]);
1312
+ const getRenderedItem = React5.useCallback((key) => {
1095
1313
  var _a2, _b2;
1096
1314
  const state = refState.current;
1097
1315
  if (!state) {
@@ -1102,89 +1320,27 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
1102
1320
  if (index === void 0) {
1103
1321
  return null;
1104
1322
  }
1105
- const useViewability = (configId, callback) => {
1106
- const key2 = containerId + configId;
1107
- useInit(() => {
1108
- const value = ctx.mapViewabilityValues.get(key2);
1109
- if (value) {
1110
- callback(value);
1111
- }
1112
- });
1113
- ctx.mapViewabilityCallbacks.set(key2, callback);
1114
- React4.useEffect(
1115
- () => () => {
1116
- ctx.mapViewabilityCallbacks.delete(key2);
1117
- },
1118
- []
1119
- );
1323
+ const useViewability2 = (configId, callback) => {
1324
+ useViewability(configId, callback);
1120
1325
  };
1121
- const useViewabilityAmount = (callback) => {
1122
- useInit(() => {
1123
- const value = ctx.mapViewabilityAmountValues.get(containerId);
1124
- if (value) {
1125
- callback(value);
1126
- }
1127
- });
1128
- ctx.mapViewabilityAmountCallbacks.set(containerId, callback);
1129
- React4.useEffect(
1130
- () => () => {
1131
- ctx.mapViewabilityAmountCallbacks.delete(containerId);
1132
- },
1133
- []
1134
- );
1326
+ const useViewabilityAmount2 = (callback) => {
1327
+ useViewabilityAmount(callback);
1135
1328
  };
1136
- const useRecyclingEffect = (effect) => {
1137
- React4.useEffect(() => {
1138
- const state2 = refState.current;
1139
- let prevIndex = index;
1140
- let prevItem = state2.data[index];
1141
- const signal = `containerItemKey${containerId}`;
1142
- const run = () => {
1143
- const data3 = state2.data;
1144
- if (data3) {
1145
- const newKey = peek$(ctx, signal);
1146
- const newIndex = state2.indexByKey.get(newKey);
1147
- const newItem = data3[newIndex];
1148
- if (newItem) {
1149
- effect({
1150
- index: newIndex,
1151
- item: newItem,
1152
- prevIndex,
1153
- prevItem
1154
- });
1155
- }
1156
- prevIndex = newIndex;
1157
- prevItem = newItem;
1158
- }
1159
- };
1160
- run();
1161
- return listen$(ctx, signal, run);
1162
- }, []);
1329
+ const useRecyclingEffect2 = (effect) => {
1330
+ useRecyclingEffect(effect);
1163
1331
  };
1164
- const useRecyclingState = (valueOrFun) => {
1165
- const stateInfo = React4.useState(
1166
- () => typeof valueOrFun === "function" ? valueOrFun({
1167
- index,
1168
- item: refState.current.data[index],
1169
- prevIndex: void 0,
1170
- prevItem: void 0
1171
- }) : valueOrFun
1172
- );
1173
- useRecyclingEffect((state2) => {
1174
- const newState = typeof valueOrFun === "function" ? valueOrFun(state2) : valueOrFun;
1175
- stateInfo[1](newState);
1176
- });
1177
- return stateInfo;
1332
+ const useRecyclingState2 = (valueOrFun) => {
1333
+ return useRecyclingState(valueOrFun);
1178
1334
  };
1179
1335
  const renderedItem = (_b2 = (_a2 = refState.current).renderItem) == null ? void 0 : _b2.call(_a2, {
1180
1336
  item: data2[index],
1181
1337
  index,
1182
- useViewability,
1183
- useViewabilityAmount,
1184
- useRecyclingEffect,
1185
- useRecyclingState
1338
+ useViewability: useViewability2,
1339
+ useViewabilityAmount: useViewabilityAmount2,
1340
+ useRecyclingEffect: useRecyclingEffect2,
1341
+ useRecyclingState: useRecyclingState2
1186
1342
  });
1187
- return renderedItem;
1343
+ return { index, renderedItem };
1188
1344
  }, []);
1189
1345
  useInit(() => {
1190
1346
  var _a2;
@@ -1196,33 +1352,26 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
1196
1352
  const averageItemSize = (_a2 = estimatedItemSize != null ? estimatedItemSize : getEstimatedItemSize == null ? void 0 : getEstimatedItemSize(0, data[0])) != null ? _a2 : DEFAULT_ITEM_SIZE;
1197
1353
  const numContainers = Math.ceil((scrollLength + scrollBuffer * 2) / averageItemSize) * numColumnsProp;
1198
1354
  for (let i = 0; i < numContainers; i++) {
1199
- set$(ctx, `containerPosition${i}`, POSITION_OUT_OF_VIEW);
1355
+ set$(ctx, `containerPosition${i}`, ANCHORED_POSITION_OUT_OF_VIEW);
1200
1356
  set$(ctx, `containerColumn${i}`, -1);
1201
1357
  }
1202
1358
  set$(ctx, "numContainers", numContainers);
1203
1359
  set$(ctx, "numContainersPooled", numContainers * 2);
1204
1360
  calculateItemsInView(state.scrollVelocity);
1205
1361
  });
1206
- const updateItemSize = React4.useCallback((containerId, itemKey, size) => {
1207
- var _a2;
1208
- const data2 = (_a2 = refState.current) == null ? void 0 : _a2.data;
1362
+ const updateItemSize = React5.useCallback((containerId, itemKey, size) => {
1363
+ const state = refState.current;
1364
+ const { sizes, indexByKey, columns, sizesLaidOut, data: data2 } = state;
1209
1365
  if (!data2) {
1210
1366
  return;
1211
1367
  }
1212
- const state = refState.current;
1213
- const { sizes, indexByKey, idsInFirstRender, columns, sizesLaidOut } = state;
1214
1368
  const index = indexByKey.get(itemKey);
1215
1369
  const numColumns = peek$(ctx, "numColumns");
1216
- const row = Math.floor(index / numColumns);
1217
- const prevSize = getRowHeight(row);
1218
- const measured = peek$(ctx, `containerDidLayout${containerId}`);
1219
- if (!measured) {
1220
- state.layoutsPending.add(containerId);
1221
- }
1370
+ state.minIndexSizeChanged = state.minIndexSizeChanged !== void 0 ? Math.min(state.minIndexSizeChanged, index) : index;
1371
+ const prevSize = getItemSize(itemKey, index, data2);
1222
1372
  if (!prevSize || Math.abs(prevSize - size) > 0.5) {
1223
1373
  let diff;
1224
1374
  if (numColumns > 1) {
1225
- const prevMaxSizeInRow = getRowHeight(row);
1226
1375
  sizes.set(itemKey, size);
1227
1376
  const column = columns.get(itemKey);
1228
1377
  const loopStart = index - (column - 1);
@@ -1232,7 +1381,7 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
1232
1381
  const size2 = getItemSize(id, i, data2[i]);
1233
1382
  nextMaxSizeInRow = Math.max(nextMaxSizeInRow, size2);
1234
1383
  }
1235
- diff = nextMaxSizeInRow - prevMaxSizeInRow;
1384
+ diff = nextMaxSizeInRow - prevSize;
1236
1385
  } else {
1237
1386
  sizes.set(itemKey, size);
1238
1387
  diff = size - prevSize;
@@ -1260,11 +1409,14 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
1260
1409
  addTotalSize(itemKey, diff, 0);
1261
1410
  doMaintainScrollAtEnd(true);
1262
1411
  const scrollVelocity = state.scrollVelocity;
1263
- if (!state.animFrameLayout && (Number.isNaN(scrollVelocity) || Math.abs(scrollVelocity) < 1)) {
1264
- if (!peek$(ctx, `containerDidLayout${containerId}`)) {
1265
- state.animFrameLayout = requestAnimationFrame(() => {
1266
- state.animFrameLayout = null;
1267
- calculateItemsInView(state.scrollVelocity);
1412
+ if (!state.waitingForMicrotask && (Number.isNaN(scrollVelocity) || Math.abs(scrollVelocity) < 1)) {
1413
+ if (!peek$(ctx, "containersDidLayout")) {
1414
+ state.waitingForMicrotask = true;
1415
+ queueMicrotask(() => {
1416
+ if (state.waitingForMicrotask) {
1417
+ state.waitingForMicrotask = false;
1418
+ calculateItemsInView(state.scrollVelocity);
1419
+ }
1268
1420
  });
1269
1421
  } else {
1270
1422
  calculateItemsInView(state.scrollVelocity);
@@ -1273,22 +1425,24 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
1273
1425
  if (onItemSizeChanged) {
1274
1426
  onItemSizeChanged({ size, previous: prevSize, index, itemKey, itemData: data2[index] });
1275
1427
  }
1276
- } else {
1277
- set$(ctx, `containerDidLayout${containerId}`, true);
1278
1428
  }
1279
1429
  }, []);
1280
- const handleScrollDebounced = React4.useCallback((velocity) => {
1430
+ const handleScrollDebounced = React5.useCallback((velocity) => {
1281
1431
  calculateItemsInView(velocity);
1282
1432
  checkAtBottom();
1283
1433
  checkAtTop();
1284
1434
  }, []);
1285
- const onLayout = React4.useCallback((event) => {
1435
+ const onLayout = React5.useCallback((event) => {
1286
1436
  const scrollLength = event.nativeEvent.layout[horizontal ? "width" : "height"];
1437
+ const didChange = scrollLength !== refState.current.scrollLength;
1287
1438
  refState.current.scrollLength = scrollLength;
1288
1439
  doMaintainScrollAtEnd(false);
1289
1440
  doUpdatePaddingTop();
1290
1441
  checkAtBottom();
1291
1442
  checkAtTop();
1443
+ if (didChange) {
1444
+ calculateItemsInView(0);
1445
+ }
1292
1446
  if (__DEV__) {
1293
1447
  const isWidthZero = event.nativeEvent.layout.width === 0;
1294
1448
  const isHeightZero = event.nativeEvent.layout.height === 0;
@@ -1298,8 +1452,11 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
1298
1452
  );
1299
1453
  }
1300
1454
  }
1455
+ if (onLayoutProp) {
1456
+ onLayoutProp(event);
1457
+ }
1301
1458
  }, []);
1302
- const handleScroll = React4.useCallback(
1459
+ const handleScroll = React5.useCallback(
1303
1460
  (event, fromSelf) => {
1304
1461
  var _a2, _b2, _c2;
1305
1462
  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) {
@@ -1341,7 +1498,7 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
1341
1498
  },
1342
1499
  []
1343
1500
  );
1344
- React4.useImperativeHandle(
1501
+ React5.useImperativeHandle(
1345
1502
  forwardedRef,
1346
1503
  () => {
1347
1504
  const scrollToIndex = ({ index, animated }) => {
@@ -1351,9 +1508,9 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
1351
1508
  };
1352
1509
  return {
1353
1510
  getNativeScrollRef: () => refScroller.current,
1354
- getScrollableNode: refScroller.current.getScrollableNode,
1355
- getScrollResponder: refScroller.current.getScrollResponder,
1356
- flashScrollIndicators: refScroller.current.flashScrollIndicators,
1511
+ getScrollableNode: () => refScroller.current.getScrollableNode(),
1512
+ getScrollResponder: () => refScroller.current.getScrollResponder(),
1513
+ flashScrollIndicators: () => refScroller.current.flashScrollIndicators(),
1357
1514
  scrollToIndex,
1358
1515
  scrollToOffset: ({ offset, animated }) => {
1359
1516
  const offsetObj = horizontal ? { x: offset, y: 0 } : { x: 0, y: offset };
@@ -1365,26 +1522,17 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
1365
1522
  scrollToIndex({ index, animated });
1366
1523
  }
1367
1524
  },
1368
- scrollToEnd: refScroller.current.scrollToEnd
1525
+ scrollToEnd: () => refScroller.current.scrollToEnd()
1369
1526
  };
1370
1527
  },
1371
1528
  []
1372
1529
  );
1373
- return /* @__PURE__ */ React4__namespace.createElement(
1530
+ return /* @__PURE__ */ React5__namespace.createElement(
1374
1531
  ListComponent,
1375
1532
  {
1376
1533
  ...rest,
1377
1534
  horizontal,
1378
- refScrollView: (r) => {
1379
- refScroller.current = r;
1380
- if (refScrollView) {
1381
- if (typeof refScrollView === "function") {
1382
- refScrollView(r);
1383
- } else {
1384
- refScrollView.current = r;
1385
- }
1386
- }
1387
- },
1535
+ refScrollView: combinedRef,
1388
1536
  initialContentOffset,
1389
1537
  getRenderedItem,
1390
1538
  updateItemSize,
@@ -1395,9 +1543,14 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
1395
1543
  ListEmptyComponent: data.length === 0 ? ListEmptyComponent : void 0,
1396
1544
  maintainVisibleContentPosition,
1397
1545
  scrollEventThrottle: scrollEventThrottle != null ? scrollEventThrottle : reactNative.Platform.OS === "web" ? 16 : void 0,
1546
+ waitForInitialLayout,
1398
1547
  style
1399
1548
  }
1400
1549
  );
1401
1550
  });
1402
1551
 
1403
1552
  exports.LegendList = LegendList;
1553
+ exports.useRecyclingEffect = useRecyclingEffect;
1554
+ exports.useRecyclingState = useRecyclingState;
1555
+ exports.useViewability = useViewability;
1556
+ exports.useViewabilityAmount = useViewabilityAmount;