@legendapp/list 1.0.0-beta.42 → 1.0.0-beta.44

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/animated.d.mts CHANGED
@@ -3,7 +3,7 @@ import * as _legendapp_list from '@legendapp/list';
3
3
  import * as react_native from 'react-native';
4
4
  import { Animated } from 'react-native';
5
5
 
6
- declare const AnimatedLegendList: Animated.AnimatedComponent<(<T>(props: Omit<react_native.ScrollViewProps, "maintainVisibleContentPosition" | "stickyHeaderIndices" | "contentInset" | "contentOffset"> & {
6
+ declare const AnimatedLegendList: Animated.AnimatedComponent<(<T>(props: Omit<react_native.ScrollViewProps, "contentOffset" | "contentInset" | "maintainVisibleContentPosition" | "stickyHeaderIndices"> & {
7
7
  alignItemsAtEnd?: boolean;
8
8
  columnWrapperStyle?: _legendapp_list.ColumnWrapperStyle;
9
9
  data: readonly T[];
package/animated.d.ts CHANGED
@@ -3,7 +3,7 @@ import * as _legendapp_list from '@legendapp/list';
3
3
  import * as react_native from 'react-native';
4
4
  import { Animated } from 'react-native';
5
5
 
6
- declare const AnimatedLegendList: Animated.AnimatedComponent<(<T>(props: Omit<react_native.ScrollViewProps, "maintainVisibleContentPosition" | "stickyHeaderIndices" | "contentInset" | "contentOffset"> & {
6
+ declare const AnimatedLegendList: Animated.AnimatedComponent<(<T>(props: Omit<react_native.ScrollViewProps, "contentOffset" | "contentInset" | "maintainVisibleContentPosition" | "stickyHeaderIndices"> & {
7
7
  alignItemsAtEnd?: boolean;
8
8
  columnWrapperStyle?: _legendapp_list.ColumnWrapperStyle;
9
9
  data: readonly T[];
package/index.d.mts CHANGED
@@ -453,7 +453,7 @@ type TypedMemo = <T extends React.ComponentType<any>>(Component: T, propsAreEqua
453
453
  };
454
454
  declare const typedMemo: TypedMemo;
455
455
 
456
- declare const LegendList: <T>(props: Omit<react_native.ScrollViewProps, "maintainVisibleContentPosition" | "stickyHeaderIndices" | "contentInset" | "contentOffset"> & {
456
+ declare const LegendList: <T>(props: Omit<react_native.ScrollViewProps, "contentOffset" | "contentInset" | "maintainVisibleContentPosition" | "stickyHeaderIndices"> & {
457
457
  alignItemsAtEnd?: boolean;
458
458
  columnWrapperStyle?: ColumnWrapperStyle;
459
459
  data: readonly T[];
@@ -505,7 +505,7 @@ declare const LegendList: <T>(props: Omit<react_native.ScrollViewProps, "maintai
505
505
  waitForInitialLayout?: boolean;
506
506
  } & React$1.RefAttributes<LegendListRef>) => React$1.ReactNode;
507
507
 
508
- declare function useViewability(configId: string, callback: ViewabilityCallback): void;
508
+ declare function useViewability(callback: ViewabilityCallback, configId?: string): void;
509
509
  declare function useViewabilityAmount(callback: ViewabilityAmountCallback): void;
510
510
  declare function useRecyclingEffect(effect: (info: LegendListRecyclingState<unknown>) => void | (() => void)): void;
511
511
  declare function useRecyclingState(valueOrFun: ((info: LegendListRecyclingState<unknown>) => any) | any): [any, React$1.Dispatch<any>];
package/index.d.ts CHANGED
@@ -453,7 +453,7 @@ type TypedMemo = <T extends React.ComponentType<any>>(Component: T, propsAreEqua
453
453
  };
454
454
  declare const typedMemo: TypedMemo;
455
455
 
456
- declare const LegendList: <T>(props: Omit<react_native.ScrollViewProps, "maintainVisibleContentPosition" | "stickyHeaderIndices" | "contentInset" | "contentOffset"> & {
456
+ declare const LegendList: <T>(props: Omit<react_native.ScrollViewProps, "contentOffset" | "contentInset" | "maintainVisibleContentPosition" | "stickyHeaderIndices"> & {
457
457
  alignItemsAtEnd?: boolean;
458
458
  columnWrapperStyle?: ColumnWrapperStyle;
459
459
  data: readonly T[];
@@ -505,7 +505,7 @@ declare const LegendList: <T>(props: Omit<react_native.ScrollViewProps, "maintai
505
505
  waitForInitialLayout?: boolean;
506
506
  } & React$1.RefAttributes<LegendListRef>) => React$1.ReactNode;
507
507
 
508
- declare function useViewability(configId: string, callback: ViewabilityCallback): void;
508
+ declare function useViewability(callback: ViewabilityCallback, configId?: string): void;
509
509
  declare function useViewabilityAmount(callback: ViewabilityAmountCallback): void;
510
510
  declare function useRecyclingEffect(effect: (info: LegendListRecyclingState<unknown>) => void | (() => void)): void;
511
511
  declare function useRecyclingState(valueOrFun: ((info: LegendListRecyclingState<unknown>) => any) | any): [any, React$1.Dispatch<any>];
package/index.js CHANGED
@@ -28,7 +28,12 @@ var ContextState = React6__namespace.createContext(null);
28
28
  function StateProvider({ children }) {
29
29
  const [value] = React6__namespace.useState(() => ({
30
30
  listeners: /* @__PURE__ */ new Map(),
31
- values: /* @__PURE__ */ new Map(),
31
+ values: /* @__PURE__ */ new Map([
32
+ ["paddingTop", 0],
33
+ ["alignItemsPaddingTop", 0],
34
+ ["stylePaddingTop", 0],
35
+ ["headerSize", 0]
36
+ ]),
32
37
  mapViewabilityCallbacks: /* @__PURE__ */ new Map(),
33
38
  mapViewabilityValues: /* @__PURE__ */ new Map(),
34
39
  mapViewabilityAmountCallbacks: /* @__PURE__ */ new Map(),
@@ -149,10 +154,10 @@ function useInit(cb) {
149
154
 
150
155
  // src/ContextContainer.ts
151
156
  var ContextContainer = React6.createContext(null);
152
- function useViewability(configId, callback) {
157
+ function useViewability(callback, configId) {
153
158
  const ctx = useStateContext();
154
159
  const { containerId } = React6.useContext(ContextContainer);
155
- const key = containerId + configId;
160
+ const key = containerId + (configId != null ? configId : "");
156
161
  useInit(() => {
157
162
  const value = ctx.mapViewabilityValues.get(key);
158
163
  if (value) {
@@ -262,13 +267,20 @@ var Container = ({
262
267
  const refLastSize = React6.useRef();
263
268
  const otherAxisPos = numColumns > 1 ? `${(column - 1) / numColumns * 100}%` : 0;
264
269
  const otherAxisSize = numColumns > 1 ? `${1 / numColumns * 100}%` : void 0;
265
- let verticalPaddingStyles;
270
+ let paddingStyles;
266
271
  if (columnWrapperStyle) {
267
272
  const { columnGap, rowGap, gap } = columnWrapperStyle;
268
- verticalPaddingStyles = {
269
- paddingBottom: !lastItemKeys.includes(itemKey) ? rowGap || gap || void 0 : void 0,
270
- paddingHorizontal: (columnGap || gap || 0) / 2
271
- };
273
+ if (horizontal) {
274
+ paddingStyles = {
275
+ paddingRight: !lastItemKeys.includes(itemKey) ? columnGap || gap || void 0 : void 0,
276
+ paddingVertical: (rowGap || gap || 0) / 2
277
+ };
278
+ } else {
279
+ paddingStyles = {
280
+ paddingBottom: !lastItemKeys.includes(itemKey) ? rowGap || gap || void 0 : void 0,
281
+ paddingHorizontal: (columnGap || gap || 0) / 2
282
+ };
283
+ }
272
284
  }
273
285
  const style = horizontal ? {
274
286
  flexDirection: ItemSeparatorComponent ? "row" : void 0,
@@ -276,14 +288,15 @@ var Container = ({
276
288
  top: otherAxisPos,
277
289
  bottom: numColumns > 1 ? null : 0,
278
290
  height: otherAxisSize,
279
- left: position.relativeCoordinate
291
+ left: position.relativeCoordinate,
292
+ ...paddingStyles || {}
280
293
  } : {
281
294
  position: "absolute",
282
295
  left: otherAxisPos,
283
296
  right: numColumns > 1 ? null : 0,
284
297
  width: otherAxisSize,
285
298
  top: position.relativeCoordinate,
286
- ...verticalPaddingStyles || {}
299
+ ...paddingStyles || {}
287
300
  };
288
301
  const renderedItemInfo = React6.useMemo(
289
302
  () => itemKey !== void 0 ? getRenderedItem(itemKey) : null,
@@ -381,7 +394,7 @@ var Containers = typedMemo(function Containers2({
381
394
  }) {
382
395
  const ctx = useStateContext();
383
396
  const columnWrapperStyle = ctx.columnWrapperStyle;
384
- const numColumns = use$("numColumns");
397
+ use$("numColumns");
385
398
  const numContainers = use$("numContainersPooled");
386
399
  const animSize = useValue$(
387
400
  "totalSizeWithScrollAdjust",
@@ -408,11 +421,18 @@ var Containers = typedMemo(function Containers2({
408
421
  );
409
422
  }
410
423
  const style = horizontal ? { width: animSize, opacity: animOpacity } : { height: animSize, opacity: animOpacity };
411
- if (columnWrapperStyle && !horizontal && numColumns > 1) {
424
+ if (columnWrapperStyle) {
412
425
  const { columnGap, rowGap, gap } = columnWrapperStyle;
413
- const mx = (columnGap || gap || 0) / 2;
414
- if (mx) {
415
- style.marginHorizontal = -mx;
426
+ if (horizontal) {
427
+ const my = (rowGap || gap || 0) / 2;
428
+ if (my) {
429
+ style.marginVertical = -my;
430
+ }
431
+ } else {
432
+ const mx = (columnGap || gap || 0) / 2;
433
+ if (mx) {
434
+ style.marginHorizontal = -mx;
435
+ }
416
436
  }
417
437
  }
418
438
  return /* @__PURE__ */ React6__namespace.createElement(reactNative.Animated.View, { style }, containers);
@@ -837,7 +857,6 @@ var LegendList = typedForwardRef(function LegendList2(props, forwardedRef) {
837
857
  return /* @__PURE__ */ React6__namespace.createElement(StateProvider, null, /* @__PURE__ */ React6__namespace.createElement(LegendListInner, { ...props, ref: forwardedRef }));
838
858
  });
839
859
  var LegendListInner = typedForwardRef(function LegendListInner2(props, forwardedRef) {
840
- var _a, _b, _c, _d;
841
860
  const {
842
861
  data: dataProp = [],
843
862
  initialScrollIndex,
@@ -884,9 +903,9 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
884
903
  });
885
904
  callbacks.current.onStartReached = rest.onStartReached;
886
905
  callbacks.current.onEndReached = rest.onEndReached;
887
- const contentContainerStyle = reactNative.StyleSheet.flatten(contentContainerStyleProp);
888
- const style = reactNative.StyleSheet.flatten(styleProp);
889
- 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;
906
+ const contentContainerStyle = { ...reactNative.StyleSheet.flatten(contentContainerStyleProp) };
907
+ const style = { ...reactNative.StyleSheet.flatten(styleProp) };
908
+ const stylePaddingTopState = ((style == null ? void 0 : style.paddingTop) || 0) + ((contentContainerStyle == null ? void 0 : contentContainerStyle.paddingTop) || 0);
890
909
  if (style == null ? void 0 : style.paddingTop) {
891
910
  style.paddingTop = void 0;
892
911
  }
@@ -901,8 +920,8 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
901
920
  const keyExtractor = keyExtractorProp != null ? keyExtractorProp : (item, index) => index.toString();
902
921
  const refState = React6.useRef();
903
922
  const getId = (index) => {
904
- var _a2;
905
- const data = (_a2 = refState.current) == null ? void 0 : _a2.data;
923
+ var _a;
924
+ const data = (_a = refState.current) == null ? void 0 : _a.data;
906
925
  if (!data) {
907
926
  return "";
908
927
  }
@@ -910,17 +929,17 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
910
929
  return `${ret}`;
911
930
  };
912
931
  const getItemSize = (key, index, data) => {
913
- var _a2;
932
+ var _a;
914
933
  const sizeKnown = refState.current.sizes.get(key);
915
934
  if (sizeKnown !== void 0) {
916
935
  return sizeKnown;
917
936
  }
918
- const size = (_a2 = getEstimatedItemSize ? getEstimatedItemSize(index, data) : estimatedItemSize) != null ? _a2 : DEFAULT_ITEM_SIZE;
937
+ const size = (_a = getEstimatedItemSize ? getEstimatedItemSize(index, data) : estimatedItemSize) != null ? _a : DEFAULT_ITEM_SIZE;
919
938
  refState.current.sizes.set(key, size);
920
939
  return size;
921
940
  };
922
941
  const calculateOffsetForIndex = (index = initialScrollIndex) => {
923
- var _a2;
942
+ var _a;
924
943
  const data = dataProp;
925
944
  if (index !== void 0) {
926
945
  let offset = 0;
@@ -938,7 +957,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
938
957
  } else if (estimatedItemSize) {
939
958
  offset = index * estimatedItemSize;
940
959
  }
941
- return offset / numColumnsProp - (((_a2 = refState.current) == null ? void 0 : _a2.scrollAdjustHandler.getAppliedAdjust()) || 0);
960
+ return offset / numColumnsProp - (((_a = refState.current) == null ? void 0 : _a.scrollAdjustHandler.getAppliedAdjust()) || 0);
942
961
  }
943
962
  return 0;
944
963
  };
@@ -1021,18 +1040,18 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1021
1040
  return void 0;
1022
1041
  };
1023
1042
  const setDidLayout = () => {
1024
- var _a2;
1043
+ var _a;
1025
1044
  refState.current.queuedInitialLayout = true;
1026
1045
  checkAtBottom();
1027
1046
  if (initialScrollIndex) {
1028
1047
  const updatedOffset = calculateOffsetForIndex(initialScrollIndex);
1029
- (_a2 = refState.current) == null ? void 0 : _a2.scrollAdjustHandler.setDisableAdjust(true);
1048
+ (_a = refState.current) == null ? void 0 : _a.scrollAdjustHandler.setDisableAdjust(true);
1030
1049
  queueMicrotask(() => {
1031
1050
  scrollTo(updatedOffset, false);
1032
1051
  requestAnimationFrame(() => {
1033
- var _a3;
1052
+ var _a2;
1034
1053
  set$(ctx, "containersDidLayout", true);
1035
- (_a3 = refState.current) == null ? void 0 : _a3.scrollAdjustHandler.setDisableAdjust(false);
1054
+ (_a2 = refState.current) == null ? void 0 : _a2.scrollAdjustHandler.setDisableAdjust(false);
1036
1055
  });
1037
1056
  });
1038
1057
  } else {
@@ -1077,7 +1096,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1077
1096
  set$(ctx, "totalSize", state.totalSize);
1078
1097
  set$(ctx, "totalSizeWithScrollAdjust", resultSize);
1079
1098
  if (alignItemsAtEnd) {
1080
- doUpdatePaddingTop();
1099
+ updateAlignItemsPaddingTop();
1081
1100
  }
1082
1101
  }, []);
1083
1102
  const getRowHeight = (n) => {
@@ -1105,13 +1124,13 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1105
1124
  if (!state.anchorElement) {
1106
1125
  return /* @__PURE__ */ new Map();
1107
1126
  }
1108
- let top = state.anchorElement.coordinate;
1109
1127
  const anchorIndex = state.indexByKey.get(state.anchorElement.id);
1110
1128
  if (anchorIndex === 0) {
1111
1129
  return /* @__PURE__ */ new Map();
1112
1130
  }
1113
1131
  const map = state.belowAnchorElementPositions || /* @__PURE__ */ new Map();
1114
1132
  const numColumns = peek$(ctx, "numColumns");
1133
+ let top = state.anchorElement.coordinate;
1115
1134
  for (let i = anchorIndex - 1; i >= 0; i--) {
1116
1135
  const id = getId(i);
1117
1136
  const rowNumber = Math.floor(i / numColumns);
@@ -1123,20 +1142,20 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1123
1142
  return map;
1124
1143
  };
1125
1144
  const getElementPositionBelowAchor = (id) => {
1126
- var _a2;
1145
+ var _a;
1127
1146
  const state = refState.current;
1128
1147
  if (!refState.current.belowAnchorElementPositions) {
1129
1148
  state.belowAnchorElementPositions = buildElementPositionsBelowAnchor();
1130
1149
  }
1131
1150
  const res = state.belowAnchorElementPositions.get(id);
1132
1151
  if (res === void 0) {
1133
- console.warn(`Undefined position below achor ${id} ${(_a2 = state.anchorElement) == null ? void 0 : _a2.id}`);
1152
+ console.warn(`Undefined position below anchor ${id} ${(_a = state.anchorElement) == null ? void 0 : _a.id}`);
1134
1153
  return 0;
1135
1154
  }
1136
1155
  return res;
1137
1156
  };
1138
1157
  const calculateItemsInView = React6.useCallback(() => {
1139
- var _a2;
1158
+ var _a;
1140
1159
  const state = refState.current;
1141
1160
  const {
1142
1161
  data,
@@ -1151,7 +1170,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1151
1170
  return;
1152
1171
  }
1153
1172
  const totalSize = peek$(ctx, "totalSizeWithScrollAdjust");
1154
- const topPad = (peek$(ctx, "stylePaddingTop") || 0) + (peek$(ctx, "headerSize") || 0);
1173
+ const topPad = peek$(ctx, "stylePaddingTop") + peek$(ctx, "headerSize");
1155
1174
  const numColumns = peek$(ctx, "numColumns");
1156
1175
  const previousScrollAdjust = scrollAdjustHandler.getAppliedAdjust();
1157
1176
  const scrollExtra = Math.max(-16, Math.min(16, speed)) * 16;
@@ -1224,22 +1243,22 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1224
1243
  let column = 1;
1225
1244
  let maxSizeInRow = 0;
1226
1245
  const getInitialTop = (i) => {
1227
- var _a3;
1246
+ var _a2;
1228
1247
  const id = getId(i);
1229
1248
  let topOffset = 0;
1230
1249
  if (positions.get(id)) {
1231
1250
  topOffset = positions.get(id);
1232
1251
  }
1233
- if (id === ((_a3 = state.anchorElement) == null ? void 0 : _a3.id)) {
1252
+ if (id === ((_a2 = state.anchorElement) == null ? void 0 : _a2.id)) {
1234
1253
  topOffset = state.anchorElement.coordinate;
1235
1254
  }
1236
1255
  return topOffset;
1237
1256
  };
1238
- for (let i = loopStart; i < data.length; i++) {
1257
+ for (let i = Math.max(0, loopStart); i < data.length; i++) {
1239
1258
  const id = getId(i);
1240
1259
  const size = getItemSize(id, i, data[i]);
1241
1260
  maxSizeInRow = Math.max(maxSizeInRow, size);
1242
- if (top === void 0 || id === ((_a2 = state.anchorElement) == null ? void 0 : _a2.id)) {
1261
+ if (top === void 0 || id === ((_a = state.anchorElement) == null ? void 0 : _a.id)) {
1243
1262
  top = getInitialTop(i);
1244
1263
  }
1245
1264
  if (positions.get(id) !== top) {
@@ -1420,17 +1439,33 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1420
1439
  );
1421
1440
  }
1422
1441
  }, []);
1423
- const doUpdatePaddingTop = () => {
1442
+ const setPaddingTop = ({
1443
+ stylePaddingTop,
1444
+ alignItemsPaddingTop
1445
+ }) => {
1446
+ if (stylePaddingTop !== void 0) {
1447
+ set$(ctx, "stylePaddingTop", stylePaddingTop);
1448
+ }
1449
+ if (alignItemsPaddingTop !== void 0) {
1450
+ set$(ctx, "alignItemsPaddingTop", alignItemsPaddingTop);
1451
+ }
1452
+ set$(
1453
+ ctx,
1454
+ "paddingTop",
1455
+ (stylePaddingTop != null ? stylePaddingTop : peek$(ctx, "stylePaddingTop")) + (alignItemsPaddingTop != null ? alignItemsPaddingTop : peek$(ctx, "alignItemsPaddingTop"))
1456
+ );
1457
+ };
1458
+ const updateAlignItemsPaddingTop = () => {
1424
1459
  if (alignItemsAtEnd) {
1425
1460
  const { scrollLength } = refState.current;
1426
1461
  const contentSize = getContentSize(ctx);
1427
1462
  const paddingTop = Math.max(0, Math.floor(scrollLength - contentSize));
1428
- set$(ctx, "paddingTop", paddingTop);
1463
+ setPaddingTop({ alignItemsPaddingTop: paddingTop });
1429
1464
  }
1430
1465
  };
1431
1466
  const scrollTo = (offset, animated) => {
1432
- var _a2;
1433
- (_a2 = refScroller.current) == null ? void 0 : _a2.scrollTo({
1467
+ var _a;
1468
+ (_a = refScroller.current) == null ? void 0 : _a.scrollTo({
1434
1469
  x: horizontal ? offset : 0,
1435
1470
  y: horizontal ? 0 : offset,
1436
1471
  animated: !!animated
@@ -1439,13 +1474,13 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1439
1474
  const doMaintainScrollAtEnd = (animated) => {
1440
1475
  const state = refState.current;
1441
1476
  if ((state == null ? void 0 : state.isAtBottom) && maintainScrollAtEnd && peek$(ctx, "containersDidLayout")) {
1442
- const paddingTop = peek$(ctx, "paddingTop") || 0;
1477
+ const paddingTop = peek$(ctx, "alignItemsPaddingTop");
1443
1478
  if (paddingTop > 0) {
1444
1479
  state.scroll = 0;
1445
1480
  }
1446
1481
  requestAnimationFrame(() => {
1447
- var _a2;
1448
- (_a2 = refScroller.current) == null ? void 0 : _a2.scrollToEnd({
1482
+ var _a;
1483
+ (_a = refScroller.current) == null ? void 0 : _a.scrollToEnd({
1449
1484
  animated
1450
1485
  });
1451
1486
  });
@@ -1489,8 +1524,8 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1489
1524
  refState.current.isEndReached,
1490
1525
  refState.current.endReachedBlockedByTimer,
1491
1526
  (distance) => {
1492
- var _a2, _b2;
1493
- return (_b2 = (_a2 = callbacks.current).onEndReached) == null ? void 0 : _b2.call(_a2, { distanceFromEnd: distance });
1527
+ var _a, _b;
1528
+ return (_b = (_a = callbacks.current).onEndReached) == null ? void 0 : _b.call(_a, { distanceFromEnd: distance });
1494
1529
  },
1495
1530
  (block) => {
1496
1531
  refState.current.endReachedBlockedByTimer = block;
@@ -1513,8 +1548,8 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1513
1548
  refState.current.isStartReached,
1514
1549
  refState.current.startReachedBlockedByTimer,
1515
1550
  (distance) => {
1516
- var _a2, _b2;
1517
- return (_b2 = (_a2 = callbacks.current).onStartReached) == null ? void 0 : _b2.call(_a2, { distanceFromStart: distance });
1551
+ var _a, _b;
1552
+ return (_b = (_a = callbacks.current).onStartReached) == null ? void 0 : _b.call(_a, { distanceFromStart: distance });
1518
1553
  },
1519
1554
  (block) => {
1520
1555
  refState.current.startReachedBlockedByTimer = block;
@@ -1551,14 +1586,14 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1551
1586
  }
1552
1587
  };
1553
1588
  const calcTotalSizesAndPositions = ({ forgetPositions = false }) => {
1554
- var _a2, _b2;
1589
+ var _a, _b;
1555
1590
  let totalSize = 0;
1556
1591
  let totalSizeBelowIndex = 0;
1557
1592
  const indexByKey = /* @__PURE__ */ new Map();
1558
1593
  const newPositions = /* @__PURE__ */ new Map();
1559
1594
  let column = 1;
1560
1595
  let maxSizeInRow = 0;
1561
- const numColumns = (_a2 = peek$(ctx, "numColumns")) != null ? _a2 : numColumnsProp;
1596
+ const numColumns = (_a = peek$(ctx, "numColumns")) != null ? _a : numColumnsProp;
1562
1597
  if (!refState.current) {
1563
1598
  return;
1564
1599
  }
@@ -1587,7 +1622,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1587
1622
  id: getId(0)
1588
1623
  };
1589
1624
  refState.current.anchorElement = newAnchorElement;
1590
- (_b2 = refState.current.belowAnchorElementPositions) == null ? void 0 : _b2.clear();
1625
+ (_b = refState.current.belowAnchorElementPositions) == null ? void 0 : _b.clear();
1591
1626
  scrollTo(0, false);
1592
1627
  setTimeout(() => {
1593
1628
  calculateItemsInView();
@@ -1646,20 +1681,13 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1646
1681
  const initalizeStateVars = () => {
1647
1682
  set$(ctx, "lastItemKeys", memoizedLastItemKeys);
1648
1683
  set$(ctx, "numColumns", numColumnsProp);
1649
- if (maintainVisibleContentPosition) {
1650
- const prevPaddingTop = peek$(ctx, "stylePaddingTop");
1651
- set$(ctx, "stylePaddingTop", stylePaddingTop);
1652
- if (prevPaddingTop !== void 0) {
1653
- const paddingDiff = stylePaddingTop - prevPaddingTop;
1654
- if (paddingDiff) {
1655
- set$(ctx, "paddingTop", peek$(ctx, "paddingTop") + paddingDiff);
1656
- if (reactNative.Platform.OS === "ios") {
1657
- queueMicrotask(() => {
1658
- scrollTo(refState.current.scroll + paddingDiff, false);
1659
- });
1660
- }
1661
- }
1662
- }
1684
+ const prevPaddingTop = peek$(ctx, "stylePaddingTop");
1685
+ setPaddingTop({ stylePaddingTop: stylePaddingTopState });
1686
+ const paddingDiff = stylePaddingTopState - prevPaddingTop;
1687
+ if (paddingDiff && prevPaddingTop !== void 0 && reactNative.Platform.OS === "ios") {
1688
+ queueMicrotask(() => {
1689
+ scrollTo(refState.current.scroll + paddingDiff, false);
1690
+ });
1663
1691
  }
1664
1692
  };
1665
1693
  if (isFirst) {
@@ -1686,9 +1714,9 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1686
1714
  set$(ctx, "extraData", extraData);
1687
1715
  }, [extraData]);
1688
1716
  refState.current.renderItem = renderItem;
1689
- React6.useEffect(initalizeStateVars, [memoizedLastItemKeys.join(","), numColumnsProp, stylePaddingTop]);
1717
+ React6.useEffect(initalizeStateVars, [memoizedLastItemKeys.join(","), numColumnsProp, stylePaddingTopState]);
1690
1718
  const getRenderedItem = React6.useCallback((key) => {
1691
- var _a2, _b2;
1719
+ var _a, _b;
1692
1720
  const state = refState.current;
1693
1721
  if (!state) {
1694
1722
  return null;
@@ -1718,7 +1746,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1718
1746
  `[legend-list] useRecyclingState has been moved from a render prop to a regular import: import { useRecyclingState } from "@legendapp/list";`
1719
1747
  );
1720
1748
  } : void 0;
1721
- const renderedItem = (_b2 = (_a2 = refState.current).renderItem) == null ? void 0 : _b2.call(_a2, {
1749
+ const renderedItem = (_b = (_a = refState.current).renderItem) == null ? void 0 : _b.call(_a, {
1722
1750
  item: data[index],
1723
1751
  index,
1724
1752
  extraData: peek$(ctx, "extraData"),
@@ -1731,11 +1759,11 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1731
1759
  return { index, item: data[index], renderedItem };
1732
1760
  }, []);
1733
1761
  const doInitialAllocateContainers = () => {
1734
- var _a2;
1762
+ var _a;
1735
1763
  const state = refState.current;
1736
1764
  const { scrollLength, data } = state;
1737
1765
  if (scrollLength > 0 && data.length > 0 && !peek$(ctx, "numContainers")) {
1738
- const averageItemSize = (_a2 = estimatedItemSize != null ? estimatedItemSize : getEstimatedItemSize == null ? void 0 : getEstimatedItemSize(0, data[0])) != null ? _a2 : DEFAULT_ITEM_SIZE;
1766
+ const averageItemSize = (_a = estimatedItemSize != null ? estimatedItemSize : getEstimatedItemSize == null ? void 0 : getEstimatedItemSize(0, data[0])) != null ? _a : DEFAULT_ITEM_SIZE;
1739
1767
  const numContainers = Math.ceil((scrollLength + scrollBuffer * 2) / averageItemSize) * numColumnsProp;
1740
1768
  for (let i = 0; i < numContainers; i++) {
1741
1769
  set$(ctx, `containerPosition${i}`, ANCHORED_POSITION_OUT_OF_VIEW);
@@ -1855,7 +1883,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1855
1883
  state.scrollForNextCalculateItemsInView = void 0;
1856
1884
  doInitialAllocateContainers();
1857
1885
  doMaintainScrollAtEnd(false);
1858
- doUpdatePaddingTop();
1886
+ updateAlignItemsPaddingTop();
1859
1887
  checkAtBottom();
1860
1888
  checkAtTop();
1861
1889
  if (didChange) {
@@ -1876,8 +1904,8 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1876
1904
  }, []);
1877
1905
  const handleScroll = React6.useCallback(
1878
1906
  (event, fromSelf) => {
1879
- var _a2, _b2, _c2, _d2;
1880
- 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) {
1907
+ var _a, _b, _c, _d;
1908
+ 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) {
1881
1909
  return;
1882
1910
  }
1883
1911
  const state = refState.current;
@@ -1917,7 +1945,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1917
1945
  checkAtBottom();
1918
1946
  checkAtTop();
1919
1947
  if (!fromSelf) {
1920
- (_d2 = state.onScroll) == null ? void 0 : _d2.call(state, event);
1948
+ (_d = state.onScroll) == null ? void 0 : _d.call(state, event);
1921
1949
  }
1922
1950
  },
1923
1951
  []
@@ -1931,7 +1959,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1931
1959
  animated = true,
1932
1960
  viewPosition = 0
1933
1961
  }) => {
1934
- var _a2;
1962
+ var _a;
1935
1963
  const state = refState.current;
1936
1964
  const firstIndexOffset = calculateOffsetForIndex(index);
1937
1965
  let firstIndexScrollPostion = firstIndexOffset - viewOffset;
@@ -1941,7 +1969,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1941
1969
  if (needsReanchoring) {
1942
1970
  const id = getId(index);
1943
1971
  state.anchorElement = { id, coordinate: firstIndexOffset };
1944
- (_a2 = state.belowAnchorElementPositions) == null ? void 0 : _a2.clear();
1972
+ (_a = state.belowAnchorElementPositions) == null ? void 0 : _a.clear();
1945
1973
  state.positions.clear();
1946
1974
  calcTotalSizesAndPositions({ forgetPositions: true });
1947
1975
  state.startBufferedId = id;
@@ -2014,13 +2042,13 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
2014
2042
  );
2015
2043
  if (reactNative.Platform.OS === "web") {
2016
2044
  React6.useEffect(() => {
2017
- var _a2;
2045
+ var _a;
2018
2046
  if (initialContentOffset) {
2019
- (_a2 = refState.current) == null ? void 0 : _a2.scrollAdjustHandler.setDisableAdjust(true);
2047
+ (_a = refState.current) == null ? void 0 : _a.scrollAdjustHandler.setDisableAdjust(true);
2020
2048
  scrollTo(initialContentOffset, false);
2021
2049
  setTimeout(() => {
2022
- var _a3;
2023
- (_a3 = refState.current) == null ? void 0 : _a3.scrollAdjustHandler.setDisableAdjust(false);
2050
+ var _a2;
2051
+ (_a2 = refState.current) == null ? void 0 : _a2.scrollAdjustHandler.setDisableAdjust(false);
2024
2052
  }, 0);
2025
2053
  }
2026
2054
  }, []);
@@ -2036,8 +2064,8 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
2036
2064
  updateItemSize,
2037
2065
  handleScroll,
2038
2066
  onMomentumScrollEnd: (event) => {
2039
- var _a2;
2040
- const scrollingToOffset = (_a2 = refState.current) == null ? void 0 : _a2.scrollingToOffset;
2067
+ var _a;
2068
+ const scrollingToOffset = (_a = refState.current) == null ? void 0 : _a.scrollingToOffset;
2041
2069
  if (scrollingToOffset !== void 0) {
2042
2070
  requestAnimationFrame(() => {
2043
2071
  scrollTo(scrollingToOffset, false);
package/index.mjs CHANGED
@@ -7,7 +7,12 @@ var ContextState = React6.createContext(null);
7
7
  function StateProvider({ children }) {
8
8
  const [value] = React6.useState(() => ({
9
9
  listeners: /* @__PURE__ */ new Map(),
10
- values: /* @__PURE__ */ new Map(),
10
+ values: /* @__PURE__ */ new Map([
11
+ ["paddingTop", 0],
12
+ ["alignItemsPaddingTop", 0],
13
+ ["stylePaddingTop", 0],
14
+ ["headerSize", 0]
15
+ ]),
11
16
  mapViewabilityCallbacks: /* @__PURE__ */ new Map(),
12
17
  mapViewabilityValues: /* @__PURE__ */ new Map(),
13
18
  mapViewabilityAmountCallbacks: /* @__PURE__ */ new Map(),
@@ -128,10 +133,10 @@ function useInit(cb) {
128
133
 
129
134
  // src/ContextContainer.ts
130
135
  var ContextContainer = createContext(null);
131
- function useViewability(configId, callback) {
136
+ function useViewability(callback, configId) {
132
137
  const ctx = useStateContext();
133
138
  const { containerId } = useContext(ContextContainer);
134
- const key = containerId + configId;
139
+ const key = containerId + (configId != null ? configId : "");
135
140
  useInit(() => {
136
141
  const value = ctx.mapViewabilityValues.get(key);
137
142
  if (value) {
@@ -241,13 +246,20 @@ var Container = ({
241
246
  const refLastSize = useRef();
242
247
  const otherAxisPos = numColumns > 1 ? `${(column - 1) / numColumns * 100}%` : 0;
243
248
  const otherAxisSize = numColumns > 1 ? `${1 / numColumns * 100}%` : void 0;
244
- let verticalPaddingStyles;
249
+ let paddingStyles;
245
250
  if (columnWrapperStyle) {
246
251
  const { columnGap, rowGap, gap } = columnWrapperStyle;
247
- verticalPaddingStyles = {
248
- paddingBottom: !lastItemKeys.includes(itemKey) ? rowGap || gap || void 0 : void 0,
249
- paddingHorizontal: (columnGap || gap || 0) / 2
250
- };
252
+ if (horizontal) {
253
+ paddingStyles = {
254
+ paddingRight: !lastItemKeys.includes(itemKey) ? columnGap || gap || void 0 : void 0,
255
+ paddingVertical: (rowGap || gap || 0) / 2
256
+ };
257
+ } else {
258
+ paddingStyles = {
259
+ paddingBottom: !lastItemKeys.includes(itemKey) ? rowGap || gap || void 0 : void 0,
260
+ paddingHorizontal: (columnGap || gap || 0) / 2
261
+ };
262
+ }
251
263
  }
252
264
  const style = horizontal ? {
253
265
  flexDirection: ItemSeparatorComponent ? "row" : void 0,
@@ -255,14 +267,15 @@ var Container = ({
255
267
  top: otherAxisPos,
256
268
  bottom: numColumns > 1 ? null : 0,
257
269
  height: otherAxisSize,
258
- left: position.relativeCoordinate
270
+ left: position.relativeCoordinate,
271
+ ...paddingStyles || {}
259
272
  } : {
260
273
  position: "absolute",
261
274
  left: otherAxisPos,
262
275
  right: numColumns > 1 ? null : 0,
263
276
  width: otherAxisSize,
264
277
  top: position.relativeCoordinate,
265
- ...verticalPaddingStyles || {}
278
+ ...paddingStyles || {}
266
279
  };
267
280
  const renderedItemInfo = useMemo(
268
281
  () => itemKey !== void 0 ? getRenderedItem(itemKey) : null,
@@ -360,7 +373,7 @@ var Containers = typedMemo(function Containers2({
360
373
  }) {
361
374
  const ctx = useStateContext();
362
375
  const columnWrapperStyle = ctx.columnWrapperStyle;
363
- const numColumns = use$("numColumns");
376
+ use$("numColumns");
364
377
  const numContainers = use$("numContainersPooled");
365
378
  const animSize = useValue$(
366
379
  "totalSizeWithScrollAdjust",
@@ -387,11 +400,18 @@ var Containers = typedMemo(function Containers2({
387
400
  );
388
401
  }
389
402
  const style = horizontal ? { width: animSize, opacity: animOpacity } : { height: animSize, opacity: animOpacity };
390
- if (columnWrapperStyle && !horizontal && numColumns > 1) {
403
+ if (columnWrapperStyle) {
391
404
  const { columnGap, rowGap, gap } = columnWrapperStyle;
392
- const mx = (columnGap || gap || 0) / 2;
393
- if (mx) {
394
- style.marginHorizontal = -mx;
405
+ if (horizontal) {
406
+ const my = (rowGap || gap || 0) / 2;
407
+ if (my) {
408
+ style.marginVertical = -my;
409
+ }
410
+ } else {
411
+ const mx = (columnGap || gap || 0) / 2;
412
+ if (mx) {
413
+ style.marginHorizontal = -mx;
414
+ }
395
415
  }
396
416
  }
397
417
  return /* @__PURE__ */ React6.createElement(Animated.View, { style }, containers);
@@ -816,7 +836,6 @@ var LegendList = typedForwardRef(function LegendList2(props, forwardedRef) {
816
836
  return /* @__PURE__ */ React6.createElement(StateProvider, null, /* @__PURE__ */ React6.createElement(LegendListInner, { ...props, ref: forwardedRef }));
817
837
  });
818
838
  var LegendListInner = typedForwardRef(function LegendListInner2(props, forwardedRef) {
819
- var _a, _b, _c, _d;
820
839
  const {
821
840
  data: dataProp = [],
822
841
  initialScrollIndex,
@@ -863,9 +882,9 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
863
882
  });
864
883
  callbacks.current.onStartReached = rest.onStartReached;
865
884
  callbacks.current.onEndReached = rest.onEndReached;
866
- const contentContainerStyle = StyleSheet.flatten(contentContainerStyleProp);
867
- const style = StyleSheet.flatten(styleProp);
868
- const stylePaddingTop = (_d = (_c = (_a = StyleSheet.flatten(style)) == null ? void 0 : _a.paddingTop) != null ? _c : (_b = StyleSheet.flatten(contentContainerStyle)) == null ? void 0 : _b.paddingTop) != null ? _d : 0;
885
+ const contentContainerStyle = { ...StyleSheet.flatten(contentContainerStyleProp) };
886
+ const style = { ...StyleSheet.flatten(styleProp) };
887
+ const stylePaddingTopState = ((style == null ? void 0 : style.paddingTop) || 0) + ((contentContainerStyle == null ? void 0 : contentContainerStyle.paddingTop) || 0);
869
888
  if (style == null ? void 0 : style.paddingTop) {
870
889
  style.paddingTop = void 0;
871
890
  }
@@ -880,8 +899,8 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
880
899
  const keyExtractor = keyExtractorProp != null ? keyExtractorProp : (item, index) => index.toString();
881
900
  const refState = useRef();
882
901
  const getId = (index) => {
883
- var _a2;
884
- const data = (_a2 = refState.current) == null ? void 0 : _a2.data;
902
+ var _a;
903
+ const data = (_a = refState.current) == null ? void 0 : _a.data;
885
904
  if (!data) {
886
905
  return "";
887
906
  }
@@ -889,17 +908,17 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
889
908
  return `${ret}`;
890
909
  };
891
910
  const getItemSize = (key, index, data) => {
892
- var _a2;
911
+ var _a;
893
912
  const sizeKnown = refState.current.sizes.get(key);
894
913
  if (sizeKnown !== void 0) {
895
914
  return sizeKnown;
896
915
  }
897
- const size = (_a2 = getEstimatedItemSize ? getEstimatedItemSize(index, data) : estimatedItemSize) != null ? _a2 : DEFAULT_ITEM_SIZE;
916
+ const size = (_a = getEstimatedItemSize ? getEstimatedItemSize(index, data) : estimatedItemSize) != null ? _a : DEFAULT_ITEM_SIZE;
898
917
  refState.current.sizes.set(key, size);
899
918
  return size;
900
919
  };
901
920
  const calculateOffsetForIndex = (index = initialScrollIndex) => {
902
- var _a2;
921
+ var _a;
903
922
  const data = dataProp;
904
923
  if (index !== void 0) {
905
924
  let offset = 0;
@@ -917,7 +936,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
917
936
  } else if (estimatedItemSize) {
918
937
  offset = index * estimatedItemSize;
919
938
  }
920
- return offset / numColumnsProp - (((_a2 = refState.current) == null ? void 0 : _a2.scrollAdjustHandler.getAppliedAdjust()) || 0);
939
+ return offset / numColumnsProp - (((_a = refState.current) == null ? void 0 : _a.scrollAdjustHandler.getAppliedAdjust()) || 0);
921
940
  }
922
941
  return 0;
923
942
  };
@@ -1000,18 +1019,18 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1000
1019
  return void 0;
1001
1020
  };
1002
1021
  const setDidLayout = () => {
1003
- var _a2;
1022
+ var _a;
1004
1023
  refState.current.queuedInitialLayout = true;
1005
1024
  checkAtBottom();
1006
1025
  if (initialScrollIndex) {
1007
1026
  const updatedOffset = calculateOffsetForIndex(initialScrollIndex);
1008
- (_a2 = refState.current) == null ? void 0 : _a2.scrollAdjustHandler.setDisableAdjust(true);
1027
+ (_a = refState.current) == null ? void 0 : _a.scrollAdjustHandler.setDisableAdjust(true);
1009
1028
  queueMicrotask(() => {
1010
1029
  scrollTo(updatedOffset, false);
1011
1030
  requestAnimationFrame(() => {
1012
- var _a3;
1031
+ var _a2;
1013
1032
  set$(ctx, "containersDidLayout", true);
1014
- (_a3 = refState.current) == null ? void 0 : _a3.scrollAdjustHandler.setDisableAdjust(false);
1033
+ (_a2 = refState.current) == null ? void 0 : _a2.scrollAdjustHandler.setDisableAdjust(false);
1015
1034
  });
1016
1035
  });
1017
1036
  } else {
@@ -1056,7 +1075,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1056
1075
  set$(ctx, "totalSize", state.totalSize);
1057
1076
  set$(ctx, "totalSizeWithScrollAdjust", resultSize);
1058
1077
  if (alignItemsAtEnd) {
1059
- doUpdatePaddingTop();
1078
+ updateAlignItemsPaddingTop();
1060
1079
  }
1061
1080
  }, []);
1062
1081
  const getRowHeight = (n) => {
@@ -1084,13 +1103,13 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1084
1103
  if (!state.anchorElement) {
1085
1104
  return /* @__PURE__ */ new Map();
1086
1105
  }
1087
- let top = state.anchorElement.coordinate;
1088
1106
  const anchorIndex = state.indexByKey.get(state.anchorElement.id);
1089
1107
  if (anchorIndex === 0) {
1090
1108
  return /* @__PURE__ */ new Map();
1091
1109
  }
1092
1110
  const map = state.belowAnchorElementPositions || /* @__PURE__ */ new Map();
1093
1111
  const numColumns = peek$(ctx, "numColumns");
1112
+ let top = state.anchorElement.coordinate;
1094
1113
  for (let i = anchorIndex - 1; i >= 0; i--) {
1095
1114
  const id = getId(i);
1096
1115
  const rowNumber = Math.floor(i / numColumns);
@@ -1102,20 +1121,20 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1102
1121
  return map;
1103
1122
  };
1104
1123
  const getElementPositionBelowAchor = (id) => {
1105
- var _a2;
1124
+ var _a;
1106
1125
  const state = refState.current;
1107
1126
  if (!refState.current.belowAnchorElementPositions) {
1108
1127
  state.belowAnchorElementPositions = buildElementPositionsBelowAnchor();
1109
1128
  }
1110
1129
  const res = state.belowAnchorElementPositions.get(id);
1111
1130
  if (res === void 0) {
1112
- console.warn(`Undefined position below achor ${id} ${(_a2 = state.anchorElement) == null ? void 0 : _a2.id}`);
1131
+ console.warn(`Undefined position below anchor ${id} ${(_a = state.anchorElement) == null ? void 0 : _a.id}`);
1113
1132
  return 0;
1114
1133
  }
1115
1134
  return res;
1116
1135
  };
1117
1136
  const calculateItemsInView = useCallback(() => {
1118
- var _a2;
1137
+ var _a;
1119
1138
  const state = refState.current;
1120
1139
  const {
1121
1140
  data,
@@ -1130,7 +1149,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1130
1149
  return;
1131
1150
  }
1132
1151
  const totalSize = peek$(ctx, "totalSizeWithScrollAdjust");
1133
- const topPad = (peek$(ctx, "stylePaddingTop") || 0) + (peek$(ctx, "headerSize") || 0);
1152
+ const topPad = peek$(ctx, "stylePaddingTop") + peek$(ctx, "headerSize");
1134
1153
  const numColumns = peek$(ctx, "numColumns");
1135
1154
  const previousScrollAdjust = scrollAdjustHandler.getAppliedAdjust();
1136
1155
  const scrollExtra = Math.max(-16, Math.min(16, speed)) * 16;
@@ -1203,22 +1222,22 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1203
1222
  let column = 1;
1204
1223
  let maxSizeInRow = 0;
1205
1224
  const getInitialTop = (i) => {
1206
- var _a3;
1225
+ var _a2;
1207
1226
  const id = getId(i);
1208
1227
  let topOffset = 0;
1209
1228
  if (positions.get(id)) {
1210
1229
  topOffset = positions.get(id);
1211
1230
  }
1212
- if (id === ((_a3 = state.anchorElement) == null ? void 0 : _a3.id)) {
1231
+ if (id === ((_a2 = state.anchorElement) == null ? void 0 : _a2.id)) {
1213
1232
  topOffset = state.anchorElement.coordinate;
1214
1233
  }
1215
1234
  return topOffset;
1216
1235
  };
1217
- for (let i = loopStart; i < data.length; i++) {
1236
+ for (let i = Math.max(0, loopStart); i < data.length; i++) {
1218
1237
  const id = getId(i);
1219
1238
  const size = getItemSize(id, i, data[i]);
1220
1239
  maxSizeInRow = Math.max(maxSizeInRow, size);
1221
- if (top === void 0 || id === ((_a2 = state.anchorElement) == null ? void 0 : _a2.id)) {
1240
+ if (top === void 0 || id === ((_a = state.anchorElement) == null ? void 0 : _a.id)) {
1222
1241
  top = getInitialTop(i);
1223
1242
  }
1224
1243
  if (positions.get(id) !== top) {
@@ -1399,17 +1418,33 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1399
1418
  );
1400
1419
  }
1401
1420
  }, []);
1402
- const doUpdatePaddingTop = () => {
1421
+ const setPaddingTop = ({
1422
+ stylePaddingTop,
1423
+ alignItemsPaddingTop
1424
+ }) => {
1425
+ if (stylePaddingTop !== void 0) {
1426
+ set$(ctx, "stylePaddingTop", stylePaddingTop);
1427
+ }
1428
+ if (alignItemsPaddingTop !== void 0) {
1429
+ set$(ctx, "alignItemsPaddingTop", alignItemsPaddingTop);
1430
+ }
1431
+ set$(
1432
+ ctx,
1433
+ "paddingTop",
1434
+ (stylePaddingTop != null ? stylePaddingTop : peek$(ctx, "stylePaddingTop")) + (alignItemsPaddingTop != null ? alignItemsPaddingTop : peek$(ctx, "alignItemsPaddingTop"))
1435
+ );
1436
+ };
1437
+ const updateAlignItemsPaddingTop = () => {
1403
1438
  if (alignItemsAtEnd) {
1404
1439
  const { scrollLength } = refState.current;
1405
1440
  const contentSize = getContentSize(ctx);
1406
1441
  const paddingTop = Math.max(0, Math.floor(scrollLength - contentSize));
1407
- set$(ctx, "paddingTop", paddingTop);
1442
+ setPaddingTop({ alignItemsPaddingTop: paddingTop });
1408
1443
  }
1409
1444
  };
1410
1445
  const scrollTo = (offset, animated) => {
1411
- var _a2;
1412
- (_a2 = refScroller.current) == null ? void 0 : _a2.scrollTo({
1446
+ var _a;
1447
+ (_a = refScroller.current) == null ? void 0 : _a.scrollTo({
1413
1448
  x: horizontal ? offset : 0,
1414
1449
  y: horizontal ? 0 : offset,
1415
1450
  animated: !!animated
@@ -1418,13 +1453,13 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1418
1453
  const doMaintainScrollAtEnd = (animated) => {
1419
1454
  const state = refState.current;
1420
1455
  if ((state == null ? void 0 : state.isAtBottom) && maintainScrollAtEnd && peek$(ctx, "containersDidLayout")) {
1421
- const paddingTop = peek$(ctx, "paddingTop") || 0;
1456
+ const paddingTop = peek$(ctx, "alignItemsPaddingTop");
1422
1457
  if (paddingTop > 0) {
1423
1458
  state.scroll = 0;
1424
1459
  }
1425
1460
  requestAnimationFrame(() => {
1426
- var _a2;
1427
- (_a2 = refScroller.current) == null ? void 0 : _a2.scrollToEnd({
1461
+ var _a;
1462
+ (_a = refScroller.current) == null ? void 0 : _a.scrollToEnd({
1428
1463
  animated
1429
1464
  });
1430
1465
  });
@@ -1468,8 +1503,8 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1468
1503
  refState.current.isEndReached,
1469
1504
  refState.current.endReachedBlockedByTimer,
1470
1505
  (distance) => {
1471
- var _a2, _b2;
1472
- return (_b2 = (_a2 = callbacks.current).onEndReached) == null ? void 0 : _b2.call(_a2, { distanceFromEnd: distance });
1506
+ var _a, _b;
1507
+ return (_b = (_a = callbacks.current).onEndReached) == null ? void 0 : _b.call(_a, { distanceFromEnd: distance });
1473
1508
  },
1474
1509
  (block) => {
1475
1510
  refState.current.endReachedBlockedByTimer = block;
@@ -1492,8 +1527,8 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1492
1527
  refState.current.isStartReached,
1493
1528
  refState.current.startReachedBlockedByTimer,
1494
1529
  (distance) => {
1495
- var _a2, _b2;
1496
- return (_b2 = (_a2 = callbacks.current).onStartReached) == null ? void 0 : _b2.call(_a2, { distanceFromStart: distance });
1530
+ var _a, _b;
1531
+ return (_b = (_a = callbacks.current).onStartReached) == null ? void 0 : _b.call(_a, { distanceFromStart: distance });
1497
1532
  },
1498
1533
  (block) => {
1499
1534
  refState.current.startReachedBlockedByTimer = block;
@@ -1530,14 +1565,14 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1530
1565
  }
1531
1566
  };
1532
1567
  const calcTotalSizesAndPositions = ({ forgetPositions = false }) => {
1533
- var _a2, _b2;
1568
+ var _a, _b;
1534
1569
  let totalSize = 0;
1535
1570
  let totalSizeBelowIndex = 0;
1536
1571
  const indexByKey = /* @__PURE__ */ new Map();
1537
1572
  const newPositions = /* @__PURE__ */ new Map();
1538
1573
  let column = 1;
1539
1574
  let maxSizeInRow = 0;
1540
- const numColumns = (_a2 = peek$(ctx, "numColumns")) != null ? _a2 : numColumnsProp;
1575
+ const numColumns = (_a = peek$(ctx, "numColumns")) != null ? _a : numColumnsProp;
1541
1576
  if (!refState.current) {
1542
1577
  return;
1543
1578
  }
@@ -1566,7 +1601,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1566
1601
  id: getId(0)
1567
1602
  };
1568
1603
  refState.current.anchorElement = newAnchorElement;
1569
- (_b2 = refState.current.belowAnchorElementPositions) == null ? void 0 : _b2.clear();
1604
+ (_b = refState.current.belowAnchorElementPositions) == null ? void 0 : _b.clear();
1570
1605
  scrollTo(0, false);
1571
1606
  setTimeout(() => {
1572
1607
  calculateItemsInView();
@@ -1625,20 +1660,13 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1625
1660
  const initalizeStateVars = () => {
1626
1661
  set$(ctx, "lastItemKeys", memoizedLastItemKeys);
1627
1662
  set$(ctx, "numColumns", numColumnsProp);
1628
- if (maintainVisibleContentPosition) {
1629
- const prevPaddingTop = peek$(ctx, "stylePaddingTop");
1630
- set$(ctx, "stylePaddingTop", stylePaddingTop);
1631
- if (prevPaddingTop !== void 0) {
1632
- const paddingDiff = stylePaddingTop - prevPaddingTop;
1633
- if (paddingDiff) {
1634
- set$(ctx, "paddingTop", peek$(ctx, "paddingTop") + paddingDiff);
1635
- if (Platform.OS === "ios") {
1636
- queueMicrotask(() => {
1637
- scrollTo(refState.current.scroll + paddingDiff, false);
1638
- });
1639
- }
1640
- }
1641
- }
1663
+ const prevPaddingTop = peek$(ctx, "stylePaddingTop");
1664
+ setPaddingTop({ stylePaddingTop: stylePaddingTopState });
1665
+ const paddingDiff = stylePaddingTopState - prevPaddingTop;
1666
+ if (paddingDiff && prevPaddingTop !== void 0 && Platform.OS === "ios") {
1667
+ queueMicrotask(() => {
1668
+ scrollTo(refState.current.scroll + paddingDiff, false);
1669
+ });
1642
1670
  }
1643
1671
  };
1644
1672
  if (isFirst) {
@@ -1665,9 +1693,9 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1665
1693
  set$(ctx, "extraData", extraData);
1666
1694
  }, [extraData]);
1667
1695
  refState.current.renderItem = renderItem;
1668
- useEffect(initalizeStateVars, [memoizedLastItemKeys.join(","), numColumnsProp, stylePaddingTop]);
1696
+ useEffect(initalizeStateVars, [memoizedLastItemKeys.join(","), numColumnsProp, stylePaddingTopState]);
1669
1697
  const getRenderedItem = useCallback((key) => {
1670
- var _a2, _b2;
1698
+ var _a, _b;
1671
1699
  const state = refState.current;
1672
1700
  if (!state) {
1673
1701
  return null;
@@ -1697,7 +1725,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1697
1725
  `[legend-list] useRecyclingState has been moved from a render prop to a regular import: import { useRecyclingState } from "@legendapp/list";`
1698
1726
  );
1699
1727
  } : void 0;
1700
- const renderedItem = (_b2 = (_a2 = refState.current).renderItem) == null ? void 0 : _b2.call(_a2, {
1728
+ const renderedItem = (_b = (_a = refState.current).renderItem) == null ? void 0 : _b.call(_a, {
1701
1729
  item: data[index],
1702
1730
  index,
1703
1731
  extraData: peek$(ctx, "extraData"),
@@ -1710,11 +1738,11 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1710
1738
  return { index, item: data[index], renderedItem };
1711
1739
  }, []);
1712
1740
  const doInitialAllocateContainers = () => {
1713
- var _a2;
1741
+ var _a;
1714
1742
  const state = refState.current;
1715
1743
  const { scrollLength, data } = state;
1716
1744
  if (scrollLength > 0 && data.length > 0 && !peek$(ctx, "numContainers")) {
1717
- const averageItemSize = (_a2 = estimatedItemSize != null ? estimatedItemSize : getEstimatedItemSize == null ? void 0 : getEstimatedItemSize(0, data[0])) != null ? _a2 : DEFAULT_ITEM_SIZE;
1745
+ const averageItemSize = (_a = estimatedItemSize != null ? estimatedItemSize : getEstimatedItemSize == null ? void 0 : getEstimatedItemSize(0, data[0])) != null ? _a : DEFAULT_ITEM_SIZE;
1718
1746
  const numContainers = Math.ceil((scrollLength + scrollBuffer * 2) / averageItemSize) * numColumnsProp;
1719
1747
  for (let i = 0; i < numContainers; i++) {
1720
1748
  set$(ctx, `containerPosition${i}`, ANCHORED_POSITION_OUT_OF_VIEW);
@@ -1834,7 +1862,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1834
1862
  state.scrollForNextCalculateItemsInView = void 0;
1835
1863
  doInitialAllocateContainers();
1836
1864
  doMaintainScrollAtEnd(false);
1837
- doUpdatePaddingTop();
1865
+ updateAlignItemsPaddingTop();
1838
1866
  checkAtBottom();
1839
1867
  checkAtTop();
1840
1868
  if (didChange) {
@@ -1855,8 +1883,8 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1855
1883
  }, []);
1856
1884
  const handleScroll = useCallback(
1857
1885
  (event, fromSelf) => {
1858
- var _a2, _b2, _c2, _d2;
1859
- 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) {
1886
+ var _a, _b, _c, _d;
1887
+ 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) {
1860
1888
  return;
1861
1889
  }
1862
1890
  const state = refState.current;
@@ -1896,7 +1924,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1896
1924
  checkAtBottom();
1897
1925
  checkAtTop();
1898
1926
  if (!fromSelf) {
1899
- (_d2 = state.onScroll) == null ? void 0 : _d2.call(state, event);
1927
+ (_d = state.onScroll) == null ? void 0 : _d.call(state, event);
1900
1928
  }
1901
1929
  },
1902
1930
  []
@@ -1910,7 +1938,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1910
1938
  animated = true,
1911
1939
  viewPosition = 0
1912
1940
  }) => {
1913
- var _a2;
1941
+ var _a;
1914
1942
  const state = refState.current;
1915
1943
  const firstIndexOffset = calculateOffsetForIndex(index);
1916
1944
  let firstIndexScrollPostion = firstIndexOffset - viewOffset;
@@ -1920,7 +1948,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1920
1948
  if (needsReanchoring) {
1921
1949
  const id = getId(index);
1922
1950
  state.anchorElement = { id, coordinate: firstIndexOffset };
1923
- (_a2 = state.belowAnchorElementPositions) == null ? void 0 : _a2.clear();
1951
+ (_a = state.belowAnchorElementPositions) == null ? void 0 : _a.clear();
1924
1952
  state.positions.clear();
1925
1953
  calcTotalSizesAndPositions({ forgetPositions: true });
1926
1954
  state.startBufferedId = id;
@@ -1993,13 +2021,13 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
1993
2021
  );
1994
2022
  if (Platform.OS === "web") {
1995
2023
  useEffect(() => {
1996
- var _a2;
2024
+ var _a;
1997
2025
  if (initialContentOffset) {
1998
- (_a2 = refState.current) == null ? void 0 : _a2.scrollAdjustHandler.setDisableAdjust(true);
2026
+ (_a = refState.current) == null ? void 0 : _a.scrollAdjustHandler.setDisableAdjust(true);
1999
2027
  scrollTo(initialContentOffset, false);
2000
2028
  setTimeout(() => {
2001
- var _a3;
2002
- (_a3 = refState.current) == null ? void 0 : _a3.scrollAdjustHandler.setDisableAdjust(false);
2029
+ var _a2;
2030
+ (_a2 = refState.current) == null ? void 0 : _a2.scrollAdjustHandler.setDisableAdjust(false);
2003
2031
  }, 0);
2004
2032
  }
2005
2033
  }, []);
@@ -2015,8 +2043,8 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
2015
2043
  updateItemSize,
2016
2044
  handleScroll,
2017
2045
  onMomentumScrollEnd: (event) => {
2018
- var _a2;
2019
- const scrollingToOffset = (_a2 = refState.current) == null ? void 0 : _a2.scrollingToOffset;
2046
+ var _a;
2047
+ const scrollingToOffset = (_a = refState.current) == null ? void 0 : _a.scrollingToOffset;
2020
2048
  if (scrollingToOffset !== void 0) {
2021
2049
  requestAnimationFrame(() => {
2022
2050
  scrollTo(scrollingToOffset, false);
@@ -2,6 +2,7 @@
2
2
 
3
3
  var list = require('@legendapp/list');
4
4
  var React = require('react');
5
+ var reactNative = require('react-native');
5
6
  var reactNativeKeyboardController = require('react-native-keyboard-controller');
6
7
  var reactNativeReanimated = require('react-native-reanimated');
7
8
 
@@ -28,7 +29,7 @@ var React__namespace = /*#__PURE__*/_interopNamespace(React);
28
29
  // src/keyboard-controller.tsx
29
30
  var typedForwardRef = React.forwardRef;
30
31
  var LegendList = typedForwardRef(function LegendList2(props, forwardedRef) {
31
- const { LegendList: LegendListProp, ...rest } = props;
32
+ const { LegendList: LegendListProp, style: styleProp, ...rest } = props;
32
33
  const [padding, setPadding] = React.useState(0);
33
34
  const updatePadding = (height) => {
34
35
  setPadding(height);
@@ -40,7 +41,9 @@ var LegendList = typedForwardRef(function LegendList2(props, forwardedRef) {
40
41
  }
41
42
  });
42
43
  const LegendListComponent = LegendListProp != null ? LegendListProp : list.LegendList;
43
- return /* @__PURE__ */ React__namespace.createElement(LegendListComponent, { style: { paddingTop: padding }, ...rest, ref: forwardedRef });
44
+ const styleFlattened = reactNative.StyleSheet.flatten(styleProp) || {};
45
+ const style = { ...styleFlattened, paddingTop: padding + (styleFlattened.paddingTop || 0) };
46
+ return /* @__PURE__ */ React__namespace.createElement(LegendListComponent, { ...rest, style, ref: forwardedRef });
44
47
  });
45
48
 
46
49
  exports.LegendList = LegendList;
@@ -1,13 +1,14 @@
1
1
  import { LegendList as LegendList$1 } from '@legendapp/list';
2
2
  import * as React from 'react';
3
3
  import { useState, forwardRef } from 'react';
4
+ import { StyleSheet } from 'react-native';
4
5
  import { useKeyboardHandler } from 'react-native-keyboard-controller';
5
6
  import { runOnJS } from 'react-native-reanimated';
6
7
 
7
8
  // src/keyboard-controller.tsx
8
9
  var typedForwardRef = forwardRef;
9
10
  var LegendList = typedForwardRef(function LegendList2(props, forwardedRef) {
10
- const { LegendList: LegendListProp, ...rest } = props;
11
+ const { LegendList: LegendListProp, style: styleProp, ...rest } = props;
11
12
  const [padding, setPadding] = useState(0);
12
13
  const updatePadding = (height) => {
13
14
  setPadding(height);
@@ -19,7 +20,9 @@ var LegendList = typedForwardRef(function LegendList2(props, forwardedRef) {
19
20
  }
20
21
  });
21
22
  const LegendListComponent = LegendListProp != null ? LegendListProp : LegendList$1;
22
- return /* @__PURE__ */ React.createElement(LegendListComponent, { style: { paddingTop: padding }, ...rest, ref: forwardedRef });
23
+ const styleFlattened = StyleSheet.flatten(styleProp) || {};
24
+ const style = { ...styleFlattened, paddingTop: padding + (styleFlattened.paddingTop || 0) };
25
+ return /* @__PURE__ */ React.createElement(LegendListComponent, { ...rest, style, ref: forwardedRef });
23
26
  });
24
27
 
25
28
  export { LegendList };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legendapp/list",
3
- "version": "1.0.0-beta.42",
3
+ "version": "1.0.0-beta.44",
4
4
  "description": "Legend List aims to be a drop-in replacement for FlatList with much better performance and supporting dynamically sized items.",
5
5
  "sideEffects": false,
6
6
  "private": false,