@legendapp/list 2.0.4 → 2.0.6
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/CHANGELOG.md +47 -0
- package/index.js +294 -280
- package/index.mjs +238 -224
- package/package.json +1 -1
- package/.DS_Store +0 -0
package/index.mjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import
|
|
1
|
+
import * as React2 from 'react';
|
|
2
|
+
import React2__default, { useReducer, useEffect, createContext, useRef, useState, useMemo, useLayoutEffect, useCallback, useImperativeHandle, forwardRef, memo, useContext } from 'react';
|
|
3
3
|
import { View, Text, Platform, Animated, StyleSheet, Dimensions, RefreshControl, unstable_batchedUpdates } from 'react-native';
|
|
4
4
|
import { useSyncExternalStore } from 'use-sync-external-store/shim';
|
|
5
5
|
|
|
6
6
|
// src/components/LegendList.tsx
|
|
7
|
-
var ContextState =
|
|
7
|
+
var ContextState = React2.createContext(null);
|
|
8
8
|
function StateProvider({ children }) {
|
|
9
|
-
const [value] =
|
|
9
|
+
const [value] = React2.useState(() => ({
|
|
10
10
|
animatedScrollY: new Animated.Value(0),
|
|
11
11
|
columnWrapperStyle: void 0,
|
|
12
12
|
listeners: /* @__PURE__ */ new Map(),
|
|
@@ -24,10 +24,10 @@ function StateProvider({ children }) {
|
|
|
24
24
|
]),
|
|
25
25
|
viewRefs: /* @__PURE__ */ new Map()
|
|
26
26
|
}));
|
|
27
|
-
return /* @__PURE__ */
|
|
27
|
+
return /* @__PURE__ */ React2.createElement(ContextState.Provider, { value }, children);
|
|
28
28
|
}
|
|
29
29
|
function useStateContext() {
|
|
30
|
-
return
|
|
30
|
+
return React2.useContext(ContextState);
|
|
31
31
|
}
|
|
32
32
|
function createSelectorFunctionsArr(ctx, signalNames) {
|
|
33
33
|
let lastValues = [];
|
|
@@ -97,23 +97,23 @@ function getContentSize(ctx) {
|
|
|
97
97
|
return headerSize + footerSize + totalSize + stylePaddingTop;
|
|
98
98
|
}
|
|
99
99
|
function useArr$(signalNames) {
|
|
100
|
-
const ctx =
|
|
101
|
-
const { subscribe, get } =
|
|
100
|
+
const ctx = React2.useContext(ContextState);
|
|
101
|
+
const { subscribe, get } = React2.useMemo(() => createSelectorFunctionsArr(ctx, signalNames), [ctx, signalNames]);
|
|
102
102
|
const value = useSyncExternalStore(subscribe, get);
|
|
103
103
|
return value;
|
|
104
104
|
}
|
|
105
105
|
function useSelector$(signalName, selector) {
|
|
106
|
-
const ctx =
|
|
107
|
-
const { subscribe, get } =
|
|
106
|
+
const ctx = React2.useContext(ContextState);
|
|
107
|
+
const { subscribe, get } = React2.useMemo(() => createSelectorFunctionsArr(ctx, [signalName]), [ctx, signalName]);
|
|
108
108
|
const value = useSyncExternalStore(subscribe, () => selector(get()[0]));
|
|
109
109
|
return value;
|
|
110
110
|
}
|
|
111
111
|
|
|
112
112
|
// src/components/DebugView.tsx
|
|
113
113
|
var DebugRow = ({ children }) => {
|
|
114
|
-
return /* @__PURE__ */
|
|
114
|
+
return /* @__PURE__ */ React2.createElement(View, { style: { alignItems: "center", flexDirection: "row", justifyContent: "space-between" } }, children);
|
|
115
115
|
};
|
|
116
|
-
var DebugView =
|
|
116
|
+
var DebugView = React2.memo(function DebugView2({ state }) {
|
|
117
117
|
const ctx = useStateContext();
|
|
118
118
|
const [totalSize = 0, scrollAdjust = 0, rawScroll = 0, scroll = 0, _numContainers = 0, _numContainersPooled = 0] = useArr$([
|
|
119
119
|
"totalSize",
|
|
@@ -128,7 +128,7 @@ var DebugView = React3.memo(function DebugView2({ state }) {
|
|
|
128
128
|
useInterval(() => {
|
|
129
129
|
forceUpdate();
|
|
130
130
|
}, 100);
|
|
131
|
-
return /* @__PURE__ */
|
|
131
|
+
return /* @__PURE__ */ React2.createElement(
|
|
132
132
|
View,
|
|
133
133
|
{
|
|
134
134
|
pointerEvents: "none",
|
|
@@ -144,14 +144,14 @@ var DebugView = React3.memo(function DebugView2({ state }) {
|
|
|
144
144
|
top: 0
|
|
145
145
|
}
|
|
146
146
|
},
|
|
147
|
-
/* @__PURE__ */
|
|
148
|
-
/* @__PURE__ */
|
|
149
|
-
/* @__PURE__ */
|
|
150
|
-
/* @__PURE__ */
|
|
151
|
-
/* @__PURE__ */
|
|
152
|
-
/* @__PURE__ */
|
|
153
|
-
/* @__PURE__ */
|
|
154
|
-
/* @__PURE__ */
|
|
147
|
+
/* @__PURE__ */ React2.createElement(DebugRow, null, /* @__PURE__ */ React2.createElement(Text, null, "TotalSize:"), /* @__PURE__ */ React2.createElement(Text, null, totalSize.toFixed(2))),
|
|
148
|
+
/* @__PURE__ */ React2.createElement(DebugRow, null, /* @__PURE__ */ React2.createElement(Text, null, "ContentSize:"), /* @__PURE__ */ React2.createElement(Text, null, contentSize.toFixed(2))),
|
|
149
|
+
/* @__PURE__ */ React2.createElement(DebugRow, null, /* @__PURE__ */ React2.createElement(Text, null, "At end:"), /* @__PURE__ */ React2.createElement(Text, null, String(state.isAtEnd))),
|
|
150
|
+
/* @__PURE__ */ React2.createElement(Text, null),
|
|
151
|
+
/* @__PURE__ */ React2.createElement(DebugRow, null, /* @__PURE__ */ React2.createElement(Text, null, "ScrollAdjust:"), /* @__PURE__ */ React2.createElement(Text, null, scrollAdjust.toFixed(2))),
|
|
152
|
+
/* @__PURE__ */ React2.createElement(Text, null),
|
|
153
|
+
/* @__PURE__ */ React2.createElement(DebugRow, null, /* @__PURE__ */ React2.createElement(Text, null, "RawScroll: "), /* @__PURE__ */ React2.createElement(Text, null, rawScroll.toFixed(2))),
|
|
154
|
+
/* @__PURE__ */ React2.createElement(DebugRow, null, /* @__PURE__ */ React2.createElement(Text, null, "ComputedScroll: "), /* @__PURE__ */ React2.createElement(Text, null, scroll.toFixed(2)))
|
|
155
155
|
);
|
|
156
156
|
});
|
|
157
157
|
function useInterval(callback, delay) {
|
|
@@ -160,8 +160,8 @@ function useInterval(callback, delay) {
|
|
|
160
160
|
return () => clearInterval(interval);
|
|
161
161
|
}, [delay]);
|
|
162
162
|
}
|
|
163
|
-
var LeanViewComponent =
|
|
164
|
-
return
|
|
163
|
+
var LeanViewComponent = React2.forwardRef((props, ref) => {
|
|
164
|
+
return React2.createElement("RCTView", { ...props, ref });
|
|
165
165
|
});
|
|
166
166
|
LeanViewComponent.displayName = "RCTView";
|
|
167
167
|
var LeanView = Platform.OS === "android" || Platform.OS === "ios" ? LeanViewComponent : View;
|
|
@@ -223,7 +223,7 @@ var PositionViewState = typedMemo(function PositionView({
|
|
|
223
223
|
...rest
|
|
224
224
|
}) {
|
|
225
225
|
const [position = POSITION_OUT_OF_VIEW] = useArr$([`containerPosition${id}`]);
|
|
226
|
-
return /* @__PURE__ */
|
|
226
|
+
return /* @__PURE__ */ React2.createElement(
|
|
227
227
|
LeanView,
|
|
228
228
|
{
|
|
229
229
|
ref: refView,
|
|
@@ -245,7 +245,7 @@ var PositionViewAnimated = typedMemo(function PositionView2({
|
|
|
245
245
|
const position$ = useValue$(`containerPosition${id}`, {
|
|
246
246
|
getValue: (v) => v != null ? v : POSITION_OUT_OF_VIEW
|
|
247
247
|
});
|
|
248
|
-
return /* @__PURE__ */
|
|
248
|
+
return /* @__PURE__ */ React2.createElement(
|
|
249
249
|
Animated.View,
|
|
250
250
|
{
|
|
251
251
|
ref: refView,
|
|
@@ -268,7 +268,7 @@ var PositionViewSticky = typedMemo(function PositionViewSticky2({
|
|
|
268
268
|
...rest
|
|
269
269
|
}) {
|
|
270
270
|
const [position = POSITION_OUT_OF_VIEW, headerSize] = useArr$([`containerPosition${id}`, "headerSize"]);
|
|
271
|
-
const transform =
|
|
271
|
+
const transform = React2.useMemo(() => {
|
|
272
272
|
if (animatedScrollY && stickyOffset) {
|
|
273
273
|
const stickyPosition = animatedScrollY.interpolate({
|
|
274
274
|
extrapolate: "clamp",
|
|
@@ -278,15 +278,10 @@ var PositionViewSticky = typedMemo(function PositionViewSticky2({
|
|
|
278
278
|
return horizontal ? [{ translateX: stickyPosition }] : [{ translateY: stickyPosition }];
|
|
279
279
|
}
|
|
280
280
|
}, [animatedScrollY, headerSize, horizontal, stickyOffset, position]);
|
|
281
|
-
const viewStyle =
|
|
282
|
-
return /* @__PURE__ */
|
|
281
|
+
const viewStyle = React2.useMemo(() => [style, { zIndex: index + 1e3 }, { transform }], [style, transform]);
|
|
282
|
+
return /* @__PURE__ */ React2.createElement(Animated.View, { ref: refView, style: viewStyle, ...rest });
|
|
283
283
|
});
|
|
284
284
|
var PositionView3 = IsNewArchitecture ? PositionViewState : PositionViewAnimated;
|
|
285
|
-
function Separator({ ItemSeparatorComponent, itemKey, leadingItem }) {
|
|
286
|
-
const [lastItemKeys] = useArr$(["lastItemKeys"]);
|
|
287
|
-
const isALastItem = lastItemKeys.includes(itemKey);
|
|
288
|
-
return isALastItem ? null : /* @__PURE__ */ React3.createElement(ItemSeparatorComponent, { leadingItem });
|
|
289
|
-
}
|
|
290
285
|
var symbolFirst = Symbol();
|
|
291
286
|
function useInit(cb) {
|
|
292
287
|
const refValue = useRef(symbolFirst);
|
|
@@ -434,6 +429,12 @@ function useSyncLayout() {
|
|
|
434
429
|
}
|
|
435
430
|
}
|
|
436
431
|
|
|
432
|
+
// src/components/Separator.tsx
|
|
433
|
+
function Separator({ ItemSeparatorComponent, leadingItem }) {
|
|
434
|
+
const isLastItem = useIsLastItem();
|
|
435
|
+
return isLastItem ? null : /* @__PURE__ */ React2.createElement(ItemSeparatorComponent, { leadingItem });
|
|
436
|
+
}
|
|
437
|
+
|
|
437
438
|
// src/components/Container.tsx
|
|
438
439
|
var Container = typedMemo(function Container2({
|
|
439
440
|
id,
|
|
@@ -557,7 +558,7 @@ var Container = typedMemo(function Container2({
|
|
|
557
558
|
}, [itemKey]);
|
|
558
559
|
}
|
|
559
560
|
const PositionComponent = isSticky ? PositionViewSticky : PositionView3;
|
|
560
|
-
return /* @__PURE__ */
|
|
561
|
+
return /* @__PURE__ */ React2.createElement(
|
|
561
562
|
PositionComponent,
|
|
562
563
|
{
|
|
563
564
|
animatedScrollY: isSticky ? animatedScrollY : void 0,
|
|
@@ -570,14 +571,7 @@ var Container = typedMemo(function Container2({
|
|
|
570
571
|
stickyOffset: isSticky ? stickyOffset : void 0,
|
|
571
572
|
style
|
|
572
573
|
},
|
|
573
|
-
/* @__PURE__ */
|
|
574
|
-
Separator,
|
|
575
|
-
{
|
|
576
|
-
ItemSeparatorComponent,
|
|
577
|
-
itemKey,
|
|
578
|
-
leadingItem: renderedItemInfo.item
|
|
579
|
-
}
|
|
580
|
-
))
|
|
574
|
+
/* @__PURE__ */ React2.createElement(ContextContainer.Provider, { value: contextValue }, renderedItem, renderedItemInfo && ItemSeparatorComponent && /* @__PURE__ */ React2.createElement(Separator, { ItemSeparatorComponent, leadingItem: renderedItemInfo.item }))
|
|
581
575
|
);
|
|
582
576
|
});
|
|
583
577
|
|
|
@@ -602,7 +596,7 @@ var Containers = typedMemo(function Containers2({
|
|
|
602
596
|
const containers = [];
|
|
603
597
|
for (let i = 0; i < numContainers; i++) {
|
|
604
598
|
containers.push(
|
|
605
|
-
/* @__PURE__ */
|
|
599
|
+
/* @__PURE__ */ React2.createElement(
|
|
606
600
|
Container,
|
|
607
601
|
{
|
|
608
602
|
getRenderedItem: getRenderedItem2,
|
|
@@ -637,13 +631,13 @@ var Containers = typedMemo(function Containers2({
|
|
|
637
631
|
}
|
|
638
632
|
}
|
|
639
633
|
}
|
|
640
|
-
return /* @__PURE__ */
|
|
634
|
+
return /* @__PURE__ */ React2.createElement(Animated.View, { style }, containers);
|
|
641
635
|
});
|
|
642
636
|
function ScrollAdjust() {
|
|
643
637
|
const bias = 1e7;
|
|
644
638
|
const [scrollAdjust, scrollAdjustUserOffset] = useArr$(["scrollAdjust", "scrollAdjustUserOffset"]);
|
|
645
639
|
const scrollOffset = (scrollAdjust || 0) + (scrollAdjustUserOffset || 0) + bias;
|
|
646
|
-
return /* @__PURE__ */
|
|
640
|
+
return /* @__PURE__ */ React2.createElement(
|
|
647
641
|
View,
|
|
648
642
|
{
|
|
649
643
|
style: {
|
|
@@ -656,11 +650,9 @@ function ScrollAdjust() {
|
|
|
656
650
|
}
|
|
657
651
|
);
|
|
658
652
|
}
|
|
659
|
-
|
|
660
|
-
// src/components/SnapWrapper.tsx
|
|
661
653
|
function SnapWrapper({ ScrollComponent, ...props }) {
|
|
662
654
|
const [snapToOffsets] = useArr$(["snapToOffsets"]);
|
|
663
|
-
return /* @__PURE__ */
|
|
655
|
+
return /* @__PURE__ */ React2__default.createElement(ScrollComponent, { ...props, snapToOffsets });
|
|
664
656
|
}
|
|
665
657
|
function useThrottleDebounce(mode) {
|
|
666
658
|
const timeoutRef = useRef(null);
|
|
@@ -727,21 +719,21 @@ function useSyncLayout2({
|
|
|
727
719
|
|
|
728
720
|
// src/components/ListComponent.tsx
|
|
729
721
|
var getComponent = (Component) => {
|
|
730
|
-
if (
|
|
722
|
+
if (React2.isValidElement(Component)) {
|
|
731
723
|
return Component;
|
|
732
724
|
}
|
|
733
725
|
if (Component) {
|
|
734
|
-
return /* @__PURE__ */
|
|
726
|
+
return /* @__PURE__ */ React2.createElement(Component, null);
|
|
735
727
|
}
|
|
736
728
|
return null;
|
|
737
729
|
};
|
|
738
730
|
var Padding = () => {
|
|
739
731
|
const animPaddingTop = useValue$("alignItemsPaddingTop", { delay: 0 });
|
|
740
|
-
return /* @__PURE__ */
|
|
732
|
+
return /* @__PURE__ */ React2.createElement(Animated.View, { style: { paddingTop: animPaddingTop } });
|
|
741
733
|
};
|
|
742
734
|
var PaddingDevMode = () => {
|
|
743
735
|
const animPaddingTop = useValue$("alignItemsPaddingTop", { delay: 0 });
|
|
744
|
-
return /* @__PURE__ */
|
|
736
|
+
return /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement(Animated.View, { style: { paddingTop: animPaddingTop } }), /* @__PURE__ */ React2.createElement(
|
|
745
737
|
Animated.View,
|
|
746
738
|
{
|
|
747
739
|
style: {
|
|
@@ -788,10 +780,10 @@ var ListComponent = typedMemo(function ListComponent2({
|
|
|
788
780
|
onChange: onLayoutHeader
|
|
789
781
|
});
|
|
790
782
|
const ScrollComponent = renderScrollComponent ? useMemo(
|
|
791
|
-
() =>
|
|
783
|
+
() => React2.forwardRef((props, ref) => renderScrollComponent({ ...props, ref })),
|
|
792
784
|
[renderScrollComponent]
|
|
793
785
|
) : Animated.ScrollView;
|
|
794
|
-
|
|
786
|
+
React2.useEffect(() => {
|
|
795
787
|
if (canRender) {
|
|
796
788
|
setTimeout(() => {
|
|
797
789
|
scrollAdjustHandler.setMounted();
|
|
@@ -799,7 +791,7 @@ var ListComponent = typedMemo(function ListComponent2({
|
|
|
799
791
|
}
|
|
800
792
|
}, [canRender]);
|
|
801
793
|
const SnapOrScroll = snapToIndices ? SnapWrapper : ScrollComponent;
|
|
802
|
-
return /* @__PURE__ */
|
|
794
|
+
return /* @__PURE__ */ React2.createElement(
|
|
803
795
|
SnapOrScroll,
|
|
804
796
|
{
|
|
805
797
|
...rest,
|
|
@@ -818,11 +810,11 @@ var ListComponent = typedMemo(function ListComponent2({
|
|
|
818
810
|
ScrollComponent: snapToIndices ? ScrollComponent : void 0,
|
|
819
811
|
style
|
|
820
812
|
},
|
|
821
|
-
maintainVisibleContentPosition && /* @__PURE__ */
|
|
822
|
-
ENABLE_DEVMODE ? /* @__PURE__ */
|
|
823
|
-
ListHeaderComponent && /* @__PURE__ */
|
|
813
|
+
maintainVisibleContentPosition && /* @__PURE__ */ React2.createElement(ScrollAdjust, null),
|
|
814
|
+
ENABLE_DEVMODE ? /* @__PURE__ */ React2.createElement(PaddingDevMode, null) : /* @__PURE__ */ React2.createElement(Padding, null),
|
|
815
|
+
ListHeaderComponent && /* @__PURE__ */ React2.createElement(View, { onLayout: onLayoutHeaderSync, ref: refHeader, style: ListHeaderComponentStyle }, getComponent(ListHeaderComponent)),
|
|
824
816
|
ListEmptyComponent && getComponent(ListEmptyComponent),
|
|
825
|
-
canRender && /* @__PURE__ */
|
|
817
|
+
canRender && /* @__PURE__ */ React2.createElement(
|
|
826
818
|
Containers,
|
|
827
819
|
{
|
|
828
820
|
getRenderedItem: getRenderedItem2,
|
|
@@ -833,7 +825,7 @@ var ListComponent = typedMemo(function ListComponent2({
|
|
|
833
825
|
waitForInitialLayout
|
|
834
826
|
}
|
|
835
827
|
),
|
|
836
|
-
ListFooterComponent && /* @__PURE__ */
|
|
828
|
+
ListFooterComponent && /* @__PURE__ */ React2.createElement(
|
|
837
829
|
View,
|
|
838
830
|
{
|
|
839
831
|
onLayout: (event) => {
|
|
@@ -844,11 +836,11 @@ var ListComponent = typedMemo(function ListComponent2({
|
|
|
844
836
|
},
|
|
845
837
|
getComponent(ListFooterComponent)
|
|
846
838
|
),
|
|
847
|
-
__DEV__ && ENABLE_DEVMODE && /* @__PURE__ */
|
|
839
|
+
__DEV__ && ENABLE_DEVMODE && /* @__PURE__ */ React2.createElement(DevNumbers, null)
|
|
848
840
|
);
|
|
849
841
|
});
|
|
850
|
-
var DevNumbers = __DEV__ &&
|
|
851
|
-
return Array.from({ length: 100 }).map((_, index) => /* @__PURE__ */
|
|
842
|
+
var DevNumbers = __DEV__ && React2.memo(function DevNumbers2() {
|
|
843
|
+
return Array.from({ length: 100 }).map((_, index) => /* @__PURE__ */ React2.createElement(
|
|
852
844
|
View,
|
|
853
845
|
{
|
|
854
846
|
key: index,
|
|
@@ -860,7 +852,7 @@ var DevNumbers = __DEV__ && React3.memo(function DevNumbers2() {
|
|
|
860
852
|
width: "100%"
|
|
861
853
|
}
|
|
862
854
|
},
|
|
863
|
-
/* @__PURE__ */
|
|
855
|
+
/* @__PURE__ */ React2.createElement(Text, { style: { color: "red" } }, index * 100)
|
|
864
856
|
));
|
|
865
857
|
});
|
|
866
858
|
|
|
@@ -1139,12 +1131,14 @@ function updateTotalSize(ctx, state) {
|
|
|
1139
1131
|
}
|
|
1140
1132
|
function addTotalSize(ctx, state, key, add) {
|
|
1141
1133
|
const { alignItemsAtEnd } = state.props;
|
|
1142
|
-
{
|
|
1134
|
+
if (key === null) {
|
|
1143
1135
|
state.totalSize = add;
|
|
1144
1136
|
if (state.timeoutSetPaddingTop) {
|
|
1145
1137
|
clearTimeout(state.timeoutSetPaddingTop);
|
|
1146
1138
|
state.timeoutSetPaddingTop = void 0;
|
|
1147
1139
|
}
|
|
1140
|
+
} else {
|
|
1141
|
+
state.totalSize += add;
|
|
1148
1142
|
}
|
|
1149
1143
|
set$(ctx, "totalSize", state.totalSize);
|
|
1150
1144
|
if (alignItemsAtEnd) {
|
|
@@ -1167,8 +1161,8 @@ function updateSnapToOffsets(ctx, state) {
|
|
|
1167
1161
|
set$(ctx, "snapToOffsets", snapToOffsets);
|
|
1168
1162
|
}
|
|
1169
1163
|
|
|
1170
|
-
// src/core/
|
|
1171
|
-
function
|
|
1164
|
+
// src/core/updateItemPositions.ts
|
|
1165
|
+
function updateItemPositions(ctx, state, dataChanged, { startIndex, scrollBottomBuffered } = { scrollBottomBuffered: -1, startIndex: 0 }) {
|
|
1172
1166
|
var _a, _b, _c, _d, _e, _f;
|
|
1173
1167
|
const {
|
|
1174
1168
|
columns,
|
|
@@ -1181,6 +1175,7 @@ function updateAllPositions(ctx, state, dataChanged, startIndex = 0) {
|
|
|
1181
1175
|
const data = state.props.data;
|
|
1182
1176
|
const numColumns = peek$(ctx, "numColumns");
|
|
1183
1177
|
const indexByKeyForChecking = __DEV__ ? /* @__PURE__ */ new Map() : void 0;
|
|
1178
|
+
const maxVisibleArea = scrollBottomBuffered + 1e3;
|
|
1184
1179
|
const useAverageSize = enableAverages && !getEstimatedItemSize;
|
|
1185
1180
|
let currentRowTop = 0;
|
|
1186
1181
|
let column = 1;
|
|
@@ -1200,8 +1195,17 @@ function updateAllPositions(ctx, state, dataChanged, startIndex = 0) {
|
|
|
1200
1195
|
}
|
|
1201
1196
|
}
|
|
1202
1197
|
const needsIndexByKey = dataChanged || indexByKey.size === 0;
|
|
1198
|
+
let didBreakEarly = false;
|
|
1199
|
+
let breakAt;
|
|
1203
1200
|
const dataLength = data.length;
|
|
1204
1201
|
for (let i = startIndex; i < dataLength; i++) {
|
|
1202
|
+
if (breakAt && i > breakAt) {
|
|
1203
|
+
didBreakEarly = true;
|
|
1204
|
+
break;
|
|
1205
|
+
}
|
|
1206
|
+
if (!dataChanged && currentRowTop > maxVisibleArea) {
|
|
1207
|
+
breakAt = i + 10;
|
|
1208
|
+
}
|
|
1205
1209
|
const id = (_e = idCache.get(i)) != null ? _e : getId(state, i);
|
|
1206
1210
|
const size = (_f = sizesKnown.get(id)) != null ? _f : getItemSize(state, id, i, data[i], useAverageSize);
|
|
1207
1211
|
if (__DEV__ && needsIndexByKey) {
|
|
@@ -1231,7 +1235,9 @@ function updateAllPositions(ctx, state, dataChanged, startIndex = 0) {
|
|
|
1231
1235
|
currentRowTop += size;
|
|
1232
1236
|
}
|
|
1233
1237
|
}
|
|
1234
|
-
|
|
1238
|
+
if (!didBreakEarly) {
|
|
1239
|
+
updateTotalSize(ctx, state);
|
|
1240
|
+
}
|
|
1235
1241
|
if (snapToIndices) {
|
|
1236
1242
|
updateSnapToOffsets(ctx, state);
|
|
1237
1243
|
}
|
|
@@ -1781,7 +1787,7 @@ function handleStickyRecycling(ctx, state, stickyArray, scroll, scrollBuffer, pe
|
|
|
1781
1787
|
}
|
|
1782
1788
|
function calculateItemsInView(ctx, state, params = {}) {
|
|
1783
1789
|
batchedUpdates(() => {
|
|
1784
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
1790
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
1785
1791
|
const {
|
|
1786
1792
|
columns,
|
|
1787
1793
|
containerItemKeys,
|
|
@@ -1810,20 +1816,6 @@ function calculateItemsInView(ctx, state, params = {}) {
|
|
|
1810
1816
|
const previousScrollAdjust = 0;
|
|
1811
1817
|
const { dataChanged, doMVCP } = params;
|
|
1812
1818
|
const speed = getScrollVelocity(state);
|
|
1813
|
-
if (doMVCP || dataChanged) {
|
|
1814
|
-
const checkMVCP = doMVCP ? prepareMVCP(ctx, state, dataChanged) : void 0;
|
|
1815
|
-
if (dataChanged) {
|
|
1816
|
-
indexByKey.clear();
|
|
1817
|
-
idCache.clear();
|
|
1818
|
-
positions.clear();
|
|
1819
|
-
}
|
|
1820
|
-
const startIndex = dataChanged ? 0 : minIndexSizeChanged != null ? minIndexSizeChanged : 0;
|
|
1821
|
-
updateAllPositions(ctx, state, dataChanged, startIndex);
|
|
1822
|
-
if (minIndexSizeChanged !== void 0) {
|
|
1823
|
-
state.minIndexSizeChanged = void 0;
|
|
1824
|
-
}
|
|
1825
|
-
checkMVCP == null ? void 0 : checkMVCP();
|
|
1826
|
-
}
|
|
1827
1819
|
const scrollExtra = 0;
|
|
1828
1820
|
const { queuedInitialLayout } = state;
|
|
1829
1821
|
let { scroll: scrollState } = state;
|
|
@@ -1862,6 +1854,18 @@ function calculateItemsInView(ctx, state, params = {}) {
|
|
|
1862
1854
|
return;
|
|
1863
1855
|
}
|
|
1864
1856
|
}
|
|
1857
|
+
const checkMVCP = doMVCP ? prepareMVCP(ctx, state, dataChanged) : void 0;
|
|
1858
|
+
if (dataChanged) {
|
|
1859
|
+
indexByKey.clear();
|
|
1860
|
+
idCache.clear();
|
|
1861
|
+
positions.clear();
|
|
1862
|
+
}
|
|
1863
|
+
const startIndex = dataChanged ? 0 : (_a = minIndexSizeChanged != null ? minIndexSizeChanged : state.startBuffered) != null ? _a : 0;
|
|
1864
|
+
updateItemPositions(ctx, state, dataChanged, { scrollBottomBuffered, startIndex });
|
|
1865
|
+
if (minIndexSizeChanged !== void 0) {
|
|
1866
|
+
state.minIndexSizeChanged = void 0;
|
|
1867
|
+
}
|
|
1868
|
+
checkMVCP == null ? void 0 : checkMVCP();
|
|
1865
1869
|
let startNoBuffer = null;
|
|
1866
1870
|
let startBuffered = null;
|
|
1867
1871
|
let startBufferedId = null;
|
|
@@ -1869,9 +1873,9 @@ function calculateItemsInView(ctx, state, params = {}) {
|
|
|
1869
1873
|
let endBuffered = null;
|
|
1870
1874
|
let loopStart = startBufferedIdOrig ? indexByKey.get(startBufferedIdOrig) || 0 : 0;
|
|
1871
1875
|
for (let i = loopStart; i >= 0; i--) {
|
|
1872
|
-
const id = (
|
|
1876
|
+
const id = (_b = idCache.get(i)) != null ? _b : getId(state, i);
|
|
1873
1877
|
const top = positions.get(id);
|
|
1874
|
-
const size = (
|
|
1878
|
+
const size = (_c = sizes.get(id)) != null ? _c : getItemSize(state, id, i, data[i]);
|
|
1875
1879
|
const bottom = top + size;
|
|
1876
1880
|
if (bottom > scroll - scrollBuffer) {
|
|
1877
1881
|
loopStart = i;
|
|
@@ -1897,8 +1901,8 @@ function calculateItemsInView(ctx, state, params = {}) {
|
|
|
1897
1901
|
let firstFullyOnScreenIndex;
|
|
1898
1902
|
const dataLength = data.length;
|
|
1899
1903
|
for (let i = Math.max(0, loopStart); i < dataLength && (!foundEnd || i <= maxIndexRendered); i++) {
|
|
1900
|
-
const id = (
|
|
1901
|
-
const size = (
|
|
1904
|
+
const id = (_d = idCache.get(i)) != null ? _d : getId(state, i);
|
|
1905
|
+
const size = (_e = sizes.get(id)) != null ? _e : getItemSize(state, id, i, data[i]);
|
|
1902
1906
|
const top = positions.get(id);
|
|
1903
1907
|
if (!foundEnd) {
|
|
1904
1908
|
if (startNoBuffer === null && top + size > scroll) {
|
|
@@ -1927,7 +1931,7 @@ function calculateItemsInView(ctx, state, params = {}) {
|
|
|
1927
1931
|
}
|
|
1928
1932
|
const idsInView = [];
|
|
1929
1933
|
for (let i = firstFullyOnScreenIndex; i <= endNoBuffer; i++) {
|
|
1930
|
-
const id = (
|
|
1934
|
+
const id = (_f = idCache.get(i)) != null ? _f : getId(state, i);
|
|
1931
1935
|
idsInView.push(id);
|
|
1932
1936
|
}
|
|
1933
1937
|
Object.assign(state, {
|
|
@@ -1959,7 +1963,7 @@ function calculateItemsInView(ctx, state, params = {}) {
|
|
|
1959
1963
|
let numContainers2 = prevNumContainers;
|
|
1960
1964
|
const needNewContainers = [];
|
|
1961
1965
|
for (let i = startBuffered; i <= endBuffered; i++) {
|
|
1962
|
-
const id = (
|
|
1966
|
+
const id = (_g = idCache.get(i)) != null ? _g : getId(state, i);
|
|
1963
1967
|
if (!containerItemKeys.has(id)) {
|
|
1964
1968
|
needNewContainers.push(i);
|
|
1965
1969
|
}
|
|
@@ -1996,7 +2000,7 @@ function calculateItemsInView(ctx, state, params = {}) {
|
|
|
1996
2000
|
for (let idx = 0; idx < needNewContainers.length; idx++) {
|
|
1997
2001
|
const i = needNewContainers[idx];
|
|
1998
2002
|
const containerIndex = availableContainers[idx];
|
|
1999
|
-
const id = (
|
|
2003
|
+
const id = (_h = idCache.get(i)) != null ? _h : getId(state, i);
|
|
2000
2004
|
const oldKey = peek$(ctx, `containerItemKey${containerIndex}`);
|
|
2001
2005
|
if (oldKey && oldKey !== id) {
|
|
2002
2006
|
containerItemKeys.delete(oldKey);
|
|
@@ -2051,7 +2055,7 @@ function calculateItemsInView(ctx, state, params = {}) {
|
|
|
2051
2055
|
const itemIndex = indexByKey.get(itemKey);
|
|
2052
2056
|
const item = data[itemIndex];
|
|
2053
2057
|
if (item !== void 0) {
|
|
2054
|
-
const id = (
|
|
2058
|
+
const id = (_i = idCache.get(itemIndex)) != null ? _i : getId(state, itemIndex);
|
|
2055
2059
|
const position = positions.get(id);
|
|
2056
2060
|
if (position === void 0) {
|
|
2057
2061
|
set$(ctx, `containerPosition${i}`, POSITION_OUT_OF_VIEW);
|
|
@@ -2067,7 +2071,7 @@ function calculateItemsInView(ctx, state, params = {}) {
|
|
|
2067
2071
|
set$(ctx, `containerColumn${i}`, column);
|
|
2068
2072
|
}
|
|
2069
2073
|
if (prevData !== item && (itemsAreEqual ? !itemsAreEqual(prevData, item, itemIndex, data) : true)) {
|
|
2070
|
-
set$(ctx, `containerItemData${i}`,
|
|
2074
|
+
set$(ctx, `containerItemData${i}`, item);
|
|
2071
2075
|
}
|
|
2072
2076
|
}
|
|
2073
2077
|
}
|
|
@@ -2084,55 +2088,6 @@ function calculateItemsInView(ctx, state, params = {}) {
|
|
|
2084
2088
|
});
|
|
2085
2089
|
}
|
|
2086
2090
|
|
|
2087
|
-
// src/core/doInitialAllocateContainers.ts
|
|
2088
|
-
function doInitialAllocateContainers(ctx, state) {
|
|
2089
|
-
var _a;
|
|
2090
|
-
const {
|
|
2091
|
-
scrollLength,
|
|
2092
|
-
props: {
|
|
2093
|
-
data,
|
|
2094
|
-
getEstimatedItemSize,
|
|
2095
|
-
getFixedItemSize,
|
|
2096
|
-
getItemType,
|
|
2097
|
-
scrollBuffer,
|
|
2098
|
-
numColumns,
|
|
2099
|
-
estimatedItemSize
|
|
2100
|
-
}
|
|
2101
|
-
} = state;
|
|
2102
|
-
const hasContainers = peek$(ctx, "numContainers");
|
|
2103
|
-
if (scrollLength > 0 && data.length > 0 && !hasContainers) {
|
|
2104
|
-
let averageItemSize;
|
|
2105
|
-
const fn = getFixedItemSize || getEstimatedItemSize;
|
|
2106
|
-
if (fn) {
|
|
2107
|
-
let totalSize = 0;
|
|
2108
|
-
const num = Math.min(20, data.length);
|
|
2109
|
-
for (let i = 0; i < num; i++) {
|
|
2110
|
-
totalSize += fn(0, data[0], getItemType ? (_a = getItemType(data[0], 0)) != null ? _a : "" : "");
|
|
2111
|
-
}
|
|
2112
|
-
averageItemSize = totalSize / num;
|
|
2113
|
-
} else {
|
|
2114
|
-
averageItemSize = estimatedItemSize;
|
|
2115
|
-
}
|
|
2116
|
-
const numContainers = Math.ceil((scrollLength + scrollBuffer * 2) / averageItemSize * numColumns);
|
|
2117
|
-
for (let i = 0; i < numContainers; i++) {
|
|
2118
|
-
set$(ctx, `containerPosition${i}`, POSITION_OUT_OF_VIEW);
|
|
2119
|
-
set$(ctx, `containerColumn${i}`, -1);
|
|
2120
|
-
}
|
|
2121
|
-
set$(ctx, "numContainers", numContainers);
|
|
2122
|
-
set$(ctx, "numContainersPooled", numContainers * state.props.initialContainerPoolRatio);
|
|
2123
|
-
if (!IsNewArchitecture || state.lastLayout) {
|
|
2124
|
-
if (state.props.initialScroll) {
|
|
2125
|
-
requestAnimationFrame(() => {
|
|
2126
|
-
calculateItemsInView(ctx, state, { dataChanged: true });
|
|
2127
|
-
});
|
|
2128
|
-
} else {
|
|
2129
|
-
calculateItemsInView(ctx, state, { dataChanged: true });
|
|
2130
|
-
}
|
|
2131
|
-
}
|
|
2132
|
-
return true;
|
|
2133
|
-
}
|
|
2134
|
-
}
|
|
2135
|
-
|
|
2136
2091
|
// src/core/doMaintainScrollAtEnd.ts
|
|
2137
2092
|
function doMaintainScrollAtEnd(ctx, state, animated) {
|
|
2138
2093
|
const {
|
|
@@ -2191,6 +2146,129 @@ function checkAtTop(state) {
|
|
|
2191
2146
|
);
|
|
2192
2147
|
}
|
|
2193
2148
|
|
|
2149
|
+
// src/utils/updateAveragesOnDataChange.ts
|
|
2150
|
+
function updateAveragesOnDataChange(state, oldData, newData) {
|
|
2151
|
+
var _a;
|
|
2152
|
+
const {
|
|
2153
|
+
averageSizes,
|
|
2154
|
+
sizesKnown,
|
|
2155
|
+
indexByKey,
|
|
2156
|
+
props: { itemsAreEqual, getItemType, keyExtractor }
|
|
2157
|
+
} = state;
|
|
2158
|
+
if (!itemsAreEqual || !oldData.length || !newData.length) {
|
|
2159
|
+
for (const key in averageSizes) {
|
|
2160
|
+
delete averageSizes[key];
|
|
2161
|
+
}
|
|
2162
|
+
return;
|
|
2163
|
+
}
|
|
2164
|
+
const itemTypesToPreserve = {};
|
|
2165
|
+
const newDataLength = newData.length;
|
|
2166
|
+
const oldDataLength = oldData.length;
|
|
2167
|
+
for (let newIndex = 0; newIndex < newDataLength; newIndex++) {
|
|
2168
|
+
const newItem = newData[newIndex];
|
|
2169
|
+
const id = keyExtractor ? keyExtractor(newItem, newIndex) : String(newIndex);
|
|
2170
|
+
const oldIndex = indexByKey.get(id);
|
|
2171
|
+
if (oldIndex !== void 0 && oldIndex < oldDataLength) {
|
|
2172
|
+
const knownSize = sizesKnown.get(id);
|
|
2173
|
+
if (knownSize === void 0) continue;
|
|
2174
|
+
const oldItem = oldData[oldIndex];
|
|
2175
|
+
const areEqual = itemsAreEqual(oldItem, newItem, newIndex, newData);
|
|
2176
|
+
if (areEqual) {
|
|
2177
|
+
const itemType = getItemType ? (_a = getItemType(newItem, newIndex)) != null ? _a : "" : "";
|
|
2178
|
+
let typeData = itemTypesToPreserve[itemType];
|
|
2179
|
+
if (!typeData) {
|
|
2180
|
+
typeData = itemTypesToPreserve[itemType] = { count: 0, totalSize: 0 };
|
|
2181
|
+
}
|
|
2182
|
+
typeData.totalSize += knownSize;
|
|
2183
|
+
typeData.count++;
|
|
2184
|
+
}
|
|
2185
|
+
}
|
|
2186
|
+
}
|
|
2187
|
+
for (const key in averageSizes) {
|
|
2188
|
+
delete averageSizes[key];
|
|
2189
|
+
}
|
|
2190
|
+
for (const itemType in itemTypesToPreserve) {
|
|
2191
|
+
const { totalSize, count } = itemTypesToPreserve[itemType];
|
|
2192
|
+
if (count > 0) {
|
|
2193
|
+
averageSizes[itemType] = {
|
|
2194
|
+
avg: totalSize / count,
|
|
2195
|
+
num: count
|
|
2196
|
+
};
|
|
2197
|
+
}
|
|
2198
|
+
}
|
|
2199
|
+
}
|
|
2200
|
+
|
|
2201
|
+
// src/core/checkResetContainers.ts
|
|
2202
|
+
function checkResetContainers(ctx, state, isFirst, dataProp) {
|
|
2203
|
+
if (state) {
|
|
2204
|
+
if (!isFirst && state.props.data !== dataProp) {
|
|
2205
|
+
updateAveragesOnDataChange(state, state.props.data, dataProp);
|
|
2206
|
+
}
|
|
2207
|
+
const { maintainScrollAtEnd } = state.props;
|
|
2208
|
+
if (!isFirst) {
|
|
2209
|
+
calculateItemsInView(ctx, state, { dataChanged: true, doMVCP: true });
|
|
2210
|
+
const shouldMaintainScrollAtEnd = maintainScrollAtEnd === true || maintainScrollAtEnd.onDataChange;
|
|
2211
|
+
const didMaintainScrollAtEnd = shouldMaintainScrollAtEnd && doMaintainScrollAtEnd(ctx, state, false);
|
|
2212
|
+
if (!didMaintainScrollAtEnd && dataProp.length > state.props.data.length) {
|
|
2213
|
+
state.isEndReached = false;
|
|
2214
|
+
}
|
|
2215
|
+
if (!didMaintainScrollAtEnd) {
|
|
2216
|
+
checkAtTop(state);
|
|
2217
|
+
checkAtBottom(ctx, state);
|
|
2218
|
+
}
|
|
2219
|
+
}
|
|
2220
|
+
}
|
|
2221
|
+
}
|
|
2222
|
+
|
|
2223
|
+
// src/core/doInitialAllocateContainers.ts
|
|
2224
|
+
function doInitialAllocateContainers(ctx, state) {
|
|
2225
|
+
var _a;
|
|
2226
|
+
const {
|
|
2227
|
+
scrollLength,
|
|
2228
|
+
props: {
|
|
2229
|
+
data,
|
|
2230
|
+
getEstimatedItemSize,
|
|
2231
|
+
getFixedItemSize,
|
|
2232
|
+
getItemType,
|
|
2233
|
+
scrollBuffer,
|
|
2234
|
+
numColumns,
|
|
2235
|
+
estimatedItemSize
|
|
2236
|
+
}
|
|
2237
|
+
} = state;
|
|
2238
|
+
const hasContainers = peek$(ctx, "numContainers");
|
|
2239
|
+
if (scrollLength > 0 && data.length > 0 && !hasContainers) {
|
|
2240
|
+
let averageItemSize;
|
|
2241
|
+
const fn = getFixedItemSize || getEstimatedItemSize;
|
|
2242
|
+
if (fn) {
|
|
2243
|
+
let totalSize = 0;
|
|
2244
|
+
const num = Math.min(20, data.length);
|
|
2245
|
+
for (let i = 0; i < num; i++) {
|
|
2246
|
+
totalSize += fn(0, data[0], getItemType ? (_a = getItemType(data[0], 0)) != null ? _a : "" : "");
|
|
2247
|
+
}
|
|
2248
|
+
averageItemSize = totalSize / num;
|
|
2249
|
+
} else {
|
|
2250
|
+
averageItemSize = estimatedItemSize;
|
|
2251
|
+
}
|
|
2252
|
+
const numContainers = Math.ceil((scrollLength + scrollBuffer * 2) / averageItemSize * numColumns);
|
|
2253
|
+
for (let i = 0; i < numContainers; i++) {
|
|
2254
|
+
set$(ctx, `containerPosition${i}`, POSITION_OUT_OF_VIEW);
|
|
2255
|
+
set$(ctx, `containerColumn${i}`, -1);
|
|
2256
|
+
}
|
|
2257
|
+
set$(ctx, "numContainers", numContainers);
|
|
2258
|
+
set$(ctx, "numContainersPooled", numContainers * state.props.initialContainerPoolRatio);
|
|
2259
|
+
if (!IsNewArchitecture || state.lastLayout) {
|
|
2260
|
+
if (state.props.initialScroll) {
|
|
2261
|
+
requestAnimationFrame(() => {
|
|
2262
|
+
calculateItemsInView(ctx, state, { dataChanged: true });
|
|
2263
|
+
});
|
|
2264
|
+
} else {
|
|
2265
|
+
calculateItemsInView(ctx, state, { dataChanged: true });
|
|
2266
|
+
}
|
|
2267
|
+
}
|
|
2268
|
+
return true;
|
|
2269
|
+
}
|
|
2270
|
+
}
|
|
2271
|
+
|
|
2194
2272
|
// src/core/handleLayout.ts
|
|
2195
2273
|
function handleLayout(ctx, state, layout, setCanRender) {
|
|
2196
2274
|
const { maintainScrollAtEnd } = state.props;
|
|
@@ -2368,6 +2446,7 @@ function updateItemSize(ctx, state, itemKey, sizeObj) {
|
|
|
2368
2446
|
if (prevSizeKnown !== void 0 && Math.abs(prevSizeKnown - size) > 5) {
|
|
2369
2447
|
shouldMaintainScrollAtEnd = true;
|
|
2370
2448
|
}
|
|
2449
|
+
addTotalSize(ctx, state, itemKey, diff);
|
|
2371
2450
|
onItemSizeChanged == null ? void 0 : onItemSizeChanged({
|
|
2372
2451
|
index,
|
|
2373
2452
|
itemData: state.props.data[index],
|
|
@@ -2488,7 +2567,7 @@ function getRenderedItem(ctx, state, key) {
|
|
|
2488
2567
|
item: data[index],
|
|
2489
2568
|
type: getItemType ? (_a = getItemType(data[index], index)) != null ? _a : "" : ""
|
|
2490
2569
|
};
|
|
2491
|
-
renderedItem = isFunction(renderItem) ? renderItem(itemProps) :
|
|
2570
|
+
renderedItem = isFunction(renderItem) ? renderItem(itemProps) : React2__default.createElement(renderItem, itemProps);
|
|
2492
2571
|
}
|
|
2493
2572
|
return { index, item: data[index], renderedItem };
|
|
2494
2573
|
}
|
|
@@ -2499,58 +2578,6 @@ function useThrottledOnScroll(originalHandler, scrollEventThrottle) {
|
|
|
2499
2578
|
return (event) => throttle(originalHandler, scrollEventThrottle, { nativeEvent: event.nativeEvent });
|
|
2500
2579
|
}
|
|
2501
2580
|
|
|
2502
|
-
// src/utils/updateAveragesOnDataChange.ts
|
|
2503
|
-
function updateAveragesOnDataChange(state, oldData, newData) {
|
|
2504
|
-
var _a;
|
|
2505
|
-
const {
|
|
2506
|
-
averageSizes,
|
|
2507
|
-
sizesKnown,
|
|
2508
|
-
indexByKey,
|
|
2509
|
-
props: { itemsAreEqual, getItemType, keyExtractor }
|
|
2510
|
-
} = state;
|
|
2511
|
-
if (!itemsAreEqual || !oldData.length || !newData.length) {
|
|
2512
|
-
for (const key in averageSizes) {
|
|
2513
|
-
delete averageSizes[key];
|
|
2514
|
-
}
|
|
2515
|
-
return;
|
|
2516
|
-
}
|
|
2517
|
-
const itemTypesToPreserve = {};
|
|
2518
|
-
const newDataLength = newData.length;
|
|
2519
|
-
const oldDataLength = oldData.length;
|
|
2520
|
-
for (let newIndex = 0; newIndex < newDataLength; newIndex++) {
|
|
2521
|
-
const newItem = newData[newIndex];
|
|
2522
|
-
const id = keyExtractor ? keyExtractor(newItem, newIndex) : String(newIndex);
|
|
2523
|
-
const oldIndex = indexByKey.get(id);
|
|
2524
|
-
if (oldIndex !== void 0 && oldIndex < oldDataLength) {
|
|
2525
|
-
const knownSize = sizesKnown.get(id);
|
|
2526
|
-
if (knownSize === void 0) continue;
|
|
2527
|
-
const oldItem = oldData[oldIndex];
|
|
2528
|
-
const areEqual = itemsAreEqual(oldItem, newItem, newIndex, newData);
|
|
2529
|
-
if (areEqual) {
|
|
2530
|
-
const itemType = getItemType ? (_a = getItemType(newItem, newIndex)) != null ? _a : "" : "";
|
|
2531
|
-
let typeData = itemTypesToPreserve[itemType];
|
|
2532
|
-
if (!typeData) {
|
|
2533
|
-
typeData = itemTypesToPreserve[itemType] = { count: 0, totalSize: 0 };
|
|
2534
|
-
}
|
|
2535
|
-
typeData.totalSize += knownSize;
|
|
2536
|
-
typeData.count++;
|
|
2537
|
-
}
|
|
2538
|
-
}
|
|
2539
|
-
}
|
|
2540
|
-
for (const key in averageSizes) {
|
|
2541
|
-
delete averageSizes[key];
|
|
2542
|
-
}
|
|
2543
|
-
for (const itemType in itemTypesToPreserve) {
|
|
2544
|
-
const { totalSize, count } = itemTypesToPreserve[itemType];
|
|
2545
|
-
if (count > 0) {
|
|
2546
|
-
averageSizes[itemType] = {
|
|
2547
|
-
avg: totalSize / count,
|
|
2548
|
-
num: count
|
|
2549
|
-
};
|
|
2550
|
-
}
|
|
2551
|
-
}
|
|
2552
|
-
}
|
|
2553
|
-
|
|
2554
2581
|
// src/components/LegendList.tsx
|
|
2555
2582
|
var DEFAULT_DRAW_DISTANCE = 250;
|
|
2556
2583
|
var DEFAULT_ITEM_SIZE = 100;
|
|
@@ -2560,14 +2587,14 @@ var LegendList = typedMemo(
|
|
|
2560
2587
|
const isChildrenMode = children !== void 0 && dataProp === void 0;
|
|
2561
2588
|
const processedProps = isChildrenMode ? {
|
|
2562
2589
|
...restProps,
|
|
2563
|
-
data: (isArray(children) ? children :
|
|
2590
|
+
data: (isArray(children) ? children : React2.Children.toArray(children)).flat(1),
|
|
2564
2591
|
renderItem: ({ item }) => item
|
|
2565
2592
|
} : {
|
|
2566
2593
|
...restProps,
|
|
2567
2594
|
data: dataProp || [],
|
|
2568
2595
|
renderItem: renderItemProp
|
|
2569
2596
|
};
|
|
2570
|
-
return /* @__PURE__ */
|
|
2597
|
+
return /* @__PURE__ */ React2.createElement(StateProvider, null, /* @__PURE__ */ React2.createElement(LegendListInner, { ...processedProps, ref: forwardedRef }));
|
|
2571
2598
|
})
|
|
2572
2599
|
);
|
|
2573
2600
|
var LegendListInner = typedForwardRef(function LegendListInner2(props, forwardedRef) {
|
|
@@ -2626,7 +2653,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
|
|
|
2626
2653
|
} = props;
|
|
2627
2654
|
const [renderNum, setRenderNum] = useState(0);
|
|
2628
2655
|
const initialScroll = initialScrollIndexProp || initialScrollOffsetProp ? typeof initialScrollIndexProp === "object" ? { index: initialScrollIndexProp.index || 0, viewOffset: initialScrollIndexProp.viewOffset || 0 } : { index: initialScrollIndexProp || 0, viewOffset: initialScrollOffsetProp || 0 } : void 0;
|
|
2629
|
-
const [canRender, setCanRender] =
|
|
2656
|
+
const [canRender, setCanRender] = React2.useState(!IsNewArchitecture);
|
|
2630
2657
|
const contentContainerStyle = { ...StyleSheet.flatten(contentContainerStyleProp) };
|
|
2631
2658
|
const style = { ...StyleSheet.flatten(styleProp) };
|
|
2632
2659
|
const stylePaddingTopState = extractPadding(style, contentContainerStyle, "Top");
|
|
@@ -2733,27 +2760,6 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
|
|
|
2733
2760
|
suggestEstimatedItemSize: !!suggestEstimatedItemSize
|
|
2734
2761
|
};
|
|
2735
2762
|
state.refScroller = refScroller;
|
|
2736
|
-
const checkResetContainers = (isFirst2) => {
|
|
2737
|
-
const state2 = refState.current;
|
|
2738
|
-
if (state2) {
|
|
2739
|
-
if (!isFirst2 && state2.props.data !== dataProp) {
|
|
2740
|
-
updateAveragesOnDataChange(state2, state2.props.data, dataProp);
|
|
2741
|
-
}
|
|
2742
|
-
state2.props.data = dataProp;
|
|
2743
|
-
if (!isFirst2) {
|
|
2744
|
-
calculateItemsInView(ctx, state2, { dataChanged: true, doMVCP: true });
|
|
2745
|
-
const shouldMaintainScrollAtEnd = maintainScrollAtEnd === true || maintainScrollAtEnd.onDataChange;
|
|
2746
|
-
const didMaintainScrollAtEnd = shouldMaintainScrollAtEnd && doMaintainScrollAtEnd(ctx, state2, false);
|
|
2747
|
-
if (!didMaintainScrollAtEnd && dataProp.length > state2.props.data.length) {
|
|
2748
|
-
state2.isEndReached = false;
|
|
2749
|
-
}
|
|
2750
|
-
if (!didMaintainScrollAtEnd) {
|
|
2751
|
-
checkAtTop(state2);
|
|
2752
|
-
checkAtBottom(ctx, state2);
|
|
2753
|
-
}
|
|
2754
|
-
}
|
|
2755
|
-
}
|
|
2756
|
-
};
|
|
2757
2763
|
const memoizedLastItemKeys = useMemo(() => {
|
|
2758
2764
|
if (!dataProp.length) return [];
|
|
2759
2765
|
return Array.from(
|
|
@@ -2777,7 +2783,12 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
|
|
|
2777
2783
|
};
|
|
2778
2784
|
if (isFirst) {
|
|
2779
2785
|
initializeStateVars();
|
|
2780
|
-
|
|
2786
|
+
updateItemPositions(
|
|
2787
|
+
ctx,
|
|
2788
|
+
state,
|
|
2789
|
+
/*dataChanged*/
|
|
2790
|
+
true
|
|
2791
|
+
);
|
|
2781
2792
|
}
|
|
2782
2793
|
const initialContentOffset = useMemo(() => {
|
|
2783
2794
|
if (initialScroll) {
|
|
@@ -2829,8 +2840,11 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
|
|
|
2829
2840
|
const didAllocateContainers = dataProp.length > 0 && doInitialAllocateContainersCallback();
|
|
2830
2841
|
if (!didAllocateContainers) {
|
|
2831
2842
|
checkResetContainers(
|
|
2843
|
+
ctx,
|
|
2844
|
+
state,
|
|
2832
2845
|
/*isFirst*/
|
|
2833
|
-
isFirst
|
|
2846
|
+
isFirst,
|
|
2847
|
+
dataProp
|
|
2834
2848
|
);
|
|
2835
2849
|
}
|
|
2836
2850
|
}, [dataProp, numColumnsProp]);
|
|
@@ -2990,7 +3004,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
|
|
|
2990
3004
|
}
|
|
2991
3005
|
return onScrollFn;
|
|
2992
3006
|
}, [stickyIndices == null ? void 0 : stickyIndices.length, horizontal, scrollEventThrottle]);
|
|
2993
|
-
return /* @__PURE__ */
|
|
3007
|
+
return /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement(
|
|
2994
3008
|
ListComponent,
|
|
2995
3009
|
{
|
|
2996
3010
|
...rest,
|
|
@@ -3021,9 +3035,9 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
|
|
|
3021
3035
|
},
|
|
3022
3036
|
onScroll: onScrollHandler,
|
|
3023
3037
|
recycleItems,
|
|
3024
|
-
refreshControl: refreshControl ? stylePaddingTopState > 0 ?
|
|
3038
|
+
refreshControl: refreshControl ? stylePaddingTopState > 0 ? React2.cloneElement(refreshControl, {
|
|
3025
3039
|
progressViewOffset: (refreshControl.props.progressViewOffset || 0) + stylePaddingTopState
|
|
3026
|
-
}) : refreshControl : onRefresh && /* @__PURE__ */
|
|
3040
|
+
}) : refreshControl : onRefresh && /* @__PURE__ */ React2.createElement(
|
|
3027
3041
|
RefreshControl,
|
|
3028
3042
|
{
|
|
3029
3043
|
onRefresh,
|
|
@@ -3040,7 +3054,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
|
|
|
3040
3054
|
updateItemSize: fns.updateItemSize,
|
|
3041
3055
|
waitForInitialLayout
|
|
3042
3056
|
}
|
|
3043
|
-
), __DEV__ && ENABLE_DEBUG_VIEW && /* @__PURE__ */
|
|
3057
|
+
), __DEV__ && ENABLE_DEBUG_VIEW && /* @__PURE__ */ React2.createElement(DebugView, { state: refState.current }));
|
|
3044
3058
|
});
|
|
3045
3059
|
|
|
3046
3060
|
export { LegendList, useIsLastItem, useListScrollSize, useRecyclingEffect, useRecyclingState, useSyncLayout, useViewability, useViewabilityAmount };
|