@legendapp/list 1.0.12 → 1.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/index.js +106 -96
  3. package/index.mjs +58 -48
  4. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 1.0.13
2
+ - Fix: Missing React import in ListHeaderComponentContainer crashing some environments
3
+ - Fix: `initialScrollIndex` was off by padding if using "padding" or "paddingVertical" props
4
+
1
5
  ## 1.0.12
2
6
  - Fix: Initial scroll index and scrollTo were not compensating for top padding
3
7
  - Fix: Removed an overly aggressive optimization that was sometimes causing blank spaces after scrolling
package/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var React3 = require('react');
3
+ var React2 = require('react');
4
4
  var reactNative = require('react-native');
5
5
  var shim = require('use-sync-external-store/shim');
6
6
 
@@ -22,12 +22,12 @@ function _interopNamespace(e) {
22
22
  return Object.freeze(n);
23
23
  }
24
24
 
25
- var React3__namespace = /*#__PURE__*/_interopNamespace(React3);
25
+ var React2__namespace = /*#__PURE__*/_interopNamespace(React2);
26
26
 
27
27
  // src/LegendList.tsx
28
- var ContextState = React3__namespace.createContext(null);
28
+ var ContextState = React2__namespace.createContext(null);
29
29
  function StateProvider({ children }) {
30
- const [value] = React3__namespace.useState(() => ({
30
+ const [value] = React2__namespace.useState(() => ({
31
31
  listeners: /* @__PURE__ */ new Map(),
32
32
  values: /* @__PURE__ */ new Map([
33
33
  ["paddingTop", 0],
@@ -42,10 +42,10 @@ function StateProvider({ children }) {
42
42
  columnWrapperStyle: void 0,
43
43
  viewRefs: /* @__PURE__ */ new Map()
44
44
  }));
45
- return /* @__PURE__ */ React3__namespace.createElement(ContextState.Provider, { value }, children);
45
+ return /* @__PURE__ */ React2__namespace.createElement(ContextState.Provider, { value }, children);
46
46
  }
47
47
  function useStateContext() {
48
- return React3__namespace.useContext(ContextState);
48
+ return React2__namespace.useContext(ContextState);
49
49
  }
50
50
  function createSelectorFunctionsArr(ctx, signalNames) {
51
51
  let lastValues = [];
@@ -115,17 +115,17 @@ function getContentSize(ctx) {
115
115
  return headerSize + footerSize + totalSize + stylePaddingTop;
116
116
  }
117
117
  function useArr$(signalNames) {
118
- const ctx = React3__namespace.useContext(ContextState);
119
- const { subscribe, get } = React3__namespace.useMemo(() => createSelectorFunctionsArr(ctx, signalNames), [ctx, signalNames]);
118
+ const ctx = React2__namespace.useContext(ContextState);
119
+ const { subscribe, get } = React2__namespace.useMemo(() => createSelectorFunctionsArr(ctx, signalNames), [ctx, signalNames]);
120
120
  const value = shim.useSyncExternalStore(subscribe, get);
121
121
  return value;
122
122
  }
123
123
 
124
124
  // src/DebugView.tsx
125
125
  var DebugRow = ({ children }) => {
126
- return /* @__PURE__ */ React3__namespace.createElement(reactNative.View, { style: { flexDirection: "row", alignItems: "center", justifyContent: "space-between" } }, children);
126
+ return /* @__PURE__ */ React2__namespace.createElement(reactNative.View, { style: { flexDirection: "row", alignItems: "center", justifyContent: "space-between" } }, children);
127
127
  };
128
- var DebugView = React3__namespace.memo(function DebugView2({ state }) {
128
+ var DebugView = React2__namespace.memo(function DebugView2({ state }) {
129
129
  const ctx = useStateContext();
130
130
  const [
131
131
  totalSize = 0,
@@ -145,11 +145,11 @@ var DebugView = React3__namespace.memo(function DebugView2({ state }) {
145
145
  "numContainersPooled"
146
146
  ]);
147
147
  const contentSize = getContentSize(ctx);
148
- const [, forceUpdate] = React3.useReducer((x) => x + 1, 0);
148
+ const [, forceUpdate] = React2.useReducer((x) => x + 1, 0);
149
149
  useInterval(() => {
150
150
  forceUpdate();
151
151
  }, 100);
152
- return /* @__PURE__ */ React3__namespace.createElement(
152
+ return /* @__PURE__ */ React2__namespace.createElement(
153
153
  reactNative.View,
154
154
  {
155
155
  style: {
@@ -165,19 +165,19 @@ var DebugView = React3__namespace.memo(function DebugView2({ state }) {
165
165
  },
166
166
  pointerEvents: "none"
167
167
  },
168
- /* @__PURE__ */ React3__namespace.createElement(DebugRow, null, /* @__PURE__ */ React3__namespace.createElement(reactNative.Text, null, "TotalSize:"), /* @__PURE__ */ React3__namespace.createElement(reactNative.Text, null, totalSize.toFixed(2))),
169
- /* @__PURE__ */ React3__namespace.createElement(DebugRow, null, /* @__PURE__ */ React3__namespace.createElement(reactNative.Text, null, "ContentSize:"), /* @__PURE__ */ React3__namespace.createElement(reactNative.Text, null, contentSize.toFixed(2))),
170
- /* @__PURE__ */ React3__namespace.createElement(DebugRow, null, /* @__PURE__ */ React3__namespace.createElement(reactNative.Text, null, "At end:"), /* @__PURE__ */ React3__namespace.createElement(reactNative.Text, null, String(state.isAtBottom))),
171
- /* @__PURE__ */ React3__namespace.createElement(reactNative.Text, null),
172
- /* @__PURE__ */ React3__namespace.createElement(DebugRow, null, /* @__PURE__ */ React3__namespace.createElement(reactNative.Text, null, "ScrollAdjust:"), /* @__PURE__ */ React3__namespace.createElement(reactNative.Text, null, scrollAdjust.toFixed(2))),
173
- /* @__PURE__ */ React3__namespace.createElement(DebugRow, null, /* @__PURE__ */ React3__namespace.createElement(reactNative.Text, null, "TotalSizeReal: "), /* @__PURE__ */ React3__namespace.createElement(reactNative.Text, null, totalSizeWithScrollAdjust.toFixed(2))),
174
- /* @__PURE__ */ React3__namespace.createElement(reactNative.Text, null),
175
- /* @__PURE__ */ React3__namespace.createElement(DebugRow, null, /* @__PURE__ */ React3__namespace.createElement(reactNative.Text, null, "RawScroll: "), /* @__PURE__ */ React3__namespace.createElement(reactNative.Text, null, rawScroll.toFixed(2))),
176
- /* @__PURE__ */ React3__namespace.createElement(DebugRow, null, /* @__PURE__ */ React3__namespace.createElement(reactNative.Text, null, "ComputedScroll: "), /* @__PURE__ */ React3__namespace.createElement(reactNative.Text, null, scroll.toFixed(2)))
168
+ /* @__PURE__ */ React2__namespace.createElement(DebugRow, null, /* @__PURE__ */ React2__namespace.createElement(reactNative.Text, null, "TotalSize:"), /* @__PURE__ */ React2__namespace.createElement(reactNative.Text, null, totalSize.toFixed(2))),
169
+ /* @__PURE__ */ React2__namespace.createElement(DebugRow, null, /* @__PURE__ */ React2__namespace.createElement(reactNative.Text, null, "ContentSize:"), /* @__PURE__ */ React2__namespace.createElement(reactNative.Text, null, contentSize.toFixed(2))),
170
+ /* @__PURE__ */ React2__namespace.createElement(DebugRow, null, /* @__PURE__ */ React2__namespace.createElement(reactNative.Text, null, "At end:"), /* @__PURE__ */ React2__namespace.createElement(reactNative.Text, null, String(state.isAtBottom))),
171
+ /* @__PURE__ */ React2__namespace.createElement(reactNative.Text, null),
172
+ /* @__PURE__ */ React2__namespace.createElement(DebugRow, null, /* @__PURE__ */ React2__namespace.createElement(reactNative.Text, null, "ScrollAdjust:"), /* @__PURE__ */ React2__namespace.createElement(reactNative.Text, null, scrollAdjust.toFixed(2))),
173
+ /* @__PURE__ */ React2__namespace.createElement(DebugRow, null, /* @__PURE__ */ React2__namespace.createElement(reactNative.Text, null, "TotalSizeReal: "), /* @__PURE__ */ React2__namespace.createElement(reactNative.Text, null, totalSizeWithScrollAdjust.toFixed(2))),
174
+ /* @__PURE__ */ React2__namespace.createElement(reactNative.Text, null),
175
+ /* @__PURE__ */ React2__namespace.createElement(DebugRow, null, /* @__PURE__ */ React2__namespace.createElement(reactNative.Text, null, "RawScroll: "), /* @__PURE__ */ React2__namespace.createElement(reactNative.Text, null, rawScroll.toFixed(2))),
176
+ /* @__PURE__ */ React2__namespace.createElement(DebugRow, null, /* @__PURE__ */ React2__namespace.createElement(reactNative.Text, null, "ComputedScroll: "), /* @__PURE__ */ React2__namespace.createElement(reactNative.Text, null, scroll.toFixed(2)))
177
177
  );
178
178
  });
179
179
  function useInterval(callback, delay) {
180
- React3.useEffect(() => {
180
+ React2.useEffect(() => {
181
181
  const interval = setInterval(callback, delay);
182
182
  return () => clearInterval(interval);
183
183
  }, [delay]);
@@ -206,9 +206,16 @@ function comparatorByDistance(a, b) {
206
206
  function comparatorDefault(a, b) {
207
207
  return a - b;
208
208
  }
209
+ function getPadding(s) {
210
+ var _a, _b, _c;
211
+ return (_c = (_b = (_a = s.paddingTop) != null ? _a : s.paddingVertical) != null ? _b : s.padding) != null ? _c : 0;
212
+ }
213
+ function extractPaddingTop(style, contentContainerStyle) {
214
+ return getPadding(style) + getPadding(contentContainerStyle);
215
+ }
209
216
  var symbolFirst = Symbol();
210
217
  function useInit(cb) {
211
- const refValue = React3.useRef(symbolFirst);
218
+ const refValue = React2.useRef(symbolFirst);
212
219
  if (refValue.current === symbolFirst) {
213
220
  refValue.current = cb();
214
221
  }
@@ -216,10 +223,10 @@ function useInit(cb) {
216
223
  }
217
224
 
218
225
  // src/ContextContainer.ts
219
- var ContextContainer = React3.createContext(null);
226
+ var ContextContainer = React2.createContext(null);
220
227
  function useViewability(callback, configId) {
221
228
  const ctx = useStateContext();
222
- const { containerId } = React3.useContext(ContextContainer);
229
+ const { containerId } = React2.useContext(ContextContainer);
223
230
  const key = containerId + (configId != null ? configId : "");
224
231
  useInit(() => {
225
232
  const value = ctx.mapViewabilityValues.get(key);
@@ -228,7 +235,7 @@ function useViewability(callback, configId) {
228
235
  }
229
236
  });
230
237
  ctx.mapViewabilityCallbacks.set(key, callback);
231
- React3.useEffect(
238
+ React2.useEffect(
232
239
  () => () => {
233
240
  ctx.mapViewabilityCallbacks.delete(key);
234
241
  },
@@ -237,7 +244,7 @@ function useViewability(callback, configId) {
237
244
  }
238
245
  function useViewabilityAmount(callback) {
239
246
  const ctx = useStateContext();
240
- const { containerId } = React3.useContext(ContextContainer);
247
+ const { containerId } = React2.useContext(ContextContainer);
241
248
  useInit(() => {
242
249
  const value = ctx.mapViewabilityAmountValues.get(containerId);
243
250
  if (value) {
@@ -245,7 +252,7 @@ function useViewabilityAmount(callback) {
245
252
  }
246
253
  });
247
254
  ctx.mapViewabilityAmountCallbacks.set(containerId, callback);
248
- React3.useEffect(
255
+ React2.useEffect(
249
256
  () => () => {
250
257
  ctx.mapViewabilityAmountCallbacks.delete(containerId);
251
258
  },
@@ -253,12 +260,12 @@ function useViewabilityAmount(callback) {
253
260
  );
254
261
  }
255
262
  function useRecyclingEffect(effect) {
256
- const { index, value } = React3.useContext(ContextContainer);
257
- const prevValues = React3.useRef({
263
+ const { index, value } = React2.useContext(ContextContainer);
264
+ const prevValues = React2.useRef({
258
265
  prevIndex: void 0,
259
266
  prevItem: void 0
260
267
  });
261
- React3.useEffect(() => {
268
+ React2.useEffect(() => {
262
269
  let ret = void 0;
263
270
  if (prevValues.current.prevIndex !== void 0 && prevValues.current.prevItem !== void 0) {
264
271
  ret = effect({
@@ -276,12 +283,12 @@ function useRecyclingEffect(effect) {
276
283
  }, [index, value]);
277
284
  }
278
285
  function useRecyclingState(valueOrFun) {
279
- const { index, value, itemKey, triggerLayout } = React3.useContext(ContextContainer);
280
- const refState = React3.useRef({
286
+ const { index, value, itemKey, triggerLayout } = React2.useContext(ContextContainer);
287
+ const refState = React2.useRef({
281
288
  itemKey: null,
282
289
  value: null
283
290
  });
284
- const [_, setRenderNum] = React3.useState(0);
291
+ const [_, setRenderNum] = React2.useState(0);
285
292
  if (refState.current.itemKey !== itemKey) {
286
293
  refState.current.itemKey = itemKey;
287
294
  refState.current.value = isFunction(valueOrFun) ? valueOrFun({
@@ -291,7 +298,7 @@ function useRecyclingState(valueOrFun) {
291
298
  prevItem: void 0
292
299
  }) : valueOrFun;
293
300
  }
294
- const setState = React3.useCallback(
301
+ const setState = React2.useCallback(
295
302
  (newState) => {
296
303
  refState.current.value = isFunction(newState) ? newState(refState.current.value) : newState;
297
304
  setRenderNum((v) => v + 1);
@@ -301,8 +308,8 @@ function useRecyclingState(valueOrFun) {
301
308
  );
302
309
  return [refState.current.value, setState];
303
310
  }
304
- var LeanViewComponent = React3__namespace.forwardRef((props, ref) => {
305
- return React3__namespace.createElement("RCTView", { ...props, ref });
311
+ var LeanViewComponent = React2__namespace.forwardRef((props, ref) => {
312
+ return React2__namespace.createElement("RCTView", { ...props, ref });
306
313
  });
307
314
  LeanViewComponent.displayName = "RCTView";
308
315
  var LeanView = reactNative.Platform.OS === "android" || reactNative.Platform.OS === "ios" ? LeanViewComponent : reactNative.View;
@@ -348,9 +355,9 @@ var Container = ({
348
355
  `containerItemData${id}`,
349
356
  "extraData"
350
357
  ]);
351
- const refLastSize = React3.useRef();
352
- const ref = React3.useRef(null);
353
- const [layoutRenderCount, forceLayoutRender] = React3.useState(0);
358
+ const refLastSize = React2.useRef();
359
+ const ref = React2.useRef(null);
360
+ const [layoutRenderCount, forceLayoutRender] = React2.useState(0);
354
361
  const otherAxisPos = numColumns > 1 ? `${(column - 1) / numColumns * 100}%` : 0;
355
362
  const otherAxisSize = numColumns > 1 ? `${1 / numColumns * 100}%` : void 0;
356
363
  let paddingStyles;
@@ -384,12 +391,12 @@ var Container = ({
384
391
  top: position.relativeCoordinate,
385
392
  ...paddingStyles || {}
386
393
  };
387
- const renderedItemInfo = React3.useMemo(
394
+ const renderedItemInfo = React2.useMemo(
388
395
  () => itemKey !== void 0 ? getRenderedItem(itemKey) : null,
389
396
  [itemKey, data, extraData]
390
397
  );
391
398
  const { index, renderedItem } = renderedItemInfo || {};
392
- const triggerLayout = React3.useCallback(() => {
399
+ const triggerLayout = React2.useCallback(() => {
393
400
  forceLayoutRender((v) => v + 1);
394
401
  }, []);
395
402
  const onLayout = (event) => {
@@ -412,7 +419,7 @@ var Container = ({
412
419
  }
413
420
  };
414
421
  if (IsNewArchitecture) {
415
- React3.useLayoutEffect(() => {
422
+ React2.useLayoutEffect(() => {
416
423
  var _a, _b;
417
424
  if (!isNullOrUndefined(itemKey)) {
418
425
  const measured = (_b = (_a = ref.current) == null ? void 0 : _a.unstable_getBoundingClientRect) == null ? void 0 : _b.call(_a);
@@ -425,7 +432,7 @@ var Container = ({
425
432
  }
426
433
  }, [itemKey, layoutRenderCount]);
427
434
  } else {
428
- React3.useEffect(() => {
435
+ React2.useEffect(() => {
429
436
  if (!isNullOrUndefined(itemKey)) {
430
437
  const timeout = setTimeout(() => {
431
438
  if (refLastSize.current) {
@@ -438,25 +445,25 @@ var Container = ({
438
445
  }
439
446
  }, [itemKey]);
440
447
  }
441
- const contextValue = React3.useMemo(() => {
448
+ const contextValue = React2.useMemo(() => {
442
449
  ctx.viewRefs.set(id, ref);
443
450
  return { containerId: id, itemKey, index, value: data, triggerLayout };
444
451
  }, [id, itemKey, index, data]);
445
- const contentFragment = /* @__PURE__ */ React3__namespace.default.createElement(React3__namespace.default.Fragment, { key: recycleItems ? void 0 : itemKey }, /* @__PURE__ */ React3__namespace.default.createElement(ContextContainer.Provider, { value: contextValue }, renderedItem, renderedItemInfo && ItemSeparatorComponent && !lastItemKeys.includes(itemKey) && /* @__PURE__ */ React3__namespace.default.createElement(ItemSeparatorComponent, { leadingItem: renderedItemInfo.item })));
452
+ const contentFragment = /* @__PURE__ */ React2__namespace.default.createElement(React2__namespace.default.Fragment, { key: recycleItems ? void 0 : itemKey }, /* @__PURE__ */ React2__namespace.default.createElement(ContextContainer.Provider, { value: contextValue }, renderedItem, renderedItemInfo && ItemSeparatorComponent && !lastItemKeys.includes(itemKey) && /* @__PURE__ */ React2__namespace.default.createElement(ItemSeparatorComponent, { leadingItem: renderedItemInfo.item })));
446
453
  if (maintainVisibleContentPosition) {
447
454
  const anchorStyle = position.type === "top" ? { position: "absolute", top: 0, left: 0, right: 0 } : { position: "absolute", bottom: 0, left: 0, right: 0 };
448
455
  if (__DEV__ && ENABLE_DEVMODE) {
449
456
  anchorStyle.borderColor = position.type === "top" ? "red" : "blue";
450
457
  anchorStyle.borderWidth = 1;
451
458
  }
452
- return /* @__PURE__ */ React3__namespace.default.createElement(LeanView, { style }, /* @__PURE__ */ React3__namespace.default.createElement(LeanView, { style: [anchorStyle, paddingStyles], onLayout, ref }, contentFragment, __DEV__ && ENABLE_DEVMODE && /* @__PURE__ */ React3__namespace.default.createElement(reactNative.Text, { style: { position: "absolute", top: 0, left: 0, zIndex: 1e3 } }, position.top)));
459
+ return /* @__PURE__ */ React2__namespace.default.createElement(LeanView, { style }, /* @__PURE__ */ React2__namespace.default.createElement(LeanView, { style: [anchorStyle, paddingStyles], onLayout, ref }, contentFragment, __DEV__ && ENABLE_DEVMODE && /* @__PURE__ */ React2__namespace.default.createElement(reactNative.Text, { style: { position: "absolute", top: 0, left: 0, zIndex: 1e3 } }, position.top)));
453
460
  }
454
- return /* @__PURE__ */ React3__namespace.default.createElement(LeanView, { style, onLayout, ref }, contentFragment);
461
+ return /* @__PURE__ */ React2__namespace.default.createElement(LeanView, { style, onLayout, ref }, contentFragment);
455
462
  };
456
- var typedForwardRef = React3.forwardRef;
457
- var typedMemo = React3.memo;
463
+ var typedForwardRef = React2.forwardRef;
464
+ var typedMemo = React2.memo;
458
465
  var useAnimatedValue = (initialValue) => {
459
- return React3.useRef(new reactNative.Animated.Value(initialValue)).current;
466
+ return React2.useRef(new reactNative.Animated.Value(initialValue)).current;
460
467
  };
461
468
 
462
469
  // src/useValue$.ts
@@ -464,7 +471,7 @@ function useValue$(key, getValue, useMicrotask) {
464
471
  var _a;
465
472
  const ctx = useStateContext();
466
473
  const animValue = useAnimatedValue((_a = getValue ? getValue(peek$(ctx, key)) : peek$(ctx, key)) != null ? _a : 0);
467
- React3.useMemo(() => {
474
+ React2.useMemo(() => {
468
475
  let newValue = void 0;
469
476
  listen$(ctx, key, (v) => {
470
477
  if (useMicrotask && newValue === void 0) {
@@ -504,7 +511,7 @@ var Containers = typedMemo(function Containers2({
504
511
  const containers = [];
505
512
  for (let i = 0; i < numContainers; i++) {
506
513
  containers.push(
507
- /* @__PURE__ */ React3__namespace.createElement(
514
+ /* @__PURE__ */ React2__namespace.createElement(
508
515
  Container,
509
516
  {
510
517
  id: i,
@@ -533,7 +540,7 @@ var Containers = typedMemo(function Containers2({
533
540
  }
534
541
  }
535
542
  }
536
- return /* @__PURE__ */ React3__namespace.createElement(reactNative.Animated.View, { style }, containers);
543
+ return /* @__PURE__ */ React2__namespace.createElement(reactNative.Animated.View, { style }, containers);
537
544
  });
538
545
  function ListHeaderComponentContainer({
539
546
  children,
@@ -548,7 +555,7 @@ function ListHeaderComponentContainer({
548
555
  transform: [{ translateY: reactNative.Animated.multiply(scrollAdjust, -1) }],
549
556
  opacity: animOpacity
550
557
  };
551
- return /* @__PURE__ */ React.createElement(
558
+ return /* @__PURE__ */ React2__namespace.createElement(
552
559
  reactNative.Animated.View,
553
560
  {
554
561
  style: [style, additionalSize],
@@ -563,11 +570,11 @@ function ListHeaderComponentContainer({
563
570
 
564
571
  // src/ListComponent.tsx
565
572
  var getComponent = (Component) => {
566
- if (React3__namespace.isValidElement(Component)) {
573
+ if (React2__namespace.isValidElement(Component)) {
567
574
  return Component;
568
575
  }
569
576
  if (Component) {
570
- return /* @__PURE__ */ React3__namespace.createElement(Component, null);
577
+ return /* @__PURE__ */ React2__namespace.createElement(Component, null);
571
578
  }
572
579
  return null;
573
580
  };
@@ -575,12 +582,12 @@ var PaddingAndAdjust = () => {
575
582
  const animPaddingTop = useValue$("paddingTop", (v) => v, true);
576
583
  const animScrollAdjust = useValue$("scrollAdjust", (v) => v, true);
577
584
  const additionalSize = { marginTop: animScrollAdjust, paddingTop: animPaddingTop };
578
- return /* @__PURE__ */ React3__namespace.createElement(reactNative.Animated.View, { style: additionalSize });
585
+ return /* @__PURE__ */ React2__namespace.createElement(reactNative.Animated.View, { style: additionalSize });
579
586
  };
580
587
  var PaddingAndAdjustDevMode = () => {
581
588
  const animPaddingTop = useValue$("paddingTop", (v) => v, true);
582
589
  const animScrollAdjust = useValue$("scrollAdjust", (v) => v, true);
583
- return /* @__PURE__ */ React3__namespace.createElement(React3__namespace.Fragment, null, /* @__PURE__ */ React3__namespace.createElement(reactNative.Animated.View, { style: { marginTop: animScrollAdjust } }), /* @__PURE__ */ React3__namespace.createElement(reactNative.Animated.View, { style: { paddingTop: animPaddingTop } }), /* @__PURE__ */ React3__namespace.createElement(
590
+ return /* @__PURE__ */ React2__namespace.createElement(React2__namespace.Fragment, null, /* @__PURE__ */ React2__namespace.createElement(reactNative.Animated.View, { style: { marginTop: animScrollAdjust } }), /* @__PURE__ */ React2__namespace.createElement(reactNative.Animated.View, { style: { paddingTop: animPaddingTop } }), /* @__PURE__ */ React2__namespace.createElement(
584
591
  reactNative.Animated.View,
585
592
  {
586
593
  style: {
@@ -592,7 +599,7 @@ var PaddingAndAdjustDevMode = () => {
592
599
  backgroundColor: "green"
593
600
  }
594
601
  }
595
- ), /* @__PURE__ */ React3__namespace.createElement(
602
+ ), /* @__PURE__ */ React2__namespace.createElement(
596
603
  reactNative.Animated.View,
597
604
  {
598
605
  style: {
@@ -604,7 +611,7 @@ var PaddingAndAdjustDevMode = () => {
604
611
  backgroundColor: "lightblue"
605
612
  }
606
613
  }
607
- ), /* @__PURE__ */ React3__namespace.createElement(
614
+ ), /* @__PURE__ */ React2__namespace.createElement(
608
615
  reactNative.Animated.View,
609
616
  {
610
617
  style: {
@@ -649,11 +656,11 @@ var ListComponent = typedMemo(function ListComponent2({
649
656
  ...rest
650
657
  }) {
651
658
  const ctx = useStateContext();
652
- const ScrollComponent = renderScrollComponent ? React3.useMemo(
653
- () => React3__namespace.forwardRef((props, ref) => renderScrollComponent({ ...props, ref })),
659
+ const ScrollComponent = renderScrollComponent ? React2.useMemo(
660
+ () => React2__namespace.forwardRef((props, ref) => renderScrollComponent({ ...props, ref })),
654
661
  [renderScrollComponent]
655
662
  ) : reactNative.ScrollView;
656
- return /* @__PURE__ */ React3__namespace.createElement(
663
+ return /* @__PURE__ */ React2__namespace.createElement(
657
664
  ScrollComponent,
658
665
  {
659
666
  ...rest,
@@ -671,8 +678,8 @@ var ListComponent = typedMemo(function ListComponent2({
671
678
  contentOffset: initialContentOffset ? horizontal ? { x: initialContentOffset, y: 0 } : { x: 0, y: initialContentOffset } : void 0,
672
679
  ref: refScrollView
673
680
  },
674
- !ListEmptyComponent && (ENABLE_DEVMODE ? /* @__PURE__ */ React3__namespace.createElement(PaddingAndAdjustDevMode, null) : /* @__PURE__ */ React3__namespace.createElement(PaddingAndAdjust, null)),
675
- ListHeaderComponent && /* @__PURE__ */ React3__namespace.createElement(
681
+ !ListEmptyComponent && (ENABLE_DEVMODE ? /* @__PURE__ */ React2__namespace.createElement(PaddingAndAdjustDevMode, null) : /* @__PURE__ */ React2__namespace.createElement(PaddingAndAdjust, null)),
682
+ ListHeaderComponent && /* @__PURE__ */ React2__namespace.createElement(
676
683
  ListHeaderComponentContainer,
677
684
  {
678
685
  style: ListHeaderComponentStyle,
@@ -683,7 +690,7 @@ var ListComponent = typedMemo(function ListComponent2({
683
690
  getComponent(ListHeaderComponent)
684
691
  ),
685
692
  ListEmptyComponent && getComponent(ListEmptyComponent),
686
- /* @__PURE__ */ React3__namespace.createElement(
693
+ /* @__PURE__ */ React2__namespace.createElement(
687
694
  Containers,
688
695
  {
689
696
  horizontal,
@@ -694,7 +701,7 @@ var ListComponent = typedMemo(function ListComponent2({
694
701
  updateItemSize
695
702
  }
696
703
  ),
697
- ListFooterComponent && /* @__PURE__ */ React3__namespace.createElement(
704
+ ListFooterComponent && /* @__PURE__ */ React2__namespace.createElement(
698
705
  reactNative.View,
699
706
  {
700
707
  style: ListFooterComponentStyle,
@@ -757,7 +764,7 @@ var ScrollAdjustHandler = class {
757
764
  }
758
765
  };
759
766
  var useCombinedRef = (...refs) => {
760
- const callback = React3.useCallback((element) => {
767
+ const callback = React2.useCallback((element) => {
761
768
  for (const ref of refs) {
762
769
  if (!ref) {
763
770
  continue;
@@ -976,7 +983,7 @@ function createColumnWrapperStyle(contentContainerStyle) {
976
983
  }
977
984
  }
978
985
  var LegendList = typedForwardRef(function LegendList2(props, forwardedRef) {
979
- return /* @__PURE__ */ React3__namespace.createElement(StateProvider, null, /* @__PURE__ */ React3__namespace.createElement(LegendListInner, { ...props, ref: forwardedRef }));
986
+ return /* @__PURE__ */ React2__namespace.createElement(StateProvider, null, /* @__PURE__ */ React2__namespace.createElement(LegendListInner, { ...props, ref: forwardedRef }));
980
987
  });
981
988
  var LegendListInner = typedForwardRef(function LegendListInner2(props, forwardedRef) {
982
989
  const {
@@ -1019,7 +1026,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1019
1026
  onViewableItemsChanged,
1020
1027
  ...rest
1021
1028
  } = props;
1022
- const callbacks = React3.useRef({
1029
+ const callbacks = React2.useRef({
1023
1030
  onStartReached: rest.onStartReached,
1024
1031
  onEndReached: rest.onEndReached
1025
1032
  });
@@ -1027,7 +1034,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1027
1034
  callbacks.current.onEndReached = rest.onEndReached;
1028
1035
  const contentContainerStyle = { ...reactNative.StyleSheet.flatten(contentContainerStyleProp) };
1029
1036
  const style = { ...reactNative.StyleSheet.flatten(styleProp) };
1030
- const stylePaddingTopState = ((style == null ? void 0 : style.paddingTop) || 0) + ((contentContainerStyle == null ? void 0 : contentContainerStyle.paddingTop) || 0);
1037
+ const stylePaddingTopState = extractPaddingTop(style, contentContainerStyle);
1031
1038
  if (style == null ? void 0 : style.paddingTop) {
1032
1039
  style.paddingTop = void 0;
1033
1040
  }
@@ -1036,12 +1043,12 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1036
1043
  }
1037
1044
  const ctx = useStateContext();
1038
1045
  ctx.columnWrapperStyle = columnWrapperStyle || (contentContainerStyle ? createColumnWrapperStyle(contentContainerStyle) : void 0);
1039
- const refScroller = React3.useRef(null);
1046
+ const refScroller = React2.useRef(null);
1040
1047
  const combinedRef = useCombinedRef(refScroller, refScrollView);
1041
1048
  const estimatedItemSize = estimatedItemSizeProp != null ? estimatedItemSizeProp : DEFAULT_ITEM_SIZE;
1042
1049
  const scrollBuffer = (drawDistance != null ? drawDistance : DEFAULT_DRAW_DISTANCE) || 1;
1043
1050
  const keyExtractor = keyExtractorProp != null ? keyExtractorProp : (item, index) => index.toString();
1044
- const refState = React3.useRef();
1051
+ const refState = React2.useRef();
1045
1052
  const getId = (index) => {
1046
1053
  var _a;
1047
1054
  const data = (_a = refState.current) == null ? void 0 : _a.data;
@@ -1076,8 +1083,10 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1076
1083
  state.sizes.set(key, size);
1077
1084
  return size;
1078
1085
  };
1079
- const calculateOffsetForIndex = (index = initialScrollIndex) => {
1086
+ const calculateOffsetForIndex = (indexParam) => {
1080
1087
  var _a;
1088
+ const isFromInit = indexParam === void 0;
1089
+ const index = isFromInit ? initialScrollIndex : indexParam;
1081
1090
  const data = dataProp;
1082
1091
  if (index !== void 0) {
1083
1092
  let offset = 0;
@@ -1096,12 +1105,13 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1096
1105
  offset = index * estimatedItemSize;
1097
1106
  }
1098
1107
  const adjust = peek$(ctx, "containersDidLayout") ? ((_a = refState.current) == null ? void 0 : _a.scrollAdjustHandler.getAppliedAdjust()) || 0 : 0;
1099
- const topPad = peek$(ctx, "stylePaddingTop") + peek$(ctx, "headerSize");
1108
+ const stylePaddingTop = isFromInit ? stylePaddingTopState : peek$(ctx, "stylePaddingTop");
1109
+ const topPad = (stylePaddingTop != null ? stylePaddingTop : 0) + peek$(ctx, "headerSize");
1100
1110
  return offset / numColumnsProp - adjust + topPad;
1101
1111
  }
1102
1112
  return 0;
1103
1113
  };
1104
- const initialContentOffset = initialScrollOffset != null ? initialScrollOffset : React3.useMemo(calculateOffsetForIndex, []);
1114
+ const initialContentOffset = initialScrollOffset != null ? initialScrollOffset : React2.useMemo(() => calculateOffsetForIndex(void 0), []);
1105
1115
  if (!refState.current) {
1106
1116
  const initialScrollLength = reactNative.Dimensions.get("window")[horizontal ? "width" : "height"];
1107
1117
  refState.current = {
@@ -1236,7 +1246,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1236
1246
  });
1237
1247
  }
1238
1248
  };
1239
- const addTotalSize = React3.useCallback((key, add, totalSizeBelowAnchor) => {
1249
+ const addTotalSize = React2.useCallback((key, add, totalSizeBelowAnchor) => {
1240
1250
  const state = refState.current;
1241
1251
  const { indexByKey, anchorElement } = state;
1242
1252
  const index = key === null ? 0 : indexByKey.get(key);
@@ -1343,7 +1353,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1343
1353
  }
1344
1354
  return res;
1345
1355
  };
1346
- const fixGaps = React3.useCallback(() => {
1356
+ const fixGaps = React2.useCallback(() => {
1347
1357
  var _a;
1348
1358
  const state = refState.current;
1349
1359
  const { data, scrollLength, positions, startBuffered, endBuffered } = state;
@@ -1408,7 +1418,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1408
1418
  }
1409
1419
  }
1410
1420
  }, []);
1411
- const checkAllSizesKnown = React3.useCallback(() => {
1421
+ const checkAllSizesKnown = React2.useCallback(() => {
1412
1422
  const { startBuffered, endBuffered, sizesKnown } = refState.current;
1413
1423
  if (endBuffered !== null) {
1414
1424
  let areAllKnown = true;
@@ -1420,7 +1430,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1420
1430
  }
1421
1431
  return false;
1422
1432
  }, []);
1423
- const calculateItemsInView = React3.useCallback((isReset) => {
1433
+ const calculateItemsInView = React2.useCallback((isReset) => {
1424
1434
  var _a;
1425
1435
  const state = refState.current;
1426
1436
  const {
@@ -2024,7 +2034,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
2024
2034
  return result.sort(comparatorDefault);
2025
2035
  };
2026
2036
  const isFirst = !refState.current.renderItem;
2027
- const memoizedLastItemKeys = React3.useMemo(() => {
2037
+ const memoizedLastItemKeys = React2.useMemo(() => {
2028
2038
  if (!dataProp.length) return [];
2029
2039
  return Array.from(
2030
2040
  { length: Math.min(numColumnsProp, dataProp.length) },
@@ -2059,7 +2069,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
2059
2069
  refState.current.previousTotalSize = peek$(ctx, "totalSize");
2060
2070
  calcTotalSizesAndPositions({ forgetPositions: false });
2061
2071
  }
2062
- React3.useEffect(() => {
2072
+ React2.useEffect(() => {
2063
2073
  const didAllocateContainers = doInitialAllocateContainers();
2064
2074
  if (!didAllocateContainers) {
2065
2075
  checkResetContainers(
@@ -2068,12 +2078,12 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
2068
2078
  );
2069
2079
  }
2070
2080
  }, [dataProp, numColumnsProp]);
2071
- React3.useEffect(() => {
2081
+ React2.useEffect(() => {
2072
2082
  set$(ctx, "extraData", extraData);
2073
2083
  }, [extraData]);
2074
2084
  refState.current.renderItem = renderItem;
2075
- React3.useEffect(initalizeStateVars, [memoizedLastItemKeys.join(","), numColumnsProp, stylePaddingTopState]);
2076
- const getRenderedItem = React3.useCallback((key) => {
2085
+ React2.useEffect(initalizeStateVars, [memoizedLastItemKeys.join(","), numColumnsProp, stylePaddingTopState]);
2086
+ const getRenderedItem = React2.useCallback((key) => {
2077
2087
  var _a, _b;
2078
2088
  const state = refState.current;
2079
2089
  if (!state) {
@@ -2119,7 +2129,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
2119
2129
  return true;
2120
2130
  }
2121
2131
  };
2122
- React3.useEffect(() => {
2132
+ React2.useEffect(() => {
2123
2133
  const state = refState.current;
2124
2134
  const viewability = setupViewability({
2125
2135
  viewabilityConfig,
@@ -2132,7 +2142,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
2132
2142
  useInit(() => {
2133
2143
  doInitialAllocateContainers();
2134
2144
  });
2135
- const updateItemSize = React3.useCallback((itemKey, size, fromFixGaps) => {
2145
+ const updateItemSize = React2.useCallback((itemKey, size, fromFixGaps) => {
2136
2146
  const state = refState.current;
2137
2147
  const {
2138
2148
  sizes,
@@ -2234,7 +2244,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
2234
2244
  }
2235
2245
  }
2236
2246
  }, []);
2237
- const onLayout = React3.useCallback((event) => {
2247
+ const onLayout = React2.useCallback((event) => {
2238
2248
  const state = refState.current;
2239
2249
  const scrollLength = event.nativeEvent.layout[horizontal ? "width" : "height"];
2240
2250
  const didChange = scrollLength !== state.scrollLength;
@@ -2263,7 +2273,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
2263
2273
  onLayoutProp(event);
2264
2274
  }
2265
2275
  }, []);
2266
- const handleScroll = React3.useCallback(
2276
+ const handleScroll = React2.useCallback(
2267
2277
  (event) => {
2268
2278
  var _a, _b, _c, _d;
2269
2279
  if (((_b = (_a = event.nativeEvent) == null ? void 0 : _a.contentSize) == null ? void 0 : _b.height) === 0 && ((_c = event.nativeEvent.contentSize) == null ? void 0 : _c.width) === 0) {
@@ -2280,7 +2290,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
2280
2290
  },
2281
2291
  []
2282
2292
  );
2283
- const updateScroll = React3.useCallback((newScroll) => {
2293
+ const updateScroll = React2.useCallback((newScroll) => {
2284
2294
  const state = refState.current;
2285
2295
  const scrollingToOffset = state.scrollingToOffset;
2286
2296
  if (scrollingToOffset !== void 0 && Math.abs(newScroll - scrollingToOffset) < 10) {
@@ -2334,7 +2344,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
2334
2344
  checkAtBottom();
2335
2345
  checkAtTop();
2336
2346
  }, []);
2337
- React3.useImperativeHandle(
2347
+ React2.useImperativeHandle(
2338
2348
  forwardedRef,
2339
2349
  () => {
2340
2350
  const scrollIndexIntoView = (options) => {
@@ -2395,7 +2405,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
2395
2405
  []
2396
2406
  );
2397
2407
  if (reactNative.Platform.OS === "web") {
2398
- React3.useEffect(() => {
2408
+ React2.useEffect(() => {
2399
2409
  var _a;
2400
2410
  if (initialContentOffset) {
2401
2411
  (_a = refState.current) == null ? void 0 : _a.scrollAdjustHandler.setDisableAdjust(true);
@@ -2407,7 +2417,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
2407
2417
  }
2408
2418
  }, []);
2409
2419
  }
2410
- return /* @__PURE__ */ React3__namespace.createElement(React3__namespace.Fragment, null, /* @__PURE__ */ React3__namespace.createElement(
2420
+ return /* @__PURE__ */ React2__namespace.createElement(React2__namespace.Fragment, null, /* @__PURE__ */ React2__namespace.createElement(
2411
2421
  ListComponent,
2412
2422
  {
2413
2423
  ...rest,
@@ -2446,7 +2456,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
2446
2456
  maintainVisibleContentPosition,
2447
2457
  scrollEventThrottle: reactNative.Platform.OS === "web" ? 16 : void 0,
2448
2458
  waitForInitialLayout,
2449
- refreshControl: refreshControl != null ? refreshControl : onRefresh && /* @__PURE__ */ React3__namespace.createElement(
2459
+ refreshControl: refreshControl != null ? refreshControl : onRefresh && /* @__PURE__ */ React2__namespace.createElement(
2450
2460
  reactNative.RefreshControl,
2451
2461
  {
2452
2462
  refreshing: !!refreshing,
@@ -2457,7 +2467,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
2457
2467
  style,
2458
2468
  contentContainerStyle
2459
2469
  }
2460
- ), __DEV__ && ENABLE_DEBUG_VIEW && /* @__PURE__ */ React3__namespace.createElement(DebugView, { state: refState.current }));
2470
+ ), __DEV__ && ENABLE_DEBUG_VIEW && /* @__PURE__ */ React2__namespace.createElement(DebugView, { state: refState.current }));
2461
2471
  });
2462
2472
 
2463
2473
  exports.LegendList = LegendList;
package/index.mjs CHANGED
@@ -1,12 +1,12 @@
1
- import * as React3 from 'react';
2
- import React3__default, { useReducer, useEffect, createContext, useMemo, useRef, useCallback, useImperativeHandle, useContext, useState, forwardRef, memo, useLayoutEffect } from 'react';
1
+ import * as React2 from 'react';
2
+ import React2__default, { useReducer, useEffect, createContext, useMemo, useRef, useCallback, useImperativeHandle, useContext, useState, forwardRef, memo, useLayoutEffect } from 'react';
3
3
  import { View, Text, Platform, Animated, ScrollView, StyleSheet, Dimensions, RefreshControl } from 'react-native';
4
4
  import { useSyncExternalStore } from 'use-sync-external-store/shim';
5
5
 
6
6
  // src/LegendList.tsx
7
- var ContextState = React3.createContext(null);
7
+ var ContextState = React2.createContext(null);
8
8
  function StateProvider({ children }) {
9
- const [value] = React3.useState(() => ({
9
+ const [value] = React2.useState(() => ({
10
10
  listeners: /* @__PURE__ */ new Map(),
11
11
  values: /* @__PURE__ */ new Map([
12
12
  ["paddingTop", 0],
@@ -21,10 +21,10 @@ function StateProvider({ children }) {
21
21
  columnWrapperStyle: void 0,
22
22
  viewRefs: /* @__PURE__ */ new Map()
23
23
  }));
24
- return /* @__PURE__ */ React3.createElement(ContextState.Provider, { value }, children);
24
+ return /* @__PURE__ */ React2.createElement(ContextState.Provider, { value }, children);
25
25
  }
26
26
  function useStateContext() {
27
- return React3.useContext(ContextState);
27
+ return React2.useContext(ContextState);
28
28
  }
29
29
  function createSelectorFunctionsArr(ctx, signalNames) {
30
30
  let lastValues = [];
@@ -94,17 +94,17 @@ function getContentSize(ctx) {
94
94
  return headerSize + footerSize + totalSize + stylePaddingTop;
95
95
  }
96
96
  function useArr$(signalNames) {
97
- const ctx = React3.useContext(ContextState);
98
- const { subscribe, get } = React3.useMemo(() => createSelectorFunctionsArr(ctx, signalNames), [ctx, signalNames]);
97
+ const ctx = React2.useContext(ContextState);
98
+ const { subscribe, get } = React2.useMemo(() => createSelectorFunctionsArr(ctx, signalNames), [ctx, signalNames]);
99
99
  const value = useSyncExternalStore(subscribe, get);
100
100
  return value;
101
101
  }
102
102
 
103
103
  // src/DebugView.tsx
104
104
  var DebugRow = ({ children }) => {
105
- return /* @__PURE__ */ React3.createElement(View, { style: { flexDirection: "row", alignItems: "center", justifyContent: "space-between" } }, children);
105
+ return /* @__PURE__ */ React2.createElement(View, { style: { flexDirection: "row", alignItems: "center", justifyContent: "space-between" } }, children);
106
106
  };
107
- var DebugView = React3.memo(function DebugView2({ state }) {
107
+ var DebugView = React2.memo(function DebugView2({ state }) {
108
108
  const ctx = useStateContext();
109
109
  const [
110
110
  totalSize = 0,
@@ -128,7 +128,7 @@ var DebugView = React3.memo(function DebugView2({ state }) {
128
128
  useInterval(() => {
129
129
  forceUpdate();
130
130
  }, 100);
131
- return /* @__PURE__ */ React3.createElement(
131
+ return /* @__PURE__ */ React2.createElement(
132
132
  View,
133
133
  {
134
134
  style: {
@@ -144,15 +144,15 @@ var DebugView = React3.memo(function DebugView2({ state }) {
144
144
  },
145
145
  pointerEvents: "none"
146
146
  },
147
- /* @__PURE__ */ React3.createElement(DebugRow, null, /* @__PURE__ */ React3.createElement(Text, null, "TotalSize:"), /* @__PURE__ */ React3.createElement(Text, null, totalSize.toFixed(2))),
148
- /* @__PURE__ */ React3.createElement(DebugRow, null, /* @__PURE__ */ React3.createElement(Text, null, "ContentSize:"), /* @__PURE__ */ React3.createElement(Text, null, contentSize.toFixed(2))),
149
- /* @__PURE__ */ React3.createElement(DebugRow, null, /* @__PURE__ */ React3.createElement(Text, null, "At end:"), /* @__PURE__ */ React3.createElement(Text, null, String(state.isAtBottom))),
150
- /* @__PURE__ */ React3.createElement(Text, null),
151
- /* @__PURE__ */ React3.createElement(DebugRow, null, /* @__PURE__ */ React3.createElement(Text, null, "ScrollAdjust:"), /* @__PURE__ */ React3.createElement(Text, null, scrollAdjust.toFixed(2))),
152
- /* @__PURE__ */ React3.createElement(DebugRow, null, /* @__PURE__ */ React3.createElement(Text, null, "TotalSizeReal: "), /* @__PURE__ */ React3.createElement(Text, null, totalSizeWithScrollAdjust.toFixed(2))),
153
- /* @__PURE__ */ React3.createElement(Text, null),
154
- /* @__PURE__ */ React3.createElement(DebugRow, null, /* @__PURE__ */ React3.createElement(Text, null, "RawScroll: "), /* @__PURE__ */ React3.createElement(Text, null, rawScroll.toFixed(2))),
155
- /* @__PURE__ */ React3.createElement(DebugRow, null, /* @__PURE__ */ React3.createElement(Text, null, "ComputedScroll: "), /* @__PURE__ */ React3.createElement(Text, null, scroll.toFixed(2)))
147
+ /* @__PURE__ */ React2.createElement(DebugRow, null, /* @__PURE__ */ React2.createElement(Text, null, "TotalSize:"), /* @__PURE__ */ React2.createElement(Text, null, totalSize.toFixed(2))),
148
+ /* @__PURE__ */ React2.createElement(DebugRow, null, /* @__PURE__ */ React2.createElement(Text, null, "ContentSize:"), /* @__PURE__ */ React2.createElement(Text, null, contentSize.toFixed(2))),
149
+ /* @__PURE__ */ React2.createElement(DebugRow, null, /* @__PURE__ */ React2.createElement(Text, null, "At end:"), /* @__PURE__ */ React2.createElement(Text, null, String(state.isAtBottom))),
150
+ /* @__PURE__ */ React2.createElement(Text, null),
151
+ /* @__PURE__ */ React2.createElement(DebugRow, null, /* @__PURE__ */ React2.createElement(Text, null, "ScrollAdjust:"), /* @__PURE__ */ React2.createElement(Text, null, scrollAdjust.toFixed(2))),
152
+ /* @__PURE__ */ React2.createElement(DebugRow, null, /* @__PURE__ */ React2.createElement(Text, null, "TotalSizeReal: "), /* @__PURE__ */ React2.createElement(Text, null, totalSizeWithScrollAdjust.toFixed(2))),
153
+ /* @__PURE__ */ React2.createElement(Text, null),
154
+ /* @__PURE__ */ React2.createElement(DebugRow, null, /* @__PURE__ */ React2.createElement(Text, null, "RawScroll: "), /* @__PURE__ */ React2.createElement(Text, null, rawScroll.toFixed(2))),
155
+ /* @__PURE__ */ React2.createElement(DebugRow, null, /* @__PURE__ */ React2.createElement(Text, null, "ComputedScroll: "), /* @__PURE__ */ React2.createElement(Text, null, scroll.toFixed(2)))
156
156
  );
157
157
  });
158
158
  function useInterval(callback, delay) {
@@ -185,6 +185,13 @@ function comparatorByDistance(a, b) {
185
185
  function comparatorDefault(a, b) {
186
186
  return a - b;
187
187
  }
188
+ function getPadding(s) {
189
+ var _a, _b, _c;
190
+ return (_c = (_b = (_a = s.paddingTop) != null ? _a : s.paddingVertical) != null ? _b : s.padding) != null ? _c : 0;
191
+ }
192
+ function extractPaddingTop(style, contentContainerStyle) {
193
+ return getPadding(style) + getPadding(contentContainerStyle);
194
+ }
188
195
  var symbolFirst = Symbol();
189
196
  function useInit(cb) {
190
197
  const refValue = useRef(symbolFirst);
@@ -280,8 +287,8 @@ function useRecyclingState(valueOrFun) {
280
287
  );
281
288
  return [refState.current.value, setState];
282
289
  }
283
- var LeanViewComponent = React3.forwardRef((props, ref) => {
284
- return React3.createElement("RCTView", { ...props, ref });
290
+ var LeanViewComponent = React2.forwardRef((props, ref) => {
291
+ return React2.createElement("RCTView", { ...props, ref });
285
292
  });
286
293
  LeanViewComponent.displayName = "RCTView";
287
294
  var LeanView = Platform.OS === "android" || Platform.OS === "ios" ? LeanViewComponent : View;
@@ -421,16 +428,16 @@ var Container = ({
421
428
  ctx.viewRefs.set(id, ref);
422
429
  return { containerId: id, itemKey, index, value: data, triggerLayout };
423
430
  }, [id, itemKey, index, data]);
424
- const contentFragment = /* @__PURE__ */ React3__default.createElement(React3__default.Fragment, { key: recycleItems ? void 0 : itemKey }, /* @__PURE__ */ React3__default.createElement(ContextContainer.Provider, { value: contextValue }, renderedItem, renderedItemInfo && ItemSeparatorComponent && !lastItemKeys.includes(itemKey) && /* @__PURE__ */ React3__default.createElement(ItemSeparatorComponent, { leadingItem: renderedItemInfo.item })));
431
+ const contentFragment = /* @__PURE__ */ React2__default.createElement(React2__default.Fragment, { key: recycleItems ? void 0 : itemKey }, /* @__PURE__ */ React2__default.createElement(ContextContainer.Provider, { value: contextValue }, renderedItem, renderedItemInfo && ItemSeparatorComponent && !lastItemKeys.includes(itemKey) && /* @__PURE__ */ React2__default.createElement(ItemSeparatorComponent, { leadingItem: renderedItemInfo.item })));
425
432
  if (maintainVisibleContentPosition) {
426
433
  const anchorStyle = position.type === "top" ? { position: "absolute", top: 0, left: 0, right: 0 } : { position: "absolute", bottom: 0, left: 0, right: 0 };
427
434
  if (__DEV__ && ENABLE_DEVMODE) {
428
435
  anchorStyle.borderColor = position.type === "top" ? "red" : "blue";
429
436
  anchorStyle.borderWidth = 1;
430
437
  }
431
- return /* @__PURE__ */ React3__default.createElement(LeanView, { style }, /* @__PURE__ */ React3__default.createElement(LeanView, { style: [anchorStyle, paddingStyles], onLayout, ref }, contentFragment, __DEV__ && ENABLE_DEVMODE && /* @__PURE__ */ React3__default.createElement(Text, { style: { position: "absolute", top: 0, left: 0, zIndex: 1e3 } }, position.top)));
438
+ return /* @__PURE__ */ React2__default.createElement(LeanView, { style }, /* @__PURE__ */ React2__default.createElement(LeanView, { style: [anchorStyle, paddingStyles], onLayout, ref }, contentFragment, __DEV__ && ENABLE_DEVMODE && /* @__PURE__ */ React2__default.createElement(Text, { style: { position: "absolute", top: 0, left: 0, zIndex: 1e3 } }, position.top)));
432
439
  }
433
- return /* @__PURE__ */ React3__default.createElement(LeanView, { style, onLayout, ref }, contentFragment);
440
+ return /* @__PURE__ */ React2__default.createElement(LeanView, { style, onLayout, ref }, contentFragment);
434
441
  };
435
442
  var typedForwardRef = forwardRef;
436
443
  var typedMemo = memo;
@@ -483,7 +490,7 @@ var Containers = typedMemo(function Containers2({
483
490
  const containers = [];
484
491
  for (let i = 0; i < numContainers; i++) {
485
492
  containers.push(
486
- /* @__PURE__ */ React3.createElement(
493
+ /* @__PURE__ */ React2.createElement(
487
494
  Container,
488
495
  {
489
496
  id: i,
@@ -512,7 +519,7 @@ var Containers = typedMemo(function Containers2({
512
519
  }
513
520
  }
514
521
  }
515
- return /* @__PURE__ */ React3.createElement(Animated.View, { style }, containers);
522
+ return /* @__PURE__ */ React2.createElement(Animated.View, { style }, containers);
516
523
  });
517
524
  function ListHeaderComponentContainer({
518
525
  children,
@@ -527,7 +534,7 @@ function ListHeaderComponentContainer({
527
534
  transform: [{ translateY: Animated.multiply(scrollAdjust, -1) }],
528
535
  opacity: animOpacity
529
536
  };
530
- return /* @__PURE__ */ React.createElement(
537
+ return /* @__PURE__ */ React2.createElement(
531
538
  Animated.View,
532
539
  {
533
540
  style: [style, additionalSize],
@@ -542,11 +549,11 @@ function ListHeaderComponentContainer({
542
549
 
543
550
  // src/ListComponent.tsx
544
551
  var getComponent = (Component) => {
545
- if (React3.isValidElement(Component)) {
552
+ if (React2.isValidElement(Component)) {
546
553
  return Component;
547
554
  }
548
555
  if (Component) {
549
- return /* @__PURE__ */ React3.createElement(Component, null);
556
+ return /* @__PURE__ */ React2.createElement(Component, null);
550
557
  }
551
558
  return null;
552
559
  };
@@ -554,12 +561,12 @@ var PaddingAndAdjust = () => {
554
561
  const animPaddingTop = useValue$("paddingTop", (v) => v, true);
555
562
  const animScrollAdjust = useValue$("scrollAdjust", (v) => v, true);
556
563
  const additionalSize = { marginTop: animScrollAdjust, paddingTop: animPaddingTop };
557
- return /* @__PURE__ */ React3.createElement(Animated.View, { style: additionalSize });
564
+ return /* @__PURE__ */ React2.createElement(Animated.View, { style: additionalSize });
558
565
  };
559
566
  var PaddingAndAdjustDevMode = () => {
560
567
  const animPaddingTop = useValue$("paddingTop", (v) => v, true);
561
568
  const animScrollAdjust = useValue$("scrollAdjust", (v) => v, true);
562
- return /* @__PURE__ */ React3.createElement(React3.Fragment, null, /* @__PURE__ */ React3.createElement(Animated.View, { style: { marginTop: animScrollAdjust } }), /* @__PURE__ */ React3.createElement(Animated.View, { style: { paddingTop: animPaddingTop } }), /* @__PURE__ */ React3.createElement(
569
+ return /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement(Animated.View, { style: { marginTop: animScrollAdjust } }), /* @__PURE__ */ React2.createElement(Animated.View, { style: { paddingTop: animPaddingTop } }), /* @__PURE__ */ React2.createElement(
563
570
  Animated.View,
564
571
  {
565
572
  style: {
@@ -571,7 +578,7 @@ var PaddingAndAdjustDevMode = () => {
571
578
  backgroundColor: "green"
572
579
  }
573
580
  }
574
- ), /* @__PURE__ */ React3.createElement(
581
+ ), /* @__PURE__ */ React2.createElement(
575
582
  Animated.View,
576
583
  {
577
584
  style: {
@@ -583,7 +590,7 @@ var PaddingAndAdjustDevMode = () => {
583
590
  backgroundColor: "lightblue"
584
591
  }
585
592
  }
586
- ), /* @__PURE__ */ React3.createElement(
593
+ ), /* @__PURE__ */ React2.createElement(
587
594
  Animated.View,
588
595
  {
589
596
  style: {
@@ -629,10 +636,10 @@ var ListComponent = typedMemo(function ListComponent2({
629
636
  }) {
630
637
  const ctx = useStateContext();
631
638
  const ScrollComponent = renderScrollComponent ? useMemo(
632
- () => React3.forwardRef((props, ref) => renderScrollComponent({ ...props, ref })),
639
+ () => React2.forwardRef((props, ref) => renderScrollComponent({ ...props, ref })),
633
640
  [renderScrollComponent]
634
641
  ) : ScrollView;
635
- return /* @__PURE__ */ React3.createElement(
642
+ return /* @__PURE__ */ React2.createElement(
636
643
  ScrollComponent,
637
644
  {
638
645
  ...rest,
@@ -650,8 +657,8 @@ var ListComponent = typedMemo(function ListComponent2({
650
657
  contentOffset: initialContentOffset ? horizontal ? { x: initialContentOffset, y: 0 } : { x: 0, y: initialContentOffset } : void 0,
651
658
  ref: refScrollView
652
659
  },
653
- !ListEmptyComponent && (ENABLE_DEVMODE ? /* @__PURE__ */ React3.createElement(PaddingAndAdjustDevMode, null) : /* @__PURE__ */ React3.createElement(PaddingAndAdjust, null)),
654
- ListHeaderComponent && /* @__PURE__ */ React3.createElement(
660
+ !ListEmptyComponent && (ENABLE_DEVMODE ? /* @__PURE__ */ React2.createElement(PaddingAndAdjustDevMode, null) : /* @__PURE__ */ React2.createElement(PaddingAndAdjust, null)),
661
+ ListHeaderComponent && /* @__PURE__ */ React2.createElement(
655
662
  ListHeaderComponentContainer,
656
663
  {
657
664
  style: ListHeaderComponentStyle,
@@ -662,7 +669,7 @@ var ListComponent = typedMemo(function ListComponent2({
662
669
  getComponent(ListHeaderComponent)
663
670
  ),
664
671
  ListEmptyComponent && getComponent(ListEmptyComponent),
665
- /* @__PURE__ */ React3.createElement(
672
+ /* @__PURE__ */ React2.createElement(
666
673
  Containers,
667
674
  {
668
675
  horizontal,
@@ -673,7 +680,7 @@ var ListComponent = typedMemo(function ListComponent2({
673
680
  updateItemSize
674
681
  }
675
682
  ),
676
- ListFooterComponent && /* @__PURE__ */ React3.createElement(
683
+ ListFooterComponent && /* @__PURE__ */ React2.createElement(
677
684
  View,
678
685
  {
679
686
  style: ListFooterComponentStyle,
@@ -955,7 +962,7 @@ function createColumnWrapperStyle(contentContainerStyle) {
955
962
  }
956
963
  }
957
964
  var LegendList = typedForwardRef(function LegendList2(props, forwardedRef) {
958
- return /* @__PURE__ */ React3.createElement(StateProvider, null, /* @__PURE__ */ React3.createElement(LegendListInner, { ...props, ref: forwardedRef }));
965
+ return /* @__PURE__ */ React2.createElement(StateProvider, null, /* @__PURE__ */ React2.createElement(LegendListInner, { ...props, ref: forwardedRef }));
959
966
  });
960
967
  var LegendListInner = typedForwardRef(function LegendListInner2(props, forwardedRef) {
961
968
  const {
@@ -1006,7 +1013,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1006
1013
  callbacks.current.onEndReached = rest.onEndReached;
1007
1014
  const contentContainerStyle = { ...StyleSheet.flatten(contentContainerStyleProp) };
1008
1015
  const style = { ...StyleSheet.flatten(styleProp) };
1009
- const stylePaddingTopState = ((style == null ? void 0 : style.paddingTop) || 0) + ((contentContainerStyle == null ? void 0 : contentContainerStyle.paddingTop) || 0);
1016
+ const stylePaddingTopState = extractPaddingTop(style, contentContainerStyle);
1010
1017
  if (style == null ? void 0 : style.paddingTop) {
1011
1018
  style.paddingTop = void 0;
1012
1019
  }
@@ -1055,8 +1062,10 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1055
1062
  state.sizes.set(key, size);
1056
1063
  return size;
1057
1064
  };
1058
- const calculateOffsetForIndex = (index = initialScrollIndex) => {
1065
+ const calculateOffsetForIndex = (indexParam) => {
1059
1066
  var _a;
1067
+ const isFromInit = indexParam === void 0;
1068
+ const index = isFromInit ? initialScrollIndex : indexParam;
1060
1069
  const data = dataProp;
1061
1070
  if (index !== void 0) {
1062
1071
  let offset = 0;
@@ -1075,12 +1084,13 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1075
1084
  offset = index * estimatedItemSize;
1076
1085
  }
1077
1086
  const adjust = peek$(ctx, "containersDidLayout") ? ((_a = refState.current) == null ? void 0 : _a.scrollAdjustHandler.getAppliedAdjust()) || 0 : 0;
1078
- const topPad = peek$(ctx, "stylePaddingTop") + peek$(ctx, "headerSize");
1087
+ const stylePaddingTop = isFromInit ? stylePaddingTopState : peek$(ctx, "stylePaddingTop");
1088
+ const topPad = (stylePaddingTop != null ? stylePaddingTop : 0) + peek$(ctx, "headerSize");
1079
1089
  return offset / numColumnsProp - adjust + topPad;
1080
1090
  }
1081
1091
  return 0;
1082
1092
  };
1083
- const initialContentOffset = initialScrollOffset != null ? initialScrollOffset : useMemo(calculateOffsetForIndex, []);
1093
+ const initialContentOffset = initialScrollOffset != null ? initialScrollOffset : useMemo(() => calculateOffsetForIndex(void 0), []);
1084
1094
  if (!refState.current) {
1085
1095
  const initialScrollLength = Dimensions.get("window")[horizontal ? "width" : "height"];
1086
1096
  refState.current = {
@@ -2386,7 +2396,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
2386
2396
  }
2387
2397
  }, []);
2388
2398
  }
2389
- return /* @__PURE__ */ React3.createElement(React3.Fragment, null, /* @__PURE__ */ React3.createElement(
2399
+ return /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement(
2390
2400
  ListComponent,
2391
2401
  {
2392
2402
  ...rest,
@@ -2425,7 +2435,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
2425
2435
  maintainVisibleContentPosition,
2426
2436
  scrollEventThrottle: Platform.OS === "web" ? 16 : void 0,
2427
2437
  waitForInitialLayout,
2428
- refreshControl: refreshControl != null ? refreshControl : onRefresh && /* @__PURE__ */ React3.createElement(
2438
+ refreshControl: refreshControl != null ? refreshControl : onRefresh && /* @__PURE__ */ React2.createElement(
2429
2439
  RefreshControl,
2430
2440
  {
2431
2441
  refreshing: !!refreshing,
@@ -2436,7 +2446,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
2436
2446
  style,
2437
2447
  contentContainerStyle
2438
2448
  }
2439
- ), __DEV__ && ENABLE_DEBUG_VIEW && /* @__PURE__ */ React3.createElement(DebugView, { state: refState.current }));
2449
+ ), __DEV__ && ENABLE_DEBUG_VIEW && /* @__PURE__ */ React2.createElement(DebugView, { state: refState.current }));
2440
2450
  });
2441
2451
 
2442
2452
  export { LegendList, useRecyclingEffect, useRecyclingState, useViewability, useViewabilityAmount };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legendapp/list",
3
- "version": "1.0.12",
3
+ "version": "1.0.13",
4
4
  "description": "Legend List is a drop-in replacement for FlatList with much better performance and supporting dynamically sized items.",
5
5
  "sideEffects": false,
6
6
  "private": false,