@legendapp/list 0.6.4 → 1.0.0-beta.1
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/README.md +4 -1
- package/index.d.mts +7 -2
- package/index.d.ts +7 -2
- package/index.js +39 -27
- package/index.mjs +40 -28
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -14,6 +14,10 @@ In addition to normal FlatList features:
|
|
|
14
14
|
- `maintainScrollAtEnd`: If true and scroll is within `maintainScrollAtEndThreshold * screen height` then changing items or heights will scroll to the bottom. This can be useful for chat interfaces.
|
|
15
15
|
- `recycleItems` prop enables toggling recycling of list items. If enabled it will reuse item components for improved performance, but it will reuse any local state in items. So if you have local state in items you likely want this disabled.
|
|
16
16
|
|
|
17
|
+
## Documentation
|
|
18
|
+
|
|
19
|
+
See the [documentation site](https://www.legendapp.com/open-source/list) for the full documentation.
|
|
20
|
+
|
|
17
21
|
## Usage
|
|
18
22
|
|
|
19
23
|
## Install
|
|
@@ -41,7 +45,6 @@ interface PropsOptional {
|
|
|
41
45
|
initialScrollOffset?: number;
|
|
42
46
|
initialScrollIndex?: number;
|
|
43
47
|
drawDistance?: number;
|
|
44
|
-
initialContainers?: number;
|
|
45
48
|
recycleItems?: boolean;
|
|
46
49
|
onEndReachedThreshold?: number | null | undefined;
|
|
47
50
|
maintainScrollAtEnd?: boolean;
|
package/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ComponentProps, ReactNode, ForwardedRef, ReactElement } from 'react';
|
|
2
|
-
import { ScrollView, StyleProp, ViewStyle, ScrollViewComponent, ScrollResponderMixin } from 'react-native';
|
|
2
|
+
import { ScrollView, StyleProp, ViewStyle, ScrollViewProps, ScrollViewComponent, ScrollResponderMixin } from 'react-native';
|
|
3
3
|
import Animated from 'react-native-reanimated';
|
|
4
4
|
|
|
5
5
|
declare class ScrollAdjustHandler {
|
|
@@ -19,7 +19,6 @@ type LegendListPropsBase<ItemT, TScrollView extends ComponentProps<typeof Scroll
|
|
|
19
19
|
initialScrollOffset?: number;
|
|
20
20
|
initialScrollIndex?: number;
|
|
21
21
|
drawDistance?: number;
|
|
22
|
-
initialNumContainers?: number;
|
|
23
22
|
recycleItems?: boolean;
|
|
24
23
|
onEndReachedThreshold?: number | null | undefined;
|
|
25
24
|
onStartReachedThreshold?: number | null | undefined;
|
|
@@ -57,6 +56,11 @@ type LegendListPropsBase<ItemT, TScrollView extends ComponentProps<typeof Scroll
|
|
|
57
56
|
itemKey: string;
|
|
58
57
|
itemData: ItemT;
|
|
59
58
|
}) => void;
|
|
59
|
+
/**
|
|
60
|
+
* Render custom ScrollView component.
|
|
61
|
+
* @default (props) => <ScrollView {...props} />
|
|
62
|
+
*/
|
|
63
|
+
renderScrollComponent?: (props: ScrollViewProps) => React.ReactElement<ScrollViewProps>;
|
|
60
64
|
};
|
|
61
65
|
type LegendListProps<ItemT> = LegendListPropsBase<ItemT, ComponentProps<typeof ScrollView>>;
|
|
62
66
|
interface InternalState {
|
|
@@ -110,6 +114,7 @@ interface InternalState {
|
|
|
110
114
|
top: number;
|
|
111
115
|
bottom: number;
|
|
112
116
|
} | undefined;
|
|
117
|
+
enableScrollForNextCalculateItemsInView: boolean;
|
|
113
118
|
}
|
|
114
119
|
interface ViewableRange<T> {
|
|
115
120
|
startBuffered: number;
|
package/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ComponentProps, ReactNode, ForwardedRef, ReactElement } from 'react';
|
|
2
|
-
import { ScrollView, StyleProp, ViewStyle, ScrollViewComponent, ScrollResponderMixin } from 'react-native';
|
|
2
|
+
import { ScrollView, StyleProp, ViewStyle, ScrollViewProps, ScrollViewComponent, ScrollResponderMixin } from 'react-native';
|
|
3
3
|
import Animated from 'react-native-reanimated';
|
|
4
4
|
|
|
5
5
|
declare class ScrollAdjustHandler {
|
|
@@ -19,7 +19,6 @@ type LegendListPropsBase<ItemT, TScrollView extends ComponentProps<typeof Scroll
|
|
|
19
19
|
initialScrollOffset?: number;
|
|
20
20
|
initialScrollIndex?: number;
|
|
21
21
|
drawDistance?: number;
|
|
22
|
-
initialNumContainers?: number;
|
|
23
22
|
recycleItems?: boolean;
|
|
24
23
|
onEndReachedThreshold?: number | null | undefined;
|
|
25
24
|
onStartReachedThreshold?: number | null | undefined;
|
|
@@ -57,6 +56,11 @@ type LegendListPropsBase<ItemT, TScrollView extends ComponentProps<typeof Scroll
|
|
|
57
56
|
itemKey: string;
|
|
58
57
|
itemData: ItemT;
|
|
59
58
|
}) => void;
|
|
59
|
+
/**
|
|
60
|
+
* Render custom ScrollView component.
|
|
61
|
+
* @default (props) => <ScrollView {...props} />
|
|
62
|
+
*/
|
|
63
|
+
renderScrollComponent?: (props: ScrollViewProps) => React.ReactElement<ScrollViewProps>;
|
|
60
64
|
};
|
|
61
65
|
type LegendListProps<ItemT> = LegendListPropsBase<ItemT, ComponentProps<typeof ScrollView>>;
|
|
62
66
|
interface InternalState {
|
|
@@ -110,6 +114,7 @@ interface InternalState {
|
|
|
110
114
|
top: number;
|
|
111
115
|
bottom: number;
|
|
112
116
|
} | undefined;
|
|
117
|
+
enableScrollForNextCalculateItemsInView: boolean;
|
|
113
118
|
}
|
|
114
119
|
interface ViewableRange<T> {
|
|
115
120
|
startBuffered: number;
|
package/index.js
CHANGED
|
@@ -208,14 +208,19 @@ var ListComponent = React4__namespace.memo(function ListComponent2({
|
|
|
208
208
|
updateItemSize,
|
|
209
209
|
refScrollView,
|
|
210
210
|
maintainVisibleContentPosition,
|
|
211
|
+
renderScrollComponent,
|
|
211
212
|
...rest
|
|
212
213
|
}) {
|
|
213
214
|
const ctx = useStateContext();
|
|
214
215
|
const animPaddingTop = useValue$("paddingTop");
|
|
215
216
|
const animScrollAdjust = useValue$("scrollAdjust");
|
|
217
|
+
const ScrollComponent = renderScrollComponent ? React4.useMemo(
|
|
218
|
+
() => React4__namespace.forwardRef((props, ref) => renderScrollComponent({ ...props, ref })),
|
|
219
|
+
[renderScrollComponent]
|
|
220
|
+
) : reactNative.ScrollView;
|
|
216
221
|
const additionalSize = { marginTop: animScrollAdjust, paddingTop: animPaddingTop };
|
|
217
222
|
return /* @__PURE__ */ React4__namespace.createElement(
|
|
218
|
-
|
|
223
|
+
ScrollComponent,
|
|
219
224
|
{
|
|
220
225
|
...rest,
|
|
221
226
|
style,
|
|
@@ -469,7 +474,6 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
|
|
|
469
474
|
initialScrollIndex,
|
|
470
475
|
initialScrollOffset,
|
|
471
476
|
horizontal,
|
|
472
|
-
initialNumContainers,
|
|
473
477
|
drawDistance = 250,
|
|
474
478
|
recycleItems = false,
|
|
475
479
|
onEndReachedThreshold = 0.5,
|
|
@@ -573,7 +577,8 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
|
|
|
573
577
|
rowHeights: /* @__PURE__ */ new Map(),
|
|
574
578
|
startReachedBlockedByTimer: false,
|
|
575
579
|
layoutsPending: /* @__PURE__ */ new Set(),
|
|
576
|
-
scrollForNextCalculateItemsInView: void 0
|
|
580
|
+
scrollForNextCalculateItemsInView: void 0,
|
|
581
|
+
enableScrollForNextCalculateItemsInView: true
|
|
577
582
|
};
|
|
578
583
|
refState.current.idsInFirstRender = new Set(data.map((_, i) => getId(i)));
|
|
579
584
|
if (maintainVisibleContentPosition) {
|
|
@@ -651,7 +656,7 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
|
|
|
651
656
|
}
|
|
652
657
|
let rowHeight = 0;
|
|
653
658
|
const startEl = n * numColumnsProp;
|
|
654
|
-
for (let i = startEl; i < startEl + numColumnsProp; i++) {
|
|
659
|
+
for (let i = startEl; i < startEl + numColumnsProp && i < data.length; i++) {
|
|
655
660
|
const id = getId(i);
|
|
656
661
|
const size = getItemSize(id, i, data[i]);
|
|
657
662
|
rowHeight = Math.max(rowHeight, size);
|
|
@@ -692,7 +697,6 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
|
|
|
692
697
|
return res;
|
|
693
698
|
};
|
|
694
699
|
const calculateItemsInView = React4.useCallback((speed) => {
|
|
695
|
-
var _a2, _b2, _c2, _d2;
|
|
696
700
|
const state = refState.current;
|
|
697
701
|
const {
|
|
698
702
|
data: data2,
|
|
@@ -715,8 +719,8 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
|
|
|
715
719
|
const previousScrollAdjust = scrollAdjustHandler.getAppliedAdjust();
|
|
716
720
|
const scrollExtra = Math.max(-16, Math.min(16, speed)) * 16;
|
|
717
721
|
const scroll = scrollState - previousScrollAdjust - topPad - scrollExtra;
|
|
718
|
-
if (
|
|
719
|
-
const { top: top2, bottom } =
|
|
722
|
+
if (state.scrollForNextCalculateItemsInView) {
|
|
723
|
+
const { top: top2, bottom } = state.scrollForNextCalculateItemsInView;
|
|
720
724
|
if (scroll > top2 && scroll < bottom) {
|
|
721
725
|
return;
|
|
722
726
|
}
|
|
@@ -759,13 +763,13 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
|
|
|
759
763
|
let column = 1;
|
|
760
764
|
let maxSizeInRow = 0;
|
|
761
765
|
const getInitialTop = (i) => {
|
|
762
|
-
var
|
|
766
|
+
var _a2;
|
|
763
767
|
const id = getId(i);
|
|
764
768
|
let topOffset = 0;
|
|
765
769
|
if (positions.get(id)) {
|
|
766
770
|
topOffset = positions.get(id);
|
|
767
771
|
}
|
|
768
|
-
if (id === ((
|
|
772
|
+
if (id === ((_a2 = state.anchorElement) == null ? void 0 : _a2.id)) {
|
|
769
773
|
topOffset = initialContentOffset || 0;
|
|
770
774
|
}
|
|
771
775
|
return topOffset;
|
|
@@ -807,7 +811,7 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
|
|
|
807
811
|
maxSizeInRow = 0;
|
|
808
812
|
}
|
|
809
813
|
}
|
|
810
|
-
Object.assign(
|
|
814
|
+
Object.assign(state, {
|
|
811
815
|
startBuffered,
|
|
812
816
|
startBufferedId,
|
|
813
817
|
startNoBuffer,
|
|
@@ -818,10 +822,12 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
|
|
|
818
822
|
const nextBottom = Math.floor(
|
|
819
823
|
endBuffered ? (positions.get(getId(endBuffered + 1)) || 0) - scrollLength - scrollBuffer : 0
|
|
820
824
|
);
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
+
if (state.enableScrollForNextCalculateItemsInView) {
|
|
826
|
+
state.scrollForNextCalculateItemsInView = nextTop >= 0 && nextBottom >= 0 ? {
|
|
827
|
+
top: nextTop,
|
|
828
|
+
bottom: nextBottom
|
|
829
|
+
} : void 0;
|
|
830
|
+
}
|
|
825
831
|
if (startBuffered !== null && endBuffered !== null) {
|
|
826
832
|
const prevNumContainers = ctx.values.get("numContainers");
|
|
827
833
|
let numContainers = prevNumContainers;
|
|
@@ -845,7 +851,7 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
|
|
|
845
851
|
furthestIndex = u;
|
|
846
852
|
break;
|
|
847
853
|
}
|
|
848
|
-
const index =
|
|
854
|
+
const index = state.indexByKey.get(key);
|
|
849
855
|
const pos = peek$(ctx, `containerPosition${u}`);
|
|
850
856
|
if (index < startBuffered || index > endBuffered) {
|
|
851
857
|
const distance = Math.abs(pos - top2);
|
|
@@ -857,19 +863,19 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
|
|
|
857
863
|
}
|
|
858
864
|
if (furthestIndex >= 0) {
|
|
859
865
|
set$(ctx, `containerItemKey${furthestIndex}`, id);
|
|
860
|
-
const index =
|
|
866
|
+
const index = state.indexByKey.get(id);
|
|
861
867
|
set$(ctx, `containerItemData${furthestIndex}`, data2[index]);
|
|
862
868
|
} else {
|
|
863
869
|
const containerId = numContainers;
|
|
864
870
|
numContainers++;
|
|
865
871
|
set$(ctx, `containerItemKey${containerId}`, id);
|
|
866
|
-
const index =
|
|
872
|
+
const index = state.indexByKey.get(id);
|
|
867
873
|
set$(ctx, `containerItemData${containerId}`, data2[index]);
|
|
868
874
|
set$(ctx, `containerPosition${containerId}`, POSITION_OUT_OF_VIEW);
|
|
869
875
|
set$(ctx, `containerColumn${containerId}`, -1);
|
|
870
876
|
if (__DEV__ && numContainers > peek$(ctx, "numContainersPooled")) {
|
|
871
877
|
console.warn(
|
|
872
|
-
"[legend-list] No container to recycle,
|
|
878
|
+
"[legend-list] No container to recycle, so creating one on demand. This can be a performance issue and is likely caused by the estimatedItemSize being too small. Consider increasing estimatedItemSize. numContainers:",
|
|
873
879
|
numContainers
|
|
874
880
|
);
|
|
875
881
|
}
|
|
@@ -884,7 +890,7 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
|
|
|
884
890
|
}
|
|
885
891
|
for (let i = 0; i < numContainers; i++) {
|
|
886
892
|
const itemKey = peek$(ctx, `containerItemKey${i}`);
|
|
887
|
-
const itemIndex =
|
|
893
|
+
const itemIndex = state.indexByKey.get(itemKey);
|
|
888
894
|
const item = data2[itemIndex];
|
|
889
895
|
if (item) {
|
|
890
896
|
const id = getId(itemIndex);
|
|
@@ -920,11 +926,11 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
|
|
|
920
926
|
}
|
|
921
927
|
layoutsPending.clear();
|
|
922
928
|
}
|
|
923
|
-
if (
|
|
929
|
+
if (state.viewabilityConfigCallbackPairs) {
|
|
924
930
|
updateViewableItems(
|
|
925
|
-
|
|
931
|
+
state,
|
|
926
932
|
ctx,
|
|
927
|
-
|
|
933
|
+
state.viewabilityConfigCallbackPairs,
|
|
928
934
|
getId,
|
|
929
935
|
scrollLength,
|
|
930
936
|
startNoBuffer,
|
|
@@ -1062,6 +1068,9 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
|
|
|
1062
1068
|
maxSizeInRow = 0;
|
|
1063
1069
|
}
|
|
1064
1070
|
}
|
|
1071
|
+
if (maxSizeInRow > 0) {
|
|
1072
|
+
totalSize += maxSizeInRow;
|
|
1073
|
+
}
|
|
1065
1074
|
addTotalSize(null, totalSize, totalSizeBelowIndex);
|
|
1066
1075
|
}
|
|
1067
1076
|
React4.useEffect(() => {
|
|
@@ -1179,17 +1188,20 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
|
|
|
1179
1188
|
}, []);
|
|
1180
1189
|
useInit(() => {
|
|
1181
1190
|
var _a2;
|
|
1182
|
-
refState.current
|
|
1183
|
-
const
|
|
1191
|
+
const state = refState.current;
|
|
1192
|
+
const viewability = setupViewability(props);
|
|
1193
|
+
state.viewabilityConfigCallbackPairs = viewability;
|
|
1194
|
+
state.enableScrollForNextCalculateItemsInView = !viewability;
|
|
1195
|
+
const scrollLength = state.scrollLength;
|
|
1184
1196
|
const averageItemSize = (_a2 = estimatedItemSize != null ? estimatedItemSize : getEstimatedItemSize == null ? void 0 : getEstimatedItemSize(0, data[0])) != null ? _a2 : DEFAULT_ITEM_SIZE;
|
|
1185
|
-
const numContainers =
|
|
1197
|
+
const numContainers = Math.ceil((scrollLength + scrollBuffer * 2) / averageItemSize) * numColumnsProp;
|
|
1186
1198
|
for (let i = 0; i < numContainers; i++) {
|
|
1187
1199
|
set$(ctx, `containerPosition${i}`, POSITION_OUT_OF_VIEW);
|
|
1188
1200
|
set$(ctx, `containerColumn${i}`, -1);
|
|
1189
1201
|
}
|
|
1190
1202
|
set$(ctx, "numContainers", numContainers);
|
|
1191
1203
|
set$(ctx, "numContainersPooled", numContainers * 2);
|
|
1192
|
-
calculateItemsInView(
|
|
1204
|
+
calculateItemsInView(state.scrollVelocity);
|
|
1193
1205
|
});
|
|
1194
1206
|
const updateItemSize = React4.useCallback((containerId, itemKey, size) => {
|
|
1195
1207
|
var _a2;
|
|
@@ -1215,7 +1227,7 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
|
|
|
1215
1227
|
const column = columns.get(itemKey);
|
|
1216
1228
|
const loopStart = index - (column - 1);
|
|
1217
1229
|
let nextMaxSizeInRow = 0;
|
|
1218
|
-
for (let i = loopStart; i < loopStart + numColumns; i++) {
|
|
1230
|
+
for (let i = loopStart; i < loopStart + numColumns && i < data2.length; i++) {
|
|
1219
1231
|
const id = getId(i);
|
|
1220
1232
|
const size2 = getItemSize(id, i, data2[i]);
|
|
1221
1233
|
nextMaxSizeInRow = Math.max(nextMaxSizeInRow, size2);
|
package/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React4 from 'react';
|
|
2
|
-
import React4__default, { forwardRef, useRef,
|
|
2
|
+
import React4__default, { useMemo, forwardRef, useRef, useCallback, useEffect, useImperativeHandle, useSyncExternalStore, useState } from 'react';
|
|
3
3
|
import { Animated, ScrollView, View, Dimensions, StyleSheet, Platform, useAnimatedValue as useAnimatedValue$1 } from 'react-native';
|
|
4
4
|
|
|
5
5
|
// src/LegendList.tsx
|
|
@@ -187,14 +187,19 @@ var ListComponent = React4.memo(function ListComponent2({
|
|
|
187
187
|
updateItemSize,
|
|
188
188
|
refScrollView,
|
|
189
189
|
maintainVisibleContentPosition,
|
|
190
|
+
renderScrollComponent,
|
|
190
191
|
...rest
|
|
191
192
|
}) {
|
|
192
193
|
const ctx = useStateContext();
|
|
193
194
|
const animPaddingTop = useValue$("paddingTop");
|
|
194
195
|
const animScrollAdjust = useValue$("scrollAdjust");
|
|
196
|
+
const ScrollComponent = renderScrollComponent ? useMemo(
|
|
197
|
+
() => React4.forwardRef((props, ref) => renderScrollComponent({ ...props, ref })),
|
|
198
|
+
[renderScrollComponent]
|
|
199
|
+
) : ScrollView;
|
|
195
200
|
const additionalSize = { marginTop: animScrollAdjust, paddingTop: animPaddingTop };
|
|
196
201
|
return /* @__PURE__ */ React4.createElement(
|
|
197
|
-
|
|
202
|
+
ScrollComponent,
|
|
198
203
|
{
|
|
199
204
|
...rest,
|
|
200
205
|
style,
|
|
@@ -448,7 +453,6 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
|
|
|
448
453
|
initialScrollIndex,
|
|
449
454
|
initialScrollOffset,
|
|
450
455
|
horizontal,
|
|
451
|
-
initialNumContainers,
|
|
452
456
|
drawDistance = 250,
|
|
453
457
|
recycleItems = false,
|
|
454
458
|
onEndReachedThreshold = 0.5,
|
|
@@ -552,7 +556,8 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
|
|
|
552
556
|
rowHeights: /* @__PURE__ */ new Map(),
|
|
553
557
|
startReachedBlockedByTimer: false,
|
|
554
558
|
layoutsPending: /* @__PURE__ */ new Set(),
|
|
555
|
-
scrollForNextCalculateItemsInView: void 0
|
|
559
|
+
scrollForNextCalculateItemsInView: void 0,
|
|
560
|
+
enableScrollForNextCalculateItemsInView: true
|
|
556
561
|
};
|
|
557
562
|
refState.current.idsInFirstRender = new Set(data.map((_, i) => getId(i)));
|
|
558
563
|
if (maintainVisibleContentPosition) {
|
|
@@ -630,7 +635,7 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
|
|
|
630
635
|
}
|
|
631
636
|
let rowHeight = 0;
|
|
632
637
|
const startEl = n * numColumnsProp;
|
|
633
|
-
for (let i = startEl; i < startEl + numColumnsProp; i++) {
|
|
638
|
+
for (let i = startEl; i < startEl + numColumnsProp && i < data.length; i++) {
|
|
634
639
|
const id = getId(i);
|
|
635
640
|
const size = getItemSize(id, i, data[i]);
|
|
636
641
|
rowHeight = Math.max(rowHeight, size);
|
|
@@ -671,7 +676,6 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
|
|
|
671
676
|
return res;
|
|
672
677
|
};
|
|
673
678
|
const calculateItemsInView = useCallback((speed) => {
|
|
674
|
-
var _a2, _b2, _c2, _d2;
|
|
675
679
|
const state = refState.current;
|
|
676
680
|
const {
|
|
677
681
|
data: data2,
|
|
@@ -694,8 +698,8 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
|
|
|
694
698
|
const previousScrollAdjust = scrollAdjustHandler.getAppliedAdjust();
|
|
695
699
|
const scrollExtra = Math.max(-16, Math.min(16, speed)) * 16;
|
|
696
700
|
const scroll = scrollState - previousScrollAdjust - topPad - scrollExtra;
|
|
697
|
-
if (
|
|
698
|
-
const { top: top2, bottom } =
|
|
701
|
+
if (state.scrollForNextCalculateItemsInView) {
|
|
702
|
+
const { top: top2, bottom } = state.scrollForNextCalculateItemsInView;
|
|
699
703
|
if (scroll > top2 && scroll < bottom) {
|
|
700
704
|
return;
|
|
701
705
|
}
|
|
@@ -738,13 +742,13 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
|
|
|
738
742
|
let column = 1;
|
|
739
743
|
let maxSizeInRow = 0;
|
|
740
744
|
const getInitialTop = (i) => {
|
|
741
|
-
var
|
|
745
|
+
var _a2;
|
|
742
746
|
const id = getId(i);
|
|
743
747
|
let topOffset = 0;
|
|
744
748
|
if (positions.get(id)) {
|
|
745
749
|
topOffset = positions.get(id);
|
|
746
750
|
}
|
|
747
|
-
if (id === ((
|
|
751
|
+
if (id === ((_a2 = state.anchorElement) == null ? void 0 : _a2.id)) {
|
|
748
752
|
topOffset = initialContentOffset || 0;
|
|
749
753
|
}
|
|
750
754
|
return topOffset;
|
|
@@ -786,7 +790,7 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
|
|
|
786
790
|
maxSizeInRow = 0;
|
|
787
791
|
}
|
|
788
792
|
}
|
|
789
|
-
Object.assign(
|
|
793
|
+
Object.assign(state, {
|
|
790
794
|
startBuffered,
|
|
791
795
|
startBufferedId,
|
|
792
796
|
startNoBuffer,
|
|
@@ -797,10 +801,12 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
|
|
|
797
801
|
const nextBottom = Math.floor(
|
|
798
802
|
endBuffered ? (positions.get(getId(endBuffered + 1)) || 0) - scrollLength - scrollBuffer : 0
|
|
799
803
|
);
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
+
if (state.enableScrollForNextCalculateItemsInView) {
|
|
805
|
+
state.scrollForNextCalculateItemsInView = nextTop >= 0 && nextBottom >= 0 ? {
|
|
806
|
+
top: nextTop,
|
|
807
|
+
bottom: nextBottom
|
|
808
|
+
} : void 0;
|
|
809
|
+
}
|
|
804
810
|
if (startBuffered !== null && endBuffered !== null) {
|
|
805
811
|
const prevNumContainers = ctx.values.get("numContainers");
|
|
806
812
|
let numContainers = prevNumContainers;
|
|
@@ -824,7 +830,7 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
|
|
|
824
830
|
furthestIndex = u;
|
|
825
831
|
break;
|
|
826
832
|
}
|
|
827
|
-
const index =
|
|
833
|
+
const index = state.indexByKey.get(key);
|
|
828
834
|
const pos = peek$(ctx, `containerPosition${u}`);
|
|
829
835
|
if (index < startBuffered || index > endBuffered) {
|
|
830
836
|
const distance = Math.abs(pos - top2);
|
|
@@ -836,19 +842,19 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
|
|
|
836
842
|
}
|
|
837
843
|
if (furthestIndex >= 0) {
|
|
838
844
|
set$(ctx, `containerItemKey${furthestIndex}`, id);
|
|
839
|
-
const index =
|
|
845
|
+
const index = state.indexByKey.get(id);
|
|
840
846
|
set$(ctx, `containerItemData${furthestIndex}`, data2[index]);
|
|
841
847
|
} else {
|
|
842
848
|
const containerId = numContainers;
|
|
843
849
|
numContainers++;
|
|
844
850
|
set$(ctx, `containerItemKey${containerId}`, id);
|
|
845
|
-
const index =
|
|
851
|
+
const index = state.indexByKey.get(id);
|
|
846
852
|
set$(ctx, `containerItemData${containerId}`, data2[index]);
|
|
847
853
|
set$(ctx, `containerPosition${containerId}`, POSITION_OUT_OF_VIEW);
|
|
848
854
|
set$(ctx, `containerColumn${containerId}`, -1);
|
|
849
855
|
if (__DEV__ && numContainers > peek$(ctx, "numContainersPooled")) {
|
|
850
856
|
console.warn(
|
|
851
|
-
"[legend-list] No container to recycle,
|
|
857
|
+
"[legend-list] No container to recycle, so creating one on demand. This can be a performance issue and is likely caused by the estimatedItemSize being too small. Consider increasing estimatedItemSize. numContainers:",
|
|
852
858
|
numContainers
|
|
853
859
|
);
|
|
854
860
|
}
|
|
@@ -863,7 +869,7 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
|
|
|
863
869
|
}
|
|
864
870
|
for (let i = 0; i < numContainers; i++) {
|
|
865
871
|
const itemKey = peek$(ctx, `containerItemKey${i}`);
|
|
866
|
-
const itemIndex =
|
|
872
|
+
const itemIndex = state.indexByKey.get(itemKey);
|
|
867
873
|
const item = data2[itemIndex];
|
|
868
874
|
if (item) {
|
|
869
875
|
const id = getId(itemIndex);
|
|
@@ -899,11 +905,11 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
|
|
|
899
905
|
}
|
|
900
906
|
layoutsPending.clear();
|
|
901
907
|
}
|
|
902
|
-
if (
|
|
908
|
+
if (state.viewabilityConfigCallbackPairs) {
|
|
903
909
|
updateViewableItems(
|
|
904
|
-
|
|
910
|
+
state,
|
|
905
911
|
ctx,
|
|
906
|
-
|
|
912
|
+
state.viewabilityConfigCallbackPairs,
|
|
907
913
|
getId,
|
|
908
914
|
scrollLength,
|
|
909
915
|
startNoBuffer,
|
|
@@ -1041,6 +1047,9 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
|
|
|
1041
1047
|
maxSizeInRow = 0;
|
|
1042
1048
|
}
|
|
1043
1049
|
}
|
|
1050
|
+
if (maxSizeInRow > 0) {
|
|
1051
|
+
totalSize += maxSizeInRow;
|
|
1052
|
+
}
|
|
1044
1053
|
addTotalSize(null, totalSize, totalSizeBelowIndex);
|
|
1045
1054
|
}
|
|
1046
1055
|
useEffect(() => {
|
|
@@ -1158,17 +1167,20 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
|
|
|
1158
1167
|
}, []);
|
|
1159
1168
|
useInit(() => {
|
|
1160
1169
|
var _a2;
|
|
1161
|
-
refState.current
|
|
1162
|
-
const
|
|
1170
|
+
const state = refState.current;
|
|
1171
|
+
const viewability = setupViewability(props);
|
|
1172
|
+
state.viewabilityConfigCallbackPairs = viewability;
|
|
1173
|
+
state.enableScrollForNextCalculateItemsInView = !viewability;
|
|
1174
|
+
const scrollLength = state.scrollLength;
|
|
1163
1175
|
const averageItemSize = (_a2 = estimatedItemSize != null ? estimatedItemSize : getEstimatedItemSize == null ? void 0 : getEstimatedItemSize(0, data[0])) != null ? _a2 : DEFAULT_ITEM_SIZE;
|
|
1164
|
-
const numContainers =
|
|
1176
|
+
const numContainers = Math.ceil((scrollLength + scrollBuffer * 2) / averageItemSize) * numColumnsProp;
|
|
1165
1177
|
for (let i = 0; i < numContainers; i++) {
|
|
1166
1178
|
set$(ctx, `containerPosition${i}`, POSITION_OUT_OF_VIEW);
|
|
1167
1179
|
set$(ctx, `containerColumn${i}`, -1);
|
|
1168
1180
|
}
|
|
1169
1181
|
set$(ctx, "numContainers", numContainers);
|
|
1170
1182
|
set$(ctx, "numContainersPooled", numContainers * 2);
|
|
1171
|
-
calculateItemsInView(
|
|
1183
|
+
calculateItemsInView(state.scrollVelocity);
|
|
1172
1184
|
});
|
|
1173
1185
|
const updateItemSize = useCallback((containerId, itemKey, size) => {
|
|
1174
1186
|
var _a2;
|
|
@@ -1194,7 +1206,7 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
|
|
|
1194
1206
|
const column = columns.get(itemKey);
|
|
1195
1207
|
const loopStart = index - (column - 1);
|
|
1196
1208
|
let nextMaxSizeInRow = 0;
|
|
1197
|
-
for (let i = loopStart; i < loopStart + numColumns; i++) {
|
|
1209
|
+
for (let i = loopStart; i < loopStart + numColumns && i < data2.length; i++) {
|
|
1198
1210
|
const id = getId(i);
|
|
1199
1211
|
const size2 = getItemSize(id, i, data2[i]);
|
|
1200
1212
|
nextMaxSizeInRow = Math.max(nextMaxSizeInRow, size2);
|