@legendapp/list 0.5.4 → 0.5.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.mts +3 -1
- package/index.d.ts +3 -1
- package/index.js +95 -22
- package/index.mjs +95 -22
- package/package.json +1 -1
package/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ComponentProps, ReactNode, ForwardedRef, ReactElement } from 'react';
|
|
2
2
|
import { ScrollView, StyleProp, ViewStyle, ScrollViewComponent, ScrollResponderMixin } from 'react-native';
|
|
3
3
|
|
|
4
|
-
type LegendListProps<T> = Omit<ComponentProps<typeof ScrollView>, 'contentOffset' | 'contentInset' | 'maintainVisibleContentPosition'> & {
|
|
4
|
+
type LegendListProps<T> = Omit<ComponentProps<typeof ScrollView>, 'contentOffset' | 'contentInset' | 'maintainVisibleContentPosition' | 'stickyHeaderIndices'> & {
|
|
5
5
|
data: ArrayLike<any> & T[];
|
|
6
6
|
initialScrollOffset?: number;
|
|
7
7
|
initialScrollIndex?: number;
|
|
@@ -14,6 +14,7 @@ type LegendListProps<T> = Omit<ComponentProps<typeof ScrollView>, 'contentOffset
|
|
|
14
14
|
maintainScrollAtEndThreshold?: number;
|
|
15
15
|
alignItemsAtEnd?: boolean;
|
|
16
16
|
maintainVisibleContentPosition?: boolean;
|
|
17
|
+
numColumns?: number;
|
|
17
18
|
estimatedItemSize: number;
|
|
18
19
|
getEstimatedItemSize?: (index: number, item: T) => number;
|
|
19
20
|
onEndReached?: ((info: {
|
|
@@ -37,6 +38,7 @@ type LegendListProps<T> = Omit<ComponentProps<typeof ScrollView>, 'contentOffset
|
|
|
37
38
|
};
|
|
38
39
|
interface InternalState {
|
|
39
40
|
positions: Map<string, number>;
|
|
41
|
+
columns: Map<string, number>;
|
|
40
42
|
sizes: Map<string, number>;
|
|
41
43
|
pendingAdjust: number;
|
|
42
44
|
animFrameLayout: any;
|
package/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ComponentProps, ReactNode, ForwardedRef, ReactElement } from 'react';
|
|
2
2
|
import { ScrollView, StyleProp, ViewStyle, ScrollViewComponent, ScrollResponderMixin } from 'react-native';
|
|
3
3
|
|
|
4
|
-
type LegendListProps<T> = Omit<ComponentProps<typeof ScrollView>, 'contentOffset' | 'contentInset' | 'maintainVisibleContentPosition'> & {
|
|
4
|
+
type LegendListProps<T> = Omit<ComponentProps<typeof ScrollView>, 'contentOffset' | 'contentInset' | 'maintainVisibleContentPosition' | 'stickyHeaderIndices'> & {
|
|
5
5
|
data: ArrayLike<any> & T[];
|
|
6
6
|
initialScrollOffset?: number;
|
|
7
7
|
initialScrollIndex?: number;
|
|
@@ -14,6 +14,7 @@ type LegendListProps<T> = Omit<ComponentProps<typeof ScrollView>, 'contentOffset
|
|
|
14
14
|
maintainScrollAtEndThreshold?: number;
|
|
15
15
|
alignItemsAtEnd?: boolean;
|
|
16
16
|
maintainVisibleContentPosition?: boolean;
|
|
17
|
+
numColumns?: number;
|
|
17
18
|
estimatedItemSize: number;
|
|
18
19
|
getEstimatedItemSize?: (index: number, item: T) => number;
|
|
19
20
|
onEndReached?: ((info: {
|
|
@@ -37,6 +38,7 @@ type LegendListProps<T> = Omit<ComponentProps<typeof ScrollView>, 'contentOffset
|
|
|
37
38
|
};
|
|
38
39
|
interface InternalState {
|
|
39
40
|
positions: Map<string, number>;
|
|
41
|
+
columns: Map<string, number>;
|
|
40
42
|
sizes: Map<string, number>;
|
|
41
43
|
pendingAdjust: number;
|
|
42
44
|
animFrameLayout: any;
|
package/index.js
CHANGED
|
@@ -100,11 +100,11 @@ var LeanView = React7__namespace.forwardRef((props, ref) => {
|
|
|
100
100
|
LeanView.displayName = "RCTView";
|
|
101
101
|
|
|
102
102
|
// src/$View.tsx
|
|
103
|
-
function $View({ $key, $key2, $style, ...rest }) {
|
|
103
|
+
function $View({ $key, $key2, $key3, $key4, $style, ...rest }) {
|
|
104
104
|
use$($key);
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
105
|
+
$key2 && use$($key2);
|
|
106
|
+
$key3 && use$($key3);
|
|
107
|
+
$key4 && use$($key4);
|
|
108
108
|
const style = $style();
|
|
109
109
|
return /* @__PURE__ */ React7__namespace.createElement(LeanView, { style, ...rest });
|
|
110
110
|
}
|
|
@@ -128,17 +128,23 @@ var Container = ({
|
|
|
128
128
|
const ctx = useStateContext();
|
|
129
129
|
const createStyle = () => {
|
|
130
130
|
const position = peek$(ctx, `containerPosition${id}`);
|
|
131
|
+
const column = peek$(ctx, `containerColumn${id}`) || 0;
|
|
131
132
|
const visible = peek$(ctx, `containerDidLayout${id}`);
|
|
133
|
+
const numColumns = peek$(ctx, "numColumns");
|
|
134
|
+
const otherAxisPos = numColumns > 1 ? `${(column - 1) / numColumns * 100}%` : 0;
|
|
135
|
+
const otherAxisSize = numColumns > 1 ? `${1 / numColumns * 100}%` : void 0;
|
|
132
136
|
return horizontal ? {
|
|
133
137
|
flexDirection: "row",
|
|
134
138
|
position: "absolute",
|
|
135
|
-
top: visible ?
|
|
136
|
-
bottom: 0,
|
|
139
|
+
top: visible ? otherAxisPos : -1e7,
|
|
140
|
+
bottom: numColumns > 1 ? null : 0,
|
|
141
|
+
height: otherAxisSize,
|
|
137
142
|
left: position
|
|
138
143
|
} : {
|
|
139
144
|
position: "absolute",
|
|
140
|
-
left: visible ?
|
|
141
|
-
right: 0,
|
|
145
|
+
left: visible ? otherAxisPos : -1e7,
|
|
146
|
+
right: numColumns > 1 ? null : 0,
|
|
147
|
+
width: otherAxisSize,
|
|
142
148
|
top: position
|
|
143
149
|
};
|
|
144
150
|
};
|
|
@@ -147,6 +153,8 @@ var Container = ({
|
|
|
147
153
|
{
|
|
148
154
|
$key: `containerPosition${id}`,
|
|
149
155
|
$key2: `containerDidLayout${id}`,
|
|
156
|
+
$key3: `containerColumn${id}`,
|
|
157
|
+
$key4: "numColumns",
|
|
150
158
|
$style: createStyle,
|
|
151
159
|
onLayout: (event) => {
|
|
152
160
|
const key = peek$(ctx, `containerItemKey${id}`);
|
|
@@ -486,6 +494,7 @@ var LegendListInner = React7.forwardRef(function LegendListInner2(props, forward
|
|
|
486
494
|
alignItemsAtEnd = false,
|
|
487
495
|
maintainVisibleContentPosition = false,
|
|
488
496
|
onScroll: onScrollProp,
|
|
497
|
+
numColumns: numColumnsProp = 1,
|
|
489
498
|
keyExtractor,
|
|
490
499
|
renderItem,
|
|
491
500
|
estimatedItemSize,
|
|
@@ -538,6 +547,7 @@ var LegendListInner = React7.forwardRef(function LegendListInner2(props, forward
|
|
|
538
547
|
refState.current = {
|
|
539
548
|
sizes: /* @__PURE__ */ new Map(),
|
|
540
549
|
positions: /* @__PURE__ */ new Map(),
|
|
550
|
+
columns: /* @__PURE__ */ new Map(),
|
|
541
551
|
pendingAdjust: 0,
|
|
542
552
|
animFrameLayout: null,
|
|
543
553
|
animFrameTotalSize: null,
|
|
@@ -576,12 +586,12 @@ var LegendListInner = React7.forwardRef(function LegendListInner2(props, forward
|
|
|
576
586
|
refState.current.scrollAdjustPending -= diff;
|
|
577
587
|
}
|
|
578
588
|
};
|
|
579
|
-
const addTotalSize = React7.useCallback((key, add
|
|
589
|
+
const addTotalSize = React7.useCallback((key, add) => {
|
|
580
590
|
const state = refState.current;
|
|
581
591
|
const index = key === null ? 0 : state.indexByKey.get(key);
|
|
582
592
|
const isAbove = key !== null && index < (state.startNoBuffer || 0);
|
|
583
593
|
const prev = state.totalSize;
|
|
584
|
-
if (
|
|
594
|
+
if (key === null) {
|
|
585
595
|
state.totalSize = add;
|
|
586
596
|
} else {
|
|
587
597
|
state.totalSize += add;
|
|
@@ -597,7 +607,7 @@ var LegendListInner = React7.forwardRef(function LegendListInner2(props, forward
|
|
|
597
607
|
if (isAbove) {
|
|
598
608
|
adjustScroll(add);
|
|
599
609
|
}
|
|
600
|
-
if (!prev ||
|
|
610
|
+
if (!prev || key === null) {
|
|
601
611
|
doAdd();
|
|
602
612
|
} else if (!state.animFrameTotalSize) {
|
|
603
613
|
state.animFrameTotalSize = requestAnimationFrame(doAdd);
|
|
@@ -606,7 +616,14 @@ var LegendListInner = React7.forwardRef(function LegendListInner2(props, forward
|
|
|
606
616
|
const calculateItemsInView = React7.useCallback((speed = 0) => {
|
|
607
617
|
var _a2, _b2, _c2;
|
|
608
618
|
const state = refState.current;
|
|
609
|
-
const {
|
|
619
|
+
const {
|
|
620
|
+
data: data2,
|
|
621
|
+
scrollLength,
|
|
622
|
+
scroll: scrollState,
|
|
623
|
+
startBuffered: startBufferedState,
|
|
624
|
+
positions,
|
|
625
|
+
columns
|
|
626
|
+
} = state;
|
|
610
627
|
if (state.animFrameLayout) {
|
|
611
628
|
cancelAnimationFrame(state.animFrameLayout);
|
|
612
629
|
state.animFrameLayout = null;
|
|
@@ -641,13 +658,24 @@ var LegendListInner = React7.forwardRef(function LegendListInner2(props, forward
|
|
|
641
658
|
}
|
|
642
659
|
}
|
|
643
660
|
}
|
|
661
|
+
const numColumns = peek$(ctx, "numColumns");
|
|
662
|
+
const loopStartMod = loopStart % numColumns;
|
|
663
|
+
if (loopStartMod > 0) {
|
|
664
|
+
loopStart -= loopStartMod;
|
|
665
|
+
}
|
|
644
666
|
let top = loopStart > 0 ? positions.get(getId(loopStart)) : 0;
|
|
667
|
+
let column = 1;
|
|
668
|
+
let maxSizeInRow = 0;
|
|
645
669
|
for (let i = loopStart; i < data2.length; i++) {
|
|
646
670
|
const id = getId(i);
|
|
647
671
|
const size = getItemSize(id, i, data2[i]);
|
|
672
|
+
maxSizeInRow = Math.max(maxSizeInRow, size);
|
|
648
673
|
if (positions.get(id) !== top) {
|
|
649
674
|
positions.set(id, top);
|
|
650
675
|
}
|
|
676
|
+
if (columns.get(id) !== column) {
|
|
677
|
+
columns.set(id, column);
|
|
678
|
+
}
|
|
651
679
|
if (startNoBuffer === null && top + size > scroll) {
|
|
652
680
|
startNoBuffer = i;
|
|
653
681
|
}
|
|
@@ -664,7 +692,12 @@ var LegendListInner = React7.forwardRef(function LegendListInner2(props, forward
|
|
|
664
692
|
break;
|
|
665
693
|
}
|
|
666
694
|
}
|
|
667
|
-
|
|
695
|
+
column++;
|
|
696
|
+
if (column > numColumns) {
|
|
697
|
+
top += maxSizeInRow;
|
|
698
|
+
column = 1;
|
|
699
|
+
maxSizeInRow = 0;
|
|
700
|
+
}
|
|
668
701
|
}
|
|
669
702
|
Object.assign(refState.current, {
|
|
670
703
|
startBuffered,
|
|
@@ -712,6 +745,7 @@ var LegendListInner = React7.forwardRef(function LegendListInner2(props, forward
|
|
|
712
745
|
numContainers++;
|
|
713
746
|
set$(ctx, `containerItemKey${containerId}`, id);
|
|
714
747
|
set$(ctx, `containerPosition${containerId}`, POSITION_OUT_OF_VIEW);
|
|
748
|
+
set$(ctx, `containerColumn${containerId}`, -1);
|
|
715
749
|
if (__DEV__ && numContainers > peek$(ctx, "numContainersPooled")) {
|
|
716
750
|
console.warn(
|
|
717
751
|
"[legend-list] No container to recycle, consider increasing initialContainers or estimatedItemSize. numContainers:",
|
|
@@ -735,10 +769,15 @@ var LegendListInner = React7.forwardRef(function LegendListInner2(props, forward
|
|
|
735
769
|
const id = getId(itemIndex);
|
|
736
770
|
if (!(itemKey !== id || itemIndex < startBuffered || itemIndex > endBuffered)) {
|
|
737
771
|
const pos = (positions.get(id) || 0) + scrollAdjustPending;
|
|
772
|
+
const column2 = columns.get(id) || 1;
|
|
738
773
|
const prevPos = peek$(ctx, `containerPosition${i}`);
|
|
774
|
+
const prevColumn = peek$(ctx, `containerColumn${i}`);
|
|
739
775
|
if (pos >= 0 && pos !== prevPos) {
|
|
740
776
|
set$(ctx, `containerPosition${i}`, pos);
|
|
741
777
|
}
|
|
778
|
+
if (column2 >= 0 && column2 !== prevColumn) {
|
|
779
|
+
set$(ctx, `containerColumn${i}`, column2);
|
|
780
|
+
}
|
|
742
781
|
}
|
|
743
782
|
}
|
|
744
783
|
}
|
|
@@ -819,20 +858,29 @@ var LegendListInner = React7.forwardRef(function LegendListInner2(props, forward
|
|
|
819
858
|
}
|
|
820
859
|
};
|
|
821
860
|
const isFirst = !refState.current.renderItem;
|
|
822
|
-
if (isFirst || data !== refState.current.data) {
|
|
861
|
+
if (isFirst || data !== refState.current.data || numColumnsProp !== peek$(ctx, "numColumns")) {
|
|
823
862
|
refState.current.data = data;
|
|
824
863
|
let totalSize = 0;
|
|
825
864
|
const indexByKey = /* @__PURE__ */ new Map();
|
|
865
|
+
let column = 1;
|
|
866
|
+
let maxSizeInRow = 0;
|
|
826
867
|
for (let i = 0; i < data.length; i++) {
|
|
827
868
|
const key = getId(i);
|
|
828
869
|
indexByKey.set(key, i);
|
|
829
|
-
|
|
870
|
+
const size = getItemSize(key, i, data[i]);
|
|
871
|
+
maxSizeInRow = Math.max(maxSizeInRow, size);
|
|
830
872
|
if (maintainVisibleContentPosition && i < refState.current.startNoBuffer && !refState.current.indexByKey.has(key)) {
|
|
831
|
-
const
|
|
832
|
-
adjustScroll(
|
|
873
|
+
const size2 = getItemSize(key, i, data[i]);
|
|
874
|
+
adjustScroll(size2);
|
|
875
|
+
}
|
|
876
|
+
column++;
|
|
877
|
+
if (column > numColumnsProp) {
|
|
878
|
+
totalSize += maxSizeInRow;
|
|
879
|
+
column = 1;
|
|
880
|
+
maxSizeInRow = 0;
|
|
833
881
|
}
|
|
834
882
|
}
|
|
835
|
-
addTotalSize(null, totalSize
|
|
883
|
+
addTotalSize(null, totalSize);
|
|
836
884
|
if (maintainVisibleContentPosition) {
|
|
837
885
|
for (const [key, index] of refState.current.indexByKey) {
|
|
838
886
|
if (index < refState.current.startNoBuffer && !indexByKey.has(key)) {
|
|
@@ -850,6 +898,7 @@ var LegendListInner = React7.forwardRef(function LegendListInner2(props, forward
|
|
|
850
898
|
for (let i = 0; i < numContainers; i++) {
|
|
851
899
|
set$(ctx, `containerItemKey${i}`, void 0);
|
|
852
900
|
set$(ctx, `containerPosition${i}`, POSITION_OUT_OF_VIEW);
|
|
901
|
+
set$(ctx, `containerColumn${i}`, -1);
|
|
853
902
|
}
|
|
854
903
|
calculateItemsInView();
|
|
855
904
|
doMaintainScrollAtEnd(false);
|
|
@@ -859,6 +908,7 @@ var LegendListInner = React7.forwardRef(function LegendListInner2(props, forward
|
|
|
859
908
|
}
|
|
860
909
|
refState.current.renderItem = renderItem;
|
|
861
910
|
set$(ctx, "lastItemKey", getId(data[data.length - 1]));
|
|
911
|
+
set$(ctx, "numColumns", numColumnsProp);
|
|
862
912
|
set$(
|
|
863
913
|
ctx,
|
|
864
914
|
"stylePaddingTop",
|
|
@@ -963,9 +1013,10 @@ var LegendListInner = React7.forwardRef(function LegendListInner2(props, forward
|
|
|
963
1013
|
refState.current.viewabilityConfigCallbackPairs = setupViewability(props);
|
|
964
1014
|
const scrollLength = refState.current.scrollLength;
|
|
965
1015
|
const averageItemSize = estimatedItemSize != null ? estimatedItemSize : getEstimatedItemSize == null ? void 0 : getEstimatedItemSize(0, data[0]);
|
|
966
|
-
const numContainers = initialNumContainers || Math.ceil((scrollLength + scrollBuffer * 2) / averageItemSize);
|
|
1016
|
+
const numContainers = (initialNumContainers || Math.ceil((scrollLength + scrollBuffer * 2) / averageItemSize)) * numColumnsProp;
|
|
967
1017
|
for (let i = 0; i < numContainers; i++) {
|
|
968
1018
|
set$(ctx, `containerPosition${i}`, POSITION_OUT_OF_VIEW);
|
|
1019
|
+
set$(ctx, `containerColumn${i}`, -1);
|
|
969
1020
|
}
|
|
970
1021
|
set$(ctx, "numContainers", numContainers);
|
|
971
1022
|
set$(ctx, "numContainersPooled", numContainers * 2);
|
|
@@ -977,13 +1028,35 @@ var LegendListInner = React7.forwardRef(function LegendListInner2(props, forward
|
|
|
977
1028
|
if (!data2) {
|
|
978
1029
|
return;
|
|
979
1030
|
}
|
|
980
|
-
const { sizes, indexByKey, idsInFirstRender } = refState.current;
|
|
1031
|
+
const { sizes, indexByKey, idsInFirstRender, columns } = refState.current;
|
|
981
1032
|
const index = indexByKey.get(key);
|
|
982
1033
|
const wasInFirstRender = idsInFirstRender.has(key);
|
|
983
1034
|
const prevSize = sizes.get(key) || (wasInFirstRender ? getItemSize(key, index, data2[index]) : 0);
|
|
984
1035
|
if (!prevSize || Math.abs(prevSize - size) > 0.5) {
|
|
985
|
-
|
|
986
|
-
|
|
1036
|
+
let diff;
|
|
1037
|
+
const numColumns = peek$(ctx, "numColumns");
|
|
1038
|
+
if (numColumns > 1) {
|
|
1039
|
+
const column = columns.get(key);
|
|
1040
|
+
const loopStart = index - (column - 1);
|
|
1041
|
+
let prevMaxSizeInRow = 0;
|
|
1042
|
+
for (let i = loopStart; i < loopStart + numColumns; i++) {
|
|
1043
|
+
const id = getId(i);
|
|
1044
|
+
const size2 = getItemSize(id, i, data2[i]);
|
|
1045
|
+
prevMaxSizeInRow = Math.max(prevMaxSizeInRow, size2);
|
|
1046
|
+
}
|
|
1047
|
+
sizes.set(key, size);
|
|
1048
|
+
let nextMaxSizeInRow = 0;
|
|
1049
|
+
for (let i = loopStart; i < loopStart + numColumns; i++) {
|
|
1050
|
+
const id = getId(i);
|
|
1051
|
+
const size2 = getItemSize(id, i, data2[i]);
|
|
1052
|
+
nextMaxSizeInRow = Math.max(nextMaxSizeInRow, size2);
|
|
1053
|
+
}
|
|
1054
|
+
diff = nextMaxSizeInRow - prevMaxSizeInRow;
|
|
1055
|
+
} else {
|
|
1056
|
+
sizes.set(key, size);
|
|
1057
|
+
diff = size - prevSize;
|
|
1058
|
+
}
|
|
1059
|
+
addTotalSize(key, diff);
|
|
987
1060
|
doMaintainScrollAtEnd(true);
|
|
988
1061
|
const state = refState.current;
|
|
989
1062
|
const scrollVelocity = state.scrollVelocity;
|
package/index.mjs
CHANGED
|
@@ -79,11 +79,11 @@ var LeanView = React7.forwardRef((props, ref) => {
|
|
|
79
79
|
LeanView.displayName = "RCTView";
|
|
80
80
|
|
|
81
81
|
// src/$View.tsx
|
|
82
|
-
function $View({ $key, $key2, $style, ...rest }) {
|
|
82
|
+
function $View({ $key, $key2, $key3, $key4, $style, ...rest }) {
|
|
83
83
|
use$($key);
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
84
|
+
$key2 && use$($key2);
|
|
85
|
+
$key3 && use$($key3);
|
|
86
|
+
$key4 && use$($key4);
|
|
87
87
|
const style = $style();
|
|
88
88
|
return /* @__PURE__ */ React7.createElement(LeanView, { style, ...rest });
|
|
89
89
|
}
|
|
@@ -107,17 +107,23 @@ var Container = ({
|
|
|
107
107
|
const ctx = useStateContext();
|
|
108
108
|
const createStyle = () => {
|
|
109
109
|
const position = peek$(ctx, `containerPosition${id}`);
|
|
110
|
+
const column = peek$(ctx, `containerColumn${id}`) || 0;
|
|
110
111
|
const visible = peek$(ctx, `containerDidLayout${id}`);
|
|
112
|
+
const numColumns = peek$(ctx, "numColumns");
|
|
113
|
+
const otherAxisPos = numColumns > 1 ? `${(column - 1) / numColumns * 100}%` : 0;
|
|
114
|
+
const otherAxisSize = numColumns > 1 ? `${1 / numColumns * 100}%` : void 0;
|
|
111
115
|
return horizontal ? {
|
|
112
116
|
flexDirection: "row",
|
|
113
117
|
position: "absolute",
|
|
114
|
-
top: visible ?
|
|
115
|
-
bottom: 0,
|
|
118
|
+
top: visible ? otherAxisPos : -1e7,
|
|
119
|
+
bottom: numColumns > 1 ? null : 0,
|
|
120
|
+
height: otherAxisSize,
|
|
116
121
|
left: position
|
|
117
122
|
} : {
|
|
118
123
|
position: "absolute",
|
|
119
|
-
left: visible ?
|
|
120
|
-
right: 0,
|
|
124
|
+
left: visible ? otherAxisPos : -1e7,
|
|
125
|
+
right: numColumns > 1 ? null : 0,
|
|
126
|
+
width: otherAxisSize,
|
|
121
127
|
top: position
|
|
122
128
|
};
|
|
123
129
|
};
|
|
@@ -126,6 +132,8 @@ var Container = ({
|
|
|
126
132
|
{
|
|
127
133
|
$key: `containerPosition${id}`,
|
|
128
134
|
$key2: `containerDidLayout${id}`,
|
|
135
|
+
$key3: `containerColumn${id}`,
|
|
136
|
+
$key4: "numColumns",
|
|
129
137
|
$style: createStyle,
|
|
130
138
|
onLayout: (event) => {
|
|
131
139
|
const key = peek$(ctx, `containerItemKey${id}`);
|
|
@@ -465,6 +473,7 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
|
|
|
465
473
|
alignItemsAtEnd = false,
|
|
466
474
|
maintainVisibleContentPosition = false,
|
|
467
475
|
onScroll: onScrollProp,
|
|
476
|
+
numColumns: numColumnsProp = 1,
|
|
468
477
|
keyExtractor,
|
|
469
478
|
renderItem,
|
|
470
479
|
estimatedItemSize,
|
|
@@ -517,6 +526,7 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
|
|
|
517
526
|
refState.current = {
|
|
518
527
|
sizes: /* @__PURE__ */ new Map(),
|
|
519
528
|
positions: /* @__PURE__ */ new Map(),
|
|
529
|
+
columns: /* @__PURE__ */ new Map(),
|
|
520
530
|
pendingAdjust: 0,
|
|
521
531
|
animFrameLayout: null,
|
|
522
532
|
animFrameTotalSize: null,
|
|
@@ -555,12 +565,12 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
|
|
|
555
565
|
refState.current.scrollAdjustPending -= diff;
|
|
556
566
|
}
|
|
557
567
|
};
|
|
558
|
-
const addTotalSize = useCallback((key, add
|
|
568
|
+
const addTotalSize = useCallback((key, add) => {
|
|
559
569
|
const state = refState.current;
|
|
560
570
|
const index = key === null ? 0 : state.indexByKey.get(key);
|
|
561
571
|
const isAbove = key !== null && index < (state.startNoBuffer || 0);
|
|
562
572
|
const prev = state.totalSize;
|
|
563
|
-
if (
|
|
573
|
+
if (key === null) {
|
|
564
574
|
state.totalSize = add;
|
|
565
575
|
} else {
|
|
566
576
|
state.totalSize += add;
|
|
@@ -576,7 +586,7 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
|
|
|
576
586
|
if (isAbove) {
|
|
577
587
|
adjustScroll(add);
|
|
578
588
|
}
|
|
579
|
-
if (!prev ||
|
|
589
|
+
if (!prev || key === null) {
|
|
580
590
|
doAdd();
|
|
581
591
|
} else if (!state.animFrameTotalSize) {
|
|
582
592
|
state.animFrameTotalSize = requestAnimationFrame(doAdd);
|
|
@@ -585,7 +595,14 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
|
|
|
585
595
|
const calculateItemsInView = useCallback((speed = 0) => {
|
|
586
596
|
var _a2, _b2, _c2;
|
|
587
597
|
const state = refState.current;
|
|
588
|
-
const {
|
|
598
|
+
const {
|
|
599
|
+
data: data2,
|
|
600
|
+
scrollLength,
|
|
601
|
+
scroll: scrollState,
|
|
602
|
+
startBuffered: startBufferedState,
|
|
603
|
+
positions,
|
|
604
|
+
columns
|
|
605
|
+
} = state;
|
|
589
606
|
if (state.animFrameLayout) {
|
|
590
607
|
cancelAnimationFrame(state.animFrameLayout);
|
|
591
608
|
state.animFrameLayout = null;
|
|
@@ -620,13 +637,24 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
|
|
|
620
637
|
}
|
|
621
638
|
}
|
|
622
639
|
}
|
|
640
|
+
const numColumns = peek$(ctx, "numColumns");
|
|
641
|
+
const loopStartMod = loopStart % numColumns;
|
|
642
|
+
if (loopStartMod > 0) {
|
|
643
|
+
loopStart -= loopStartMod;
|
|
644
|
+
}
|
|
623
645
|
let top = loopStart > 0 ? positions.get(getId(loopStart)) : 0;
|
|
646
|
+
let column = 1;
|
|
647
|
+
let maxSizeInRow = 0;
|
|
624
648
|
for (let i = loopStart; i < data2.length; i++) {
|
|
625
649
|
const id = getId(i);
|
|
626
650
|
const size = getItemSize(id, i, data2[i]);
|
|
651
|
+
maxSizeInRow = Math.max(maxSizeInRow, size);
|
|
627
652
|
if (positions.get(id) !== top) {
|
|
628
653
|
positions.set(id, top);
|
|
629
654
|
}
|
|
655
|
+
if (columns.get(id) !== column) {
|
|
656
|
+
columns.set(id, column);
|
|
657
|
+
}
|
|
630
658
|
if (startNoBuffer === null && top + size > scroll) {
|
|
631
659
|
startNoBuffer = i;
|
|
632
660
|
}
|
|
@@ -643,7 +671,12 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
|
|
|
643
671
|
break;
|
|
644
672
|
}
|
|
645
673
|
}
|
|
646
|
-
|
|
674
|
+
column++;
|
|
675
|
+
if (column > numColumns) {
|
|
676
|
+
top += maxSizeInRow;
|
|
677
|
+
column = 1;
|
|
678
|
+
maxSizeInRow = 0;
|
|
679
|
+
}
|
|
647
680
|
}
|
|
648
681
|
Object.assign(refState.current, {
|
|
649
682
|
startBuffered,
|
|
@@ -691,6 +724,7 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
|
|
|
691
724
|
numContainers++;
|
|
692
725
|
set$(ctx, `containerItemKey${containerId}`, id);
|
|
693
726
|
set$(ctx, `containerPosition${containerId}`, POSITION_OUT_OF_VIEW);
|
|
727
|
+
set$(ctx, `containerColumn${containerId}`, -1);
|
|
694
728
|
if (__DEV__ && numContainers > peek$(ctx, "numContainersPooled")) {
|
|
695
729
|
console.warn(
|
|
696
730
|
"[legend-list] No container to recycle, consider increasing initialContainers or estimatedItemSize. numContainers:",
|
|
@@ -714,10 +748,15 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
|
|
|
714
748
|
const id = getId(itemIndex);
|
|
715
749
|
if (!(itemKey !== id || itemIndex < startBuffered || itemIndex > endBuffered)) {
|
|
716
750
|
const pos = (positions.get(id) || 0) + scrollAdjustPending;
|
|
751
|
+
const column2 = columns.get(id) || 1;
|
|
717
752
|
const prevPos = peek$(ctx, `containerPosition${i}`);
|
|
753
|
+
const prevColumn = peek$(ctx, `containerColumn${i}`);
|
|
718
754
|
if (pos >= 0 && pos !== prevPos) {
|
|
719
755
|
set$(ctx, `containerPosition${i}`, pos);
|
|
720
756
|
}
|
|
757
|
+
if (column2 >= 0 && column2 !== prevColumn) {
|
|
758
|
+
set$(ctx, `containerColumn${i}`, column2);
|
|
759
|
+
}
|
|
721
760
|
}
|
|
722
761
|
}
|
|
723
762
|
}
|
|
@@ -798,20 +837,29 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
|
|
|
798
837
|
}
|
|
799
838
|
};
|
|
800
839
|
const isFirst = !refState.current.renderItem;
|
|
801
|
-
if (isFirst || data !== refState.current.data) {
|
|
840
|
+
if (isFirst || data !== refState.current.data || numColumnsProp !== peek$(ctx, "numColumns")) {
|
|
802
841
|
refState.current.data = data;
|
|
803
842
|
let totalSize = 0;
|
|
804
843
|
const indexByKey = /* @__PURE__ */ new Map();
|
|
844
|
+
let column = 1;
|
|
845
|
+
let maxSizeInRow = 0;
|
|
805
846
|
for (let i = 0; i < data.length; i++) {
|
|
806
847
|
const key = getId(i);
|
|
807
848
|
indexByKey.set(key, i);
|
|
808
|
-
|
|
849
|
+
const size = getItemSize(key, i, data[i]);
|
|
850
|
+
maxSizeInRow = Math.max(maxSizeInRow, size);
|
|
809
851
|
if (maintainVisibleContentPosition && i < refState.current.startNoBuffer && !refState.current.indexByKey.has(key)) {
|
|
810
|
-
const
|
|
811
|
-
adjustScroll(
|
|
852
|
+
const size2 = getItemSize(key, i, data[i]);
|
|
853
|
+
adjustScroll(size2);
|
|
854
|
+
}
|
|
855
|
+
column++;
|
|
856
|
+
if (column > numColumnsProp) {
|
|
857
|
+
totalSize += maxSizeInRow;
|
|
858
|
+
column = 1;
|
|
859
|
+
maxSizeInRow = 0;
|
|
812
860
|
}
|
|
813
861
|
}
|
|
814
|
-
addTotalSize(null, totalSize
|
|
862
|
+
addTotalSize(null, totalSize);
|
|
815
863
|
if (maintainVisibleContentPosition) {
|
|
816
864
|
for (const [key, index] of refState.current.indexByKey) {
|
|
817
865
|
if (index < refState.current.startNoBuffer && !indexByKey.has(key)) {
|
|
@@ -829,6 +877,7 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
|
|
|
829
877
|
for (let i = 0; i < numContainers; i++) {
|
|
830
878
|
set$(ctx, `containerItemKey${i}`, void 0);
|
|
831
879
|
set$(ctx, `containerPosition${i}`, POSITION_OUT_OF_VIEW);
|
|
880
|
+
set$(ctx, `containerColumn${i}`, -1);
|
|
832
881
|
}
|
|
833
882
|
calculateItemsInView();
|
|
834
883
|
doMaintainScrollAtEnd(false);
|
|
@@ -838,6 +887,7 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
|
|
|
838
887
|
}
|
|
839
888
|
refState.current.renderItem = renderItem;
|
|
840
889
|
set$(ctx, "lastItemKey", getId(data[data.length - 1]));
|
|
890
|
+
set$(ctx, "numColumns", numColumnsProp);
|
|
841
891
|
set$(
|
|
842
892
|
ctx,
|
|
843
893
|
"stylePaddingTop",
|
|
@@ -942,9 +992,10 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
|
|
|
942
992
|
refState.current.viewabilityConfigCallbackPairs = setupViewability(props);
|
|
943
993
|
const scrollLength = refState.current.scrollLength;
|
|
944
994
|
const averageItemSize = estimatedItemSize != null ? estimatedItemSize : getEstimatedItemSize == null ? void 0 : getEstimatedItemSize(0, data[0]);
|
|
945
|
-
const numContainers = initialNumContainers || Math.ceil((scrollLength + scrollBuffer * 2) / averageItemSize);
|
|
995
|
+
const numContainers = (initialNumContainers || Math.ceil((scrollLength + scrollBuffer * 2) / averageItemSize)) * numColumnsProp;
|
|
946
996
|
for (let i = 0; i < numContainers; i++) {
|
|
947
997
|
set$(ctx, `containerPosition${i}`, POSITION_OUT_OF_VIEW);
|
|
998
|
+
set$(ctx, `containerColumn${i}`, -1);
|
|
948
999
|
}
|
|
949
1000
|
set$(ctx, "numContainers", numContainers);
|
|
950
1001
|
set$(ctx, "numContainersPooled", numContainers * 2);
|
|
@@ -956,13 +1007,35 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
|
|
|
956
1007
|
if (!data2) {
|
|
957
1008
|
return;
|
|
958
1009
|
}
|
|
959
|
-
const { sizes, indexByKey, idsInFirstRender } = refState.current;
|
|
1010
|
+
const { sizes, indexByKey, idsInFirstRender, columns } = refState.current;
|
|
960
1011
|
const index = indexByKey.get(key);
|
|
961
1012
|
const wasInFirstRender = idsInFirstRender.has(key);
|
|
962
1013
|
const prevSize = sizes.get(key) || (wasInFirstRender ? getItemSize(key, index, data2[index]) : 0);
|
|
963
1014
|
if (!prevSize || Math.abs(prevSize - size) > 0.5) {
|
|
964
|
-
|
|
965
|
-
|
|
1015
|
+
let diff;
|
|
1016
|
+
const numColumns = peek$(ctx, "numColumns");
|
|
1017
|
+
if (numColumns > 1) {
|
|
1018
|
+
const column = columns.get(key);
|
|
1019
|
+
const loopStart = index - (column - 1);
|
|
1020
|
+
let prevMaxSizeInRow = 0;
|
|
1021
|
+
for (let i = loopStart; i < loopStart + numColumns; i++) {
|
|
1022
|
+
const id = getId(i);
|
|
1023
|
+
const size2 = getItemSize(id, i, data2[i]);
|
|
1024
|
+
prevMaxSizeInRow = Math.max(prevMaxSizeInRow, size2);
|
|
1025
|
+
}
|
|
1026
|
+
sizes.set(key, size);
|
|
1027
|
+
let nextMaxSizeInRow = 0;
|
|
1028
|
+
for (let i = loopStart; i < loopStart + numColumns; i++) {
|
|
1029
|
+
const id = getId(i);
|
|
1030
|
+
const size2 = getItemSize(id, i, data2[i]);
|
|
1031
|
+
nextMaxSizeInRow = Math.max(nextMaxSizeInRow, size2);
|
|
1032
|
+
}
|
|
1033
|
+
diff = nextMaxSizeInRow - prevMaxSizeInRow;
|
|
1034
|
+
} else {
|
|
1035
|
+
sizes.set(key, size);
|
|
1036
|
+
diff = size - prevSize;
|
|
1037
|
+
}
|
|
1038
|
+
addTotalSize(key, diff);
|
|
966
1039
|
doMaintainScrollAtEnd(true);
|
|
967
1040
|
const state = refState.current;
|
|
968
1041
|
const scrollVelocity = state.scrollVelocity;
|