@legendapp/list 1.0.0-beta.13 → 1.0.0-beta.15
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 +1 -0
- package/animated.d.ts +1 -0
- package/index.d.mts +12 -2
- package/index.d.ts +12 -2
- package/index.js +134 -39
- package/index.mjs +135 -40
- package/package.json +1 -1
package/animated.d.mts
CHANGED
|
@@ -16,6 +16,7 @@ declare const AnimatedLegendList: Animated.AnimatedComponent<(<T>(props: Omit<re
|
|
|
16
16
|
alignItemsAtEnd?: boolean;
|
|
17
17
|
maintainVisibleContentPosition?: boolean;
|
|
18
18
|
numColumns?: number;
|
|
19
|
+
columnWrapperStyle?: _legendapp_list.ColumnWrapperStyle;
|
|
19
20
|
refScrollView?: React.Ref<react_native.ScrollView>;
|
|
20
21
|
waitForInitialLayout?: boolean;
|
|
21
22
|
estimatedItemSize?: number;
|
package/animated.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ declare const AnimatedLegendList: Animated.AnimatedComponent<(<T>(props: Omit<re
|
|
|
16
16
|
alignItemsAtEnd?: boolean;
|
|
17
17
|
maintainVisibleContentPosition?: boolean;
|
|
18
18
|
numColumns?: number;
|
|
19
|
+
columnWrapperStyle?: _legendapp_list.ColumnWrapperStyle;
|
|
19
20
|
refScrollView?: React.Ref<react_native.ScrollView>;
|
|
20
21
|
waitForInitialLayout?: boolean;
|
|
21
22
|
estimatedItemSize?: number;
|
package/index.d.mts
CHANGED
|
@@ -7,12 +7,15 @@ import Animated from 'react-native-reanimated';
|
|
|
7
7
|
declare class ScrollAdjustHandler {
|
|
8
8
|
private ctx;
|
|
9
9
|
private appliedAdjust;
|
|
10
|
-
private pendingAdjust;
|
|
11
10
|
private busy;
|
|
12
11
|
private context;
|
|
12
|
+
private isPaused;
|
|
13
13
|
constructor(ctx: any);
|
|
14
|
+
private doAjdust;
|
|
14
15
|
requestAdjust(adjust: number, onAdjusted: (diff: number) => void): void;
|
|
15
16
|
getAppliedAdjust(): number;
|
|
17
|
+
pauseAdjust(): void;
|
|
18
|
+
unPauseAdjust(): boolean;
|
|
16
19
|
}
|
|
17
20
|
|
|
18
21
|
type LegendListPropsBase<ItemT, TScrollView extends ComponentProps<typeof ScrollView> | ComponentProps<typeof Animated.ScrollView>> = Omit<TScrollView, "contentOffset" | "contentInset" | "maintainVisibleContentPosition" | "stickyHeaderIndices"> & {
|
|
@@ -28,6 +31,7 @@ type LegendListPropsBase<ItemT, TScrollView extends ComponentProps<typeof Scroll
|
|
|
28
31
|
alignItemsAtEnd?: boolean;
|
|
29
32
|
maintainVisibleContentPosition?: boolean;
|
|
30
33
|
numColumns?: number;
|
|
34
|
+
columnWrapperStyle?: ColumnWrapperStyle;
|
|
31
35
|
refScrollView?: React.Ref<ScrollView>;
|
|
32
36
|
waitForInitialLayout?: boolean;
|
|
33
37
|
estimatedItemSize?: number;
|
|
@@ -63,6 +67,11 @@ type LegendListPropsBase<ItemT, TScrollView extends ComponentProps<typeof Scroll
|
|
|
63
67
|
renderScrollComponent?: (props: ScrollViewProps) => React.ReactElement<ScrollViewProps>;
|
|
64
68
|
extraData?: any;
|
|
65
69
|
};
|
|
70
|
+
interface ColumnWrapperStyle {
|
|
71
|
+
rowGap?: number;
|
|
72
|
+
gap?: number;
|
|
73
|
+
columnGap?: number;
|
|
74
|
+
}
|
|
66
75
|
type AnchoredPosition = {
|
|
67
76
|
type: "top" | "bottom";
|
|
68
77
|
relativeCoordinate: number;
|
|
@@ -248,6 +257,7 @@ declare const LegendList: <T>(props: Omit<react_native.ScrollViewProps, "content
|
|
|
248
257
|
alignItemsAtEnd?: boolean;
|
|
249
258
|
maintainVisibleContentPosition?: boolean;
|
|
250
259
|
numColumns?: number;
|
|
260
|
+
columnWrapperStyle?: ColumnWrapperStyle;
|
|
251
261
|
refScrollView?: React$1.Ref<ScrollView>;
|
|
252
262
|
waitForInitialLayout?: boolean;
|
|
253
263
|
estimatedItemSize?: number;
|
|
@@ -285,4 +295,4 @@ declare function useViewabilityAmount(callback: ViewabilityAmountCallback): void
|
|
|
285
295
|
declare function useRecyclingEffect(effect: (info: LegendListRecyclingState<unknown>) => void | (() => void)): void;
|
|
286
296
|
declare function useRecyclingState(valueOrFun: ((info: LegendListRecyclingState<unknown>) => any) | any): [any, React$1.Dispatch<any>];
|
|
287
297
|
|
|
288
|
-
export { type AnchoredPosition, type InternalState, LegendList, type LegendListProps, type LegendListPropsBase, type LegendListRecyclingState, type LegendListRef, type LegendListRenderItemProps, type OnViewableItemsChanged, type TypedForwardRef, type ViewAmountToken, type ViewToken, type ViewabilityAmountCallback, type ViewabilityCallback, type ViewabilityConfig, type ViewabilityConfigCallbackPair, type ViewabilityConfigCallbackPairs, type ViewableRange, typedForwardRef, useRecyclingEffect, useRecyclingState, useViewability, useViewabilityAmount };
|
|
298
|
+
export { type AnchoredPosition, type ColumnWrapperStyle, type InternalState, LegendList, type LegendListProps, type LegendListPropsBase, type LegendListRecyclingState, type LegendListRef, type LegendListRenderItemProps, type OnViewableItemsChanged, type TypedForwardRef, type ViewAmountToken, type ViewToken, type ViewabilityAmountCallback, type ViewabilityCallback, type ViewabilityConfig, type ViewabilityConfigCallbackPair, type ViewabilityConfigCallbackPairs, type ViewableRange, typedForwardRef, useRecyclingEffect, useRecyclingState, useViewability, useViewabilityAmount };
|
package/index.d.ts
CHANGED
|
@@ -7,12 +7,15 @@ import Animated from 'react-native-reanimated';
|
|
|
7
7
|
declare class ScrollAdjustHandler {
|
|
8
8
|
private ctx;
|
|
9
9
|
private appliedAdjust;
|
|
10
|
-
private pendingAdjust;
|
|
11
10
|
private busy;
|
|
12
11
|
private context;
|
|
12
|
+
private isPaused;
|
|
13
13
|
constructor(ctx: any);
|
|
14
|
+
private doAjdust;
|
|
14
15
|
requestAdjust(adjust: number, onAdjusted: (diff: number) => void): void;
|
|
15
16
|
getAppliedAdjust(): number;
|
|
17
|
+
pauseAdjust(): void;
|
|
18
|
+
unPauseAdjust(): boolean;
|
|
16
19
|
}
|
|
17
20
|
|
|
18
21
|
type LegendListPropsBase<ItemT, TScrollView extends ComponentProps<typeof ScrollView> | ComponentProps<typeof Animated.ScrollView>> = Omit<TScrollView, "contentOffset" | "contentInset" | "maintainVisibleContentPosition" | "stickyHeaderIndices"> & {
|
|
@@ -28,6 +31,7 @@ type LegendListPropsBase<ItemT, TScrollView extends ComponentProps<typeof Scroll
|
|
|
28
31
|
alignItemsAtEnd?: boolean;
|
|
29
32
|
maintainVisibleContentPosition?: boolean;
|
|
30
33
|
numColumns?: number;
|
|
34
|
+
columnWrapperStyle?: ColumnWrapperStyle;
|
|
31
35
|
refScrollView?: React.Ref<ScrollView>;
|
|
32
36
|
waitForInitialLayout?: boolean;
|
|
33
37
|
estimatedItemSize?: number;
|
|
@@ -63,6 +67,11 @@ type LegendListPropsBase<ItemT, TScrollView extends ComponentProps<typeof Scroll
|
|
|
63
67
|
renderScrollComponent?: (props: ScrollViewProps) => React.ReactElement<ScrollViewProps>;
|
|
64
68
|
extraData?: any;
|
|
65
69
|
};
|
|
70
|
+
interface ColumnWrapperStyle {
|
|
71
|
+
rowGap?: number;
|
|
72
|
+
gap?: number;
|
|
73
|
+
columnGap?: number;
|
|
74
|
+
}
|
|
66
75
|
type AnchoredPosition = {
|
|
67
76
|
type: "top" | "bottom";
|
|
68
77
|
relativeCoordinate: number;
|
|
@@ -248,6 +257,7 @@ declare const LegendList: <T>(props: Omit<react_native.ScrollViewProps, "content
|
|
|
248
257
|
alignItemsAtEnd?: boolean;
|
|
249
258
|
maintainVisibleContentPosition?: boolean;
|
|
250
259
|
numColumns?: number;
|
|
260
|
+
columnWrapperStyle?: ColumnWrapperStyle;
|
|
251
261
|
refScrollView?: React$1.Ref<ScrollView>;
|
|
252
262
|
waitForInitialLayout?: boolean;
|
|
253
263
|
estimatedItemSize?: number;
|
|
@@ -285,4 +295,4 @@ declare function useViewabilityAmount(callback: ViewabilityAmountCallback): void
|
|
|
285
295
|
declare function useRecyclingEffect(effect: (info: LegendListRecyclingState<unknown>) => void | (() => void)): void;
|
|
286
296
|
declare function useRecyclingState(valueOrFun: ((info: LegendListRecyclingState<unknown>) => any) | any): [any, React$1.Dispatch<any>];
|
|
287
297
|
|
|
288
|
-
export { type AnchoredPosition, type InternalState, LegendList, type LegendListProps, type LegendListPropsBase, type LegendListRecyclingState, type LegendListRef, type LegendListRenderItemProps, type OnViewableItemsChanged, type TypedForwardRef, type ViewAmountToken, type ViewToken, type ViewabilityAmountCallback, type ViewabilityCallback, type ViewabilityConfig, type ViewabilityConfigCallbackPair, type ViewabilityConfigCallbackPairs, type ViewableRange, typedForwardRef, useRecyclingEffect, useRecyclingState, useViewability, useViewabilityAmount };
|
|
298
|
+
export { type AnchoredPosition, type ColumnWrapperStyle, type InternalState, LegendList, type LegendListProps, type LegendListPropsBase, type LegendListRecyclingState, type LegendListRef, type LegendListRenderItemProps, type OnViewableItemsChanged, type TypedForwardRef, type ViewAmountToken, type ViewToken, type ViewabilityAmountCallback, type ViewabilityCallback, type ViewabilityConfig, type ViewabilityConfigCallbackPair, type ViewabilityConfigCallbackPairs, type ViewableRange, typedForwardRef, useRecyclingEffect, useRecyclingState, useViewability, useViewabilityAmount };
|
package/index.js
CHANGED
|
@@ -32,7 +32,8 @@ function StateProvider({ children }) {
|
|
|
32
32
|
mapViewabilityCallbacks: /* @__PURE__ */ new Map(),
|
|
33
33
|
mapViewabilityValues: /* @__PURE__ */ new Map(),
|
|
34
34
|
mapViewabilityAmountCallbacks: /* @__PURE__ */ new Map(),
|
|
35
|
-
mapViewabilityAmountValues: /* @__PURE__ */ new Map()
|
|
35
|
+
mapViewabilityAmountValues: /* @__PURE__ */ new Map(),
|
|
36
|
+
columnWrapperStyle: void 0
|
|
36
37
|
}));
|
|
37
38
|
return /* @__PURE__ */ React6__namespace.createElement(ContextState.Provider, { value }, children);
|
|
38
39
|
}
|
|
@@ -217,12 +218,24 @@ var Container = ({
|
|
|
217
218
|
updateItemSize,
|
|
218
219
|
ItemSeparatorComponent
|
|
219
220
|
}) => {
|
|
221
|
+
const ctx = useStateContext();
|
|
222
|
+
const columnWrapperStyle = ctx.columnWrapperStyle;
|
|
220
223
|
const maintainVisibleContentPosition = use$("maintainVisibleContentPosition");
|
|
221
224
|
const position = use$(`containerPosition${id}`) || ANCHORED_POSITION_OUT_OF_VIEW;
|
|
222
225
|
const column = use$(`containerColumn${id}`) || 0;
|
|
223
226
|
const numColumns = use$("numColumns");
|
|
224
227
|
const otherAxisPos = numColumns > 1 ? `${(column - 1) / numColumns * 100}%` : 0;
|
|
225
228
|
const otherAxisSize = numColumns > 1 ? `${1 / numColumns * 100}%` : void 0;
|
|
229
|
+
let verticalPaddingStyles;
|
|
230
|
+
if (columnWrapperStyle && !horizontal && numColumns > 1) {
|
|
231
|
+
const { columnGap, rowGap, gap } = columnWrapperStyle;
|
|
232
|
+
verticalPaddingStyles = {
|
|
233
|
+
paddingVertical: rowGap || gap || void 0,
|
|
234
|
+
// Apply horizontal padding based on column position (first, middle, or last)
|
|
235
|
+
paddingLeft: column > 1 ? (columnGap || gap || 0) / 2 : void 0,
|
|
236
|
+
paddingRight: column < numColumns ? (columnGap || gap || 0) / 2 : void 0
|
|
237
|
+
};
|
|
238
|
+
}
|
|
226
239
|
const style = horizontal ? {
|
|
227
240
|
flexDirection: ItemSeparatorComponent ? "row" : void 0,
|
|
228
241
|
position: "absolute",
|
|
@@ -235,7 +248,8 @@ var Container = ({
|
|
|
235
248
|
left: otherAxisPos,
|
|
236
249
|
right: numColumns > 1 ? null : 0,
|
|
237
250
|
width: otherAxisSize,
|
|
238
|
-
top: position.relativeCoordinate
|
|
251
|
+
top: position.relativeCoordinate,
|
|
252
|
+
...verticalPaddingStyles || {}
|
|
239
253
|
};
|
|
240
254
|
const lastItemKey = use$("lastItemKey");
|
|
241
255
|
const itemKey = use$(`containerItemKey${id}`);
|
|
@@ -286,9 +300,9 @@ var Container = ({
|
|
|
286
300
|
}
|
|
287
301
|
return /* @__PURE__ */ React6__namespace.default.createElement(LeanView, { style, onLayout, ref }, contentFragment);
|
|
288
302
|
};
|
|
289
|
-
var useAnimatedValue =
|
|
303
|
+
var useAnimatedValue = (initialValue) => {
|
|
290
304
|
return React6.useRef(new reactNative.Animated.Value(initialValue)).current;
|
|
291
|
-
}
|
|
305
|
+
};
|
|
292
306
|
|
|
293
307
|
// src/useValue$.ts
|
|
294
308
|
function useValue$(key, getValue, useMicrotask) {
|
|
@@ -494,30 +508,41 @@ var ScrollAdjustHandler = class {
|
|
|
494
508
|
constructor(ctx) {
|
|
495
509
|
this.ctx = ctx;
|
|
496
510
|
this.appliedAdjust = 0;
|
|
497
|
-
this.pendingAdjust = 0;
|
|
498
511
|
this.busy = false;
|
|
512
|
+
this.isPaused = false;
|
|
499
513
|
this.context = ctx;
|
|
500
514
|
}
|
|
515
|
+
doAjdust() {
|
|
516
|
+
set$(this.context, "scrollAdjust", this.appliedAdjust);
|
|
517
|
+
this.busy = false;
|
|
518
|
+
}
|
|
501
519
|
requestAdjust(adjust, onAdjusted) {
|
|
502
520
|
const oldAdjustTop = peek$(this.context, "scrollAdjust");
|
|
503
521
|
if (oldAdjustTop === adjust) {
|
|
504
522
|
return;
|
|
505
523
|
}
|
|
506
524
|
this.appliedAdjust = adjust;
|
|
507
|
-
this.
|
|
508
|
-
const doAjdust = () => {
|
|
509
|
-
set$(this.context, "scrollAdjust", this.pendingAdjust);
|
|
510
|
-
onAdjusted(oldAdjustTop - this.pendingAdjust);
|
|
511
|
-
this.busy = false;
|
|
512
|
-
};
|
|
513
|
-
if (!this.busy) {
|
|
525
|
+
if (!this.busy && !this.isPaused) {
|
|
514
526
|
this.busy = true;
|
|
515
|
-
doAjdust();
|
|
527
|
+
this.doAjdust();
|
|
528
|
+
onAdjusted(oldAdjustTop - adjust);
|
|
516
529
|
}
|
|
517
530
|
}
|
|
518
531
|
getAppliedAdjust() {
|
|
519
532
|
return this.appliedAdjust;
|
|
520
533
|
}
|
|
534
|
+
pauseAdjust() {
|
|
535
|
+
this.isPaused = true;
|
|
536
|
+
}
|
|
537
|
+
// return true if it was paused
|
|
538
|
+
unPauseAdjust() {
|
|
539
|
+
if (this.isPaused) {
|
|
540
|
+
this.isPaused = false;
|
|
541
|
+
this.doAjdust();
|
|
542
|
+
return true;
|
|
543
|
+
}
|
|
544
|
+
return false;
|
|
545
|
+
}
|
|
521
546
|
};
|
|
522
547
|
var typedForwardRef = React6.forwardRef;
|
|
523
548
|
var useCombinedRef = (...refs) => {
|
|
@@ -690,7 +715,7 @@ var LegendList = typedForwardRef(function LegendList2(props, forwardedRef) {
|
|
|
690
715
|
return /* @__PURE__ */ React6__namespace.createElement(StateProvider, null, /* @__PURE__ */ React6__namespace.createElement(LegendListInner, { ...props, ref: forwardedRef }));
|
|
691
716
|
});
|
|
692
717
|
var LegendListInner = typedForwardRef(function LegendListInner2(props, forwardedRef) {
|
|
693
|
-
var _a, _b, _c, _d
|
|
718
|
+
var _a, _b, _c, _d;
|
|
694
719
|
const {
|
|
695
720
|
data: dataProp,
|
|
696
721
|
initialScrollIndex,
|
|
@@ -705,7 +730,9 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
|
|
|
705
730
|
alignItemsAtEnd = false,
|
|
706
731
|
maintainVisibleContentPosition = false,
|
|
707
732
|
onScroll: onScrollProp,
|
|
733
|
+
onMomentumScrollEnd,
|
|
708
734
|
numColumns: numColumnsProp = 1,
|
|
735
|
+
columnWrapperStyle,
|
|
709
736
|
keyExtractor: keyExtractorProp,
|
|
710
737
|
renderItem,
|
|
711
738
|
estimatedItemSize,
|
|
@@ -727,6 +754,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
|
|
|
727
754
|
callbacks.current.onStartReached = rest.onStartReached;
|
|
728
755
|
callbacks.current.onEndReached = rest.onEndReached;
|
|
729
756
|
const ctx = useStateContext();
|
|
757
|
+
ctx.columnWrapperStyle = columnWrapperStyle;
|
|
730
758
|
const refScroller = React6.useRef(null);
|
|
731
759
|
const combinedRef = useCombinedRef(refScroller, refScrollView);
|
|
732
760
|
const scrollBuffer = drawDistance != null ? drawDistance : DEFAULT_DRAW_DISTANCE;
|
|
@@ -751,13 +779,20 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
|
|
|
751
779
|
refState.current.sizes.set(key, size);
|
|
752
780
|
return size;
|
|
753
781
|
};
|
|
754
|
-
const
|
|
782
|
+
const calculateOffsetForIndex = (index = initialScrollIndex) => {
|
|
755
783
|
const data = dataProp;
|
|
756
784
|
if (index) {
|
|
757
785
|
let offset = 0;
|
|
758
|
-
|
|
786
|
+
const canGetSize = !!refState.current;
|
|
787
|
+
if (canGetSize || getEstimatedItemSize) {
|
|
788
|
+
const sizeFn = (index2) => {
|
|
789
|
+
if (canGetSize) {
|
|
790
|
+
return getItemSize(getId(index2), index2, data[index2]);
|
|
791
|
+
}
|
|
792
|
+
return getEstimatedItemSize(index2, data[index2]);
|
|
793
|
+
};
|
|
759
794
|
for (let i = 0; i < index; i++) {
|
|
760
|
-
offset +=
|
|
795
|
+
offset += sizeFn(i);
|
|
761
796
|
}
|
|
762
797
|
} else if (estimatedItemSize) {
|
|
763
798
|
offset = index * estimatedItemSize;
|
|
@@ -766,7 +801,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
|
|
|
766
801
|
}
|
|
767
802
|
return 0;
|
|
768
803
|
};
|
|
769
|
-
const initialContentOffset = initialScrollOffset != null ? initialScrollOffset : React6.useMemo(
|
|
804
|
+
const initialContentOffset = initialScrollOffset != null ? initialScrollOffset : React6.useMemo(calculateOffsetForIndex, []);
|
|
770
805
|
if (!refState.current) {
|
|
771
806
|
const initialScrollLength = reactNative.Dimensions.get("window")[horizontal ? "width" : "height"];
|
|
772
807
|
refState.current = {
|
|
@@ -918,17 +953,20 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
|
|
|
918
953
|
return map;
|
|
919
954
|
};
|
|
920
955
|
const getElementPositionBelowAchor = (id) => {
|
|
956
|
+
var _a2;
|
|
921
957
|
const state = refState.current;
|
|
922
958
|
if (!refState.current.belowAnchorElementPositions) {
|
|
923
959
|
state.belowAnchorElementPositions = buildElementPositionsBelowAnchor();
|
|
924
960
|
}
|
|
925
961
|
const res = state.belowAnchorElementPositions.get(id);
|
|
926
962
|
if (res === void 0) {
|
|
927
|
-
|
|
963
|
+
console.warn(`Undefined position below achor ${id} ${(_a2 = state.anchorElement) == null ? void 0 : _a2.id}`);
|
|
964
|
+
return 0;
|
|
928
965
|
}
|
|
929
966
|
return res;
|
|
930
967
|
};
|
|
931
968
|
const calculateItemsInView = React6.useCallback((speed) => {
|
|
969
|
+
var _a2;
|
|
932
970
|
const state = refState.current;
|
|
933
971
|
const {
|
|
934
972
|
data,
|
|
@@ -1006,14 +1044,14 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
|
|
|
1006
1044
|
let column = 1;
|
|
1007
1045
|
let maxSizeInRow = 0;
|
|
1008
1046
|
const getInitialTop = (i) => {
|
|
1009
|
-
var
|
|
1047
|
+
var _a3;
|
|
1010
1048
|
const id = getId(i);
|
|
1011
1049
|
let topOffset = 0;
|
|
1012
1050
|
if (positions.get(id)) {
|
|
1013
1051
|
topOffset = positions.get(id);
|
|
1014
1052
|
}
|
|
1015
|
-
if (id === ((
|
|
1016
|
-
topOffset =
|
|
1053
|
+
if (id === ((_a3 = state.anchorElement) == null ? void 0 : _a3.id)) {
|
|
1054
|
+
topOffset = state.anchorElement.coordinate;
|
|
1017
1055
|
}
|
|
1018
1056
|
return topOffset;
|
|
1019
1057
|
};
|
|
@@ -1021,7 +1059,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
|
|
|
1021
1059
|
const id = getId(i);
|
|
1022
1060
|
const size = getItemSize(id, i, data[i]);
|
|
1023
1061
|
maxSizeInRow = Math.max(maxSizeInRow, size);
|
|
1024
|
-
if (top === void 0) {
|
|
1062
|
+
if (top === void 0 || id === ((_a2 = state.anchorElement) == null ? void 0 : _a2.id)) {
|
|
1025
1063
|
top = getInitialTop(i);
|
|
1026
1064
|
}
|
|
1027
1065
|
if (positions.get(id) !== top) {
|
|
@@ -1287,18 +1325,17 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
|
|
|
1287
1325
|
}
|
|
1288
1326
|
}
|
|
1289
1327
|
};
|
|
1290
|
-
const
|
|
1291
|
-
|
|
1292
|
-
if (!keyExtractorProp && !isFirst && dataProp !== refState.current.data) {
|
|
1293
|
-
refState.current.positions.clear();
|
|
1294
|
-
}
|
|
1295
|
-
refState.current.data = dataProp;
|
|
1328
|
+
const calcTotalSizesAndPositions = ({ forgetPositions = false }) => {
|
|
1329
|
+
var _a2, _b2, _c2;
|
|
1296
1330
|
let totalSize = 0;
|
|
1297
1331
|
let totalSizeBelowIndex = 0;
|
|
1298
1332
|
const indexByKey = /* @__PURE__ */ new Map();
|
|
1299
1333
|
const newPositions = /* @__PURE__ */ new Map();
|
|
1300
1334
|
let column = 1;
|
|
1301
1335
|
let maxSizeInRow = 0;
|
|
1336
|
+
if (!refState.current) {
|
|
1337
|
+
return;
|
|
1338
|
+
}
|
|
1302
1339
|
for (let i = 0; i < dataProp.length; i++) {
|
|
1303
1340
|
const key = getId(i);
|
|
1304
1341
|
if (__DEV__) {
|
|
@@ -1309,13 +1346,13 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
|
|
|
1309
1346
|
}
|
|
1310
1347
|
}
|
|
1311
1348
|
indexByKey.set(key, i);
|
|
1312
|
-
if (refState.current.positions.get(key) != null && refState.current.indexByKey.get(key) === i) {
|
|
1349
|
+
if (!forgetPositions && refState.current.positions.get(key) != null && refState.current.indexByKey.get(key) === i) {
|
|
1313
1350
|
newPositions.set(key, refState.current.positions.get(key));
|
|
1314
1351
|
}
|
|
1315
1352
|
}
|
|
1316
1353
|
refState.current.indexByKey = indexByKey;
|
|
1317
1354
|
refState.current.positions = newPositions;
|
|
1318
|
-
if (!isFirst) {
|
|
1355
|
+
if (!forgetPositions && !isFirst) {
|
|
1319
1356
|
if (maintainVisibleContentPosition) {
|
|
1320
1357
|
if (refState.current.anchorElement == null || indexByKey.get(refState.current.anchorElement.id) == null) {
|
|
1321
1358
|
if (dataProp.length) {
|
|
@@ -1324,8 +1361,8 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
|
|
|
1324
1361
|
id: getId(0)
|
|
1325
1362
|
};
|
|
1326
1363
|
refState.current.anchorElement = newAnchorElement;
|
|
1327
|
-
(
|
|
1328
|
-
(
|
|
1364
|
+
(_a2 = refState.current.belowAnchorElementPositions) == null ? void 0 : _a2.clear();
|
|
1365
|
+
(_b2 = refScroller.current) == null ? void 0 : _b2.scrollTo({ x: 0, y: 0, animated: false });
|
|
1329
1366
|
setTimeout(() => {
|
|
1330
1367
|
calculateItemsInView(0);
|
|
1331
1368
|
}, 0);
|
|
@@ -1340,7 +1377,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
|
|
|
1340
1377
|
} else {
|
|
1341
1378
|
refState.current.startBufferedId = void 0;
|
|
1342
1379
|
}
|
|
1343
|
-
(
|
|
1380
|
+
(_c2 = refScroller.current) == null ? void 0 : _c2.scrollTo({ x: 0, y: 0, animated: false });
|
|
1344
1381
|
setTimeout(() => {
|
|
1345
1382
|
calculateItemsInView(0);
|
|
1346
1383
|
}, 0);
|
|
@@ -1366,6 +1403,21 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
|
|
|
1366
1403
|
totalSize += maxSizeInRow;
|
|
1367
1404
|
}
|
|
1368
1405
|
addTotalSize(null, totalSize, totalSizeBelowIndex);
|
|
1406
|
+
};
|
|
1407
|
+
const isFirst = !refState.current.renderItem;
|
|
1408
|
+
if (isFirst || dataProp !== refState.current.data || numColumnsProp !== peek$(ctx, "numColumns")) {
|
|
1409
|
+
if (!keyExtractorProp && !isFirst && dataProp !== refState.current.data) {
|
|
1410
|
+
refState.current.sizes.clear();
|
|
1411
|
+
refState.current.positions.clear();
|
|
1412
|
+
}
|
|
1413
|
+
refState.current.data = dataProp;
|
|
1414
|
+
const indexByKey = /* @__PURE__ */ new Map();
|
|
1415
|
+
for (let i = 0; i < dataProp.length; i++) {
|
|
1416
|
+
const key = getId(i);
|
|
1417
|
+
indexByKey.set(key, i);
|
|
1418
|
+
}
|
|
1419
|
+
refState.current.indexByKey = indexByKey;
|
|
1420
|
+
calcTotalSizesAndPositions({ forgetPositions: false });
|
|
1369
1421
|
}
|
|
1370
1422
|
React6.useEffect(() => {
|
|
1371
1423
|
checkResetContainers(
|
|
@@ -1378,7 +1430,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
|
|
|
1378
1430
|
}, [extraData]);
|
|
1379
1431
|
refState.current.renderItem = renderItem;
|
|
1380
1432
|
const lastItemKey = dataProp.length > 0 ? getId(dataProp.length - 1) : void 0;
|
|
1381
|
-
const stylePaddingTop = (
|
|
1433
|
+
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;
|
|
1382
1434
|
const initalizeStateVars = () => {
|
|
1383
1435
|
set$(ctx, "lastItemKey", lastItemKey);
|
|
1384
1436
|
set$(ctx, "numColumns", numColumnsProp);
|
|
@@ -1582,10 +1634,42 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
|
|
|
1582
1634
|
React6.useImperativeHandle(
|
|
1583
1635
|
forwardedRef,
|
|
1584
1636
|
() => {
|
|
1585
|
-
const scrollToIndex = ({ index, animated }) => {
|
|
1586
|
-
|
|
1587
|
-
const
|
|
1588
|
-
|
|
1637
|
+
const scrollToIndex = ({ index, animated = true }) => {
|
|
1638
|
+
var _a2;
|
|
1639
|
+
const state = refState.current;
|
|
1640
|
+
const firstIndexOffset = calculateOffsetForIndex(index);
|
|
1641
|
+
let firstIndexScrollPostion = firstIndexOffset;
|
|
1642
|
+
if (maintainVisibleContentPosition) {
|
|
1643
|
+
const id = getId(index);
|
|
1644
|
+
state.anchorElement = { id, coordinate: firstIndexOffset };
|
|
1645
|
+
(_a2 = state.belowAnchorElementPositions) == null ? void 0 : _a2.clear();
|
|
1646
|
+
state.positions.clear();
|
|
1647
|
+
calcTotalSizesAndPositions({ forgetPositions: true });
|
|
1648
|
+
state.scrollForNextCalculateItemsInView = void 0;
|
|
1649
|
+
state.startBufferedId = id;
|
|
1650
|
+
state.minIndexSizeChanged = index;
|
|
1651
|
+
firstIndexScrollPostion = firstIndexOffset + state.scrollAdjustHandler.getAppliedAdjust();
|
|
1652
|
+
state.scrollAdjustHandler.pauseAdjust();
|
|
1653
|
+
setTimeout(
|
|
1654
|
+
() => {
|
|
1655
|
+
const wasAdjusted = state.scrollAdjustHandler.unPauseAdjust();
|
|
1656
|
+
if (wasAdjusted) {
|
|
1657
|
+
refState.current.scrollVelocity = 0;
|
|
1658
|
+
refState.current.scrollHistory = [];
|
|
1659
|
+
calculateItemsInView(0);
|
|
1660
|
+
}
|
|
1661
|
+
},
|
|
1662
|
+
animated ? 1e3 : 50
|
|
1663
|
+
);
|
|
1664
|
+
}
|
|
1665
|
+
const offset = horizontal ? { x: firstIndexScrollPostion, y: 0 } : { x: 0, y: firstIndexScrollPostion };
|
|
1666
|
+
if (maintainVisibleContentPosition) {
|
|
1667
|
+
setTimeout(() => {
|
|
1668
|
+
refScroller.current.scrollTo({ ...offset, animated });
|
|
1669
|
+
}, 50);
|
|
1670
|
+
} else {
|
|
1671
|
+
refScroller.current.scrollTo({ ...offset, animated });
|
|
1672
|
+
}
|
|
1589
1673
|
};
|
|
1590
1674
|
return {
|
|
1591
1675
|
getNativeScrollRef: () => refScroller.current,
|
|
@@ -1619,6 +1703,17 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
|
|
|
1619
1703
|
getRenderedItem,
|
|
1620
1704
|
updateItemSize,
|
|
1621
1705
|
handleScroll,
|
|
1706
|
+
onMomentumScrollEnd: (event) => {
|
|
1707
|
+
const wasPaused = refState.current.scrollAdjustHandler.unPauseAdjust();
|
|
1708
|
+
if (wasPaused) {
|
|
1709
|
+
refState.current.scrollVelocity = 0;
|
|
1710
|
+
refState.current.scrollHistory = [];
|
|
1711
|
+
calculateItemsInView(0);
|
|
1712
|
+
}
|
|
1713
|
+
if (onMomentumScrollEnd) {
|
|
1714
|
+
onMomentumScrollEnd(event);
|
|
1715
|
+
}
|
|
1716
|
+
},
|
|
1622
1717
|
onLayout,
|
|
1623
1718
|
recycleItems,
|
|
1624
1719
|
alignItemsAtEnd,
|
package/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React6 from 'react';
|
|
2
2
|
import React6__default, { createContext, memo, useReducer, useEffect, useMemo, useRef, useCallback, useImperativeHandle, useSyncExternalStore, useContext, useState, forwardRef, useLayoutEffect } from 'react';
|
|
3
|
-
import { View, Text, Platform, Animated, ScrollView, Dimensions, StyleSheet
|
|
3
|
+
import { View, Text, Platform, Animated, ScrollView, Dimensions, StyleSheet } from 'react-native';
|
|
4
4
|
|
|
5
5
|
// src/LegendList.tsx
|
|
6
6
|
var ContextState = React6.createContext(null);
|
|
@@ -11,7 +11,8 @@ function StateProvider({ children }) {
|
|
|
11
11
|
mapViewabilityCallbacks: /* @__PURE__ */ new Map(),
|
|
12
12
|
mapViewabilityValues: /* @__PURE__ */ new Map(),
|
|
13
13
|
mapViewabilityAmountCallbacks: /* @__PURE__ */ new Map(),
|
|
14
|
-
mapViewabilityAmountValues: /* @__PURE__ */ new Map()
|
|
14
|
+
mapViewabilityAmountValues: /* @__PURE__ */ new Map(),
|
|
15
|
+
columnWrapperStyle: void 0
|
|
15
16
|
}));
|
|
16
17
|
return /* @__PURE__ */ React6.createElement(ContextState.Provider, { value }, children);
|
|
17
18
|
}
|
|
@@ -196,12 +197,24 @@ var Container = ({
|
|
|
196
197
|
updateItemSize,
|
|
197
198
|
ItemSeparatorComponent
|
|
198
199
|
}) => {
|
|
200
|
+
const ctx = useStateContext();
|
|
201
|
+
const columnWrapperStyle = ctx.columnWrapperStyle;
|
|
199
202
|
const maintainVisibleContentPosition = use$("maintainVisibleContentPosition");
|
|
200
203
|
const position = use$(`containerPosition${id}`) || ANCHORED_POSITION_OUT_OF_VIEW;
|
|
201
204
|
const column = use$(`containerColumn${id}`) || 0;
|
|
202
205
|
const numColumns = use$("numColumns");
|
|
203
206
|
const otherAxisPos = numColumns > 1 ? `${(column - 1) / numColumns * 100}%` : 0;
|
|
204
207
|
const otherAxisSize = numColumns > 1 ? `${1 / numColumns * 100}%` : void 0;
|
|
208
|
+
let verticalPaddingStyles;
|
|
209
|
+
if (columnWrapperStyle && !horizontal && numColumns > 1) {
|
|
210
|
+
const { columnGap, rowGap, gap } = columnWrapperStyle;
|
|
211
|
+
verticalPaddingStyles = {
|
|
212
|
+
paddingVertical: rowGap || gap || void 0,
|
|
213
|
+
// Apply horizontal padding based on column position (first, middle, or last)
|
|
214
|
+
paddingLeft: column > 1 ? (columnGap || gap || 0) / 2 : void 0,
|
|
215
|
+
paddingRight: column < numColumns ? (columnGap || gap || 0) / 2 : void 0
|
|
216
|
+
};
|
|
217
|
+
}
|
|
205
218
|
const style = horizontal ? {
|
|
206
219
|
flexDirection: ItemSeparatorComponent ? "row" : void 0,
|
|
207
220
|
position: "absolute",
|
|
@@ -214,7 +227,8 @@ var Container = ({
|
|
|
214
227
|
left: otherAxisPos,
|
|
215
228
|
right: numColumns > 1 ? null : 0,
|
|
216
229
|
width: otherAxisSize,
|
|
217
|
-
top: position.relativeCoordinate
|
|
230
|
+
top: position.relativeCoordinate,
|
|
231
|
+
...verticalPaddingStyles || {}
|
|
218
232
|
};
|
|
219
233
|
const lastItemKey = use$("lastItemKey");
|
|
220
234
|
const itemKey = use$(`containerItemKey${id}`);
|
|
@@ -265,9 +279,9 @@ var Container = ({
|
|
|
265
279
|
}
|
|
266
280
|
return /* @__PURE__ */ React6__default.createElement(LeanView, { style, onLayout, ref }, contentFragment);
|
|
267
281
|
};
|
|
268
|
-
var useAnimatedValue =
|
|
282
|
+
var useAnimatedValue = (initialValue) => {
|
|
269
283
|
return useRef(new Animated.Value(initialValue)).current;
|
|
270
|
-
}
|
|
284
|
+
};
|
|
271
285
|
|
|
272
286
|
// src/useValue$.ts
|
|
273
287
|
function useValue$(key, getValue, useMicrotask) {
|
|
@@ -473,30 +487,41 @@ var ScrollAdjustHandler = class {
|
|
|
473
487
|
constructor(ctx) {
|
|
474
488
|
this.ctx = ctx;
|
|
475
489
|
this.appliedAdjust = 0;
|
|
476
|
-
this.pendingAdjust = 0;
|
|
477
490
|
this.busy = false;
|
|
491
|
+
this.isPaused = false;
|
|
478
492
|
this.context = ctx;
|
|
479
493
|
}
|
|
494
|
+
doAjdust() {
|
|
495
|
+
set$(this.context, "scrollAdjust", this.appliedAdjust);
|
|
496
|
+
this.busy = false;
|
|
497
|
+
}
|
|
480
498
|
requestAdjust(adjust, onAdjusted) {
|
|
481
499
|
const oldAdjustTop = peek$(this.context, "scrollAdjust");
|
|
482
500
|
if (oldAdjustTop === adjust) {
|
|
483
501
|
return;
|
|
484
502
|
}
|
|
485
503
|
this.appliedAdjust = adjust;
|
|
486
|
-
this.
|
|
487
|
-
const doAjdust = () => {
|
|
488
|
-
set$(this.context, "scrollAdjust", this.pendingAdjust);
|
|
489
|
-
onAdjusted(oldAdjustTop - this.pendingAdjust);
|
|
490
|
-
this.busy = false;
|
|
491
|
-
};
|
|
492
|
-
if (!this.busy) {
|
|
504
|
+
if (!this.busy && !this.isPaused) {
|
|
493
505
|
this.busy = true;
|
|
494
|
-
doAjdust();
|
|
506
|
+
this.doAjdust();
|
|
507
|
+
onAdjusted(oldAdjustTop - adjust);
|
|
495
508
|
}
|
|
496
509
|
}
|
|
497
510
|
getAppliedAdjust() {
|
|
498
511
|
return this.appliedAdjust;
|
|
499
512
|
}
|
|
513
|
+
pauseAdjust() {
|
|
514
|
+
this.isPaused = true;
|
|
515
|
+
}
|
|
516
|
+
// return true if it was paused
|
|
517
|
+
unPauseAdjust() {
|
|
518
|
+
if (this.isPaused) {
|
|
519
|
+
this.isPaused = false;
|
|
520
|
+
this.doAjdust();
|
|
521
|
+
return true;
|
|
522
|
+
}
|
|
523
|
+
return false;
|
|
524
|
+
}
|
|
500
525
|
};
|
|
501
526
|
var typedForwardRef = forwardRef;
|
|
502
527
|
var useCombinedRef = (...refs) => {
|
|
@@ -669,7 +694,7 @@ var LegendList = typedForwardRef(function LegendList2(props, forwardedRef) {
|
|
|
669
694
|
return /* @__PURE__ */ React6.createElement(StateProvider, null, /* @__PURE__ */ React6.createElement(LegendListInner, { ...props, ref: forwardedRef }));
|
|
670
695
|
});
|
|
671
696
|
var LegendListInner = typedForwardRef(function LegendListInner2(props, forwardedRef) {
|
|
672
|
-
var _a, _b, _c, _d
|
|
697
|
+
var _a, _b, _c, _d;
|
|
673
698
|
const {
|
|
674
699
|
data: dataProp,
|
|
675
700
|
initialScrollIndex,
|
|
@@ -684,7 +709,9 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
|
|
|
684
709
|
alignItemsAtEnd = false,
|
|
685
710
|
maintainVisibleContentPosition = false,
|
|
686
711
|
onScroll: onScrollProp,
|
|
712
|
+
onMomentumScrollEnd,
|
|
687
713
|
numColumns: numColumnsProp = 1,
|
|
714
|
+
columnWrapperStyle,
|
|
688
715
|
keyExtractor: keyExtractorProp,
|
|
689
716
|
renderItem,
|
|
690
717
|
estimatedItemSize,
|
|
@@ -706,6 +733,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
|
|
|
706
733
|
callbacks.current.onStartReached = rest.onStartReached;
|
|
707
734
|
callbacks.current.onEndReached = rest.onEndReached;
|
|
708
735
|
const ctx = useStateContext();
|
|
736
|
+
ctx.columnWrapperStyle = columnWrapperStyle;
|
|
709
737
|
const refScroller = useRef(null);
|
|
710
738
|
const combinedRef = useCombinedRef(refScroller, refScrollView);
|
|
711
739
|
const scrollBuffer = drawDistance != null ? drawDistance : DEFAULT_DRAW_DISTANCE;
|
|
@@ -730,13 +758,20 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
|
|
|
730
758
|
refState.current.sizes.set(key, size);
|
|
731
759
|
return size;
|
|
732
760
|
};
|
|
733
|
-
const
|
|
761
|
+
const calculateOffsetForIndex = (index = initialScrollIndex) => {
|
|
734
762
|
const data = dataProp;
|
|
735
763
|
if (index) {
|
|
736
764
|
let offset = 0;
|
|
737
|
-
|
|
765
|
+
const canGetSize = !!refState.current;
|
|
766
|
+
if (canGetSize || getEstimatedItemSize) {
|
|
767
|
+
const sizeFn = (index2) => {
|
|
768
|
+
if (canGetSize) {
|
|
769
|
+
return getItemSize(getId(index2), index2, data[index2]);
|
|
770
|
+
}
|
|
771
|
+
return getEstimatedItemSize(index2, data[index2]);
|
|
772
|
+
};
|
|
738
773
|
for (let i = 0; i < index; i++) {
|
|
739
|
-
offset +=
|
|
774
|
+
offset += sizeFn(i);
|
|
740
775
|
}
|
|
741
776
|
} else if (estimatedItemSize) {
|
|
742
777
|
offset = index * estimatedItemSize;
|
|
@@ -745,7 +780,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
|
|
|
745
780
|
}
|
|
746
781
|
return 0;
|
|
747
782
|
};
|
|
748
|
-
const initialContentOffset = initialScrollOffset != null ? initialScrollOffset : useMemo(
|
|
783
|
+
const initialContentOffset = initialScrollOffset != null ? initialScrollOffset : useMemo(calculateOffsetForIndex, []);
|
|
749
784
|
if (!refState.current) {
|
|
750
785
|
const initialScrollLength = Dimensions.get("window")[horizontal ? "width" : "height"];
|
|
751
786
|
refState.current = {
|
|
@@ -897,17 +932,20 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
|
|
|
897
932
|
return map;
|
|
898
933
|
};
|
|
899
934
|
const getElementPositionBelowAchor = (id) => {
|
|
935
|
+
var _a2;
|
|
900
936
|
const state = refState.current;
|
|
901
937
|
if (!refState.current.belowAnchorElementPositions) {
|
|
902
938
|
state.belowAnchorElementPositions = buildElementPositionsBelowAnchor();
|
|
903
939
|
}
|
|
904
940
|
const res = state.belowAnchorElementPositions.get(id);
|
|
905
941
|
if (res === void 0) {
|
|
906
|
-
|
|
942
|
+
console.warn(`Undefined position below achor ${id} ${(_a2 = state.anchorElement) == null ? void 0 : _a2.id}`);
|
|
943
|
+
return 0;
|
|
907
944
|
}
|
|
908
945
|
return res;
|
|
909
946
|
};
|
|
910
947
|
const calculateItemsInView = useCallback((speed) => {
|
|
948
|
+
var _a2;
|
|
911
949
|
const state = refState.current;
|
|
912
950
|
const {
|
|
913
951
|
data,
|
|
@@ -985,14 +1023,14 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
|
|
|
985
1023
|
let column = 1;
|
|
986
1024
|
let maxSizeInRow = 0;
|
|
987
1025
|
const getInitialTop = (i) => {
|
|
988
|
-
var
|
|
1026
|
+
var _a3;
|
|
989
1027
|
const id = getId(i);
|
|
990
1028
|
let topOffset = 0;
|
|
991
1029
|
if (positions.get(id)) {
|
|
992
1030
|
topOffset = positions.get(id);
|
|
993
1031
|
}
|
|
994
|
-
if (id === ((
|
|
995
|
-
topOffset =
|
|
1032
|
+
if (id === ((_a3 = state.anchorElement) == null ? void 0 : _a3.id)) {
|
|
1033
|
+
topOffset = state.anchorElement.coordinate;
|
|
996
1034
|
}
|
|
997
1035
|
return topOffset;
|
|
998
1036
|
};
|
|
@@ -1000,7 +1038,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
|
|
|
1000
1038
|
const id = getId(i);
|
|
1001
1039
|
const size = getItemSize(id, i, data[i]);
|
|
1002
1040
|
maxSizeInRow = Math.max(maxSizeInRow, size);
|
|
1003
|
-
if (top === void 0) {
|
|
1041
|
+
if (top === void 0 || id === ((_a2 = state.anchorElement) == null ? void 0 : _a2.id)) {
|
|
1004
1042
|
top = getInitialTop(i);
|
|
1005
1043
|
}
|
|
1006
1044
|
if (positions.get(id) !== top) {
|
|
@@ -1266,18 +1304,17 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
|
|
|
1266
1304
|
}
|
|
1267
1305
|
}
|
|
1268
1306
|
};
|
|
1269
|
-
const
|
|
1270
|
-
|
|
1271
|
-
if (!keyExtractorProp && !isFirst && dataProp !== refState.current.data) {
|
|
1272
|
-
refState.current.positions.clear();
|
|
1273
|
-
}
|
|
1274
|
-
refState.current.data = dataProp;
|
|
1307
|
+
const calcTotalSizesAndPositions = ({ forgetPositions = false }) => {
|
|
1308
|
+
var _a2, _b2, _c2;
|
|
1275
1309
|
let totalSize = 0;
|
|
1276
1310
|
let totalSizeBelowIndex = 0;
|
|
1277
1311
|
const indexByKey = /* @__PURE__ */ new Map();
|
|
1278
1312
|
const newPositions = /* @__PURE__ */ new Map();
|
|
1279
1313
|
let column = 1;
|
|
1280
1314
|
let maxSizeInRow = 0;
|
|
1315
|
+
if (!refState.current) {
|
|
1316
|
+
return;
|
|
1317
|
+
}
|
|
1281
1318
|
for (let i = 0; i < dataProp.length; i++) {
|
|
1282
1319
|
const key = getId(i);
|
|
1283
1320
|
if (__DEV__) {
|
|
@@ -1288,13 +1325,13 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
|
|
|
1288
1325
|
}
|
|
1289
1326
|
}
|
|
1290
1327
|
indexByKey.set(key, i);
|
|
1291
|
-
if (refState.current.positions.get(key) != null && refState.current.indexByKey.get(key) === i) {
|
|
1328
|
+
if (!forgetPositions && refState.current.positions.get(key) != null && refState.current.indexByKey.get(key) === i) {
|
|
1292
1329
|
newPositions.set(key, refState.current.positions.get(key));
|
|
1293
1330
|
}
|
|
1294
1331
|
}
|
|
1295
1332
|
refState.current.indexByKey = indexByKey;
|
|
1296
1333
|
refState.current.positions = newPositions;
|
|
1297
|
-
if (!isFirst) {
|
|
1334
|
+
if (!forgetPositions && !isFirst) {
|
|
1298
1335
|
if (maintainVisibleContentPosition) {
|
|
1299
1336
|
if (refState.current.anchorElement == null || indexByKey.get(refState.current.anchorElement.id) == null) {
|
|
1300
1337
|
if (dataProp.length) {
|
|
@@ -1303,8 +1340,8 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
|
|
|
1303
1340
|
id: getId(0)
|
|
1304
1341
|
};
|
|
1305
1342
|
refState.current.anchorElement = newAnchorElement;
|
|
1306
|
-
(
|
|
1307
|
-
(
|
|
1343
|
+
(_a2 = refState.current.belowAnchorElementPositions) == null ? void 0 : _a2.clear();
|
|
1344
|
+
(_b2 = refScroller.current) == null ? void 0 : _b2.scrollTo({ x: 0, y: 0, animated: false });
|
|
1308
1345
|
setTimeout(() => {
|
|
1309
1346
|
calculateItemsInView(0);
|
|
1310
1347
|
}, 0);
|
|
@@ -1319,7 +1356,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
|
|
|
1319
1356
|
} else {
|
|
1320
1357
|
refState.current.startBufferedId = void 0;
|
|
1321
1358
|
}
|
|
1322
|
-
(
|
|
1359
|
+
(_c2 = refScroller.current) == null ? void 0 : _c2.scrollTo({ x: 0, y: 0, animated: false });
|
|
1323
1360
|
setTimeout(() => {
|
|
1324
1361
|
calculateItemsInView(0);
|
|
1325
1362
|
}, 0);
|
|
@@ -1345,6 +1382,21 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
|
|
|
1345
1382
|
totalSize += maxSizeInRow;
|
|
1346
1383
|
}
|
|
1347
1384
|
addTotalSize(null, totalSize, totalSizeBelowIndex);
|
|
1385
|
+
};
|
|
1386
|
+
const isFirst = !refState.current.renderItem;
|
|
1387
|
+
if (isFirst || dataProp !== refState.current.data || numColumnsProp !== peek$(ctx, "numColumns")) {
|
|
1388
|
+
if (!keyExtractorProp && !isFirst && dataProp !== refState.current.data) {
|
|
1389
|
+
refState.current.sizes.clear();
|
|
1390
|
+
refState.current.positions.clear();
|
|
1391
|
+
}
|
|
1392
|
+
refState.current.data = dataProp;
|
|
1393
|
+
const indexByKey = /* @__PURE__ */ new Map();
|
|
1394
|
+
for (let i = 0; i < dataProp.length; i++) {
|
|
1395
|
+
const key = getId(i);
|
|
1396
|
+
indexByKey.set(key, i);
|
|
1397
|
+
}
|
|
1398
|
+
refState.current.indexByKey = indexByKey;
|
|
1399
|
+
calcTotalSizesAndPositions({ forgetPositions: false });
|
|
1348
1400
|
}
|
|
1349
1401
|
useEffect(() => {
|
|
1350
1402
|
checkResetContainers(
|
|
@@ -1357,7 +1409,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
|
|
|
1357
1409
|
}, [extraData]);
|
|
1358
1410
|
refState.current.renderItem = renderItem;
|
|
1359
1411
|
const lastItemKey = dataProp.length > 0 ? getId(dataProp.length - 1) : void 0;
|
|
1360
|
-
const stylePaddingTop = (
|
|
1412
|
+
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;
|
|
1361
1413
|
const initalizeStateVars = () => {
|
|
1362
1414
|
set$(ctx, "lastItemKey", lastItemKey);
|
|
1363
1415
|
set$(ctx, "numColumns", numColumnsProp);
|
|
@@ -1561,10 +1613,42 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
|
|
|
1561
1613
|
useImperativeHandle(
|
|
1562
1614
|
forwardedRef,
|
|
1563
1615
|
() => {
|
|
1564
|
-
const scrollToIndex = ({ index, animated }) => {
|
|
1565
|
-
|
|
1566
|
-
const
|
|
1567
|
-
|
|
1616
|
+
const scrollToIndex = ({ index, animated = true }) => {
|
|
1617
|
+
var _a2;
|
|
1618
|
+
const state = refState.current;
|
|
1619
|
+
const firstIndexOffset = calculateOffsetForIndex(index);
|
|
1620
|
+
let firstIndexScrollPostion = firstIndexOffset;
|
|
1621
|
+
if (maintainVisibleContentPosition) {
|
|
1622
|
+
const id = getId(index);
|
|
1623
|
+
state.anchorElement = { id, coordinate: firstIndexOffset };
|
|
1624
|
+
(_a2 = state.belowAnchorElementPositions) == null ? void 0 : _a2.clear();
|
|
1625
|
+
state.positions.clear();
|
|
1626
|
+
calcTotalSizesAndPositions({ forgetPositions: true });
|
|
1627
|
+
state.scrollForNextCalculateItemsInView = void 0;
|
|
1628
|
+
state.startBufferedId = id;
|
|
1629
|
+
state.minIndexSizeChanged = index;
|
|
1630
|
+
firstIndexScrollPostion = firstIndexOffset + state.scrollAdjustHandler.getAppliedAdjust();
|
|
1631
|
+
state.scrollAdjustHandler.pauseAdjust();
|
|
1632
|
+
setTimeout(
|
|
1633
|
+
() => {
|
|
1634
|
+
const wasAdjusted = state.scrollAdjustHandler.unPauseAdjust();
|
|
1635
|
+
if (wasAdjusted) {
|
|
1636
|
+
refState.current.scrollVelocity = 0;
|
|
1637
|
+
refState.current.scrollHistory = [];
|
|
1638
|
+
calculateItemsInView(0);
|
|
1639
|
+
}
|
|
1640
|
+
},
|
|
1641
|
+
animated ? 1e3 : 50
|
|
1642
|
+
);
|
|
1643
|
+
}
|
|
1644
|
+
const offset = horizontal ? { x: firstIndexScrollPostion, y: 0 } : { x: 0, y: firstIndexScrollPostion };
|
|
1645
|
+
if (maintainVisibleContentPosition) {
|
|
1646
|
+
setTimeout(() => {
|
|
1647
|
+
refScroller.current.scrollTo({ ...offset, animated });
|
|
1648
|
+
}, 50);
|
|
1649
|
+
} else {
|
|
1650
|
+
refScroller.current.scrollTo({ ...offset, animated });
|
|
1651
|
+
}
|
|
1568
1652
|
};
|
|
1569
1653
|
return {
|
|
1570
1654
|
getNativeScrollRef: () => refScroller.current,
|
|
@@ -1598,6 +1682,17 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
|
|
|
1598
1682
|
getRenderedItem,
|
|
1599
1683
|
updateItemSize,
|
|
1600
1684
|
handleScroll,
|
|
1685
|
+
onMomentumScrollEnd: (event) => {
|
|
1686
|
+
const wasPaused = refState.current.scrollAdjustHandler.unPauseAdjust();
|
|
1687
|
+
if (wasPaused) {
|
|
1688
|
+
refState.current.scrollVelocity = 0;
|
|
1689
|
+
refState.current.scrollHistory = [];
|
|
1690
|
+
calculateItemsInView(0);
|
|
1691
|
+
}
|
|
1692
|
+
if (onMomentumScrollEnd) {
|
|
1693
|
+
onMomentumScrollEnd(event);
|
|
1694
|
+
}
|
|
1695
|
+
},
|
|
1601
1696
|
onLayout,
|
|
1602
1697
|
recycleItems,
|
|
1603
1698
|
alignItemsAtEnd,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@legendapp/list",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.15",
|
|
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,
|