@legendapp/list 3.0.0-beta.16 → 3.0.0-beta.18
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 +756 -9
- package/index.d.ts +756 -9
- package/index.js +37 -18
- package/index.mjs +36 -19
- package/index.native.js +37 -29
- package/index.native.mjs +36 -30
- package/package.json +1 -1
- package/section-list.d.mts +1 -2
- package/section-list.d.ts +1 -2
- package/section-list.js +25 -3891
- package/section-list.mjs +23 -3890
- package/index.native.d.mts +0 -23
- package/index.native.d.ts +0 -23
- package/section-list.native.d.mts +0 -113
- package/section-list.native.d.ts +0 -113
- package/section-list.native.js +0 -3986
- package/section-list.native.mjs +0 -3965
- package/types-Dj2MEm9V.d.mts +0 -752
- package/types-Dj2MEm9V.d.ts +0 -752
package/section-list.mjs
CHANGED
|
@@ -1,3885 +1,18 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import { useSyncExternalStore } from 'use-sync-external-store/shim';
|
|
5
|
-
import { unstable_batchedUpdates } from 'react-dom';
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { Platform } from 'react-native';
|
|
3
|
+
import { typedMemo, typedForwardRef, LegendList } from '@legendapp/list';
|
|
6
4
|
|
|
7
5
|
// src/section-list/SectionList.tsx
|
|
8
|
-
forwardRef(function AnimatedView2(props, ref) {
|
|
9
|
-
return /* @__PURE__ */ React3.createElement("div", { ref, ...props });
|
|
10
|
-
});
|
|
11
|
-
var View = forwardRef(function View2(props, ref) {
|
|
12
|
-
return /* @__PURE__ */ React3.createElement("div", { ref, ...props });
|
|
13
|
-
});
|
|
14
|
-
var Text = View;
|
|
15
|
-
|
|
16
|
-
// src/state/getContentInsetEnd.ts
|
|
17
|
-
function getContentInsetEnd(state) {
|
|
18
|
-
var _a3;
|
|
19
|
-
const { props } = state;
|
|
20
|
-
const horizontal = props.horizontal;
|
|
21
|
-
let contentInset = props.contentInset;
|
|
22
|
-
if (!contentInset) {
|
|
23
|
-
const animatedInset = (_a3 = props.animatedProps) == null ? void 0 : _a3.contentInset;
|
|
24
|
-
if (animatedInset) {
|
|
25
|
-
if ("get" in animatedInset) {
|
|
26
|
-
contentInset = animatedInset.get();
|
|
27
|
-
} else {
|
|
28
|
-
contentInset = animatedInset;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
return (horizontal ? contentInset == null ? void 0 : contentInset.right : contentInset == null ? void 0 : contentInset.bottom) || 0;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// src/state/getContentSize.ts
|
|
36
|
-
function getContentSize(ctx) {
|
|
37
|
-
var _a3;
|
|
38
|
-
const { values, state } = ctx;
|
|
39
|
-
const stylePaddingTop = values.get("stylePaddingTop") || 0;
|
|
40
|
-
const stylePaddingBottom = state.props.stylePaddingBottom || 0;
|
|
41
|
-
const headerSize = values.get("headerSize") || 0;
|
|
42
|
-
const footerSize = values.get("footerSize") || 0;
|
|
43
|
-
const contentInsetBottom = getContentInsetEnd(state);
|
|
44
|
-
const totalSize = (_a3 = state.pendingTotalSize) != null ? _a3 : values.get("totalSize");
|
|
45
|
-
return headerSize + footerSize + totalSize + stylePaddingTop + stylePaddingBottom + (contentInsetBottom || 0);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// src/platform/Animated.tsx
|
|
49
|
-
var createAnimatedValue = (value) => value;
|
|
50
|
-
|
|
51
|
-
// src/state/state.tsx
|
|
52
|
-
var ContextState = React3.createContext(null);
|
|
53
|
-
var contextNum = 0;
|
|
54
|
-
function StateProvider({ children }) {
|
|
55
|
-
const [value] = React3.useState(() => ({
|
|
56
|
-
animatedScrollY: createAnimatedValue(0),
|
|
57
|
-
columnWrapperStyle: void 0,
|
|
58
|
-
contextNum: contextNum++,
|
|
59
|
-
listeners: /* @__PURE__ */ new Map(),
|
|
60
|
-
mapViewabilityAmountCallbacks: /* @__PURE__ */ new Map(),
|
|
61
|
-
mapViewabilityAmountValues: /* @__PURE__ */ new Map(),
|
|
62
|
-
mapViewabilityCallbacks: /* @__PURE__ */ new Map(),
|
|
63
|
-
mapViewabilityConfigStates: /* @__PURE__ */ new Map(),
|
|
64
|
-
mapViewabilityValues: /* @__PURE__ */ new Map(),
|
|
65
|
-
positionListeners: /* @__PURE__ */ new Map(),
|
|
66
|
-
state: void 0,
|
|
67
|
-
values: /* @__PURE__ */ new Map([
|
|
68
|
-
["alignItemsPaddingTop", 0],
|
|
69
|
-
["stylePaddingTop", 0],
|
|
70
|
-
["headerSize", 0],
|
|
71
|
-
["numContainers", 0],
|
|
72
|
-
["activeStickyIndex", -1],
|
|
73
|
-
["totalSize", 0],
|
|
74
|
-
["scrollAdjustPending", 0]
|
|
75
|
-
]),
|
|
76
|
-
viewRefs: /* @__PURE__ */ new Map()
|
|
77
|
-
}));
|
|
78
|
-
return /* @__PURE__ */ React3.createElement(ContextState.Provider, { value }, children);
|
|
79
|
-
}
|
|
80
|
-
function useStateContext() {
|
|
81
|
-
return React3.useContext(ContextState);
|
|
82
|
-
}
|
|
83
|
-
function createSelectorFunctionsArr(ctx, signalNames) {
|
|
84
|
-
let lastValues = [];
|
|
85
|
-
let lastSignalValues = [];
|
|
86
|
-
return {
|
|
87
|
-
get: () => {
|
|
88
|
-
const currentValues = [];
|
|
89
|
-
let hasChanged = false;
|
|
90
|
-
for (let i = 0; i < signalNames.length; i++) {
|
|
91
|
-
const value = peek$(ctx, signalNames[i]);
|
|
92
|
-
currentValues.push(value);
|
|
93
|
-
if (value !== lastSignalValues[i]) {
|
|
94
|
-
hasChanged = true;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
lastSignalValues = currentValues;
|
|
98
|
-
if (hasChanged) {
|
|
99
|
-
lastValues = currentValues;
|
|
100
|
-
}
|
|
101
|
-
return lastValues;
|
|
102
|
-
},
|
|
103
|
-
subscribe: (cb) => {
|
|
104
|
-
const listeners = [];
|
|
105
|
-
for (const signalName of signalNames) {
|
|
106
|
-
listeners.push(listen$(ctx, signalName, cb));
|
|
107
|
-
}
|
|
108
|
-
return () => {
|
|
109
|
-
for (const listener of listeners) {
|
|
110
|
-
listener();
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
function listen$(ctx, signalName, cb) {
|
|
117
|
-
const { listeners } = ctx;
|
|
118
|
-
let setListeners = listeners.get(signalName);
|
|
119
|
-
if (!setListeners) {
|
|
120
|
-
setListeners = /* @__PURE__ */ new Set();
|
|
121
|
-
listeners.set(signalName, setListeners);
|
|
122
|
-
}
|
|
123
|
-
setListeners.add(cb);
|
|
124
|
-
return () => setListeners.delete(cb);
|
|
125
|
-
}
|
|
126
|
-
function peek$(ctx, signalName) {
|
|
127
|
-
const { values } = ctx;
|
|
128
|
-
return values.get(signalName);
|
|
129
|
-
}
|
|
130
|
-
function set$(ctx, signalName, value) {
|
|
131
|
-
const { listeners, values } = ctx;
|
|
132
|
-
if (values.get(signalName) !== value) {
|
|
133
|
-
values.set(signalName, value);
|
|
134
|
-
const setListeners = listeners.get(signalName);
|
|
135
|
-
if (setListeners) {
|
|
136
|
-
for (const listener of setListeners) {
|
|
137
|
-
listener(value);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
function listenPosition$(ctx, key, cb) {
|
|
143
|
-
const { positionListeners } = ctx;
|
|
144
|
-
let setListeners = positionListeners.get(key);
|
|
145
|
-
if (!setListeners) {
|
|
146
|
-
setListeners = /* @__PURE__ */ new Set();
|
|
147
|
-
positionListeners.set(key, setListeners);
|
|
148
|
-
}
|
|
149
|
-
setListeners.add(cb);
|
|
150
|
-
return () => setListeners.delete(cb);
|
|
151
|
-
}
|
|
152
|
-
function notifyPosition$(ctx, key, value) {
|
|
153
|
-
const { positionListeners } = ctx;
|
|
154
|
-
const setListeners = positionListeners.get(key);
|
|
155
|
-
if (setListeners) {
|
|
156
|
-
for (const listener of setListeners) {
|
|
157
|
-
listener(value);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
function useArr$(signalNames) {
|
|
162
|
-
const ctx = React3.useContext(ContextState);
|
|
163
|
-
const { subscribe, get } = React3.useMemo(() => createSelectorFunctionsArr(ctx, signalNames), [ctx, signalNames]);
|
|
164
|
-
const value = useSyncExternalStore(subscribe, get);
|
|
165
|
-
return value;
|
|
166
|
-
}
|
|
167
|
-
function useSelector$(signalName, selector) {
|
|
168
|
-
const ctx = React3.useContext(ContextState);
|
|
169
|
-
const { subscribe, get } = React3.useMemo(() => createSelectorFunctionsArr(ctx, [signalName]), [ctx, signalName]);
|
|
170
|
-
const value = useSyncExternalStore(subscribe, () => selector(get()[0]));
|
|
171
|
-
return value;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
// src/components/DebugView.tsx
|
|
175
|
-
var DebugRow = ({ children }) => {
|
|
176
|
-
return /* @__PURE__ */ React3.createElement(View, { style: { alignItems: "center", flexDirection: "row", justifyContent: "space-between" } }, children);
|
|
177
|
-
};
|
|
178
|
-
var DebugView = React3.memo(function DebugView2({ state }) {
|
|
179
|
-
const ctx = useStateContext();
|
|
180
|
-
const [totalSize = 0, scrollAdjust = 0, rawScroll = 0, scroll = 0, _numContainers = 0, _numContainersPooled = 0] = useArr$([
|
|
181
|
-
"totalSize",
|
|
182
|
-
"scrollAdjust",
|
|
183
|
-
"debugRawScroll",
|
|
184
|
-
"debugComputedScroll",
|
|
185
|
-
"numContainers",
|
|
186
|
-
"numContainersPooled"
|
|
187
|
-
]);
|
|
188
|
-
const contentSize = getContentSize(ctx);
|
|
189
|
-
const [, forceUpdate] = useReducer((x) => x + 1, 0);
|
|
190
|
-
useInterval(() => {
|
|
191
|
-
forceUpdate();
|
|
192
|
-
}, 100);
|
|
193
|
-
return /* @__PURE__ */ React3.createElement(
|
|
194
|
-
View,
|
|
195
|
-
{
|
|
196
|
-
pointerEvents: "none",
|
|
197
|
-
style: {
|
|
198
|
-
// height: 100,
|
|
199
|
-
backgroundColor: "#FFFFFFCC",
|
|
200
|
-
borderRadius: 4,
|
|
201
|
-
padding: 4,
|
|
202
|
-
paddingBottom: 4,
|
|
203
|
-
paddingLeft: 4,
|
|
204
|
-
position: "absolute",
|
|
205
|
-
right: 0,
|
|
206
|
-
top: 0
|
|
207
|
-
}
|
|
208
|
-
},
|
|
209
|
-
/* @__PURE__ */ React3.createElement(DebugRow, null, /* @__PURE__ */ React3.createElement(Text, null, "TotalSize:"), /* @__PURE__ */ React3.createElement(Text, null, totalSize.toFixed(2))),
|
|
210
|
-
/* @__PURE__ */ React3.createElement(DebugRow, null, /* @__PURE__ */ React3.createElement(Text, null, "ContentSize:"), /* @__PURE__ */ React3.createElement(Text, null, contentSize.toFixed(2))),
|
|
211
|
-
/* @__PURE__ */ React3.createElement(DebugRow, null, /* @__PURE__ */ React3.createElement(Text, null, "At end:"), /* @__PURE__ */ React3.createElement(Text, null, String(state.isAtEnd))),
|
|
212
|
-
/* @__PURE__ */ React3.createElement(DebugRow, null, /* @__PURE__ */ React3.createElement(Text, null, "ScrollAdjust:"), /* @__PURE__ */ React3.createElement(Text, null, scrollAdjust.toFixed(2))),
|
|
213
|
-
/* @__PURE__ */ React3.createElement(DebugRow, null, /* @__PURE__ */ React3.createElement(Text, null, "RawScroll: "), /* @__PURE__ */ React3.createElement(Text, null, rawScroll.toFixed(2))),
|
|
214
|
-
/* @__PURE__ */ React3.createElement(DebugRow, null, /* @__PURE__ */ React3.createElement(Text, null, "ComputedScroll: "), /* @__PURE__ */ React3.createElement(Text, null, scroll.toFixed(2)))
|
|
215
|
-
);
|
|
216
|
-
});
|
|
217
|
-
function useInterval(callback, delay) {
|
|
218
|
-
useEffect(() => {
|
|
219
|
-
const interval = setInterval(callback, delay);
|
|
220
|
-
return () => clearInterval(interval);
|
|
221
|
-
}, [delay]);
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
// src/utils/devEnvironment.ts
|
|
225
|
-
var metroDev = typeof __DEV__ !== "undefined" ? __DEV__ : void 0;
|
|
226
|
-
var _a;
|
|
227
|
-
var envMode = typeof process !== "undefined" && typeof process.env === "object" && process.env ? (_a = process.env.NODE_ENV) != null ? _a : process.env.MODE : void 0;
|
|
228
|
-
var processDev = typeof envMode === "string" ? envMode.toLowerCase() !== "production" : void 0;
|
|
229
|
-
var _a2;
|
|
230
|
-
var IS_DEV = (_a2 = metroDev != null ? metroDev : processDev) != null ? _a2 : false;
|
|
231
|
-
|
|
232
|
-
// src/constants.ts
|
|
233
|
-
var POSITION_OUT_OF_VIEW = -1e7;
|
|
234
|
-
var ENABLE_DEVMODE = IS_DEV && false;
|
|
235
|
-
var ENABLE_DEBUG_VIEW = IS_DEV && false;
|
|
236
|
-
var typedForwardRef = forwardRef;
|
|
237
|
-
var typedMemo = memo;
|
|
238
|
-
|
|
239
|
-
// src/utils/helpers.ts
|
|
240
|
-
function isFunction(obj) {
|
|
241
|
-
return typeof obj === "function";
|
|
242
|
-
}
|
|
243
|
-
function isArray(obj) {
|
|
244
|
-
return Array.isArray(obj);
|
|
245
|
-
}
|
|
246
|
-
var warned = /* @__PURE__ */ new Set();
|
|
247
|
-
function warnDevOnce(id, text) {
|
|
248
|
-
if (IS_DEV && !warned.has(id)) {
|
|
249
|
-
warned.add(id);
|
|
250
|
-
console.warn(`[legend-list] ${text}`);
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
function roundSize(size) {
|
|
254
|
-
return Math.floor(size * 8) / 8;
|
|
255
|
-
}
|
|
256
|
-
function isNullOrUndefined(value) {
|
|
257
|
-
return value === null || value === void 0;
|
|
258
|
-
}
|
|
259
|
-
function comparatorDefault(a, b) {
|
|
260
|
-
return a - b;
|
|
261
|
-
}
|
|
262
|
-
function getPadding(s, type) {
|
|
263
|
-
var _a3, _b, _c;
|
|
264
|
-
return (_c = (_b = (_a3 = s[`padding${type}`]) != null ? _a3 : s.paddingVertical) != null ? _b : s.padding) != null ? _c : 0;
|
|
265
|
-
}
|
|
266
|
-
function extractPadding(style, contentContainerStyle, type) {
|
|
267
|
-
return getPadding(style, type) + getPadding(contentContainerStyle, type);
|
|
268
|
-
}
|
|
269
|
-
function findContainerId(ctx, key) {
|
|
270
|
-
const numContainers = peek$(ctx, "numContainers");
|
|
271
|
-
for (let i = 0; i < numContainers; i++) {
|
|
272
|
-
const itemKey = peek$(ctx, `containerItemKey${i}`);
|
|
273
|
-
if (itemKey === key) {
|
|
274
|
-
return i;
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
return -1;
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
// src/components/PositionView.tsx
|
|
281
|
-
var PositionViewState = typedMemo(function PositionViewState2({
|
|
282
|
-
id,
|
|
283
|
-
horizontal,
|
|
284
|
-
style,
|
|
285
|
-
refView,
|
|
286
|
-
...props
|
|
287
|
-
}) {
|
|
288
|
-
const [position = POSITION_OUT_OF_VIEW] = useArr$([`containerPosition${id}`]);
|
|
289
|
-
const base = {
|
|
290
|
-
contain: "paint layout style"
|
|
291
|
-
};
|
|
292
|
-
const composed = isArray(style) ? Object.assign({}, ...style) : style;
|
|
293
|
-
const combinedStyle = horizontal ? { ...base, ...composed, left: position } : { ...base, ...composed, top: position };
|
|
294
|
-
const { animatedScrollY, stickyOffset, onLayout, ...webProps } = props;
|
|
295
|
-
return /* @__PURE__ */ React3.createElement("div", { ref: refView, ...webProps, style: combinedStyle });
|
|
296
|
-
});
|
|
297
|
-
var PositionViewSticky = typedMemo(function PositionViewSticky2({
|
|
298
|
-
id,
|
|
299
|
-
horizontal,
|
|
300
|
-
style,
|
|
301
|
-
refView,
|
|
302
|
-
index,
|
|
303
|
-
stickyOffset,
|
|
304
|
-
animatedScrollY: _animatedScrollY,
|
|
305
|
-
children,
|
|
306
|
-
...rest
|
|
307
|
-
}) {
|
|
308
|
-
const [position = POSITION_OUT_OF_VIEW, headerSize = 0, activeStickyIndex] = useArr$([
|
|
309
|
-
`containerPosition${id}`,
|
|
310
|
-
"headerSize",
|
|
311
|
-
"activeStickyIndex"
|
|
312
|
-
]);
|
|
313
|
-
const base = {
|
|
314
|
-
contain: "paint layout style"
|
|
315
|
-
};
|
|
316
|
-
const composed = React3.useMemo(
|
|
317
|
-
() => {
|
|
318
|
-
var _a3;
|
|
319
|
-
return (_a3 = isArray(style) ? Object.assign({}, ...style) : style) != null ? _a3 : {};
|
|
320
|
-
},
|
|
321
|
-
[style]
|
|
322
|
-
);
|
|
323
|
-
const viewStyle = React3.useMemo(() => {
|
|
324
|
-
var _a3;
|
|
325
|
-
const styleBase = { ...base, ...composed };
|
|
326
|
-
delete styleBase.transform;
|
|
327
|
-
const offset = (_a3 = stickyOffset != null ? stickyOffset : headerSize) != null ? _a3 : 0;
|
|
328
|
-
const isActive = activeStickyIndex === index;
|
|
329
|
-
styleBase.position = isActive ? "sticky" : "absolute";
|
|
330
|
-
styleBase.zIndex = index + 1e3;
|
|
331
|
-
if (horizontal) {
|
|
332
|
-
styleBase.left = isActive ? offset : position;
|
|
333
|
-
} else {
|
|
334
|
-
styleBase.top = isActive ? offset : position;
|
|
335
|
-
}
|
|
336
|
-
return styleBase;
|
|
337
|
-
}, [composed, horizontal, position, index, stickyOffset, headerSize, activeStickyIndex]);
|
|
338
|
-
return /* @__PURE__ */ React3.createElement("div", { ref: refView, style: viewStyle, ...rest }, children);
|
|
339
|
-
});
|
|
340
|
-
var PositionView = PositionViewState;
|
|
341
|
-
|
|
342
|
-
// src/constants-platform.ts
|
|
343
|
-
var IsNewArchitecture = true;
|
|
344
|
-
|
|
345
|
-
// src/state/ContextContainer.ts
|
|
346
|
-
var ContextContainer = createContext(null);
|
|
347
|
-
function useContextContainer() {
|
|
348
|
-
return useContext(ContextContainer);
|
|
349
|
-
}
|
|
350
|
-
function useIsLastItem() {
|
|
351
|
-
const containerContext = useContextContainer();
|
|
352
|
-
const isLast = useSelector$("lastItemKeys", (lastItemKeys) => {
|
|
353
|
-
if (containerContext) {
|
|
354
|
-
const { itemKey } = containerContext;
|
|
355
|
-
if (!isNullOrUndefined(itemKey)) {
|
|
356
|
-
return (lastItemKeys == null ? void 0 : lastItemKeys.includes(itemKey)) || false;
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
return false;
|
|
360
|
-
});
|
|
361
|
-
return isLast;
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
// src/components/Separator.tsx
|
|
365
|
-
function Separator({ ItemSeparatorComponent, leadingItem }) {
|
|
366
|
-
const isLastItem = useIsLastItem();
|
|
367
|
-
return isLastItem ? null : /* @__PURE__ */ React3.createElement(ItemSeparatorComponent, { leadingItem });
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
// src/hooks/createResizeObserver.ts
|
|
371
|
-
var globalResizeObserver = null;
|
|
372
|
-
function getGlobalResizeObserver() {
|
|
373
|
-
if (!globalResizeObserver) {
|
|
374
|
-
globalResizeObserver = new ResizeObserver((entries) => {
|
|
375
|
-
for (const entry of entries) {
|
|
376
|
-
const callbacks = callbackMap.get(entry.target);
|
|
377
|
-
if (callbacks) {
|
|
378
|
-
for (const callback of callbacks) {
|
|
379
|
-
callback(entry);
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
});
|
|
384
|
-
}
|
|
385
|
-
return globalResizeObserver;
|
|
386
|
-
}
|
|
387
|
-
var callbackMap = /* @__PURE__ */ new WeakMap();
|
|
388
|
-
function createResizeObserver(element, callback) {
|
|
389
|
-
if (typeof ResizeObserver === "undefined") {
|
|
390
|
-
return () => {
|
|
391
|
-
};
|
|
392
|
-
}
|
|
393
|
-
if (!element) {
|
|
394
|
-
return () => {
|
|
395
|
-
};
|
|
396
|
-
}
|
|
397
|
-
const observer = getGlobalResizeObserver();
|
|
398
|
-
let callbacks = callbackMap.get(element);
|
|
399
|
-
if (!callbacks) {
|
|
400
|
-
callbacks = /* @__PURE__ */ new Set();
|
|
401
|
-
callbackMap.set(element, callbacks);
|
|
402
|
-
observer.observe(element);
|
|
403
|
-
}
|
|
404
|
-
callbacks.add(callback);
|
|
405
|
-
return () => {
|
|
406
|
-
if (callbacks) {
|
|
407
|
-
callbacks.delete(callback);
|
|
408
|
-
if (callbacks.size === 0) {
|
|
409
|
-
callbackMap.delete(element);
|
|
410
|
-
observer.unobserve(element);
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
};
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
// src/hooks/useOnLayoutSync.tsx
|
|
417
|
-
function useOnLayoutSync({
|
|
418
|
-
ref,
|
|
419
|
-
onLayoutProp,
|
|
420
|
-
onLayoutChange
|
|
421
|
-
}, deps) {
|
|
422
|
-
useLayoutEffect(() => {
|
|
423
|
-
var _a3, _b;
|
|
424
|
-
const current = ref.current;
|
|
425
|
-
const scrollableNode = (_b = (_a3 = current == null ? void 0 : current.getScrollableNode) == null ? void 0 : _a3.call(current)) != null ? _b : null;
|
|
426
|
-
const element = scrollableNode || current;
|
|
427
|
-
if (!element) {
|
|
428
|
-
return;
|
|
429
|
-
}
|
|
430
|
-
const emit = (layout, fromLayoutEffect) => {
|
|
431
|
-
if (layout.height === 0 && layout.width === 0) {
|
|
432
|
-
return;
|
|
433
|
-
}
|
|
434
|
-
onLayoutChange(layout, fromLayoutEffect);
|
|
435
|
-
onLayoutProp == null ? void 0 : onLayoutProp({ nativeEvent: { layout } });
|
|
436
|
-
};
|
|
437
|
-
const rect = element.getBoundingClientRect();
|
|
438
|
-
emit(toLayout(rect), true);
|
|
439
|
-
let prevRect = rect;
|
|
440
|
-
return createResizeObserver(element, (entry) => {
|
|
441
|
-
var _a4;
|
|
442
|
-
const target = entry.target instanceof HTMLElement ? entry.target : void 0;
|
|
443
|
-
const rectObserved = (_a4 = entry.contentRect) != null ? _a4 : target == null ? void 0 : target.getBoundingClientRect();
|
|
444
|
-
if (rectObserved.width !== prevRect.width || rectObserved.height !== prevRect.height) {
|
|
445
|
-
prevRect = rectObserved;
|
|
446
|
-
emit(toLayout(rectObserved), false);
|
|
447
|
-
}
|
|
448
|
-
});
|
|
449
|
-
}, deps || []);
|
|
450
|
-
return {};
|
|
451
|
-
}
|
|
452
|
-
function toLayout(rect) {
|
|
453
|
-
if (!rect) {
|
|
454
|
-
return { height: 0, width: 0, x: 0, y: 0 };
|
|
455
|
-
}
|
|
456
|
-
return {
|
|
457
|
-
height: rect.height,
|
|
458
|
-
width: rect.width,
|
|
459
|
-
x: rect.left,
|
|
460
|
-
y: rect.top
|
|
461
|
-
};
|
|
462
|
-
}
|
|
463
|
-
|
|
464
|
-
// src/components/Container.tsx
|
|
465
|
-
var Container = typedMemo(function Container2({
|
|
466
|
-
id,
|
|
467
|
-
recycleItems,
|
|
468
|
-
horizontal,
|
|
469
|
-
getRenderedItem: getRenderedItem2,
|
|
470
|
-
updateItemSize: updateItemSize2,
|
|
471
|
-
ItemSeparatorComponent,
|
|
472
|
-
stickyHeaderConfig
|
|
473
|
-
}) {
|
|
474
|
-
const ctx = useStateContext();
|
|
475
|
-
const { columnWrapperStyle, animatedScrollY } = ctx;
|
|
476
|
-
const [column = 0, data, itemKey, numColumns, extraData, isSticky, stickyOffset] = useArr$([
|
|
477
|
-
`containerColumn${id}`,
|
|
478
|
-
`containerItemData${id}`,
|
|
479
|
-
`containerItemKey${id}`,
|
|
480
|
-
"numColumns",
|
|
481
|
-
"extraData",
|
|
482
|
-
`containerSticky${id}`,
|
|
483
|
-
`containerStickyOffset${id}`
|
|
484
|
-
]);
|
|
485
|
-
const itemLayoutRef = useRef({
|
|
486
|
-
horizontal,
|
|
487
|
-
itemKey,
|
|
488
|
-
updateItemSize: updateItemSize2
|
|
489
|
-
});
|
|
490
|
-
itemLayoutRef.current.horizontal = horizontal;
|
|
491
|
-
itemLayoutRef.current.itemKey = itemKey;
|
|
492
|
-
itemLayoutRef.current.updateItemSize = updateItemSize2;
|
|
493
|
-
const ref = useRef(null);
|
|
494
|
-
const [layoutRenderCount, forceLayoutRender] = useState(0);
|
|
495
|
-
const otherAxisPos = numColumns > 1 ? `${(column - 1) / numColumns * 100}%` : 0;
|
|
496
|
-
const otherAxisSize = numColumns > 1 ? `${1 / numColumns * 100}%` : void 0;
|
|
497
|
-
const didLayoutRef = useRef(false);
|
|
498
|
-
const style = useMemo(() => {
|
|
499
|
-
let paddingStyles;
|
|
500
|
-
if (columnWrapperStyle) {
|
|
501
|
-
const { columnGap, rowGap, gap } = columnWrapperStyle;
|
|
502
|
-
if (horizontal) {
|
|
503
|
-
paddingStyles = {
|
|
504
|
-
paddingRight: columnGap || gap || void 0,
|
|
505
|
-
paddingVertical: numColumns > 1 ? (rowGap || gap || 0) / 2 : void 0
|
|
506
|
-
};
|
|
507
|
-
} else {
|
|
508
|
-
paddingStyles = {
|
|
509
|
-
paddingBottom: rowGap || gap || void 0,
|
|
510
|
-
paddingHorizontal: numColumns > 1 ? (columnGap || gap || 0) / 2 : void 0
|
|
511
|
-
};
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
return horizontal ? {
|
|
515
|
-
flexDirection: ItemSeparatorComponent ? "row" : void 0,
|
|
516
|
-
height: otherAxisSize,
|
|
517
|
-
left: 0,
|
|
518
|
-
position: "absolute",
|
|
519
|
-
top: otherAxisPos,
|
|
520
|
-
...paddingStyles || {}
|
|
521
|
-
} : {
|
|
522
|
-
left: otherAxisPos,
|
|
523
|
-
position: "absolute",
|
|
524
|
-
right: numColumns > 1 ? null : 0,
|
|
525
|
-
top: 0,
|
|
526
|
-
width: otherAxisSize,
|
|
527
|
-
...paddingStyles || {}
|
|
528
|
-
};
|
|
529
|
-
}, [horizontal, otherAxisPos, otherAxisSize, columnWrapperStyle, numColumns]);
|
|
530
|
-
const renderedItemInfo = useMemo(
|
|
531
|
-
() => itemKey !== void 0 ? getRenderedItem2(itemKey) : null,
|
|
532
|
-
[itemKey, data, extraData]
|
|
533
|
-
);
|
|
534
|
-
const { index, renderedItem } = renderedItemInfo || {};
|
|
535
|
-
const contextValue = useMemo(() => {
|
|
536
|
-
ctx.viewRefs.set(id, ref);
|
|
537
|
-
return {
|
|
538
|
-
containerId: id,
|
|
539
|
-
index,
|
|
540
|
-
itemKey,
|
|
541
|
-
triggerLayout: () => {
|
|
542
|
-
forceLayoutRender((v) => v + 1);
|
|
543
|
-
},
|
|
544
|
-
value: data
|
|
545
|
-
};
|
|
546
|
-
}, [id, itemKey, index, data]);
|
|
547
|
-
const onLayoutChange = useCallback((rectangle) => {
|
|
548
|
-
const {
|
|
549
|
-
horizontal: currentHorizontal,
|
|
550
|
-
itemKey: currentItemKey,
|
|
551
|
-
updateItemSize: updateItemSizeFn
|
|
552
|
-
} = itemLayoutRef.current;
|
|
553
|
-
if (isNullOrUndefined(currentItemKey)) {
|
|
554
|
-
return;
|
|
555
|
-
}
|
|
556
|
-
didLayoutRef.current = true;
|
|
557
|
-
let layout = rectangle;
|
|
558
|
-
roundSize(rectangle[currentHorizontal ? "width" : "height"]);
|
|
559
|
-
const doUpdate = () => {
|
|
560
|
-
itemLayoutRef.current.lastSize = { height: layout.height, width: layout.width };
|
|
561
|
-
updateItemSizeFn(currentItemKey, layout);
|
|
562
|
-
didLayoutRef.current = true;
|
|
563
|
-
};
|
|
564
|
-
{
|
|
565
|
-
doUpdate();
|
|
566
|
-
}
|
|
567
|
-
}, []);
|
|
568
|
-
const { onLayout } = useOnLayoutSync(
|
|
569
|
-
{
|
|
570
|
-
onLayoutChange,
|
|
571
|
-
ref
|
|
572
|
-
},
|
|
573
|
-
[itemKey, layoutRenderCount]
|
|
574
|
-
);
|
|
575
|
-
const PositionComponent = isSticky ? PositionViewSticky : PositionView;
|
|
576
|
-
return /* @__PURE__ */ React3.createElement(
|
|
577
|
-
PositionComponent,
|
|
578
|
-
{
|
|
579
|
-
animatedScrollY: isSticky ? animatedScrollY : void 0,
|
|
580
|
-
horizontal,
|
|
581
|
-
id,
|
|
582
|
-
index,
|
|
583
|
-
key: recycleItems ? void 0 : itemKey,
|
|
584
|
-
onLayout,
|
|
585
|
-
refView: ref,
|
|
586
|
-
stickyHeaderConfig,
|
|
587
|
-
stickyOffset: isSticky ? stickyOffset : void 0,
|
|
588
|
-
style
|
|
589
|
-
},
|
|
590
|
-
/* @__PURE__ */ React3.createElement(ContextContainer.Provider, { value: contextValue }, renderedItem, renderedItemInfo && ItemSeparatorComponent && /* @__PURE__ */ React3.createElement(Separator, { ItemSeparatorComponent, leadingItem: renderedItemInfo.item }))
|
|
591
|
-
);
|
|
592
|
-
});
|
|
593
|
-
|
|
594
|
-
// src/platform/Platform.ts
|
|
595
|
-
var Platform = {
|
|
596
|
-
// Widen the type to avoid unreachable-branch lints in cross-platform code that compares against other OSes
|
|
597
|
-
OS: "web"
|
|
598
|
-
};
|
|
599
|
-
|
|
600
|
-
// src/utils/reordering.ts
|
|
601
|
-
var mapFn = (element) => {
|
|
602
|
-
const indexStr = element.getAttribute("index");
|
|
603
|
-
return [element, indexStr === null ? null : parseInt(indexStr)];
|
|
604
|
-
};
|
|
605
|
-
function sortDOMElements(container) {
|
|
606
|
-
const elements = Array.from(container.children);
|
|
607
|
-
if (elements.length <= 1) return elements;
|
|
608
|
-
const items = elements.map(mapFn);
|
|
609
|
-
items.sort((a, b) => {
|
|
610
|
-
const aKey = a[1];
|
|
611
|
-
const bKey = b[1];
|
|
612
|
-
if (aKey === null) {
|
|
613
|
-
return 1;
|
|
614
|
-
}
|
|
615
|
-
if (bKey === null) {
|
|
616
|
-
return -1;
|
|
617
|
-
}
|
|
618
|
-
return aKey - bKey;
|
|
619
|
-
});
|
|
620
|
-
const targetPositions = /* @__PURE__ */ new Map();
|
|
621
|
-
items.forEach((item, index) => {
|
|
622
|
-
targetPositions.set(item[0], index);
|
|
623
|
-
});
|
|
624
|
-
const currentPositions = elements.map((el) => targetPositions.get(el));
|
|
625
|
-
const lis = findLIS(currentPositions);
|
|
626
|
-
const stableIndices = new Set(lis);
|
|
627
|
-
for (let targetPos = 0; targetPos < items.length; targetPos++) {
|
|
628
|
-
const element = items[targetPos][0];
|
|
629
|
-
const currentPos = elements.indexOf(element);
|
|
630
|
-
if (!stableIndices.has(currentPos)) {
|
|
631
|
-
let nextStableElement = null;
|
|
632
|
-
for (let i = targetPos + 1; i < items.length; i++) {
|
|
633
|
-
const nextEl = items[i][0];
|
|
634
|
-
const nextCurrentPos = elements.indexOf(nextEl);
|
|
635
|
-
if (stableIndices.has(nextCurrentPos)) {
|
|
636
|
-
nextStableElement = nextEl;
|
|
637
|
-
break;
|
|
638
|
-
}
|
|
639
|
-
}
|
|
640
|
-
if (nextStableElement) {
|
|
641
|
-
container.insertBefore(element, nextStableElement);
|
|
642
|
-
} else {
|
|
643
|
-
container.appendChild(element);
|
|
644
|
-
}
|
|
645
|
-
}
|
|
646
|
-
}
|
|
647
|
-
}
|
|
648
|
-
function findLIS(arr) {
|
|
649
|
-
const n = arr.length;
|
|
650
|
-
const tails = [];
|
|
651
|
-
const predecessors = new Array(n).fill(-1);
|
|
652
|
-
const indices = [];
|
|
653
|
-
for (let i = 0; i < n; i++) {
|
|
654
|
-
const num = arr[i];
|
|
655
|
-
let left = 0, right = tails.length;
|
|
656
|
-
while (left < right) {
|
|
657
|
-
const mid = Math.floor((left + right) / 2);
|
|
658
|
-
if (arr[indices[mid]] < num) {
|
|
659
|
-
left = mid + 1;
|
|
660
|
-
} else {
|
|
661
|
-
right = mid;
|
|
662
|
-
}
|
|
663
|
-
}
|
|
664
|
-
if (left === tails.length) {
|
|
665
|
-
tails.push(num);
|
|
666
|
-
indices.push(i);
|
|
667
|
-
} else {
|
|
668
|
-
tails[left] = num;
|
|
669
|
-
indices[left] = i;
|
|
670
|
-
}
|
|
671
|
-
if (left > 0) {
|
|
672
|
-
predecessors[i] = indices[left - 1];
|
|
673
|
-
}
|
|
674
|
-
}
|
|
675
|
-
const result = [];
|
|
676
|
-
let k = indices[indices.length - 1];
|
|
677
|
-
while (k !== -1) {
|
|
678
|
-
result.unshift(k);
|
|
679
|
-
k = predecessors[k];
|
|
680
|
-
}
|
|
681
|
-
return result;
|
|
682
|
-
}
|
|
683
|
-
|
|
684
|
-
// src/hooks/useDOMOrder.ts
|
|
685
|
-
function useDOMOrder(ref) {
|
|
686
|
-
const ctx = useStateContext();
|
|
687
|
-
const debounceRef = useRef(void 0);
|
|
688
|
-
useEffect(() => {
|
|
689
|
-
const unsubscribe = listen$(ctx, "lastPositionUpdate", () => {
|
|
690
|
-
if (debounceRef.current !== void 0) {
|
|
691
|
-
clearTimeout(debounceRef.current);
|
|
692
|
-
}
|
|
693
|
-
debounceRef.current = setTimeout(() => {
|
|
694
|
-
const parent = ref.current;
|
|
695
|
-
if (parent) {
|
|
696
|
-
sortDOMElements(parent);
|
|
697
|
-
}
|
|
698
|
-
debounceRef.current = void 0;
|
|
699
|
-
}, 500);
|
|
700
|
-
});
|
|
701
|
-
return () => {
|
|
702
|
-
unsubscribe();
|
|
703
|
-
if (debounceRef.current !== void 0) {
|
|
704
|
-
clearTimeout(debounceRef.current);
|
|
705
|
-
}
|
|
706
|
-
};
|
|
707
|
-
}, [ctx]);
|
|
708
|
-
}
|
|
709
|
-
|
|
710
|
-
// src/components/Containers.tsx
|
|
711
|
-
var ContainersInner = typedMemo(function ContainersInner2({ horizontal, numColumns, children }) {
|
|
712
|
-
const ref = useRef(null);
|
|
713
|
-
const ctx = useStateContext();
|
|
714
|
-
const columnWrapperStyle = ctx.columnWrapperStyle;
|
|
715
|
-
const [totalSize, otherAxisSize] = useArr$(["totalSize", "otherAxisSize"]);
|
|
716
|
-
useDOMOrder(ref);
|
|
717
|
-
const style = horizontal ? { minHeight: otherAxisSize, position: "relative", width: totalSize } : { height: totalSize, minWidth: otherAxisSize, position: "relative" };
|
|
718
|
-
if (columnWrapperStyle && numColumns > 1) {
|
|
719
|
-
const { columnGap, rowGap, gap } = columnWrapperStyle;
|
|
720
|
-
const gapX = columnGap || gap || 0;
|
|
721
|
-
const gapY = rowGap || gap || 0;
|
|
722
|
-
if (horizontal) {
|
|
723
|
-
if (gapY) {
|
|
724
|
-
style.marginTop = style.marginBottom = -gapY / 2;
|
|
725
|
-
}
|
|
726
|
-
if (gapX) {
|
|
727
|
-
style.marginRight = -gapX;
|
|
728
|
-
}
|
|
729
|
-
} else {
|
|
730
|
-
if (gapX) {
|
|
731
|
-
style.marginLeft = style.marginRight = -gapX;
|
|
732
|
-
}
|
|
733
|
-
if (gapY) {
|
|
734
|
-
style.marginBottom = -gapY;
|
|
735
|
-
}
|
|
736
|
-
}
|
|
737
|
-
}
|
|
738
|
-
return /* @__PURE__ */ React3.createElement("div", { ref, style }, children);
|
|
739
|
-
});
|
|
740
|
-
var Containers = typedMemo(function Containers2({
|
|
741
|
-
horizontal,
|
|
742
|
-
recycleItems,
|
|
743
|
-
ItemSeparatorComponent,
|
|
744
|
-
waitForInitialLayout,
|
|
745
|
-
updateItemSize: updateItemSize2,
|
|
746
|
-
getRenderedItem: getRenderedItem2,
|
|
747
|
-
stickyHeaderConfig
|
|
748
|
-
}) {
|
|
749
|
-
const [numContainers, numColumns] = useArr$(["numContainersPooled", "numColumns"]);
|
|
750
|
-
const containers = [];
|
|
751
|
-
for (let i = 0; i < numContainers; i++) {
|
|
752
|
-
containers.push(
|
|
753
|
-
/* @__PURE__ */ React3.createElement(
|
|
754
|
-
Container,
|
|
755
|
-
{
|
|
756
|
-
getRenderedItem: getRenderedItem2,
|
|
757
|
-
horizontal,
|
|
758
|
-
ItemSeparatorComponent,
|
|
759
|
-
id: i,
|
|
760
|
-
key: i,
|
|
761
|
-
recycleItems,
|
|
762
|
-
stickyHeaderConfig,
|
|
763
|
-
updateItemSize: updateItemSize2
|
|
764
|
-
}
|
|
765
|
-
)
|
|
766
|
-
);
|
|
767
|
-
}
|
|
768
|
-
return /* @__PURE__ */ React3.createElement(ContainersInner, { horizontal, numColumns, waitForInitialLayout }, containers);
|
|
769
|
-
});
|
|
770
|
-
function DevNumbers() {
|
|
771
|
-
return IS_DEV && // biome-ignore lint/nursery/noShadow: const function name shadowing is intentional
|
|
772
|
-
React3.memo(function DevNumbers2() {
|
|
773
|
-
return Array.from({ length: 100 }).map((_, index) => /* @__PURE__ */ React3.createElement(
|
|
774
|
-
"div",
|
|
775
|
-
{
|
|
776
|
-
key: index,
|
|
777
|
-
style: {
|
|
778
|
-
height: 100,
|
|
779
|
-
pointerEvents: "none",
|
|
780
|
-
position: "absolute",
|
|
781
|
-
top: index * 100,
|
|
782
|
-
width: "100%"
|
|
783
|
-
}
|
|
784
|
-
},
|
|
785
|
-
/* @__PURE__ */ React3.createElement("div", { style: { color: "red" } }, index * 100)
|
|
786
|
-
));
|
|
787
|
-
});
|
|
788
|
-
}
|
|
789
|
-
|
|
790
|
-
// src/platform/StyleSheet.tsx
|
|
791
|
-
function flattenStyles(styles) {
|
|
792
|
-
if (isArray(styles)) {
|
|
793
|
-
return Object.assign({}, ...styles.filter(Boolean));
|
|
794
|
-
}
|
|
795
|
-
return styles;
|
|
796
|
-
}
|
|
797
|
-
var StyleSheet = {
|
|
798
|
-
create: (styles) => styles,
|
|
799
|
-
flatten: (style) => flattenStyles(style)
|
|
800
|
-
};
|
|
801
|
-
|
|
802
|
-
// src/components/ListComponentScrollView.tsx
|
|
803
|
-
var ListComponentScrollView = forwardRef(function ListComponentScrollView2({
|
|
804
|
-
children,
|
|
805
|
-
style,
|
|
806
|
-
contentContainerStyle,
|
|
807
|
-
horizontal = false,
|
|
808
|
-
contentOffset,
|
|
809
|
-
maintainVisibleContentPosition,
|
|
810
|
-
onScroll: onScroll2,
|
|
811
|
-
onMomentumScrollEnd,
|
|
812
|
-
showsHorizontalScrollIndicator = true,
|
|
813
|
-
showsVerticalScrollIndicator = true,
|
|
814
|
-
refreshControl,
|
|
815
|
-
onLayout,
|
|
816
|
-
...props
|
|
817
|
-
}, ref) {
|
|
818
|
-
const scrollRef = useRef(null);
|
|
819
|
-
const contentRef = useRef(null);
|
|
820
|
-
useImperativeHandle(ref, () => {
|
|
821
|
-
const api = {
|
|
822
|
-
getBoundingClientRect: () => {
|
|
823
|
-
var _a3;
|
|
824
|
-
return (_a3 = scrollRef.current) == null ? void 0 : _a3.getBoundingClientRect();
|
|
825
|
-
},
|
|
826
|
-
getScrollableNode: () => scrollRef.current,
|
|
827
|
-
getScrollResponder: () => scrollRef.current,
|
|
828
|
-
scrollBy: (x, y) => {
|
|
829
|
-
const el = scrollRef.current;
|
|
830
|
-
if (!el) return;
|
|
831
|
-
el.scrollBy(x, y);
|
|
832
|
-
},
|
|
833
|
-
scrollTo: (options) => {
|
|
834
|
-
const el = scrollRef.current;
|
|
835
|
-
if (!el) return;
|
|
836
|
-
const { x = 0, y = 0, animated = true } = options;
|
|
837
|
-
el.scrollTo({ behavior: animated ? "smooth" : "auto", left: x, top: y });
|
|
838
|
-
},
|
|
839
|
-
scrollToEnd: (options = {}) => {
|
|
840
|
-
const el = scrollRef.current;
|
|
841
|
-
if (!el) return;
|
|
842
|
-
const { animated = true } = options;
|
|
843
|
-
if (horizontal) {
|
|
844
|
-
el.scrollTo({ behavior: animated ? "smooth" : "auto", left: el.scrollWidth });
|
|
845
|
-
} else {
|
|
846
|
-
el.scrollTo({ behavior: animated ? "smooth" : "auto", top: el.scrollHeight });
|
|
847
|
-
}
|
|
848
|
-
},
|
|
849
|
-
scrollToOffset: (params) => {
|
|
850
|
-
const el = scrollRef.current;
|
|
851
|
-
if (!el) return;
|
|
852
|
-
const { offset, animated = true } = params;
|
|
853
|
-
if (horizontal) {
|
|
854
|
-
el.scrollTo({ behavior: animated ? "smooth" : "auto", left: offset });
|
|
855
|
-
} else {
|
|
856
|
-
el.scrollTo({ behavior: animated ? "smooth" : "auto", top: offset });
|
|
857
|
-
}
|
|
858
|
-
}
|
|
859
|
-
};
|
|
860
|
-
return api;
|
|
861
|
-
}, [horizontal]);
|
|
862
|
-
const handleScroll = useCallback(
|
|
863
|
-
(event) => {
|
|
864
|
-
if (!onScroll2 || !(event == null ? void 0 : event.target)) {
|
|
865
|
-
return;
|
|
866
|
-
}
|
|
867
|
-
const target = event.target;
|
|
868
|
-
const scrollEvent = {
|
|
869
|
-
nativeEvent: {
|
|
870
|
-
contentOffset: {
|
|
871
|
-
x: target.scrollLeft,
|
|
872
|
-
y: target.scrollTop
|
|
873
|
-
},
|
|
874
|
-
contentSize: {
|
|
875
|
-
height: target.scrollHeight,
|
|
876
|
-
width: target.scrollWidth
|
|
877
|
-
},
|
|
878
|
-
layoutMeasurement: {
|
|
879
|
-
height: target.clientHeight,
|
|
880
|
-
width: target.clientWidth
|
|
881
|
-
}
|
|
882
|
-
}
|
|
883
|
-
};
|
|
884
|
-
onScroll2(scrollEvent);
|
|
885
|
-
},
|
|
886
|
-
[onScroll2, onMomentumScrollEnd]
|
|
887
|
-
);
|
|
888
|
-
useLayoutEffect(() => {
|
|
889
|
-
const element = scrollRef.current;
|
|
890
|
-
if (!element) return;
|
|
891
|
-
element.addEventListener("scroll", handleScroll);
|
|
892
|
-
return () => {
|
|
893
|
-
element.removeEventListener("scroll", handleScroll);
|
|
894
|
-
};
|
|
895
|
-
}, [handleScroll]);
|
|
896
|
-
useEffect(() => {
|
|
897
|
-
const doScroll = () => {
|
|
898
|
-
if (contentOffset && scrollRef.current) {
|
|
899
|
-
scrollRef.current.scrollLeft = contentOffset.x || 0;
|
|
900
|
-
scrollRef.current.scrollTop = contentOffset.y || 0;
|
|
901
|
-
}
|
|
902
|
-
};
|
|
903
|
-
doScroll();
|
|
904
|
-
requestAnimationFrame(doScroll);
|
|
905
|
-
}, [contentOffset == null ? void 0 : contentOffset.x, contentOffset == null ? void 0 : contentOffset.y]);
|
|
906
|
-
useLayoutEffect(() => {
|
|
907
|
-
if (!onLayout || !scrollRef.current) return;
|
|
908
|
-
const element = scrollRef.current;
|
|
909
|
-
const fireLayout = () => {
|
|
910
|
-
const rect = element.getBoundingClientRect();
|
|
911
|
-
onLayout({
|
|
912
|
-
nativeEvent: {
|
|
913
|
-
layout: {
|
|
914
|
-
height: rect.height,
|
|
915
|
-
width: rect.width,
|
|
916
|
-
x: rect.left,
|
|
917
|
-
y: rect.top
|
|
918
|
-
}
|
|
919
|
-
}
|
|
920
|
-
});
|
|
921
|
-
};
|
|
922
|
-
fireLayout();
|
|
923
|
-
const resizeObserver = new ResizeObserver(() => {
|
|
924
|
-
fireLayout();
|
|
925
|
-
});
|
|
926
|
-
resizeObserver.observe(element);
|
|
927
|
-
return () => resizeObserver.disconnect();
|
|
928
|
-
}, [onLayout]);
|
|
929
|
-
const scrollViewStyle = {
|
|
930
|
-
overflow: "auto",
|
|
931
|
-
overflowX: horizontal ? "auto" : showsHorizontalScrollIndicator ? "auto" : "hidden",
|
|
932
|
-
overflowY: horizontal ? showsVerticalScrollIndicator ? "auto" : "hidden" : "auto",
|
|
933
|
-
position: "relative",
|
|
934
|
-
// Ensure proper positioning context
|
|
935
|
-
WebkitOverflowScrolling: "touch",
|
|
936
|
-
// iOS momentum scrolling
|
|
937
|
-
...StyleSheet.flatten(style)
|
|
938
|
-
};
|
|
939
|
-
const contentStyle = {
|
|
940
|
-
display: horizontal ? "flex" : "block",
|
|
941
|
-
flexDirection: horizontal ? "row" : void 0,
|
|
942
|
-
minHeight: horizontal ? void 0 : "100%",
|
|
943
|
-
minWidth: horizontal ? "100%" : void 0,
|
|
944
|
-
...StyleSheet.flatten(contentContainerStyle)
|
|
945
|
-
};
|
|
946
|
-
const { contentInset, scrollEventThrottle, ScrollComponent, ...webProps } = props;
|
|
947
|
-
return /* @__PURE__ */ React3.createElement("div", { ref: scrollRef, ...webProps, style: scrollViewStyle }, refreshControl, /* @__PURE__ */ React3.createElement("div", { ref: contentRef, style: contentStyle }, children));
|
|
948
|
-
});
|
|
949
|
-
function Padding() {
|
|
950
|
-
const [paddingTop] = useArr$(["alignItemsPaddingTop"]);
|
|
951
|
-
return /* @__PURE__ */ React3.createElement("div", { style: { paddingTop } });
|
|
952
|
-
}
|
|
953
|
-
function PaddingDevMode() {
|
|
954
|
-
const [paddingTop] = useArr$(["alignItemsPaddingTop"]);
|
|
955
|
-
return /* @__PURE__ */ React3.createElement(React3.Fragment, null, /* @__PURE__ */ React3.createElement("div", { style: { paddingTop } }), /* @__PURE__ */ React3.createElement(
|
|
956
|
-
"div",
|
|
957
|
-
{
|
|
958
|
-
style: {
|
|
959
|
-
backgroundColor: "green",
|
|
960
|
-
height: paddingTop,
|
|
961
|
-
left: 0,
|
|
962
|
-
position: "absolute",
|
|
963
|
-
right: 0,
|
|
964
|
-
top: 0
|
|
965
|
-
}
|
|
966
|
-
}
|
|
967
|
-
));
|
|
968
|
-
}
|
|
969
|
-
function useValueListener$(key, callback) {
|
|
970
|
-
const ctx = useStateContext();
|
|
971
|
-
useLayoutEffect(() => {
|
|
972
|
-
const unsubscribe = listen$(ctx, key, (value) => {
|
|
973
|
-
callback(value);
|
|
974
|
-
});
|
|
975
|
-
return unsubscribe;
|
|
976
|
-
}, [callback, ctx, key]);
|
|
977
|
-
}
|
|
978
|
-
|
|
979
|
-
// src/components/ScrollAdjust.tsx
|
|
980
|
-
function ScrollAdjust() {
|
|
981
|
-
const ctx = useStateContext();
|
|
982
|
-
const lastScrollOffsetRef = React3.useRef(0);
|
|
983
|
-
const callback = React3.useCallback(() => {
|
|
984
|
-
var _a3;
|
|
985
|
-
const scrollAdjust = peek$(ctx, "scrollAdjust");
|
|
986
|
-
const scrollAdjustUserOffset = peek$(ctx, "scrollAdjustUserOffset");
|
|
987
|
-
const scrollOffset = (scrollAdjust || 0) + (scrollAdjustUserOffset || 0);
|
|
988
|
-
const scrollView = (_a3 = ctx.state) == null ? void 0 : _a3.refScroller.current;
|
|
989
|
-
if (scrollView && scrollOffset !== lastScrollOffsetRef.current) {
|
|
990
|
-
const scrollDelta = scrollOffset - lastScrollOffsetRef.current;
|
|
991
|
-
if (scrollDelta !== 0) {
|
|
992
|
-
const el = scrollView.getScrollableNode();
|
|
993
|
-
const prevScroll = el.scrollTop;
|
|
994
|
-
const nextScroll = prevScroll + scrollDelta;
|
|
995
|
-
const totalSize = el.scrollHeight;
|
|
996
|
-
if (scrollDelta > 0 && !ctx.state.adjustingFromInitialMount && totalSize < nextScroll + el.clientHeight) {
|
|
997
|
-
const child = el.firstElementChild;
|
|
998
|
-
const prevPaddingBottom = child.style.paddingBottom;
|
|
999
|
-
const pad = (nextScroll + el.clientHeight - totalSize) * 2;
|
|
1000
|
-
child.style.paddingBottom = `${pad}px`;
|
|
1001
|
-
void el.offsetHeight;
|
|
1002
|
-
scrollView.scrollBy(0, scrollDelta);
|
|
1003
|
-
requestAnimationFrame(() => {
|
|
1004
|
-
child.style.paddingBottom = prevPaddingBottom;
|
|
1005
|
-
});
|
|
1006
|
-
} else {
|
|
1007
|
-
scrollView.scrollBy(0, scrollDelta);
|
|
1008
|
-
}
|
|
1009
|
-
}
|
|
1010
|
-
lastScrollOffsetRef.current = scrollOffset;
|
|
1011
|
-
}
|
|
1012
|
-
}, [ctx]);
|
|
1013
|
-
useValueListener$("scrollAdjust", callback);
|
|
1014
|
-
useValueListener$("scrollAdjustUserOffset", callback);
|
|
1015
|
-
return null;
|
|
1016
|
-
}
|
|
1017
|
-
function SnapWrapper({ ScrollComponent, ...props }) {
|
|
1018
|
-
const [snapToOffsets] = useArr$(["snapToOffsets"]);
|
|
1019
|
-
return /* @__PURE__ */ React3.createElement(ScrollComponent, { ...props, snapToOffsets });
|
|
1020
|
-
}
|
|
1021
|
-
var LayoutView = ({ onLayoutChange, refView, children, ...rest }) => {
|
|
1022
|
-
const ref = refView != null ? refView : useRef();
|
|
1023
|
-
useOnLayoutSync({ onLayoutChange, ref });
|
|
1024
|
-
return /* @__PURE__ */ React3.createElement("div", { ...rest, ref }, children);
|
|
1025
|
-
};
|
|
1026
|
-
var getComponent = (Component) => {
|
|
1027
|
-
if (React3.isValidElement(Component)) {
|
|
1028
|
-
return Component;
|
|
1029
|
-
}
|
|
1030
|
-
if (Component) {
|
|
1031
|
-
return /* @__PURE__ */ React3.createElement(Component, null);
|
|
1032
|
-
}
|
|
1033
|
-
return null;
|
|
1034
|
-
};
|
|
1035
|
-
|
|
1036
|
-
// src/components/ListComponent.tsx
|
|
1037
|
-
var ListComponent = typedMemo(function ListComponent2({
|
|
1038
|
-
canRender,
|
|
1039
|
-
style,
|
|
1040
|
-
contentContainerStyle,
|
|
1041
|
-
horizontal,
|
|
1042
|
-
initialContentOffset,
|
|
1043
|
-
recycleItems,
|
|
1044
|
-
ItemSeparatorComponent,
|
|
1045
|
-
alignItemsAtEnd,
|
|
1046
|
-
waitForInitialLayout,
|
|
1047
|
-
onScroll: onScroll2,
|
|
1048
|
-
onLayout,
|
|
1049
|
-
ListHeaderComponent,
|
|
1050
|
-
ListHeaderComponentStyle,
|
|
1051
|
-
ListFooterComponent,
|
|
1052
|
-
ListFooterComponentStyle,
|
|
1053
|
-
ListEmptyComponent,
|
|
1054
|
-
getRenderedItem: getRenderedItem2,
|
|
1055
|
-
updateItemSize: updateItemSize2,
|
|
1056
|
-
refScrollView,
|
|
1057
|
-
renderScrollComponent,
|
|
1058
|
-
scrollAdjustHandler,
|
|
1059
|
-
onLayoutHeader,
|
|
1060
|
-
snapToIndices,
|
|
1061
|
-
stickyHeaderConfig,
|
|
1062
|
-
stickyHeaderIndices,
|
|
1063
|
-
...rest
|
|
1064
|
-
}) {
|
|
1065
|
-
const ctx = useStateContext();
|
|
1066
|
-
const maintainVisibleContentPosition = ctx.state.props.maintainVisibleContentPosition;
|
|
1067
|
-
const ScrollComponent = renderScrollComponent ? useMemo(
|
|
1068
|
-
() => React3.forwardRef((props, ref) => renderScrollComponent({ ...props, ref })),
|
|
1069
|
-
[renderScrollComponent]
|
|
1070
|
-
) : ListComponentScrollView;
|
|
1071
|
-
const SnapOrScroll = snapToIndices ? SnapWrapper : ScrollComponent;
|
|
1072
|
-
return /* @__PURE__ */ React3.createElement(
|
|
1073
|
-
SnapOrScroll,
|
|
1074
|
-
{
|
|
1075
|
-
...rest,
|
|
1076
|
-
contentContainerStyle: [
|
|
1077
|
-
contentContainerStyle,
|
|
1078
|
-
horizontal ? {
|
|
1079
|
-
height: "100%"
|
|
1080
|
-
} : {}
|
|
1081
|
-
],
|
|
1082
|
-
contentOffset: initialContentOffset ? horizontal ? { x: initialContentOffset, y: 0 } : { x: 0, y: initialContentOffset } : void 0,
|
|
1083
|
-
horizontal,
|
|
1084
|
-
maintainVisibleContentPosition: maintainVisibleContentPosition.size || maintainVisibleContentPosition.data ? { minIndexForVisible: 0 } : void 0,
|
|
1085
|
-
onLayout,
|
|
1086
|
-
onScroll: onScroll2,
|
|
1087
|
-
ref: refScrollView,
|
|
1088
|
-
ScrollComponent: snapToIndices ? ScrollComponent : void 0,
|
|
1089
|
-
style
|
|
1090
|
-
},
|
|
1091
|
-
/* @__PURE__ */ React3.createElement(ScrollAdjust, null),
|
|
1092
|
-
ENABLE_DEVMODE ? /* @__PURE__ */ React3.createElement(PaddingDevMode, null) : /* @__PURE__ */ React3.createElement(Padding, null),
|
|
1093
|
-
ListHeaderComponent && /* @__PURE__ */ React3.createElement(LayoutView, { onLayoutChange: onLayoutHeader, style: ListHeaderComponentStyle }, getComponent(ListHeaderComponent)),
|
|
1094
|
-
ListEmptyComponent && getComponent(ListEmptyComponent),
|
|
1095
|
-
canRender && !ListEmptyComponent && /* @__PURE__ */ React3.createElement(
|
|
1096
|
-
Containers,
|
|
1097
|
-
{
|
|
1098
|
-
getRenderedItem: getRenderedItem2,
|
|
1099
|
-
horizontal,
|
|
1100
|
-
ItemSeparatorComponent,
|
|
1101
|
-
recycleItems,
|
|
1102
|
-
stickyHeaderConfig,
|
|
1103
|
-
updateItemSize: updateItemSize2,
|
|
1104
|
-
waitForInitialLayout
|
|
1105
|
-
}
|
|
1106
|
-
),
|
|
1107
|
-
ListFooterComponent && /* @__PURE__ */ React3.createElement(
|
|
1108
|
-
LayoutView,
|
|
1109
|
-
{
|
|
1110
|
-
onLayoutChange: (layout) => {
|
|
1111
|
-
const size = layout[horizontal ? "width" : "height"];
|
|
1112
|
-
set$(ctx, "footerSize", size);
|
|
1113
|
-
},
|
|
1114
|
-
style: ListFooterComponentStyle
|
|
1115
|
-
},
|
|
1116
|
-
getComponent(ListFooterComponent)
|
|
1117
|
-
),
|
|
1118
|
-
IS_DEV && ENABLE_DEVMODE && /* @__PURE__ */ React3.createElement(DevNumbers, null)
|
|
1119
|
-
);
|
|
1120
|
-
});
|
|
1121
|
-
|
|
1122
|
-
// src/utils/getId.ts
|
|
1123
|
-
function getId(state, index) {
|
|
1124
|
-
const { data, keyExtractor } = state.props;
|
|
1125
|
-
if (!data) {
|
|
1126
|
-
return "";
|
|
1127
|
-
}
|
|
1128
|
-
const ret = index < data.length ? keyExtractor ? keyExtractor(data[index], index) : index : null;
|
|
1129
|
-
const id = ret;
|
|
1130
|
-
state.idCache[index] = id;
|
|
1131
|
-
return id;
|
|
1132
|
-
}
|
|
1133
|
-
|
|
1134
|
-
// src/core/calculateOffsetForIndex.ts
|
|
1135
|
-
function calculateOffsetForIndex(ctx, index) {
|
|
1136
|
-
const state = ctx.state;
|
|
1137
|
-
let position = 0;
|
|
1138
|
-
if (index !== void 0) {
|
|
1139
|
-
position = state.positions.get(getId(state, index)) || 0;
|
|
1140
|
-
const paddingTop = peek$(ctx, "stylePaddingTop");
|
|
1141
|
-
if (paddingTop) {
|
|
1142
|
-
position += paddingTop;
|
|
1143
|
-
}
|
|
1144
|
-
const headerSize = peek$(ctx, "headerSize");
|
|
1145
|
-
if (headerSize) {
|
|
1146
|
-
position += headerSize;
|
|
1147
|
-
}
|
|
1148
|
-
}
|
|
1149
|
-
return position;
|
|
1150
|
-
}
|
|
1151
|
-
|
|
1152
|
-
// src/utils/setPaddingTop.ts
|
|
1153
|
-
function setPaddingTop(ctx, { stylePaddingTop, alignItemsPaddingTop }) {
|
|
1154
|
-
const state = ctx.state;
|
|
1155
|
-
if (stylePaddingTop !== void 0) {
|
|
1156
|
-
const prevStylePaddingTop = peek$(ctx, "stylePaddingTop") || 0;
|
|
1157
|
-
if (stylePaddingTop < prevStylePaddingTop) {
|
|
1158
|
-
let prevTotalSize = peek$(ctx, "totalSize") || 0;
|
|
1159
|
-
set$(ctx, "totalSize", prevTotalSize + prevStylePaddingTop);
|
|
1160
|
-
state.timeoutSetPaddingTop = setTimeout(() => {
|
|
1161
|
-
prevTotalSize = peek$(ctx, "totalSize") || 0;
|
|
1162
|
-
set$(ctx, "totalSize", prevTotalSize - prevStylePaddingTop);
|
|
1163
|
-
}, 16);
|
|
1164
|
-
}
|
|
1165
|
-
set$(ctx, "stylePaddingTop", stylePaddingTop);
|
|
1166
|
-
}
|
|
1167
|
-
if (alignItemsPaddingTop !== void 0) {
|
|
1168
|
-
set$(ctx, "alignItemsPaddingTop", alignItemsPaddingTop);
|
|
1169
|
-
}
|
|
1170
|
-
}
|
|
1171
|
-
|
|
1172
|
-
// src/utils/updateAlignItemsPaddingTop.ts
|
|
1173
|
-
function updateAlignItemsPaddingTop(ctx) {
|
|
1174
|
-
const state = ctx.state;
|
|
1175
|
-
const {
|
|
1176
|
-
scrollLength,
|
|
1177
|
-
props: { alignItemsAtEnd, data }
|
|
1178
|
-
} = state;
|
|
1179
|
-
if (alignItemsAtEnd) {
|
|
1180
|
-
let alignItemsPaddingTop = 0;
|
|
1181
|
-
if ((data == null ? void 0 : data.length) > 0) {
|
|
1182
|
-
const contentSize = getContentSize(ctx);
|
|
1183
|
-
alignItemsPaddingTop = Math.max(0, Math.floor(scrollLength - contentSize));
|
|
1184
|
-
}
|
|
1185
|
-
setPaddingTop(ctx, { alignItemsPaddingTop });
|
|
1186
|
-
}
|
|
1187
|
-
}
|
|
1188
|
-
|
|
1189
|
-
// src/core/addTotalSize.ts
|
|
1190
|
-
function addTotalSize(ctx, key, add) {
|
|
1191
|
-
const state = ctx.state;
|
|
1192
|
-
const { alignItemsAtEnd } = state.props;
|
|
1193
|
-
const prevTotalSize = state.totalSize;
|
|
1194
|
-
let totalSize = state.totalSize;
|
|
1195
|
-
if (key === null) {
|
|
1196
|
-
totalSize = add;
|
|
1197
|
-
if (state.timeoutSetPaddingTop) {
|
|
1198
|
-
clearTimeout(state.timeoutSetPaddingTop);
|
|
1199
|
-
state.timeoutSetPaddingTop = void 0;
|
|
1200
|
-
}
|
|
1201
|
-
} else {
|
|
1202
|
-
totalSize += add;
|
|
1203
|
-
}
|
|
1204
|
-
if (prevTotalSize !== totalSize) {
|
|
1205
|
-
{
|
|
1206
|
-
state.pendingTotalSize = void 0;
|
|
1207
|
-
state.totalSize = totalSize;
|
|
1208
|
-
set$(ctx, "totalSize", totalSize);
|
|
1209
|
-
if (alignItemsAtEnd) {
|
|
1210
|
-
updateAlignItemsPaddingTop(ctx);
|
|
1211
|
-
}
|
|
1212
|
-
}
|
|
1213
|
-
}
|
|
1214
|
-
}
|
|
1215
|
-
|
|
1216
|
-
// src/core/setSize.ts
|
|
1217
|
-
function setSize(ctx, itemKey, size) {
|
|
1218
|
-
const state = ctx.state;
|
|
1219
|
-
const { sizes } = state;
|
|
1220
|
-
const previousSize = sizes.get(itemKey);
|
|
1221
|
-
const diff = previousSize !== void 0 ? size - previousSize : size;
|
|
1222
|
-
if (diff !== 0) {
|
|
1223
|
-
addTotalSize(ctx, itemKey, diff);
|
|
1224
|
-
}
|
|
1225
|
-
sizes.set(itemKey, size);
|
|
1226
|
-
}
|
|
1227
|
-
|
|
1228
|
-
// src/utils/getItemSize.ts
|
|
1229
|
-
function getItemSize(ctx, key, index, data, useAverageSize, preferCachedSize) {
|
|
1230
|
-
var _a3, _b;
|
|
1231
|
-
const state = ctx.state;
|
|
1232
|
-
const {
|
|
1233
|
-
sizesKnown,
|
|
1234
|
-
sizes,
|
|
1235
|
-
averageSizes,
|
|
1236
|
-
props: { estimatedItemSize, getEstimatedItemSize, getFixedItemSize, getItemType },
|
|
1237
|
-
scrollingTo
|
|
1238
|
-
} = state;
|
|
1239
|
-
const sizeKnown = sizesKnown.get(key);
|
|
1240
|
-
if (sizeKnown !== void 0) {
|
|
1241
|
-
return sizeKnown;
|
|
1242
|
-
}
|
|
1243
|
-
let size;
|
|
1244
|
-
const itemType = getItemType ? (_a3 = getItemType(data, index)) != null ? _a3 : "" : "";
|
|
1245
|
-
if (preferCachedSize) {
|
|
1246
|
-
const cachedSize = sizes.get(key);
|
|
1247
|
-
if (cachedSize !== void 0) {
|
|
1248
|
-
return cachedSize;
|
|
1249
|
-
}
|
|
1250
|
-
}
|
|
1251
|
-
if (getFixedItemSize) {
|
|
1252
|
-
size = getFixedItemSize(index, data, itemType);
|
|
1253
|
-
if (size !== void 0) {
|
|
1254
|
-
sizesKnown.set(key, size);
|
|
1255
|
-
}
|
|
1256
|
-
}
|
|
1257
|
-
if (size === void 0 && useAverageSize && sizeKnown === void 0 && !scrollingTo) {
|
|
1258
|
-
const averageSizeForType = (_b = averageSizes[itemType]) == null ? void 0 : _b.avg;
|
|
1259
|
-
if (averageSizeForType !== void 0) {
|
|
1260
|
-
size = roundSize(averageSizeForType);
|
|
1261
|
-
}
|
|
1262
|
-
}
|
|
1263
|
-
if (size === void 0) {
|
|
1264
|
-
size = sizes.get(key);
|
|
1265
|
-
if (size !== void 0) {
|
|
1266
|
-
return size;
|
|
1267
|
-
}
|
|
1268
|
-
}
|
|
1269
|
-
if (size === void 0) {
|
|
1270
|
-
size = getEstimatedItemSize ? getEstimatedItemSize(index, data, itemType) : estimatedItemSize;
|
|
1271
|
-
}
|
|
1272
|
-
setSize(ctx, key, size);
|
|
1273
|
-
return size;
|
|
1274
|
-
}
|
|
1275
|
-
|
|
1276
|
-
// src/core/calculateOffsetWithOffsetPosition.ts
|
|
1277
|
-
function calculateOffsetWithOffsetPosition(ctx, offsetParam, params) {
|
|
1278
|
-
const state = ctx.state;
|
|
1279
|
-
const { index, viewOffset, viewPosition } = params;
|
|
1280
|
-
let offset = offsetParam;
|
|
1281
|
-
if (viewOffset) {
|
|
1282
|
-
offset -= viewOffset;
|
|
1283
|
-
}
|
|
1284
|
-
if (viewPosition !== void 0 && index !== void 0) {
|
|
1285
|
-
const itemSize = getItemSize(ctx, getId(state, index), index, state.props.data[index]);
|
|
1286
|
-
const trailingInset = getContentInsetEnd(state);
|
|
1287
|
-
offset -= viewPosition * (state.scrollLength - trailingInset - itemSize);
|
|
1288
|
-
}
|
|
1289
|
-
return offset;
|
|
1290
|
-
}
|
|
1291
|
-
|
|
1292
|
-
// src/core/clampScrollOffset.ts
|
|
1293
|
-
function clampScrollOffset(ctx, offset) {
|
|
1294
|
-
const state = ctx.state;
|
|
1295
|
-
const contentSize = getContentSize(ctx);
|
|
1296
|
-
let clampedOffset = offset;
|
|
1297
|
-
if (Number.isFinite(contentSize) && Number.isFinite(state.scrollLength) && (Platform.OS !== "android")) {
|
|
1298
|
-
const maxOffset = Math.max(0, contentSize - state.scrollLength);
|
|
1299
|
-
clampedOffset = Math.min(offset, maxOffset);
|
|
1300
|
-
}
|
|
1301
|
-
clampedOffset = Math.max(0, clampedOffset);
|
|
1302
|
-
return clampedOffset;
|
|
1303
|
-
}
|
|
1304
|
-
|
|
1305
|
-
// src/utils/setInitialRenderState.ts
|
|
1306
|
-
function setInitialRenderState(ctx, {
|
|
1307
|
-
didLayout,
|
|
1308
|
-
didInitialScroll
|
|
1309
|
-
}) {
|
|
1310
|
-
const { state } = ctx;
|
|
1311
|
-
if (didLayout) {
|
|
1312
|
-
state.didContainersLayout = true;
|
|
1313
|
-
}
|
|
1314
|
-
if (didInitialScroll) {
|
|
1315
|
-
state.didFinishInitialScroll = true;
|
|
1316
|
-
}
|
|
1317
|
-
if (state.didContainersLayout && state.didFinishInitialScroll) {
|
|
1318
|
-
set$(ctx, "readyToRender", true);
|
|
1319
|
-
}
|
|
1320
|
-
}
|
|
1321
|
-
|
|
1322
|
-
// src/core/finishScrollTo.ts
|
|
1323
|
-
function finishScrollTo(ctx) {
|
|
1324
|
-
var _a3, _b;
|
|
1325
|
-
const state = ctx.state;
|
|
1326
|
-
if (state == null ? void 0 : state.scrollingTo) {
|
|
1327
|
-
const scrollingTo = state.scrollingTo;
|
|
1328
|
-
state.scrollHistory.length = 0;
|
|
1329
|
-
state.initialScroll = void 0;
|
|
1330
|
-
state.initialAnchor = void 0;
|
|
1331
|
-
state.scrollingTo = void 0;
|
|
1332
|
-
if (state.pendingTotalSize !== void 0) {
|
|
1333
|
-
addTotalSize(ctx, null, state.pendingTotalSize);
|
|
1334
|
-
}
|
|
1335
|
-
if ((_a3 = state.props) == null ? void 0 : _a3.data) {
|
|
1336
|
-
(_b = state.triggerCalculateItemsInView) == null ? void 0 : _b.call(state, { forceFullItemPositions: true });
|
|
1337
|
-
}
|
|
1338
|
-
{
|
|
1339
|
-
state.scrollAdjustHandler.commitPendingAdjust(scrollingTo);
|
|
1340
|
-
}
|
|
1341
|
-
setInitialRenderState(ctx, { didInitialScroll: true });
|
|
1342
|
-
}
|
|
1343
|
-
}
|
|
1344
|
-
|
|
1345
|
-
// src/core/doScrollTo.ts
|
|
1346
|
-
var SCROLL_END_IDLE_MS = 80;
|
|
1347
|
-
var SCROLL_END_MAX_MS = 1500;
|
|
1348
|
-
var SMOOTH_SCROLL_DURATION_MS = 320;
|
|
1349
|
-
function doScrollTo(ctx, params) {
|
|
1350
|
-
const state = ctx.state;
|
|
1351
|
-
const { animated, horizontal, offset } = params;
|
|
1352
|
-
const scroller = state.refScroller.current;
|
|
1353
|
-
const node = typeof (scroller == null ? void 0 : scroller.getScrollableNode) === "function" ? scroller.getScrollableNode() : scroller;
|
|
1354
|
-
if (node) {
|
|
1355
|
-
const left = horizontal ? offset : 0;
|
|
1356
|
-
const top = horizontal ? 0 : offset;
|
|
1357
|
-
node.scrollTo({ behavior: animated ? "smooth" : "auto", left, top });
|
|
1358
|
-
if (animated) {
|
|
1359
|
-
listenForScrollEnd(ctx, node);
|
|
1360
|
-
} else {
|
|
1361
|
-
state.scroll = offset;
|
|
1362
|
-
setTimeout(() => {
|
|
1363
|
-
finishScrollTo(ctx);
|
|
1364
|
-
}, 100);
|
|
1365
|
-
}
|
|
1366
|
-
}
|
|
1367
|
-
}
|
|
1368
|
-
function listenForScrollEnd(ctx, node) {
|
|
1369
|
-
const supportsScrollEnd = "onscrollend" in node;
|
|
1370
|
-
let idleTimeout;
|
|
1371
|
-
let maxTimeout;
|
|
1372
|
-
let settled = false;
|
|
1373
|
-
const targetToken = ctx.state.scrollingTo;
|
|
1374
|
-
const finish = () => {
|
|
1375
|
-
if (settled) return;
|
|
1376
|
-
settled = true;
|
|
1377
|
-
cleanup();
|
|
1378
|
-
if (targetToken === ctx.state.scrollingTo) {
|
|
1379
|
-
finishScrollTo(ctx);
|
|
1380
|
-
}
|
|
1381
|
-
};
|
|
1382
|
-
const onScroll2 = () => {
|
|
1383
|
-
if (idleTimeout) {
|
|
1384
|
-
clearTimeout(idleTimeout);
|
|
1385
|
-
}
|
|
1386
|
-
idleTimeout = setTimeout(finish, SCROLL_END_IDLE_MS);
|
|
1387
|
-
};
|
|
1388
|
-
const cleanup = () => {
|
|
1389
|
-
if (supportsScrollEnd) {
|
|
1390
|
-
node.removeEventListener("scrollend", finish);
|
|
1391
|
-
} else {
|
|
1392
|
-
node.removeEventListener("scroll", onScroll2);
|
|
1393
|
-
}
|
|
1394
|
-
if (idleTimeout) {
|
|
1395
|
-
clearTimeout(idleTimeout);
|
|
1396
|
-
}
|
|
1397
|
-
if (maxTimeout) {
|
|
1398
|
-
clearTimeout(maxTimeout);
|
|
1399
|
-
}
|
|
1400
|
-
};
|
|
1401
|
-
if (supportsScrollEnd) {
|
|
1402
|
-
node.addEventListener("scrollend", finish, { once: true });
|
|
1403
|
-
} else {
|
|
1404
|
-
node.addEventListener("scroll", onScroll2);
|
|
1405
|
-
idleTimeout = setTimeout(finish, SMOOTH_SCROLL_DURATION_MS);
|
|
1406
|
-
maxTimeout = setTimeout(finish, SCROLL_END_MAX_MS);
|
|
1407
|
-
}
|
|
1408
|
-
return cleanup;
|
|
1409
|
-
}
|
|
1410
|
-
|
|
1411
|
-
// src/core/scrollTo.ts
|
|
1412
|
-
function scrollTo(ctx, params) {
|
|
1413
|
-
const state = ctx.state;
|
|
1414
|
-
const { noScrollingTo, forceScroll, ...scrollTarget } = params;
|
|
1415
|
-
const { animated, isInitialScroll, offset: scrollTargetOffset, precomputedWithViewOffset } = scrollTarget;
|
|
1416
|
-
const {
|
|
1417
|
-
props: { horizontal }
|
|
1418
|
-
} = state;
|
|
1419
|
-
if (state.animFrameCheckFinishedScroll) {
|
|
1420
|
-
cancelAnimationFrame(ctx.state.animFrameCheckFinishedScroll);
|
|
1421
|
-
}
|
|
1422
|
-
if (state.timeoutCheckFinishedScrollFallback) {
|
|
1423
|
-
clearTimeout(ctx.state.timeoutCheckFinishedScrollFallback);
|
|
1424
|
-
}
|
|
1425
|
-
let offset = precomputedWithViewOffset ? scrollTargetOffset : calculateOffsetWithOffsetPosition(ctx, scrollTargetOffset, scrollTarget);
|
|
1426
|
-
offset = clampScrollOffset(ctx, offset);
|
|
1427
|
-
state.scrollHistory.length = 0;
|
|
1428
|
-
if (!noScrollingTo) {
|
|
1429
|
-
state.scrollingTo = scrollTarget;
|
|
1430
|
-
}
|
|
1431
|
-
state.scrollPending = offset;
|
|
1432
|
-
if (forceScroll || !isInitialScroll || Platform.OS === "android") {
|
|
1433
|
-
doScrollTo(ctx, { animated, horizontal, isInitialScroll, offset });
|
|
1434
|
-
} else {
|
|
1435
|
-
state.scroll = offset;
|
|
1436
|
-
}
|
|
1437
|
-
}
|
|
1438
|
-
|
|
1439
|
-
// src/utils/checkThreshold.ts
|
|
1440
|
-
var HYSTERESIS_MULTIPLIER = 1.3;
|
|
1441
|
-
var checkThreshold = (distance, atThreshold, threshold, wasReached, snapshot, context, onReached, setSnapshot) => {
|
|
1442
|
-
const absDistance = Math.abs(distance);
|
|
1443
|
-
const within = atThreshold || threshold > 0 && absDistance <= threshold;
|
|
1444
|
-
if (wasReached === null) {
|
|
1445
|
-
if (!within && distance >= 0) {
|
|
1446
|
-
return false;
|
|
1447
|
-
}
|
|
1448
|
-
return null;
|
|
1449
|
-
}
|
|
1450
|
-
const updateSnapshot = () => {
|
|
1451
|
-
setSnapshot == null ? void 0 : setSnapshot({
|
|
1452
|
-
atThreshold,
|
|
1453
|
-
contentSize: context.contentSize,
|
|
1454
|
-
dataLength: context.dataLength,
|
|
1455
|
-
scrollPosition: context.scrollPosition
|
|
1456
|
-
});
|
|
1457
|
-
};
|
|
1458
|
-
if (!wasReached) {
|
|
1459
|
-
if (!within) {
|
|
1460
|
-
return false;
|
|
1461
|
-
}
|
|
1462
|
-
onReached == null ? void 0 : onReached(distance);
|
|
1463
|
-
updateSnapshot();
|
|
1464
|
-
return true;
|
|
1465
|
-
}
|
|
1466
|
-
const reset = !atThreshold && threshold > 0 && absDistance >= threshold * HYSTERESIS_MULTIPLIER || !atThreshold && threshold <= 0 && absDistance > 0;
|
|
1467
|
-
if (reset) {
|
|
1468
|
-
setSnapshot == null ? void 0 : setSnapshot(void 0);
|
|
1469
|
-
return false;
|
|
1470
|
-
}
|
|
1471
|
-
if (within) {
|
|
1472
|
-
const changed = !snapshot || snapshot.atThreshold !== atThreshold || snapshot.contentSize !== context.contentSize || snapshot.dataLength !== context.dataLength;
|
|
1473
|
-
if (changed) {
|
|
1474
|
-
onReached == null ? void 0 : onReached(distance);
|
|
1475
|
-
updateSnapshot();
|
|
1476
|
-
}
|
|
1477
|
-
}
|
|
1478
|
-
return true;
|
|
1479
|
-
};
|
|
1480
|
-
|
|
1481
|
-
// src/utils/checkAtBottom.ts
|
|
1482
|
-
function checkAtBottom(ctx) {
|
|
1483
|
-
var _a3;
|
|
1484
|
-
const state = ctx.state;
|
|
1485
|
-
if (!state) {
|
|
1486
|
-
return;
|
|
1487
|
-
}
|
|
1488
|
-
const {
|
|
1489
|
-
queuedInitialLayout,
|
|
1490
|
-
scrollLength,
|
|
1491
|
-
scroll,
|
|
1492
|
-
maintainingScrollAtEnd,
|
|
1493
|
-
props: { maintainScrollAtEndThreshold, onEndReachedThreshold }
|
|
1494
|
-
} = state;
|
|
1495
|
-
const contentSize = getContentSize(ctx);
|
|
1496
|
-
if (contentSize > 0 && queuedInitialLayout && !maintainingScrollAtEnd) {
|
|
1497
|
-
const distanceFromEnd = contentSize - scroll - scrollLength;
|
|
1498
|
-
const isContentLess = contentSize < scrollLength;
|
|
1499
|
-
state.isAtEnd = isContentLess || distanceFromEnd < scrollLength * maintainScrollAtEndThreshold;
|
|
1500
|
-
state.isEndReached = checkThreshold(
|
|
1501
|
-
distanceFromEnd,
|
|
1502
|
-
isContentLess,
|
|
1503
|
-
onEndReachedThreshold * scrollLength,
|
|
1504
|
-
state.isEndReached,
|
|
1505
|
-
state.endReachedSnapshot,
|
|
1506
|
-
{
|
|
1507
|
-
contentSize,
|
|
1508
|
-
dataLength: (_a3 = state.props.data) == null ? void 0 : _a3.length,
|
|
1509
|
-
scrollPosition: scroll
|
|
1510
|
-
},
|
|
1511
|
-
(distance) => {
|
|
1512
|
-
var _a4, _b;
|
|
1513
|
-
return (_b = (_a4 = state.props).onEndReached) == null ? void 0 : _b.call(_a4, { distanceFromEnd: distance });
|
|
1514
|
-
},
|
|
1515
|
-
(snapshot) => {
|
|
1516
|
-
state.endReachedSnapshot = snapshot;
|
|
1517
|
-
}
|
|
1518
|
-
);
|
|
1519
|
-
}
|
|
1520
|
-
}
|
|
1521
|
-
|
|
1522
|
-
// src/utils/checkAtTop.ts
|
|
1523
|
-
function checkAtTop(state) {
|
|
1524
|
-
var _a3;
|
|
1525
|
-
if (!state) {
|
|
1526
|
-
return;
|
|
1527
|
-
}
|
|
1528
|
-
const {
|
|
1529
|
-
scrollLength,
|
|
1530
|
-
scroll,
|
|
1531
|
-
props: { onStartReachedThreshold }
|
|
1532
|
-
} = state;
|
|
1533
|
-
const distanceFromTop = scroll;
|
|
1534
|
-
state.isAtStart = distanceFromTop <= 0;
|
|
1535
|
-
state.isStartReached = checkThreshold(
|
|
1536
|
-
distanceFromTop,
|
|
1537
|
-
false,
|
|
1538
|
-
onStartReachedThreshold * scrollLength,
|
|
1539
|
-
state.isStartReached,
|
|
1540
|
-
state.startReachedSnapshot,
|
|
1541
|
-
{
|
|
1542
|
-
contentSize: state.totalSize,
|
|
1543
|
-
dataLength: (_a3 = state.props.data) == null ? void 0 : _a3.length,
|
|
1544
|
-
scrollPosition: scroll
|
|
1545
|
-
},
|
|
1546
|
-
(distance) => {
|
|
1547
|
-
var _a4, _b;
|
|
1548
|
-
return (_b = (_a4 = state.props).onStartReached) == null ? void 0 : _b.call(_a4, { distanceFromStart: distance });
|
|
1549
|
-
},
|
|
1550
|
-
(snapshot) => {
|
|
1551
|
-
state.startReachedSnapshot = snapshot;
|
|
1552
|
-
}
|
|
1553
|
-
);
|
|
1554
|
-
}
|
|
1555
|
-
|
|
1556
|
-
// src/core/updateScroll.ts
|
|
1557
|
-
function updateScroll(ctx, newScroll, forceUpdate) {
|
|
1558
|
-
var _a3;
|
|
1559
|
-
const state = ctx.state;
|
|
1560
|
-
const { scrollingTo, scrollAdjustHandler, lastScrollAdjustForHistory } = state;
|
|
1561
|
-
state.hasScrolled = true;
|
|
1562
|
-
state.lastBatchingAction = Date.now();
|
|
1563
|
-
const currentTime = Date.now();
|
|
1564
|
-
const adjust = scrollAdjustHandler.getAdjust();
|
|
1565
|
-
const adjustChanged = lastScrollAdjustForHistory !== void 0 && Math.abs(adjust - lastScrollAdjustForHistory) > 0.1;
|
|
1566
|
-
if (adjustChanged) {
|
|
1567
|
-
state.scrollHistory.length = 0;
|
|
1568
|
-
}
|
|
1569
|
-
state.lastScrollAdjustForHistory = adjust;
|
|
1570
|
-
if (scrollingTo === void 0 && !(state.scrollHistory.length === 0 && newScroll === state.scroll)) {
|
|
1571
|
-
if (!adjustChanged) {
|
|
1572
|
-
state.scrollHistory.push({ scroll: newScroll, time: currentTime });
|
|
1573
|
-
}
|
|
1574
|
-
}
|
|
1575
|
-
if (state.scrollHistory.length > 5) {
|
|
1576
|
-
state.scrollHistory.shift();
|
|
1577
|
-
}
|
|
1578
|
-
state.scrollPrev = state.scroll;
|
|
1579
|
-
state.scrollPrevTime = state.scrollTime;
|
|
1580
|
-
state.scroll = newScroll;
|
|
1581
|
-
state.scrollTime = currentTime;
|
|
1582
|
-
const ignoreScrollFromMVCP = state.ignoreScrollFromMVCP;
|
|
1583
|
-
if (ignoreScrollFromMVCP && !scrollingTo) {
|
|
1584
|
-
const { lt, gt } = ignoreScrollFromMVCP;
|
|
1585
|
-
if (lt && newScroll < lt || gt && newScroll > gt) {
|
|
1586
|
-
state.ignoreScrollFromMVCPIgnored = true;
|
|
1587
|
-
return;
|
|
1588
|
-
}
|
|
1589
|
-
}
|
|
1590
|
-
const lastCalculated = state.scrollLastCalculate;
|
|
1591
|
-
const shouldUpdate = state.dataChangeNeedsScrollUpdate || state.scrollLastCalculate === void 0 || lastCalculated === void 0 || Math.abs(state.scroll - lastCalculated) > 2;
|
|
1592
|
-
if (shouldUpdate) {
|
|
1593
|
-
state.scrollLastCalculate = state.scroll;
|
|
1594
|
-
state.ignoreScrollFromMVCPIgnored = false;
|
|
1595
|
-
(_a3 = state.triggerCalculateItemsInView) == null ? void 0 : _a3.call(state, { doMVCP: scrollingTo !== void 0 });
|
|
1596
|
-
checkAtBottom(ctx);
|
|
1597
|
-
checkAtTop(state);
|
|
1598
|
-
state.dataChangeNeedsScrollUpdate = false;
|
|
1599
|
-
}
|
|
1600
|
-
}
|
|
1601
|
-
|
|
1602
|
-
// src/utils/requestAdjust.ts
|
|
1603
|
-
function requestAdjust(ctx, positionDiff, dataChanged) {
|
|
1604
|
-
const state = ctx.state;
|
|
1605
|
-
if (Math.abs(positionDiff) > 0.1) {
|
|
1606
|
-
const doit = () => {
|
|
1607
|
-
{
|
|
1608
|
-
state.scrollAdjustHandler.requestAdjust(positionDiff);
|
|
1609
|
-
if (state.adjustingFromInitialMount) {
|
|
1610
|
-
state.adjustingFromInitialMount--;
|
|
1611
|
-
}
|
|
1612
|
-
}
|
|
1613
|
-
};
|
|
1614
|
-
state.scroll += positionDiff;
|
|
1615
|
-
state.scrollForNextCalculateItemsInView = void 0;
|
|
1616
|
-
const readyToRender = peek$(ctx, "readyToRender");
|
|
1617
|
-
if (readyToRender) {
|
|
1618
|
-
doit();
|
|
1619
|
-
} else {
|
|
1620
|
-
state.adjustingFromInitialMount = (state.adjustingFromInitialMount || 0) + 1;
|
|
1621
|
-
requestAnimationFrame(doit);
|
|
1622
|
-
}
|
|
1623
|
-
}
|
|
1624
|
-
}
|
|
1625
|
-
|
|
1626
|
-
// src/core/mvcp.ts
|
|
1627
|
-
function prepareMVCP(ctx, dataChanged) {
|
|
1628
|
-
const state = ctx.state;
|
|
1629
|
-
const { idsInView, positions, props } = state;
|
|
1630
|
-
const {
|
|
1631
|
-
maintainVisibleContentPosition: { data: mvcpData, size: mvcpScroll }
|
|
1632
|
-
} = props;
|
|
1633
|
-
const scrollingTo = state.scrollingTo;
|
|
1634
|
-
let prevPosition;
|
|
1635
|
-
let targetId;
|
|
1636
|
-
const idsInViewWithPositions = [];
|
|
1637
|
-
const scrollTarget = scrollingTo == null ? void 0 : scrollingTo.index;
|
|
1638
|
-
const scrollingToViewPosition = scrollingTo == null ? void 0 : scrollingTo.viewPosition;
|
|
1639
|
-
const shouldMVCP = dataChanged ? mvcpData : mvcpScroll;
|
|
1640
|
-
const indexByKey = state.indexByKey;
|
|
1641
|
-
if (shouldMVCP) {
|
|
1642
|
-
if (scrollTarget !== void 0) {
|
|
1643
|
-
targetId = getId(state, scrollTarget);
|
|
1644
|
-
} else if (idsInView.length > 0 && state.didContainersLayout) {
|
|
1645
|
-
if (dataChanged) {
|
|
1646
|
-
for (let i = 0; i < idsInView.length; i++) {
|
|
1647
|
-
const id = idsInView[i];
|
|
1648
|
-
const index = indexByKey.get(id);
|
|
1649
|
-
if (index !== void 0) {
|
|
1650
|
-
idsInViewWithPositions.push({ id, position: positions.get(id) });
|
|
1651
|
-
}
|
|
1652
|
-
}
|
|
1653
|
-
} else {
|
|
1654
|
-
targetId = idsInView.find((id) => indexByKey.get(id) !== void 0);
|
|
1655
|
-
}
|
|
1656
|
-
}
|
|
1657
|
-
if (targetId !== void 0) {
|
|
1658
|
-
prevPosition = positions.get(targetId);
|
|
1659
|
-
}
|
|
1660
|
-
return () => {
|
|
1661
|
-
let positionDiff = 0;
|
|
1662
|
-
if (dataChanged && targetId === void 0 && mvcpData) {
|
|
1663
|
-
for (let i = 0; i < idsInViewWithPositions.length; i++) {
|
|
1664
|
-
const { id, position } = idsInViewWithPositions[i];
|
|
1665
|
-
const newPosition = positions.get(id);
|
|
1666
|
-
if (newPosition !== void 0) {
|
|
1667
|
-
positionDiff = newPosition - position;
|
|
1668
|
-
break;
|
|
1669
|
-
}
|
|
1670
|
-
}
|
|
1671
|
-
}
|
|
1672
|
-
if (targetId !== void 0 && prevPosition !== void 0) {
|
|
1673
|
-
const newPosition = positions.get(targetId);
|
|
1674
|
-
if (newPosition !== void 0) {
|
|
1675
|
-
const totalSize = getContentSize(ctx);
|
|
1676
|
-
let diff = newPosition - prevPosition;
|
|
1677
|
-
if (diff !== 0 && state.scroll + state.scrollLength > totalSize) {
|
|
1678
|
-
if (diff > 0) {
|
|
1679
|
-
diff = Math.max(0, totalSize - state.scroll - state.scrollLength);
|
|
1680
|
-
} else {
|
|
1681
|
-
diff = 0;
|
|
1682
|
-
}
|
|
1683
|
-
}
|
|
1684
|
-
positionDiff = diff;
|
|
1685
|
-
}
|
|
1686
|
-
}
|
|
1687
|
-
if (scrollingToViewPosition && scrollingToViewPosition > 0) {
|
|
1688
|
-
const newSize = getItemSize(ctx, targetId, scrollTarget, state.props.data[scrollTarget]);
|
|
1689
|
-
const prevSize = scrollingTo == null ? void 0 : scrollingTo.itemSize;
|
|
1690
|
-
if (newSize !== void 0 && prevSize !== void 0 && newSize !== (scrollingTo == null ? void 0 : scrollingTo.itemSize)) {
|
|
1691
|
-
const diff = newSize - prevSize;
|
|
1692
|
-
if (diff !== 0) {
|
|
1693
|
-
positionDiff += (newSize - prevSize) * scrollingToViewPosition;
|
|
1694
|
-
scrollingTo.itemSize = newSize;
|
|
1695
|
-
}
|
|
1696
|
-
}
|
|
1697
|
-
}
|
|
1698
|
-
if (Math.abs(positionDiff) > 0.1) {
|
|
1699
|
-
requestAdjust(ctx, positionDiff);
|
|
1700
|
-
}
|
|
1701
|
-
};
|
|
1702
|
-
}
|
|
1703
|
-
}
|
|
1704
|
-
|
|
1705
|
-
// src/core/prepareColumnStartState.ts
|
|
1706
|
-
function prepareColumnStartState(ctx, startIndex, useAverageSize) {
|
|
1707
|
-
var _a3;
|
|
1708
|
-
const state = ctx.state;
|
|
1709
|
-
const numColumns = peek$(ctx, "numColumns");
|
|
1710
|
-
let rowStartIndex = startIndex;
|
|
1711
|
-
const columnAtStart = state.columns.get(state.idCache[startIndex]);
|
|
1712
|
-
if (columnAtStart !== 1) {
|
|
1713
|
-
rowStartIndex = findRowStartIndex(state, numColumns, startIndex);
|
|
1714
|
-
}
|
|
1715
|
-
let currentRowTop = 0;
|
|
1716
|
-
const curId = state.idCache[rowStartIndex];
|
|
1717
|
-
const column = state.columns.get(curId);
|
|
1718
|
-
if (rowStartIndex > 0) {
|
|
1719
|
-
const prevIndex = rowStartIndex - 1;
|
|
1720
|
-
const prevId = state.idCache[prevIndex];
|
|
1721
|
-
const prevPosition = (_a3 = state.positions.get(prevId)) != null ? _a3 : 0;
|
|
1722
|
-
const prevRowStart = findRowStartIndex(state, numColumns, prevIndex);
|
|
1723
|
-
const prevRowHeight = calculateRowMaxSize(ctx, prevRowStart, prevIndex, useAverageSize);
|
|
1724
|
-
currentRowTop = prevPosition + prevRowHeight;
|
|
1725
|
-
}
|
|
1726
|
-
return {
|
|
1727
|
-
column,
|
|
1728
|
-
currentRowTop,
|
|
1729
|
-
startIndex: rowStartIndex
|
|
1730
|
-
};
|
|
1731
|
-
}
|
|
1732
|
-
function findRowStartIndex(state, numColumns, index) {
|
|
1733
|
-
if (numColumns <= 1) {
|
|
1734
|
-
return Math.max(0, index);
|
|
1735
|
-
}
|
|
1736
|
-
let rowStart = Math.max(0, index);
|
|
1737
|
-
while (rowStart > 0) {
|
|
1738
|
-
const columnForIndex = state.columns.get(state.idCache[rowStart]);
|
|
1739
|
-
if (columnForIndex === 1) {
|
|
1740
|
-
break;
|
|
1741
|
-
}
|
|
1742
|
-
rowStart--;
|
|
1743
|
-
}
|
|
1744
|
-
return rowStart;
|
|
1745
|
-
}
|
|
1746
|
-
function calculateRowMaxSize(ctx, startIndex, endIndex, useAverageSize) {
|
|
1747
|
-
const state = ctx.state;
|
|
1748
|
-
if (endIndex < startIndex) {
|
|
1749
|
-
return 0;
|
|
1750
|
-
}
|
|
1751
|
-
const { data } = state.props;
|
|
1752
|
-
if (!data) {
|
|
1753
|
-
return 0;
|
|
1754
|
-
}
|
|
1755
|
-
let maxSize = 0;
|
|
1756
|
-
for (let i = startIndex; i <= endIndex; i++) {
|
|
1757
|
-
if (i < 0 || i >= data.length) {
|
|
1758
|
-
continue;
|
|
1759
|
-
}
|
|
1760
|
-
const id = state.idCache[i];
|
|
1761
|
-
const size = getItemSize(ctx, id, i, data[i], useAverageSize);
|
|
1762
|
-
if (size > maxSize) {
|
|
1763
|
-
maxSize = size;
|
|
1764
|
-
}
|
|
1765
|
-
}
|
|
1766
|
-
return maxSize;
|
|
1767
|
-
}
|
|
1768
|
-
|
|
1769
|
-
// src/core/updateTotalSize.ts
|
|
1770
|
-
function updateTotalSize(ctx) {
|
|
1771
|
-
const state = ctx.state;
|
|
1772
|
-
const {
|
|
1773
|
-
positions,
|
|
1774
|
-
props: { data }
|
|
1775
|
-
} = state;
|
|
1776
|
-
if (data.length === 0) {
|
|
1777
|
-
addTotalSize(ctx, null, 0);
|
|
1778
|
-
} else {
|
|
1779
|
-
const lastId = getId(state, data.length - 1);
|
|
1780
|
-
if (lastId !== void 0) {
|
|
1781
|
-
const lastPosition = positions.get(lastId);
|
|
1782
|
-
if (lastPosition !== void 0) {
|
|
1783
|
-
const lastSize = getItemSize(ctx, lastId, data.length - 1, data[data.length - 1]);
|
|
1784
|
-
if (lastSize !== void 0) {
|
|
1785
|
-
const totalSize = lastPosition + lastSize;
|
|
1786
|
-
addTotalSize(ctx, null, totalSize);
|
|
1787
|
-
}
|
|
1788
|
-
}
|
|
1789
|
-
}
|
|
1790
|
-
}
|
|
1791
|
-
}
|
|
1792
|
-
|
|
1793
|
-
// src/utils/getScrollVelocity.ts
|
|
1794
|
-
var getScrollVelocity = (state) => {
|
|
1795
|
-
const { scrollHistory } = state;
|
|
1796
|
-
const newestIndex = scrollHistory.length - 1;
|
|
1797
|
-
if (newestIndex < 1) {
|
|
1798
|
-
return 0;
|
|
1799
|
-
}
|
|
1800
|
-
const newest = scrollHistory[newestIndex];
|
|
1801
|
-
const now = Date.now();
|
|
1802
|
-
let direction = 0;
|
|
1803
|
-
for (let i = newestIndex; i > 0; i--) {
|
|
1804
|
-
const delta = scrollHistory[i].scroll - scrollHistory[i - 1].scroll;
|
|
1805
|
-
if (delta !== 0) {
|
|
1806
|
-
direction = Math.sign(delta);
|
|
1807
|
-
break;
|
|
1808
|
-
}
|
|
1809
|
-
}
|
|
1810
|
-
if (direction === 0) {
|
|
1811
|
-
return 0;
|
|
1812
|
-
}
|
|
1813
|
-
let oldest = newest;
|
|
1814
|
-
for (let i = newestIndex - 1; i >= 0; i--) {
|
|
1815
|
-
const current = scrollHistory[i];
|
|
1816
|
-
const next = scrollHistory[i + 1];
|
|
1817
|
-
const delta = next.scroll - current.scroll;
|
|
1818
|
-
const deltaSign = Math.sign(delta);
|
|
1819
|
-
if (deltaSign !== 0 && deltaSign !== direction) {
|
|
1820
|
-
break;
|
|
1821
|
-
}
|
|
1822
|
-
if (now - current.time > 1e3) {
|
|
1823
|
-
break;
|
|
1824
|
-
}
|
|
1825
|
-
oldest = current;
|
|
1826
|
-
}
|
|
1827
|
-
const scrollDiff = newest.scroll - oldest.scroll;
|
|
1828
|
-
const timeDiff = newest.time - oldest.time;
|
|
1829
|
-
return timeDiff > 0 ? scrollDiff / timeDiff : 0;
|
|
1830
|
-
};
|
|
1831
|
-
|
|
1832
|
-
// src/utils/updateSnapToOffsets.ts
|
|
1833
|
-
function updateSnapToOffsets(ctx) {
|
|
1834
|
-
const state = ctx.state;
|
|
1835
|
-
const {
|
|
1836
|
-
positions,
|
|
1837
|
-
props: { snapToIndices }
|
|
1838
|
-
} = state;
|
|
1839
|
-
const snapToOffsets = Array(snapToIndices.length);
|
|
1840
|
-
for (let i = 0; i < snapToIndices.length; i++) {
|
|
1841
|
-
const idx = snapToIndices[i];
|
|
1842
|
-
const key = getId(state, idx);
|
|
1843
|
-
snapToOffsets[i] = positions.get(key);
|
|
1844
|
-
}
|
|
1845
|
-
set$(ctx, "snapToOffsets", snapToOffsets);
|
|
1846
|
-
}
|
|
1847
|
-
|
|
1848
|
-
// src/core/updateItemPositions.ts
|
|
1849
|
-
function updateItemPositions(ctx, dataChanged, { startIndex, scrollBottomBuffered, forceFullUpdate = false, doMVCP } = {
|
|
1850
|
-
doMVCP: false,
|
|
1851
|
-
forceFullUpdate: false,
|
|
1852
|
-
scrollBottomBuffered: -1,
|
|
1853
|
-
startIndex: 0
|
|
1854
|
-
}) {
|
|
1855
|
-
var _a3, _b, _c, _d, _e;
|
|
1856
|
-
const state = ctx.state;
|
|
1857
|
-
const {
|
|
1858
|
-
columns,
|
|
1859
|
-
indexByKey,
|
|
1860
|
-
positions,
|
|
1861
|
-
idCache,
|
|
1862
|
-
sizesKnown,
|
|
1863
|
-
props: { data, getEstimatedItemSize, snapToIndices },
|
|
1864
|
-
scrollingTo
|
|
1865
|
-
} = state;
|
|
1866
|
-
const dataLength = data.length;
|
|
1867
|
-
const numColumns = peek$(ctx, "numColumns");
|
|
1868
|
-
const hasColumns = numColumns > 1;
|
|
1869
|
-
const indexByKeyForChecking = IS_DEV ? /* @__PURE__ */ new Map() : void 0;
|
|
1870
|
-
const shouldOptimize = !forceFullUpdate && !dataChanged && Math.abs(getScrollVelocity(state)) > 0;
|
|
1871
|
-
const maxVisibleArea = scrollBottomBuffered + 1e3;
|
|
1872
|
-
const useAverageSize = !getEstimatedItemSize;
|
|
1873
|
-
const preferCachedSize = !doMVCP || dataChanged || state.scrollAdjustHandler.getAdjust() !== 0 || ((_a3 = peek$(ctx, "scrollAdjustPending")) != null ? _a3 : 0) !== 0;
|
|
1874
|
-
let currentRowTop = 0;
|
|
1875
|
-
let column = 1;
|
|
1876
|
-
let maxSizeInRow = 0;
|
|
1877
|
-
if (startIndex > 0) {
|
|
1878
|
-
if (hasColumns) {
|
|
1879
|
-
const { startIndex: processedStartIndex, currentRowTop: initialRowTop } = prepareColumnStartState(
|
|
1880
|
-
ctx,
|
|
1881
|
-
startIndex,
|
|
1882
|
-
useAverageSize
|
|
1883
|
-
);
|
|
1884
|
-
startIndex = processedStartIndex;
|
|
1885
|
-
currentRowTop = initialRowTop;
|
|
1886
|
-
} else if (startIndex < dataLength) {
|
|
1887
|
-
const prevIndex = startIndex - 1;
|
|
1888
|
-
const prevId = getId(state, prevIndex);
|
|
1889
|
-
const prevPosition = (_b = positions.get(prevId)) != null ? _b : 0;
|
|
1890
|
-
const prevSize = (_c = sizesKnown.get(prevId)) != null ? _c : getItemSize(ctx, prevId, prevIndex, data[prevIndex], useAverageSize, preferCachedSize);
|
|
1891
|
-
currentRowTop = prevPosition + prevSize;
|
|
1892
|
-
}
|
|
1893
|
-
}
|
|
1894
|
-
const needsIndexByKey = dataChanged || indexByKey.size === 0;
|
|
1895
|
-
let didBreakEarly = false;
|
|
1896
|
-
let breakAt;
|
|
1897
|
-
for (let i = startIndex; i < dataLength; i++) {
|
|
1898
|
-
if (shouldOptimize && breakAt !== void 0 && i > breakAt) {
|
|
1899
|
-
didBreakEarly = true;
|
|
1900
|
-
break;
|
|
1901
|
-
}
|
|
1902
|
-
if (shouldOptimize && breakAt === void 0 && !scrollingTo && !dataChanged && currentRowTop > maxVisibleArea) {
|
|
1903
|
-
const itemsPerRow = hasColumns ? numColumns : 1;
|
|
1904
|
-
breakAt = i + itemsPerRow + 10;
|
|
1905
|
-
}
|
|
1906
|
-
const id = (_d = idCache[i]) != null ? _d : getId(state, i);
|
|
1907
|
-
const size = (_e = sizesKnown.get(id)) != null ? _e : getItemSize(ctx, id, i, data[i], useAverageSize, preferCachedSize);
|
|
1908
|
-
if (IS_DEV && needsIndexByKey) {
|
|
1909
|
-
if (indexByKeyForChecking.has(id)) {
|
|
1910
|
-
console.error(
|
|
1911
|
-
`[legend-list] Error: Detected overlapping key (${id}) which causes missing items and gaps and other terrrible things. Check that keyExtractor returns unique values.`
|
|
1912
|
-
);
|
|
1913
|
-
}
|
|
1914
|
-
indexByKeyForChecking.set(id, i);
|
|
1915
|
-
}
|
|
1916
|
-
if (currentRowTop !== positions.get(id)) {
|
|
1917
|
-
positions.set(id, currentRowTop);
|
|
1918
|
-
notifyPosition$(ctx, id, currentRowTop);
|
|
1919
|
-
}
|
|
1920
|
-
if (needsIndexByKey) {
|
|
1921
|
-
indexByKey.set(id, i);
|
|
1922
|
-
}
|
|
1923
|
-
columns.set(id, column);
|
|
1924
|
-
if (hasColumns) {
|
|
1925
|
-
if (size > maxSizeInRow) {
|
|
1926
|
-
maxSizeInRow = size;
|
|
1927
|
-
}
|
|
1928
|
-
column++;
|
|
1929
|
-
if (column > numColumns) {
|
|
1930
|
-
currentRowTop += maxSizeInRow;
|
|
1931
|
-
column = 1;
|
|
1932
|
-
maxSizeInRow = 0;
|
|
1933
|
-
}
|
|
1934
|
-
} else {
|
|
1935
|
-
currentRowTop += size;
|
|
1936
|
-
}
|
|
1937
|
-
}
|
|
1938
|
-
if (!didBreakEarly) {
|
|
1939
|
-
updateTotalSize(ctx);
|
|
1940
|
-
}
|
|
1941
|
-
if (snapToIndices) {
|
|
1942
|
-
updateSnapToOffsets(ctx);
|
|
1943
|
-
}
|
|
1944
|
-
}
|
|
1945
|
-
|
|
1946
|
-
// src/core/viewability.ts
|
|
1947
|
-
function ensureViewabilityState(ctx, configId) {
|
|
1948
|
-
let map = ctx.mapViewabilityConfigStates;
|
|
1949
|
-
if (!map) {
|
|
1950
|
-
map = /* @__PURE__ */ new Map();
|
|
1951
|
-
ctx.mapViewabilityConfigStates = map;
|
|
1952
|
-
}
|
|
1953
|
-
let state = map.get(configId);
|
|
1954
|
-
if (!state) {
|
|
1955
|
-
state = { end: -1, previousEnd: -1, previousStart: -1, start: -1, viewableItems: [] };
|
|
1956
|
-
map.set(configId, state);
|
|
1957
|
-
}
|
|
1958
|
-
return state;
|
|
1959
|
-
}
|
|
1960
|
-
function setupViewability(props) {
|
|
1961
|
-
let { viewabilityConfig, viewabilityConfigCallbackPairs, onViewableItemsChanged } = props;
|
|
1962
|
-
if (viewabilityConfig || onViewableItemsChanged) {
|
|
1963
|
-
viewabilityConfigCallbackPairs = [
|
|
1964
|
-
...viewabilityConfigCallbackPairs || [],
|
|
1965
|
-
{
|
|
1966
|
-
onViewableItemsChanged,
|
|
1967
|
-
viewabilityConfig: viewabilityConfig || {
|
|
1968
|
-
viewAreaCoveragePercentThreshold: 0
|
|
1969
|
-
}
|
|
1970
|
-
}
|
|
1971
|
-
];
|
|
1972
|
-
}
|
|
1973
|
-
return viewabilityConfigCallbackPairs;
|
|
1974
|
-
}
|
|
1975
|
-
function updateViewableItems(state, ctx, viewabilityConfigCallbackPairs, scrollSize, start, end) {
|
|
1976
|
-
const {
|
|
1977
|
-
timeouts,
|
|
1978
|
-
props: { data }
|
|
1979
|
-
} = state;
|
|
1980
|
-
for (const viewabilityConfigCallbackPair of viewabilityConfigCallbackPairs) {
|
|
1981
|
-
const viewabilityState = ensureViewabilityState(ctx, viewabilityConfigCallbackPair.viewabilityConfig.id);
|
|
1982
|
-
viewabilityState.start = start;
|
|
1983
|
-
viewabilityState.end = end;
|
|
1984
|
-
if (viewabilityConfigCallbackPair.viewabilityConfig.minimumViewTime) {
|
|
1985
|
-
const timer = setTimeout(() => {
|
|
1986
|
-
timeouts.delete(timer);
|
|
1987
|
-
updateViewableItemsWithConfig(data, viewabilityConfigCallbackPair, state, ctx, scrollSize);
|
|
1988
|
-
}, viewabilityConfigCallbackPair.viewabilityConfig.minimumViewTime);
|
|
1989
|
-
timeouts.add(timer);
|
|
1990
|
-
} else {
|
|
1991
|
-
updateViewableItemsWithConfig(data, viewabilityConfigCallbackPair, state, ctx, scrollSize);
|
|
1992
|
-
}
|
|
1993
|
-
}
|
|
1994
|
-
}
|
|
1995
|
-
function updateViewableItemsWithConfig(data, viewabilityConfigCallbackPair, state, ctx, scrollSize) {
|
|
1996
|
-
const { viewabilityConfig, onViewableItemsChanged } = viewabilityConfigCallbackPair;
|
|
1997
|
-
const configId = viewabilityConfig.id;
|
|
1998
|
-
const viewabilityState = ensureViewabilityState(ctx, configId);
|
|
1999
|
-
const { viewableItems: previousViewableItems, start, end } = viewabilityState;
|
|
2000
|
-
const viewabilityTokens = /* @__PURE__ */ new Map();
|
|
2001
|
-
for (const [containerId, value] of ctx.mapViewabilityAmountValues) {
|
|
2002
|
-
viewabilityTokens.set(
|
|
2003
|
-
containerId,
|
|
2004
|
-
computeViewability(
|
|
2005
|
-
state,
|
|
2006
|
-
ctx,
|
|
2007
|
-
viewabilityConfig,
|
|
2008
|
-
containerId,
|
|
2009
|
-
value.key,
|
|
2010
|
-
scrollSize,
|
|
2011
|
-
value.item,
|
|
2012
|
-
value.index
|
|
2013
|
-
)
|
|
2014
|
-
);
|
|
2015
|
-
}
|
|
2016
|
-
const changed = [];
|
|
2017
|
-
if (previousViewableItems) {
|
|
2018
|
-
for (const viewToken of previousViewableItems) {
|
|
2019
|
-
const containerId = findContainerId(ctx, viewToken.key);
|
|
2020
|
-
if (!checkIsViewable(
|
|
2021
|
-
state,
|
|
2022
|
-
ctx,
|
|
2023
|
-
viewabilityConfig,
|
|
2024
|
-
containerId,
|
|
2025
|
-
viewToken.key,
|
|
2026
|
-
scrollSize,
|
|
2027
|
-
viewToken.item,
|
|
2028
|
-
viewToken.index
|
|
2029
|
-
)) {
|
|
2030
|
-
viewToken.isViewable = false;
|
|
2031
|
-
changed.push(viewToken);
|
|
2032
|
-
}
|
|
2033
|
-
}
|
|
2034
|
-
}
|
|
2035
|
-
const viewableItems = [];
|
|
2036
|
-
for (let i = start; i <= end; i++) {
|
|
2037
|
-
const item = data[i];
|
|
2038
|
-
if (item) {
|
|
2039
|
-
const key = getId(state, i);
|
|
2040
|
-
const containerId = findContainerId(ctx, key);
|
|
2041
|
-
if (checkIsViewable(state, ctx, viewabilityConfig, containerId, key, scrollSize, item, i)) {
|
|
2042
|
-
const viewToken = {
|
|
2043
|
-
containerId,
|
|
2044
|
-
index: i,
|
|
2045
|
-
isViewable: true,
|
|
2046
|
-
item,
|
|
2047
|
-
key
|
|
2048
|
-
};
|
|
2049
|
-
viewableItems.push(viewToken);
|
|
2050
|
-
if (!(previousViewableItems == null ? void 0 : previousViewableItems.find((v) => v.key === viewToken.key))) {
|
|
2051
|
-
changed.push(viewToken);
|
|
2052
|
-
}
|
|
2053
|
-
}
|
|
2054
|
-
}
|
|
2055
|
-
}
|
|
2056
|
-
Object.assign(viewabilityState, {
|
|
2057
|
-
previousEnd: end,
|
|
2058
|
-
previousStart: start,
|
|
2059
|
-
viewableItems
|
|
2060
|
-
});
|
|
2061
|
-
if (changed.length > 0) {
|
|
2062
|
-
viewabilityState.viewableItems = viewableItems;
|
|
2063
|
-
for (let i = 0; i < changed.length; i++) {
|
|
2064
|
-
const change = changed[i];
|
|
2065
|
-
maybeUpdateViewabilityCallback(ctx, configId, change.containerId, change);
|
|
2066
|
-
}
|
|
2067
|
-
if (onViewableItemsChanged) {
|
|
2068
|
-
onViewableItemsChanged({ changed, viewableItems });
|
|
2069
|
-
}
|
|
2070
|
-
}
|
|
2071
|
-
for (const [containerId, value] of ctx.mapViewabilityAmountValues) {
|
|
2072
|
-
if (value.sizeVisible < 0) {
|
|
2073
|
-
ctx.mapViewabilityAmountValues.delete(containerId);
|
|
2074
|
-
}
|
|
2075
|
-
}
|
|
2076
|
-
}
|
|
2077
|
-
function shallowEqual(prev, next) {
|
|
2078
|
-
if (!prev) return false;
|
|
2079
|
-
const keys = Object.keys(next);
|
|
2080
|
-
for (let i = 0; i < keys.length; i++) {
|
|
2081
|
-
const k = keys[i];
|
|
2082
|
-
if (prev[k] !== next[k]) return false;
|
|
2083
|
-
}
|
|
2084
|
-
return true;
|
|
2085
|
-
}
|
|
2086
|
-
function computeViewability(state, ctx, viewabilityConfig, containerId, key, scrollSize, item, index) {
|
|
2087
|
-
const { sizes, positions, scroll: scrollState } = state;
|
|
2088
|
-
const topPad = (peek$(ctx, "stylePaddingTop") || 0) + (peek$(ctx, "headerSize") || 0);
|
|
2089
|
-
const { itemVisiblePercentThreshold, viewAreaCoveragePercentThreshold } = viewabilityConfig;
|
|
2090
|
-
const viewAreaMode = viewAreaCoveragePercentThreshold != null;
|
|
2091
|
-
const viewablePercentThreshold = viewAreaMode ? viewAreaCoveragePercentThreshold : itemVisiblePercentThreshold;
|
|
2092
|
-
const scroll = scrollState - topPad;
|
|
2093
|
-
const top = positions.get(key) - scroll;
|
|
2094
|
-
const size = sizes.get(key) || 0;
|
|
2095
|
-
const bottom = top + size;
|
|
2096
|
-
const isEntirelyVisible = top >= 0 && bottom <= scrollSize && bottom > top;
|
|
2097
|
-
const sizeVisible = isEntirelyVisible ? size : Math.min(bottom, scrollSize) - Math.max(top, 0);
|
|
2098
|
-
const percentVisible = size ? isEntirelyVisible ? 100 : 100 * (sizeVisible / size) : 0;
|
|
2099
|
-
const percentOfScroller = size ? 100 * (sizeVisible / scrollSize) : 0;
|
|
2100
|
-
const percent = isEntirelyVisible ? 100 : viewAreaMode ? percentOfScroller : percentVisible;
|
|
2101
|
-
const isViewable = percent >= viewablePercentThreshold;
|
|
2102
|
-
const value = {
|
|
2103
|
-
containerId,
|
|
2104
|
-
index,
|
|
2105
|
-
isViewable,
|
|
2106
|
-
item,
|
|
2107
|
-
key,
|
|
2108
|
-
percentOfScroller,
|
|
2109
|
-
percentVisible,
|
|
2110
|
-
scrollSize,
|
|
2111
|
-
size,
|
|
2112
|
-
sizeVisible
|
|
2113
|
-
};
|
|
2114
|
-
const prev = ctx.mapViewabilityAmountValues.get(containerId);
|
|
2115
|
-
if (!shallowEqual(prev, value)) {
|
|
2116
|
-
ctx.mapViewabilityAmountValues.set(containerId, value);
|
|
2117
|
-
const cb = ctx.mapViewabilityAmountCallbacks.get(containerId);
|
|
2118
|
-
if (cb) {
|
|
2119
|
-
cb(value);
|
|
2120
|
-
}
|
|
2121
|
-
}
|
|
2122
|
-
return value;
|
|
2123
|
-
}
|
|
2124
|
-
function checkIsViewable(state, ctx, viewabilityConfig, containerId, key, scrollSize, item, index) {
|
|
2125
|
-
let value = ctx.mapViewabilityAmountValues.get(containerId);
|
|
2126
|
-
if (!value || value.key !== key) {
|
|
2127
|
-
value = computeViewability(state, ctx, viewabilityConfig, containerId, key, scrollSize, item, index);
|
|
2128
|
-
}
|
|
2129
|
-
return value.isViewable;
|
|
2130
|
-
}
|
|
2131
|
-
function maybeUpdateViewabilityCallback(ctx, configId, containerId, viewToken) {
|
|
2132
|
-
const key = containerId + configId;
|
|
2133
|
-
ctx.mapViewabilityValues.set(key, viewToken);
|
|
2134
|
-
const cb = ctx.mapViewabilityCallbacks.get(key);
|
|
2135
|
-
cb == null ? void 0 : cb(viewToken);
|
|
2136
|
-
}
|
|
2137
|
-
|
|
2138
|
-
// src/utils/checkAllSizesKnown.ts
|
|
2139
|
-
function isNullOrUndefined2(value) {
|
|
2140
|
-
return value === null || value === void 0;
|
|
2141
|
-
}
|
|
2142
|
-
function checkAllSizesKnown(state) {
|
|
2143
|
-
const { startBuffered, endBuffered, sizesKnown } = state;
|
|
2144
|
-
if (!isNullOrUndefined2(endBuffered) && !isNullOrUndefined2(startBuffered) && startBuffered >= 0 && endBuffered >= 0) {
|
|
2145
|
-
let areAllKnown = true;
|
|
2146
|
-
for (let i = startBuffered; areAllKnown && i <= endBuffered; i++) {
|
|
2147
|
-
const key = getId(state, i);
|
|
2148
|
-
areAllKnown && (areAllKnown = sizesKnown.has(key));
|
|
2149
|
-
}
|
|
2150
|
-
return areAllKnown;
|
|
2151
|
-
}
|
|
2152
|
-
return false;
|
|
2153
|
-
}
|
|
2154
|
-
|
|
2155
|
-
// src/utils/findAvailableContainers.ts
|
|
2156
|
-
function findAvailableContainers(ctx, numNeeded, startBuffered, endBuffered, pendingRemoval, requiredItemTypes, needNewContainers) {
|
|
2157
|
-
const numContainers = peek$(ctx, "numContainers");
|
|
2158
|
-
const state = ctx.state;
|
|
2159
|
-
const { stickyContainerPool, containerItemTypes } = state;
|
|
2160
|
-
const result = [];
|
|
2161
|
-
const availableContainers = [];
|
|
2162
|
-
const pendingRemovalSet = new Set(pendingRemoval);
|
|
2163
|
-
let pendingRemovalChanged = false;
|
|
2164
|
-
const stickyIndicesSet = state.props.stickyIndicesSet;
|
|
2165
|
-
const stickyItemIndices = (needNewContainers == null ? void 0 : needNewContainers.filter((index) => stickyIndicesSet.has(index))) || [];
|
|
2166
|
-
const canReuseContainer = (containerIndex, requiredType) => {
|
|
2167
|
-
if (!requiredType) return true;
|
|
2168
|
-
const existingType = containerItemTypes.get(containerIndex);
|
|
2169
|
-
if (!existingType) return true;
|
|
2170
|
-
return existingType === requiredType;
|
|
2171
|
-
};
|
|
2172
|
-
const neededTypes = requiredItemTypes ? [...requiredItemTypes] : [];
|
|
2173
|
-
let typeIndex = 0;
|
|
2174
|
-
for (let i = 0; i < stickyItemIndices.length; i++) {
|
|
2175
|
-
const requiredType = neededTypes[typeIndex];
|
|
2176
|
-
let foundContainer = false;
|
|
2177
|
-
for (const containerIndex of stickyContainerPool) {
|
|
2178
|
-
const key = peek$(ctx, `containerItemKey${containerIndex}`);
|
|
2179
|
-
const isPendingRemoval = pendingRemovalSet.has(containerIndex);
|
|
2180
|
-
if ((key === void 0 || isPendingRemoval) && canReuseContainer(containerIndex, requiredType) && !result.includes(containerIndex)) {
|
|
2181
|
-
result.push(containerIndex);
|
|
2182
|
-
if (isPendingRemoval && pendingRemovalSet.delete(containerIndex)) {
|
|
2183
|
-
pendingRemovalChanged = true;
|
|
2184
|
-
}
|
|
2185
|
-
foundContainer = true;
|
|
2186
|
-
if (requiredItemTypes) typeIndex++;
|
|
2187
|
-
break;
|
|
2188
|
-
}
|
|
2189
|
-
}
|
|
2190
|
-
if (!foundContainer) {
|
|
2191
|
-
const newContainerIndex = numContainers + result.filter((index) => index >= numContainers).length;
|
|
2192
|
-
result.push(newContainerIndex);
|
|
2193
|
-
stickyContainerPool.add(newContainerIndex);
|
|
2194
|
-
if (requiredItemTypes) typeIndex++;
|
|
2195
|
-
}
|
|
2196
|
-
}
|
|
2197
|
-
for (let u = 0; u < numContainers && result.length < numNeeded; u++) {
|
|
2198
|
-
if (stickyContainerPool.has(u)) {
|
|
2199
|
-
continue;
|
|
2200
|
-
}
|
|
2201
|
-
const key = peek$(ctx, `containerItemKey${u}`);
|
|
2202
|
-
const requiredType = neededTypes[typeIndex];
|
|
2203
|
-
const isPending = key !== void 0 && pendingRemovalSet.has(u);
|
|
2204
|
-
const canUse = key === void 0 || isPending && canReuseContainer(u, requiredType);
|
|
2205
|
-
if (canUse) {
|
|
2206
|
-
if (isPending) {
|
|
2207
|
-
pendingRemovalSet.delete(u);
|
|
2208
|
-
pendingRemovalChanged = true;
|
|
2209
|
-
}
|
|
2210
|
-
result.push(u);
|
|
2211
|
-
if (requiredItemTypes) {
|
|
2212
|
-
typeIndex++;
|
|
2213
|
-
}
|
|
2214
|
-
}
|
|
2215
|
-
}
|
|
2216
|
-
for (let u = 0; u < numContainers && result.length < numNeeded; u++) {
|
|
2217
|
-
if (stickyContainerPool.has(u)) {
|
|
2218
|
-
continue;
|
|
2219
|
-
}
|
|
2220
|
-
const key = peek$(ctx, `containerItemKey${u}`);
|
|
2221
|
-
if (key === void 0) continue;
|
|
2222
|
-
const index = state.indexByKey.get(key);
|
|
2223
|
-
const isOutOfView = index < startBuffered || index > endBuffered;
|
|
2224
|
-
if (isOutOfView) {
|
|
2225
|
-
const distance = index < startBuffered ? startBuffered - index : index - endBuffered;
|
|
2226
|
-
if (!requiredItemTypes || typeIndex < neededTypes.length && canReuseContainer(u, neededTypes[typeIndex])) {
|
|
2227
|
-
availableContainers.push({ distance, index: u });
|
|
2228
|
-
}
|
|
2229
|
-
}
|
|
2230
|
-
}
|
|
2231
|
-
const remaining = numNeeded - result.length;
|
|
2232
|
-
if (remaining > 0) {
|
|
2233
|
-
if (availableContainers.length > 0) {
|
|
2234
|
-
if (availableContainers.length > remaining) {
|
|
2235
|
-
availableContainers.sort(comparatorByDistance);
|
|
2236
|
-
availableContainers.length = remaining;
|
|
2237
|
-
}
|
|
2238
|
-
for (const container of availableContainers) {
|
|
2239
|
-
result.push(container.index);
|
|
2240
|
-
if (requiredItemTypes) {
|
|
2241
|
-
typeIndex++;
|
|
2242
|
-
}
|
|
2243
|
-
}
|
|
2244
|
-
}
|
|
2245
|
-
const stillNeeded = numNeeded - result.length;
|
|
2246
|
-
if (stillNeeded > 0) {
|
|
2247
|
-
for (let i = 0; i < stillNeeded; i++) {
|
|
2248
|
-
result.push(numContainers + i);
|
|
2249
|
-
}
|
|
2250
|
-
if (IS_DEV && numContainers + stillNeeded > peek$(ctx, "numContainersPooled")) {
|
|
2251
|
-
console.warn(
|
|
2252
|
-
"[legend-list] No unused container available, so creating one on demand. This can be a minor performance issue and is likely caused by the estimatedItemSize being too large. Consider decreasing estimatedItemSize or increasing initialContainerPoolRatio.",
|
|
2253
|
-
{
|
|
2254
|
-
debugInfo: {
|
|
2255
|
-
numContainers,
|
|
2256
|
-
numContainersPooled: peek$(ctx, "numContainersPooled"),
|
|
2257
|
-
numNeeded,
|
|
2258
|
-
stillNeeded
|
|
2259
|
-
}
|
|
2260
|
-
}
|
|
2261
|
-
);
|
|
2262
|
-
}
|
|
2263
|
-
}
|
|
2264
|
-
}
|
|
2265
|
-
if (pendingRemovalChanged) {
|
|
2266
|
-
pendingRemoval.length = 0;
|
|
2267
|
-
for (const value of pendingRemovalSet) {
|
|
2268
|
-
pendingRemoval.push(value);
|
|
2269
|
-
}
|
|
2270
|
-
}
|
|
2271
|
-
return result.sort(comparatorDefault);
|
|
2272
|
-
}
|
|
2273
|
-
function comparatorByDistance(a, b) {
|
|
2274
|
-
return b.distance - a.distance;
|
|
2275
|
-
}
|
|
2276
|
-
|
|
2277
|
-
// src/core/scrollToIndex.ts
|
|
2278
|
-
function scrollToIndex(ctx, { index, viewOffset = 0, animated = true, viewPosition }) {
|
|
2279
|
-
const state = ctx.state;
|
|
2280
|
-
const { data } = state.props;
|
|
2281
|
-
if (index >= data.length) {
|
|
2282
|
-
index = data.length - 1;
|
|
2283
|
-
} else if (index < 0) {
|
|
2284
|
-
index = 0;
|
|
2285
|
-
}
|
|
2286
|
-
const firstIndexOffset = calculateOffsetForIndex(ctx, index);
|
|
2287
|
-
const isLast = index === data.length - 1;
|
|
2288
|
-
if (isLast && viewPosition === void 0) {
|
|
2289
|
-
viewPosition = 1;
|
|
2290
|
-
}
|
|
2291
|
-
state.scrollForNextCalculateItemsInView = void 0;
|
|
2292
|
-
const targetId = getId(state, index);
|
|
2293
|
-
const itemSize = getItemSize(ctx, targetId, index, state.props.data[index]);
|
|
2294
|
-
scrollTo(ctx, {
|
|
2295
|
-
animated,
|
|
2296
|
-
index,
|
|
2297
|
-
itemSize,
|
|
2298
|
-
offset: firstIndexOffset,
|
|
2299
|
-
viewOffset,
|
|
2300
|
-
viewPosition: viewPosition != null ? viewPosition : 0
|
|
2301
|
-
});
|
|
2302
|
-
}
|
|
2303
|
-
|
|
2304
|
-
// src/utils/setDidLayout.ts
|
|
2305
|
-
function setDidLayout(ctx) {
|
|
2306
|
-
const state = ctx.state;
|
|
2307
|
-
const {
|
|
2308
|
-
loadStartTime,
|
|
2309
|
-
initialScroll,
|
|
2310
|
-
props: { onLoad }
|
|
2311
|
-
} = state;
|
|
2312
|
-
state.queuedInitialLayout = true;
|
|
2313
|
-
checkAtBottom(ctx);
|
|
2314
|
-
const setIt = () => {
|
|
2315
|
-
setInitialRenderState(ctx, { didLayout: true });
|
|
2316
|
-
if (onLoad) {
|
|
2317
|
-
onLoad({ elapsedTimeInMs: Date.now() - loadStartTime });
|
|
2318
|
-
}
|
|
2319
|
-
};
|
|
2320
|
-
{
|
|
2321
|
-
setIt();
|
|
2322
|
-
}
|
|
2323
|
-
}
|
|
2324
|
-
|
|
2325
|
-
// src/core/calculateItemsInView.ts
|
|
2326
|
-
function findCurrentStickyIndex(stickyArray, scroll, state) {
|
|
2327
|
-
var _a3;
|
|
2328
|
-
const idCache = state.idCache;
|
|
2329
|
-
const positions = state.positions;
|
|
2330
|
-
for (let i = stickyArray.length - 1; i >= 0; i--) {
|
|
2331
|
-
const stickyIndex = stickyArray[i];
|
|
2332
|
-
const stickyId = (_a3 = idCache[stickyIndex]) != null ? _a3 : getId(state, stickyIndex);
|
|
2333
|
-
const stickyPos = stickyId ? positions.get(stickyId) : void 0;
|
|
2334
|
-
if (stickyPos !== void 0 && scroll >= stickyPos) {
|
|
2335
|
-
return i;
|
|
2336
|
-
}
|
|
2337
|
-
}
|
|
2338
|
-
return -1;
|
|
2339
|
-
}
|
|
2340
|
-
function getActiveStickyIndices(ctx, stickyHeaderIndices) {
|
|
2341
|
-
const state = ctx.state;
|
|
2342
|
-
return new Set(
|
|
2343
|
-
Array.from(state.stickyContainerPool).map((i) => peek$(ctx, `containerItemKey${i}`)).map((key) => key ? state.indexByKey.get(key) : void 0).filter((idx) => idx !== void 0 && stickyHeaderIndices.has(idx))
|
|
2344
|
-
);
|
|
2345
|
-
}
|
|
2346
|
-
function handleStickyActivation(ctx, stickyHeaderIndices, stickyArray, currentStickyIdx, needNewContainers, startBuffered, endBuffered) {
|
|
2347
|
-
var _a3;
|
|
2348
|
-
const state = ctx.state;
|
|
2349
|
-
const activeIndices = getActiveStickyIndices(ctx, stickyHeaderIndices);
|
|
2350
|
-
set$(ctx, "activeStickyIndex", currentStickyIdx >= 0 ? stickyArray[currentStickyIdx] : -1);
|
|
2351
|
-
for (let offset = 0; offset <= 1; offset++) {
|
|
2352
|
-
const idx = currentStickyIdx - offset;
|
|
2353
|
-
if (idx < 0 || activeIndices.has(stickyArray[idx])) continue;
|
|
2354
|
-
const stickyIndex = stickyArray[idx];
|
|
2355
|
-
const stickyId = (_a3 = state.idCache[stickyIndex]) != null ? _a3 : getId(state, stickyIndex);
|
|
2356
|
-
if (stickyId && !state.containerItemKeys.has(stickyId) && (stickyIndex < startBuffered || stickyIndex > endBuffered)) {
|
|
2357
|
-
needNewContainers.push(stickyIndex);
|
|
2358
|
-
}
|
|
2359
|
-
}
|
|
2360
|
-
}
|
|
2361
|
-
function handleStickyRecycling(ctx, stickyArray, scroll, scrollBuffer, currentStickyIdx, pendingRemoval) {
|
|
2362
|
-
var _a3, _b, _c;
|
|
2363
|
-
const state = ctx.state;
|
|
2364
|
-
for (const containerIndex of state.stickyContainerPool) {
|
|
2365
|
-
const itemKey = peek$(ctx, `containerItemKey${containerIndex}`);
|
|
2366
|
-
const itemIndex = itemKey ? state.indexByKey.get(itemKey) : void 0;
|
|
2367
|
-
if (itemIndex === void 0) continue;
|
|
2368
|
-
const arrayIdx = stickyArray.indexOf(itemIndex);
|
|
2369
|
-
if (arrayIdx === -1) {
|
|
2370
|
-
state.stickyContainerPool.delete(containerIndex);
|
|
2371
|
-
set$(ctx, `containerSticky${containerIndex}`, false);
|
|
2372
|
-
set$(ctx, `containerStickyOffset${containerIndex}`, void 0);
|
|
2373
|
-
continue;
|
|
2374
|
-
}
|
|
2375
|
-
const isRecentSticky = arrayIdx >= currentStickyIdx - 1 && arrayIdx <= currentStickyIdx + 1;
|
|
2376
|
-
if (isRecentSticky) continue;
|
|
2377
|
-
const nextIndex = stickyArray[arrayIdx + 1];
|
|
2378
|
-
let shouldRecycle = false;
|
|
2379
|
-
if (nextIndex) {
|
|
2380
|
-
const nextId = (_a3 = state.idCache[nextIndex]) != null ? _a3 : getId(state, nextIndex);
|
|
2381
|
-
const nextPos = nextId ? state.positions.get(nextId) : void 0;
|
|
2382
|
-
shouldRecycle = nextPos !== void 0 && scroll > nextPos + scrollBuffer * 2;
|
|
2383
|
-
} else {
|
|
2384
|
-
const currentId = (_b = state.idCache[itemIndex]) != null ? _b : getId(state, itemIndex);
|
|
2385
|
-
if (currentId) {
|
|
2386
|
-
const currentPos = state.positions.get(currentId);
|
|
2387
|
-
const currentSize = (_c = state.sizes.get(currentId)) != null ? _c : getItemSize(ctx, currentId, itemIndex, state.props.data[itemIndex]);
|
|
2388
|
-
shouldRecycle = currentPos !== void 0 && scroll > currentPos + currentSize + scrollBuffer * 3;
|
|
2389
|
-
}
|
|
2390
|
-
}
|
|
2391
|
-
if (shouldRecycle) {
|
|
2392
|
-
pendingRemoval.push(containerIndex);
|
|
2393
|
-
}
|
|
2394
|
-
}
|
|
2395
|
-
}
|
|
2396
|
-
function calculateItemsInView(ctx, params = {}) {
|
|
2397
|
-
const state = ctx.state;
|
|
2398
|
-
unstable_batchedUpdates(() => {
|
|
2399
|
-
var _a3, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
2400
|
-
const {
|
|
2401
|
-
columns,
|
|
2402
|
-
containerItemKeys,
|
|
2403
|
-
enableScrollForNextCalculateItemsInView,
|
|
2404
|
-
idCache,
|
|
2405
|
-
indexByKey,
|
|
2406
|
-
initialScroll,
|
|
2407
|
-
minIndexSizeChanged,
|
|
2408
|
-
positions,
|
|
2409
|
-
props: { getItemType, itemsAreEqual, keyExtractor, onStickyHeaderChange, scrollBuffer },
|
|
2410
|
-
scrollForNextCalculateItemsInView,
|
|
2411
|
-
scrollLength,
|
|
2412
|
-
sizes,
|
|
2413
|
-
startBufferedId: startBufferedIdOrig,
|
|
2414
|
-
viewabilityConfigCallbackPairs
|
|
2415
|
-
} = state;
|
|
2416
|
-
const { data } = state.props;
|
|
2417
|
-
const stickyIndicesArr = state.props.stickyIndicesArr || [];
|
|
2418
|
-
const stickyIndicesSet = state.props.stickyIndicesSet || /* @__PURE__ */ new Set();
|
|
2419
|
-
const prevNumContainers = peek$(ctx, "numContainers");
|
|
2420
|
-
if (!data || scrollLength === 0 || !prevNumContainers) {
|
|
2421
|
-
return;
|
|
2422
|
-
}
|
|
2423
|
-
const totalSize = getContentSize(ctx);
|
|
2424
|
-
const topPad = peek$(ctx, "stylePaddingTop") + peek$(ctx, "headerSize");
|
|
2425
|
-
const numColumns = peek$(ctx, "numColumns");
|
|
2426
|
-
const { dataChanged, doMVCP, forceFullItemPositions } = params;
|
|
2427
|
-
const speed = getScrollVelocity(state);
|
|
2428
|
-
const scrollExtra = 0;
|
|
2429
|
-
const { queuedInitialLayout } = state;
|
|
2430
|
-
let { scroll: scrollState } = state;
|
|
2431
|
-
if (!queuedInitialLayout && initialScroll) {
|
|
2432
|
-
const updatedOffset = calculateOffsetWithOffsetPosition(
|
|
2433
|
-
ctx,
|
|
2434
|
-
calculateOffsetForIndex(ctx, initialScroll.index),
|
|
2435
|
-
initialScroll
|
|
2436
|
-
);
|
|
2437
|
-
scrollState = updatedOffset;
|
|
2438
|
-
}
|
|
2439
|
-
const scrollAdjustPending = (_a3 = peek$(ctx, "scrollAdjustPending")) != null ? _a3 : 0;
|
|
2440
|
-
const scrollAdjustPad = scrollAdjustPending - topPad;
|
|
2441
|
-
let scroll = Math.round(scrollState + scrollExtra + scrollAdjustPad);
|
|
2442
|
-
if (scroll + scrollLength > totalSize) {
|
|
2443
|
-
scroll = Math.max(0, totalSize - scrollLength);
|
|
2444
|
-
}
|
|
2445
|
-
if (ENABLE_DEBUG_VIEW) {
|
|
2446
|
-
set$(ctx, "debugRawScroll", scrollState);
|
|
2447
|
-
set$(ctx, "debugComputedScroll", scroll);
|
|
2448
|
-
}
|
|
2449
|
-
const previousStickyIndex = peek$(ctx, "activeStickyIndex");
|
|
2450
|
-
const currentStickyIdx = stickyIndicesArr.length > 0 ? findCurrentStickyIndex(stickyIndicesArr, scroll, state) : -1;
|
|
2451
|
-
const nextActiveStickyIndex = currentStickyIdx >= 0 ? stickyIndicesArr[currentStickyIdx] : -1;
|
|
2452
|
-
if (currentStickyIdx >= 0 || previousStickyIndex >= 0) {
|
|
2453
|
-
set$(ctx, "activeStickyIndex", nextActiveStickyIndex);
|
|
2454
|
-
}
|
|
2455
|
-
let scrollBufferTop = scrollBuffer;
|
|
2456
|
-
let scrollBufferBottom = scrollBuffer;
|
|
2457
|
-
if (speed > 0 || speed === 0 && scroll < Math.max(50, scrollBuffer)) {
|
|
2458
|
-
scrollBufferTop = scrollBuffer * 0.5;
|
|
2459
|
-
scrollBufferBottom = scrollBuffer * 1.5;
|
|
2460
|
-
} else {
|
|
2461
|
-
scrollBufferTop = scrollBuffer * 1.5;
|
|
2462
|
-
scrollBufferBottom = scrollBuffer * 0.5;
|
|
2463
|
-
}
|
|
2464
|
-
const scrollTopBuffered = scroll - scrollBufferTop;
|
|
2465
|
-
const scrollBottom = scroll + scrollLength + (scroll < 0 ? -scroll : 0);
|
|
2466
|
-
const scrollBottomBuffered = scrollBottom + scrollBufferBottom;
|
|
2467
|
-
if (!dataChanged && !forceFullItemPositions && scrollForNextCalculateItemsInView) {
|
|
2468
|
-
const { top, bottom } = scrollForNextCalculateItemsInView;
|
|
2469
|
-
if ((top === null || scrollTopBuffered > top) && (bottom === null || scrollBottomBuffered < bottom)) {
|
|
2470
|
-
return;
|
|
2471
|
-
}
|
|
2472
|
-
}
|
|
2473
|
-
const checkMVCP = doMVCP ? prepareMVCP(ctx, dataChanged) : void 0;
|
|
2474
|
-
if (dataChanged) {
|
|
2475
|
-
indexByKey.clear();
|
|
2476
|
-
idCache.length = 0;
|
|
2477
|
-
positions.clear();
|
|
2478
|
-
}
|
|
2479
|
-
const startIndex = forceFullItemPositions || dataChanged ? 0 : (_b = minIndexSizeChanged != null ? minIndexSizeChanged : state.startBuffered) != null ? _b : 0;
|
|
2480
|
-
updateItemPositions(ctx, dataChanged, {
|
|
2481
|
-
doMVCP,
|
|
2482
|
-
forceFullUpdate: !!forceFullItemPositions,
|
|
2483
|
-
scrollBottomBuffered,
|
|
2484
|
-
startIndex
|
|
2485
|
-
});
|
|
2486
|
-
if (minIndexSizeChanged !== void 0) {
|
|
2487
|
-
state.minIndexSizeChanged = void 0;
|
|
2488
|
-
}
|
|
2489
|
-
checkMVCP == null ? void 0 : checkMVCP();
|
|
2490
|
-
let startNoBuffer = null;
|
|
2491
|
-
let startBuffered = null;
|
|
2492
|
-
let startBufferedId = null;
|
|
2493
|
-
let endNoBuffer = null;
|
|
2494
|
-
let endBuffered = null;
|
|
2495
|
-
let loopStart = !dataChanged && startBufferedIdOrig ? indexByKey.get(startBufferedIdOrig) || 0 : 0;
|
|
2496
|
-
for (let i = loopStart; i >= 0; i--) {
|
|
2497
|
-
const id = (_c = idCache[i]) != null ? _c : getId(state, i);
|
|
2498
|
-
const top = positions.get(id);
|
|
2499
|
-
const size = (_d = sizes.get(id)) != null ? _d : getItemSize(ctx, id, i, data[i]);
|
|
2500
|
-
const bottom = top + size;
|
|
2501
|
-
if (bottom > scroll - scrollBufferTop) {
|
|
2502
|
-
loopStart = i;
|
|
2503
|
-
} else {
|
|
2504
|
-
break;
|
|
2505
|
-
}
|
|
2506
|
-
}
|
|
2507
|
-
const loopStartMod = loopStart % numColumns;
|
|
2508
|
-
if (loopStartMod > 0) {
|
|
2509
|
-
loopStart -= loopStartMod;
|
|
2510
|
-
}
|
|
2511
|
-
let foundEnd = false;
|
|
2512
|
-
let nextTop;
|
|
2513
|
-
let nextBottom;
|
|
2514
|
-
let maxIndexRendered = 0;
|
|
2515
|
-
for (let i = 0; i < prevNumContainers; i++) {
|
|
2516
|
-
const key = peek$(ctx, `containerItemKey${i}`);
|
|
2517
|
-
if (key !== void 0) {
|
|
2518
|
-
const index = indexByKey.get(key);
|
|
2519
|
-
maxIndexRendered = Math.max(maxIndexRendered, index);
|
|
2520
|
-
}
|
|
2521
|
-
}
|
|
2522
|
-
let firstFullyOnScreenIndex;
|
|
2523
|
-
const dataLength = data.length;
|
|
2524
|
-
for (let i = Math.max(0, loopStart); i < dataLength && (!foundEnd || i <= maxIndexRendered); i++) {
|
|
2525
|
-
const id = (_e = idCache[i]) != null ? _e : getId(state, i);
|
|
2526
|
-
const size = (_f = sizes.get(id)) != null ? _f : getItemSize(ctx, id, i, data[i]);
|
|
2527
|
-
const top = positions.get(id);
|
|
2528
|
-
if (!foundEnd) {
|
|
2529
|
-
if (startNoBuffer === null && top + size > scroll) {
|
|
2530
|
-
startNoBuffer = i;
|
|
2531
|
-
}
|
|
2532
|
-
if (firstFullyOnScreenIndex === void 0 && top >= scroll - 10) {
|
|
2533
|
-
firstFullyOnScreenIndex = i;
|
|
2534
|
-
}
|
|
2535
|
-
if (startBuffered === null && top + size > scrollTopBuffered) {
|
|
2536
|
-
startBuffered = i;
|
|
2537
|
-
startBufferedId = id;
|
|
2538
|
-
if (scrollTopBuffered < 0) {
|
|
2539
|
-
nextTop = null;
|
|
2540
|
-
} else {
|
|
2541
|
-
nextTop = top;
|
|
2542
|
-
}
|
|
2543
|
-
}
|
|
2544
|
-
if (startNoBuffer !== null) {
|
|
2545
|
-
if (top <= scrollBottom) {
|
|
2546
|
-
endNoBuffer = i;
|
|
2547
|
-
}
|
|
2548
|
-
if (top <= scrollBottomBuffered) {
|
|
2549
|
-
endBuffered = i;
|
|
2550
|
-
if (scrollBottomBuffered > totalSize) {
|
|
2551
|
-
nextBottom = null;
|
|
2552
|
-
} else {
|
|
2553
|
-
nextBottom = top + size;
|
|
2554
|
-
}
|
|
2555
|
-
} else {
|
|
2556
|
-
foundEnd = true;
|
|
2557
|
-
}
|
|
2558
|
-
}
|
|
2559
|
-
}
|
|
2560
|
-
}
|
|
2561
|
-
const idsInView = [];
|
|
2562
|
-
for (let i = firstFullyOnScreenIndex; i <= endNoBuffer; i++) {
|
|
2563
|
-
const id = (_g = idCache[i]) != null ? _g : getId(state, i);
|
|
2564
|
-
idsInView.push(id);
|
|
2565
|
-
}
|
|
2566
|
-
Object.assign(state, {
|
|
2567
|
-
endBuffered,
|
|
2568
|
-
endNoBuffer,
|
|
2569
|
-
firstFullyOnScreenIndex,
|
|
2570
|
-
idsInView,
|
|
2571
|
-
startBuffered,
|
|
2572
|
-
startBufferedId,
|
|
2573
|
-
startNoBuffer
|
|
2574
|
-
});
|
|
2575
|
-
if (enableScrollForNextCalculateItemsInView && nextTop !== void 0 && nextBottom !== void 0) {
|
|
2576
|
-
state.scrollForNextCalculateItemsInView = nextTop !== void 0 && nextBottom !== void 0 ? {
|
|
2577
|
-
bottom: nextBottom,
|
|
2578
|
-
top: nextTop
|
|
2579
|
-
} : void 0;
|
|
2580
|
-
}
|
|
2581
|
-
let numContainers = prevNumContainers;
|
|
2582
|
-
const pendingRemoval = [];
|
|
2583
|
-
if (dataChanged) {
|
|
2584
|
-
for (let i = 0; i < numContainers; i++) {
|
|
2585
|
-
const itemKey = peek$(ctx, `containerItemKey${i}`);
|
|
2586
|
-
if (!keyExtractor || itemKey && indexByKey.get(itemKey) === void 0) {
|
|
2587
|
-
pendingRemoval.push(i);
|
|
2588
|
-
}
|
|
2589
|
-
}
|
|
2590
|
-
}
|
|
2591
|
-
if (startBuffered !== null && endBuffered !== null) {
|
|
2592
|
-
const needNewContainers = [];
|
|
2593
|
-
for (let i = startBuffered; i <= endBuffered; i++) {
|
|
2594
|
-
const id = (_h = idCache[i]) != null ? _h : getId(state, i);
|
|
2595
|
-
if (!containerItemKeys.has(id)) {
|
|
2596
|
-
needNewContainers.push(i);
|
|
2597
|
-
}
|
|
2598
|
-
}
|
|
2599
|
-
if (stickyIndicesArr.length > 0) {
|
|
2600
|
-
handleStickyActivation(
|
|
2601
|
-
ctx,
|
|
2602
|
-
stickyIndicesSet,
|
|
2603
|
-
stickyIndicesArr,
|
|
2604
|
-
currentStickyIdx,
|
|
2605
|
-
needNewContainers,
|
|
2606
|
-
startBuffered,
|
|
2607
|
-
endBuffered
|
|
2608
|
-
);
|
|
2609
|
-
} else if (previousStickyIndex !== -1) {
|
|
2610
|
-
set$(ctx, "activeStickyIndex", -1);
|
|
2611
|
-
}
|
|
2612
|
-
if (needNewContainers.length > 0) {
|
|
2613
|
-
const requiredItemTypes = getItemType ? needNewContainers.map((i) => {
|
|
2614
|
-
const itemType = getItemType(data[i], i);
|
|
2615
|
-
return itemType !== void 0 ? String(itemType) : "";
|
|
2616
|
-
}) : void 0;
|
|
2617
|
-
const availableContainers = findAvailableContainers(
|
|
2618
|
-
ctx,
|
|
2619
|
-
needNewContainers.length,
|
|
2620
|
-
startBuffered,
|
|
2621
|
-
endBuffered,
|
|
2622
|
-
pendingRemoval,
|
|
2623
|
-
requiredItemTypes,
|
|
2624
|
-
needNewContainers
|
|
2625
|
-
);
|
|
2626
|
-
for (let idx = 0; idx < needNewContainers.length; idx++) {
|
|
2627
|
-
const i = needNewContainers[idx];
|
|
2628
|
-
const containerIndex = availableContainers[idx];
|
|
2629
|
-
const id = (_i = idCache[i]) != null ? _i : getId(state, i);
|
|
2630
|
-
const oldKey = peek$(ctx, `containerItemKey${containerIndex}`);
|
|
2631
|
-
if (oldKey && oldKey !== id) {
|
|
2632
|
-
containerItemKeys.delete(oldKey);
|
|
2633
|
-
}
|
|
2634
|
-
set$(ctx, `containerItemKey${containerIndex}`, id);
|
|
2635
|
-
set$(ctx, `containerItemData${containerIndex}`, data[i]);
|
|
2636
|
-
if (requiredItemTypes) {
|
|
2637
|
-
state.containerItemTypes.set(containerIndex, requiredItemTypes[idx]);
|
|
2638
|
-
}
|
|
2639
|
-
containerItemKeys.add(id);
|
|
2640
|
-
const containerSticky = `containerSticky${containerIndex}`;
|
|
2641
|
-
if (stickyIndicesSet.has(i)) {
|
|
2642
|
-
set$(ctx, containerSticky, true);
|
|
2643
|
-
const topPadding = (peek$(ctx, "stylePaddingTop") || 0) + (peek$(ctx, "headerSize") || 0);
|
|
2644
|
-
set$(ctx, `containerStickyOffset${containerIndex}`, topPadding);
|
|
2645
|
-
state.stickyContainerPool.add(containerIndex);
|
|
2646
|
-
} else if (peek$(ctx, containerSticky)) {
|
|
2647
|
-
set$(ctx, containerSticky, false);
|
|
2648
|
-
state.stickyContainerPool.delete(containerIndex);
|
|
2649
|
-
}
|
|
2650
|
-
if (containerIndex >= numContainers) {
|
|
2651
|
-
numContainers = containerIndex + 1;
|
|
2652
|
-
}
|
|
2653
|
-
}
|
|
2654
|
-
if (numContainers !== prevNumContainers) {
|
|
2655
|
-
set$(ctx, "numContainers", numContainers);
|
|
2656
|
-
if (numContainers > peek$(ctx, "numContainersPooled")) {
|
|
2657
|
-
set$(ctx, "numContainersPooled", Math.ceil(numContainers * 1.5));
|
|
2658
|
-
}
|
|
2659
|
-
}
|
|
2660
|
-
}
|
|
2661
|
-
}
|
|
2662
|
-
if (stickyIndicesArr.length > 0) {
|
|
2663
|
-
handleStickyRecycling(ctx, stickyIndicesArr, scroll, scrollBuffer, currentStickyIdx, pendingRemoval);
|
|
2664
|
-
}
|
|
2665
|
-
let didChangePositions = false;
|
|
2666
|
-
for (let i = 0; i < numContainers; i++) {
|
|
2667
|
-
const itemKey = peek$(ctx, `containerItemKey${i}`);
|
|
2668
|
-
if (pendingRemoval.includes(i)) {
|
|
2669
|
-
if (itemKey !== void 0) {
|
|
2670
|
-
containerItemKeys.delete(itemKey);
|
|
2671
|
-
}
|
|
2672
|
-
state.containerItemTypes.delete(i);
|
|
2673
|
-
if (state.stickyContainerPool.has(i)) {
|
|
2674
|
-
set$(ctx, `containerSticky${i}`, false);
|
|
2675
|
-
set$(ctx, `containerStickyOffset${i}`, void 0);
|
|
2676
|
-
state.stickyContainerPool.delete(i);
|
|
2677
|
-
}
|
|
2678
|
-
set$(ctx, `containerItemKey${i}`, void 0);
|
|
2679
|
-
set$(ctx, `containerItemData${i}`, void 0);
|
|
2680
|
-
set$(ctx, `containerPosition${i}`, POSITION_OUT_OF_VIEW);
|
|
2681
|
-
set$(ctx, `containerColumn${i}`, -1);
|
|
2682
|
-
} else {
|
|
2683
|
-
const itemIndex = indexByKey.get(itemKey);
|
|
2684
|
-
const item = data[itemIndex];
|
|
2685
|
-
if (item !== void 0) {
|
|
2686
|
-
const id = (_j = idCache[itemIndex]) != null ? _j : getId(state, itemIndex);
|
|
2687
|
-
const positionValue = positions.get(id);
|
|
2688
|
-
if (positionValue === void 0) {
|
|
2689
|
-
set$(ctx, `containerPosition${i}`, POSITION_OUT_OF_VIEW);
|
|
2690
|
-
} else {
|
|
2691
|
-
const position = (positionValue || 0) - scrollAdjustPending;
|
|
2692
|
-
const column = columns.get(id) || 1;
|
|
2693
|
-
const prevPos = peek$(ctx, `containerPosition${i}`);
|
|
2694
|
-
const prevColumn = peek$(ctx, `containerColumn${i}`);
|
|
2695
|
-
const prevData = peek$(ctx, `containerItemData${i}`);
|
|
2696
|
-
if (position > POSITION_OUT_OF_VIEW && position !== prevPos) {
|
|
2697
|
-
set$(ctx, `containerPosition${i}`, position);
|
|
2698
|
-
didChangePositions = true;
|
|
2699
|
-
}
|
|
2700
|
-
if (column >= 0 && column !== prevColumn) {
|
|
2701
|
-
set$(ctx, `containerColumn${i}`, column);
|
|
2702
|
-
}
|
|
2703
|
-
if (prevData !== item && (itemsAreEqual ? !itemsAreEqual(prevData, item, itemIndex, data) : true)) {
|
|
2704
|
-
set$(ctx, `containerItemData${i}`, item);
|
|
2705
|
-
}
|
|
2706
|
-
}
|
|
2707
|
-
}
|
|
2708
|
-
}
|
|
2709
|
-
}
|
|
2710
|
-
if (didChangePositions) {
|
|
2711
|
-
set$(ctx, "lastPositionUpdate", Date.now());
|
|
2712
|
-
}
|
|
2713
|
-
if (!queuedInitialLayout && endBuffered !== null) {
|
|
2714
|
-
if (checkAllSizesKnown(state)) {
|
|
2715
|
-
setDidLayout(ctx);
|
|
2716
|
-
}
|
|
2717
|
-
}
|
|
2718
|
-
if (viewabilityConfigCallbackPairs) {
|
|
2719
|
-
updateViewableItems(state, ctx, viewabilityConfigCallbackPairs, scrollLength, startNoBuffer, endNoBuffer);
|
|
2720
|
-
}
|
|
2721
|
-
if (onStickyHeaderChange && stickyIndicesArr.length > 0 && nextActiveStickyIndex !== void 0 && nextActiveStickyIndex !== previousStickyIndex) {
|
|
2722
|
-
const item = data[nextActiveStickyIndex];
|
|
2723
|
-
if (item !== void 0) {
|
|
2724
|
-
onStickyHeaderChange({ index: nextActiveStickyIndex, item });
|
|
2725
|
-
}
|
|
2726
|
-
}
|
|
2727
|
-
});
|
|
2728
|
-
}
|
|
2729
|
-
|
|
2730
|
-
// src/core/checkActualChange.ts
|
|
2731
|
-
function checkActualChange(state, dataProp, previousData) {
|
|
2732
|
-
if (!previousData || !dataProp || dataProp.length !== previousData.length) {
|
|
2733
|
-
return true;
|
|
2734
|
-
}
|
|
2735
|
-
const {
|
|
2736
|
-
idCache,
|
|
2737
|
-
props: { keyExtractor }
|
|
2738
|
-
} = state;
|
|
2739
|
-
for (let i = 0; i < dataProp.length; i++) {
|
|
2740
|
-
if (dataProp[i] !== previousData[i]) {
|
|
2741
|
-
return true;
|
|
2742
|
-
}
|
|
2743
|
-
if (keyExtractor ? idCache[i] !== keyExtractor(previousData[i], i) : dataProp[i] !== previousData[i]) {
|
|
2744
|
-
return true;
|
|
2745
|
-
}
|
|
2746
|
-
}
|
|
2747
|
-
return false;
|
|
2748
|
-
}
|
|
2749
|
-
|
|
2750
|
-
// src/core/checkFinishedScroll.ts
|
|
2751
|
-
function checkFinishedScroll(ctx) {
|
|
2752
|
-
ctx.state.animFrameCheckFinishedScroll = requestAnimationFrame(() => checkFinishedScrollFrame(ctx));
|
|
2753
|
-
}
|
|
2754
|
-
function checkFinishedScrollFrame(ctx) {
|
|
2755
|
-
const scrollingTo = ctx.state.scrollingTo;
|
|
2756
|
-
if (scrollingTo) {
|
|
2757
|
-
const { state } = ctx;
|
|
2758
|
-
state.animFrameCheckFinishedScroll = void 0;
|
|
2759
|
-
const scroll = state.scrollPending;
|
|
2760
|
-
const adjust = state.scrollAdjustHandler.getAdjust();
|
|
2761
|
-
const clampedTargetOffset = clampScrollOffset(ctx, scrollingTo.offset - (scrollingTo.viewOffset || 0));
|
|
2762
|
-
const maxOffset = clampScrollOffset(ctx, scroll);
|
|
2763
|
-
const diff1 = Math.abs(scroll - clampedTargetOffset);
|
|
2764
|
-
const diff2 = Math.abs(diff1 - adjust);
|
|
2765
|
-
const isNotOverscrolled = Math.abs(scroll - maxOffset) < 1;
|
|
2766
|
-
if (isNotOverscrolled && (diff1 < 1 || diff2 < 1)) {
|
|
2767
|
-
finishScrollTo(ctx);
|
|
2768
|
-
}
|
|
2769
|
-
}
|
|
2770
|
-
}
|
|
2771
|
-
function checkFinishedScrollFallback(ctx) {
|
|
2772
|
-
const state = ctx.state;
|
|
2773
|
-
const scrollingTo = state.scrollingTo;
|
|
2774
|
-
const slowTimeout = (scrollingTo == null ? void 0 : scrollingTo.isInitialScroll) || !state.didContainersLayout;
|
|
2775
|
-
state.timeoutCheckFinishedScrollFallback = setTimeout(
|
|
2776
|
-
() => {
|
|
2777
|
-
let numChecks = 0;
|
|
2778
|
-
const checkHasScrolled = () => {
|
|
2779
|
-
state.timeoutCheckFinishedScrollFallback = void 0;
|
|
2780
|
-
const isStillScrollingTo = state.scrollingTo;
|
|
2781
|
-
if (isStillScrollingTo) {
|
|
2782
|
-
numChecks++;
|
|
2783
|
-
if (state.hasScrolled || numChecks > 5) {
|
|
2784
|
-
finishScrollTo(ctx);
|
|
2785
|
-
} else {
|
|
2786
|
-
state.timeoutCheckFinishedScrollFallback = setTimeout(checkHasScrolled, 100);
|
|
2787
|
-
}
|
|
2788
|
-
}
|
|
2789
|
-
};
|
|
2790
|
-
checkHasScrolled();
|
|
2791
|
-
},
|
|
2792
|
-
slowTimeout ? 500 : 100
|
|
2793
|
-
);
|
|
2794
|
-
}
|
|
2795
|
-
|
|
2796
|
-
// src/core/doMaintainScrollAtEnd.ts
|
|
2797
|
-
function doMaintainScrollAtEnd(ctx, animated) {
|
|
2798
|
-
const state = ctx.state;
|
|
2799
|
-
const {
|
|
2800
|
-
didContainersLayout,
|
|
2801
|
-
isAtEnd,
|
|
2802
|
-
refScroller,
|
|
2803
|
-
props: { maintainScrollAtEnd }
|
|
2804
|
-
} = state;
|
|
2805
|
-
if (isAtEnd && maintainScrollAtEnd && didContainersLayout) {
|
|
2806
|
-
const paddingTop = peek$(ctx, "alignItemsPaddingTop");
|
|
2807
|
-
if (paddingTop > 0) {
|
|
2808
|
-
state.scroll = 0;
|
|
2809
|
-
}
|
|
2810
|
-
requestAnimationFrame(() => {
|
|
2811
|
-
var _a3;
|
|
2812
|
-
if (state.isAtEnd) {
|
|
2813
|
-
state.maintainingScrollAtEnd = true;
|
|
2814
|
-
(_a3 = refScroller.current) == null ? void 0 : _a3.scrollToEnd({
|
|
2815
|
-
animated
|
|
2816
|
-
});
|
|
2817
|
-
setTimeout(
|
|
2818
|
-
() => {
|
|
2819
|
-
state.maintainingScrollAtEnd = false;
|
|
2820
|
-
},
|
|
2821
|
-
0
|
|
2822
|
-
);
|
|
2823
|
-
}
|
|
2824
|
-
});
|
|
2825
|
-
return true;
|
|
2826
|
-
}
|
|
2827
|
-
return false;
|
|
2828
|
-
}
|
|
2829
|
-
|
|
2830
|
-
// src/utils/updateAveragesOnDataChange.ts
|
|
2831
|
-
function updateAveragesOnDataChange(state, oldData, newData) {
|
|
2832
|
-
var _a3;
|
|
2833
|
-
const {
|
|
2834
|
-
averageSizes,
|
|
2835
|
-
sizesKnown,
|
|
2836
|
-
indexByKey,
|
|
2837
|
-
props: { itemsAreEqual, getItemType, keyExtractor }
|
|
2838
|
-
} = state;
|
|
2839
|
-
if (!itemsAreEqual || !oldData.length || !newData.length) {
|
|
2840
|
-
for (const key in averageSizes) {
|
|
2841
|
-
delete averageSizes[key];
|
|
2842
|
-
}
|
|
2843
|
-
return;
|
|
2844
|
-
}
|
|
2845
|
-
const itemTypesToPreserve = {};
|
|
2846
|
-
const newDataLength = newData.length;
|
|
2847
|
-
const oldDataLength = oldData.length;
|
|
2848
|
-
for (let newIndex = 0; newIndex < newDataLength; newIndex++) {
|
|
2849
|
-
const newItem = newData[newIndex];
|
|
2850
|
-
const id = keyExtractor ? keyExtractor(newItem, newIndex) : String(newIndex);
|
|
2851
|
-
const oldIndex = indexByKey.get(id);
|
|
2852
|
-
if (oldIndex !== void 0 && oldIndex < oldDataLength) {
|
|
2853
|
-
const knownSize = sizesKnown.get(id);
|
|
2854
|
-
if (knownSize === void 0) continue;
|
|
2855
|
-
const oldItem = oldData[oldIndex];
|
|
2856
|
-
const areEqual = itemsAreEqual(oldItem, newItem, newIndex, newData);
|
|
2857
|
-
if (areEqual) {
|
|
2858
|
-
const itemType = getItemType ? (_a3 = getItemType(newItem, newIndex)) != null ? _a3 : "" : "";
|
|
2859
|
-
let typeData = itemTypesToPreserve[itemType];
|
|
2860
|
-
if (!typeData) {
|
|
2861
|
-
typeData = itemTypesToPreserve[itemType] = { count: 0, totalSize: 0 };
|
|
2862
|
-
}
|
|
2863
|
-
typeData.totalSize += knownSize;
|
|
2864
|
-
typeData.count++;
|
|
2865
|
-
}
|
|
2866
|
-
}
|
|
2867
|
-
}
|
|
2868
|
-
for (const key in averageSizes) {
|
|
2869
|
-
delete averageSizes[key];
|
|
2870
|
-
}
|
|
2871
|
-
for (const itemType in itemTypesToPreserve) {
|
|
2872
|
-
const { totalSize, count } = itemTypesToPreserve[itemType];
|
|
2873
|
-
if (count > 0) {
|
|
2874
|
-
averageSizes[itemType] = {
|
|
2875
|
-
avg: totalSize / count,
|
|
2876
|
-
num: count
|
|
2877
|
-
};
|
|
2878
|
-
}
|
|
2879
|
-
}
|
|
2880
|
-
}
|
|
2881
|
-
|
|
2882
|
-
// src/core/checkResetContainers.ts
|
|
2883
|
-
function checkResetContainers(ctx, dataProp) {
|
|
2884
|
-
const state = ctx.state;
|
|
2885
|
-
const { previousData } = state;
|
|
2886
|
-
if (previousData) {
|
|
2887
|
-
updateAveragesOnDataChange(state, previousData, dataProp);
|
|
2888
|
-
}
|
|
2889
|
-
const { maintainScrollAtEnd } = state.props;
|
|
2890
|
-
calculateItemsInView(ctx, { dataChanged: true, doMVCP: true });
|
|
2891
|
-
const shouldMaintainScrollAtEnd = maintainScrollAtEnd === true || maintainScrollAtEnd.onDataChange;
|
|
2892
|
-
const didMaintainScrollAtEnd = shouldMaintainScrollAtEnd && doMaintainScrollAtEnd(ctx, false);
|
|
2893
|
-
if (!didMaintainScrollAtEnd && previousData && dataProp.length > previousData.length) {
|
|
2894
|
-
state.isEndReached = false;
|
|
2895
|
-
}
|
|
2896
|
-
if (!didMaintainScrollAtEnd) {
|
|
2897
|
-
checkAtTop(state);
|
|
2898
|
-
checkAtBottom(ctx);
|
|
2899
|
-
}
|
|
2900
|
-
delete state.previousData;
|
|
2901
|
-
}
|
|
2902
|
-
|
|
2903
|
-
// src/core/doInitialAllocateContainers.ts
|
|
2904
|
-
function doInitialAllocateContainers(ctx) {
|
|
2905
|
-
var _a3, _b, _c;
|
|
2906
|
-
const state = ctx.state;
|
|
2907
|
-
const {
|
|
2908
|
-
scrollLength,
|
|
2909
|
-
props: {
|
|
2910
|
-
data,
|
|
2911
|
-
getEstimatedItemSize,
|
|
2912
|
-
getFixedItemSize,
|
|
2913
|
-
getItemType,
|
|
2914
|
-
scrollBuffer,
|
|
2915
|
-
numColumns,
|
|
2916
|
-
estimatedItemSize
|
|
2917
|
-
}
|
|
2918
|
-
} = state;
|
|
2919
|
-
const hasContainers = peek$(ctx, "numContainers");
|
|
2920
|
-
if (scrollLength > 0 && data.length > 0 && !hasContainers) {
|
|
2921
|
-
let averageItemSize;
|
|
2922
|
-
if (getFixedItemSize || getEstimatedItemSize) {
|
|
2923
|
-
let totalSize = 0;
|
|
2924
|
-
const num = Math.min(20, data.length);
|
|
2925
|
-
for (let i = 0; i < num; i++) {
|
|
2926
|
-
const item = data[i];
|
|
2927
|
-
if (item !== void 0) {
|
|
2928
|
-
const itemType = (_a3 = getItemType == null ? void 0 : getItemType(item, i)) != null ? _a3 : "";
|
|
2929
|
-
totalSize += (_c = (_b = getFixedItemSize == null ? void 0 : getFixedItemSize(i, item, itemType)) != null ? _b : getEstimatedItemSize == null ? void 0 : getEstimatedItemSize(i, item, itemType)) != null ? _c : estimatedItemSize;
|
|
2930
|
-
}
|
|
2931
|
-
}
|
|
2932
|
-
averageItemSize = totalSize / num;
|
|
2933
|
-
} else {
|
|
2934
|
-
averageItemSize = estimatedItemSize;
|
|
2935
|
-
}
|
|
2936
|
-
const numContainers = Math.ceil((scrollLength + scrollBuffer * 2) / averageItemSize * numColumns);
|
|
2937
|
-
for (let i = 0; i < numContainers; i++) {
|
|
2938
|
-
set$(ctx, `containerPosition${i}`, POSITION_OUT_OF_VIEW);
|
|
2939
|
-
set$(ctx, `containerColumn${i}`, -1);
|
|
2940
|
-
}
|
|
2941
|
-
set$(ctx, "numContainers", numContainers);
|
|
2942
|
-
set$(ctx, "numContainersPooled", numContainers * state.props.initialContainerPoolRatio);
|
|
2943
|
-
if (state.lastLayout) {
|
|
2944
|
-
if (state.initialScroll) {
|
|
2945
|
-
requestAnimationFrame(() => {
|
|
2946
|
-
calculateItemsInView(ctx, { dataChanged: true, doMVCP: true });
|
|
2947
|
-
});
|
|
2948
|
-
} else {
|
|
2949
|
-
calculateItemsInView(ctx, { dataChanged: true, doMVCP: true });
|
|
2950
|
-
}
|
|
2951
|
-
}
|
|
2952
|
-
return true;
|
|
2953
|
-
}
|
|
2954
|
-
}
|
|
2955
|
-
|
|
2956
|
-
// src/core/handleLayout.ts
|
|
2957
|
-
function handleLayout(ctx, layout, setCanRender) {
|
|
2958
|
-
const state = ctx.state;
|
|
2959
|
-
const { maintainScrollAtEnd } = state.props;
|
|
2960
|
-
const measuredLength = layout[state.props.horizontal ? "width" : "height"];
|
|
2961
|
-
const previousLength = state.scrollLength;
|
|
2962
|
-
const scrollLength = measuredLength > 0 ? measuredLength : previousLength;
|
|
2963
|
-
const otherAxisSize = layout[state.props.horizontal ? "height" : "width"];
|
|
2964
|
-
const needsCalculate = !state.lastLayout || scrollLength > state.scrollLength || state.lastLayout.x !== layout.x || state.lastLayout.y !== layout.y;
|
|
2965
|
-
state.lastLayout = layout;
|
|
2966
|
-
const prevOtherAxisSize = state.otherAxisSize;
|
|
2967
|
-
const didChange = scrollLength !== state.scrollLength || otherAxisSize !== prevOtherAxisSize;
|
|
2968
|
-
if (didChange) {
|
|
2969
|
-
state.scrollLength = scrollLength;
|
|
2970
|
-
state.otherAxisSize = otherAxisSize;
|
|
2971
|
-
state.lastBatchingAction = Date.now();
|
|
2972
|
-
state.scrollForNextCalculateItemsInView = void 0;
|
|
2973
|
-
if (scrollLength > 0) {
|
|
2974
|
-
doInitialAllocateContainers(ctx);
|
|
2975
|
-
}
|
|
2976
|
-
if (needsCalculate) {
|
|
2977
|
-
calculateItemsInView(ctx, { doMVCP: true });
|
|
2978
|
-
}
|
|
2979
|
-
if (didChange || otherAxisSize !== prevOtherAxisSize) {
|
|
2980
|
-
set$(ctx, "scrollSize", { height: layout.height, width: layout.width });
|
|
2981
|
-
}
|
|
2982
|
-
if (maintainScrollAtEnd === true || maintainScrollAtEnd.onLayout) {
|
|
2983
|
-
doMaintainScrollAtEnd(ctx, false);
|
|
2984
|
-
}
|
|
2985
|
-
updateAlignItemsPaddingTop(ctx);
|
|
2986
|
-
checkAtBottom(ctx);
|
|
2987
|
-
checkAtTop(state);
|
|
2988
|
-
if (state) {
|
|
2989
|
-
state.needsOtherAxisSize = otherAxisSize - (state.props.stylePaddingTop || 0) < 10;
|
|
2990
|
-
}
|
|
2991
|
-
if (IS_DEV && measuredLength === 0) {
|
|
2992
|
-
warnDevOnce(
|
|
2993
|
-
"height0",
|
|
2994
|
-
`List ${state.props.horizontal ? "width" : "height"} is 0. You may need to set a style or \`flex: \` for the list, because children are absolutely positioned.`
|
|
2995
|
-
);
|
|
2996
|
-
}
|
|
2997
|
-
}
|
|
2998
|
-
setCanRender(true);
|
|
2999
|
-
}
|
|
3000
|
-
|
|
3001
|
-
// src/core/onScroll.ts
|
|
3002
|
-
function onScroll(ctx, event) {
|
|
3003
|
-
var _a3, _b, _c;
|
|
3004
|
-
const state = ctx.state;
|
|
3005
|
-
const {
|
|
3006
|
-
scrollProcessingEnabled,
|
|
3007
|
-
props: { onScroll: onScrollProp }
|
|
3008
|
-
} = state;
|
|
3009
|
-
if (scrollProcessingEnabled === false) {
|
|
3010
|
-
return;
|
|
3011
|
-
}
|
|
3012
|
-
if (((_b = (_a3 = event.nativeEvent) == null ? void 0 : _a3.contentSize) == null ? void 0 : _b.height) === 0 && ((_c = event.nativeEvent.contentSize) == null ? void 0 : _c.width) === 0) {
|
|
3013
|
-
return;
|
|
3014
|
-
}
|
|
3015
|
-
let newScroll = event.nativeEvent.contentOffset[state.props.horizontal ? "x" : "y"];
|
|
3016
|
-
if (state.scrollingTo) {
|
|
3017
|
-
const maxOffset = clampScrollOffset(ctx, newScroll);
|
|
3018
|
-
if (newScroll !== maxOffset && Math.abs(newScroll - maxOffset) > 1) {
|
|
3019
|
-
newScroll = maxOffset;
|
|
3020
|
-
scrollTo(ctx, {
|
|
3021
|
-
forceScroll: true,
|
|
3022
|
-
isInitialScroll: true,
|
|
3023
|
-
noScrollingTo: true,
|
|
3024
|
-
offset: newScroll
|
|
3025
|
-
});
|
|
3026
|
-
return;
|
|
3027
|
-
}
|
|
3028
|
-
}
|
|
3029
|
-
state.scrollPending = newScroll;
|
|
3030
|
-
updateScroll(ctx, newScroll);
|
|
3031
|
-
if (state.scrollingTo) {
|
|
3032
|
-
checkFinishedScroll(ctx);
|
|
3033
|
-
}
|
|
3034
|
-
onScrollProp == null ? void 0 : onScrollProp(event);
|
|
3035
|
-
}
|
|
3036
|
-
|
|
3037
|
-
// src/core/ScrollAdjustHandler.ts
|
|
3038
|
-
var ScrollAdjustHandler = class {
|
|
3039
|
-
constructor(ctx) {
|
|
3040
|
-
this.appliedAdjust = 0;
|
|
3041
|
-
this.pendingAdjust = 0;
|
|
3042
|
-
this.ctx = ctx;
|
|
3043
|
-
}
|
|
3044
|
-
requestAdjust(add) {
|
|
3045
|
-
const scrollingTo = this.ctx.state.scrollingTo;
|
|
3046
|
-
if ((scrollingTo == null ? void 0 : scrollingTo.animated) && !scrollingTo.isInitialScroll) {
|
|
3047
|
-
this.pendingAdjust += add;
|
|
3048
|
-
set$(this.ctx, "scrollAdjustPending", this.pendingAdjust);
|
|
3049
|
-
} else {
|
|
3050
|
-
this.appliedAdjust += add;
|
|
3051
|
-
set$(this.ctx, "scrollAdjust", this.appliedAdjust);
|
|
3052
|
-
}
|
|
3053
|
-
if (this.ctx.state.scrollingTo) {
|
|
3054
|
-
checkFinishedScroll(this.ctx);
|
|
3055
|
-
}
|
|
3056
|
-
}
|
|
3057
|
-
getAdjust() {
|
|
3058
|
-
return this.appliedAdjust;
|
|
3059
|
-
}
|
|
3060
|
-
commitPendingAdjust(scrollTarget) {
|
|
3061
|
-
{
|
|
3062
|
-
const state = this.ctx.state;
|
|
3063
|
-
const pending = this.pendingAdjust;
|
|
3064
|
-
this.pendingAdjust = 0;
|
|
3065
|
-
if (pending !== 0) {
|
|
3066
|
-
let targetScroll;
|
|
3067
|
-
if ((scrollTarget == null ? void 0 : scrollTarget.index) !== void 0) {
|
|
3068
|
-
const currentOffset = calculateOffsetForIndex(this.ctx, scrollTarget.index);
|
|
3069
|
-
targetScroll = calculateOffsetWithOffsetPosition(this.ctx, currentOffset, scrollTarget);
|
|
3070
|
-
targetScroll = clampScrollOffset(this.ctx, targetScroll);
|
|
3071
|
-
} else {
|
|
3072
|
-
targetScroll = clampScrollOffset(this.ctx, state.scroll + pending);
|
|
3073
|
-
}
|
|
3074
|
-
const adjustment = targetScroll - state.scroll;
|
|
3075
|
-
if (Math.abs(adjustment) > 0.1 || Math.abs(pending) > 0.1) {
|
|
3076
|
-
this.appliedAdjust += adjustment;
|
|
3077
|
-
state.scroll = targetScroll;
|
|
3078
|
-
state.scrollForNextCalculateItemsInView = void 0;
|
|
3079
|
-
set$(this.ctx, "scrollAdjust", this.appliedAdjust);
|
|
3080
|
-
}
|
|
3081
|
-
set$(this.ctx, "scrollAdjustPending", 0);
|
|
3082
|
-
calculateItemsInView(this.ctx);
|
|
3083
|
-
}
|
|
3084
|
-
}
|
|
3085
|
-
}
|
|
3086
|
-
};
|
|
3087
|
-
|
|
3088
|
-
// src/core/updateItemSize.ts
|
|
3089
|
-
function updateItemSize(ctx, itemKey, sizeObj) {
|
|
3090
|
-
var _a3;
|
|
3091
|
-
const state = ctx.state;
|
|
3092
|
-
const {
|
|
3093
|
-
didContainersLayout,
|
|
3094
|
-
sizesKnown,
|
|
3095
|
-
props: {
|
|
3096
|
-
getFixedItemSize,
|
|
3097
|
-
getItemType,
|
|
3098
|
-
horizontal,
|
|
3099
|
-
suggestEstimatedItemSize,
|
|
3100
|
-
onItemSizeChanged,
|
|
3101
|
-
data,
|
|
3102
|
-
maintainScrollAtEnd
|
|
3103
|
-
}
|
|
3104
|
-
} = state;
|
|
3105
|
-
if (!data) return;
|
|
3106
|
-
const index = state.indexByKey.get(itemKey);
|
|
3107
|
-
if (getFixedItemSize) {
|
|
3108
|
-
if (index === void 0) {
|
|
3109
|
-
return;
|
|
3110
|
-
}
|
|
3111
|
-
const itemData = state.props.data[index];
|
|
3112
|
-
if (itemData === void 0) {
|
|
3113
|
-
return;
|
|
3114
|
-
}
|
|
3115
|
-
const type = getItemType ? (_a3 = getItemType(itemData, index)) != null ? _a3 : "" : "";
|
|
3116
|
-
const size2 = getFixedItemSize(index, itemData, type);
|
|
3117
|
-
if (size2 !== void 0 && size2 === sizesKnown.get(itemKey)) {
|
|
3118
|
-
return;
|
|
3119
|
-
}
|
|
3120
|
-
}
|
|
3121
|
-
let needsRecalculate = !didContainersLayout;
|
|
3122
|
-
let shouldMaintainScrollAtEnd = false;
|
|
3123
|
-
let minIndexSizeChanged;
|
|
3124
|
-
let maxOtherAxisSize = peek$(ctx, "otherAxisSize") || 0;
|
|
3125
|
-
const prevSizeKnown = state.sizesKnown.get(itemKey);
|
|
3126
|
-
const diff = updateOneItemSize(ctx, itemKey, sizeObj);
|
|
3127
|
-
const size = roundSize(horizontal ? sizeObj.width : sizeObj.height);
|
|
3128
|
-
if (diff !== 0) {
|
|
3129
|
-
minIndexSizeChanged = minIndexSizeChanged !== void 0 ? Math.min(minIndexSizeChanged, index) : index;
|
|
3130
|
-
const { startBuffered, endBuffered } = state;
|
|
3131
|
-
needsRecalculate || (needsRecalculate = index >= startBuffered && index <= endBuffered);
|
|
3132
|
-
if (!needsRecalculate) {
|
|
3133
|
-
const numContainers = ctx.values.get("numContainers");
|
|
3134
|
-
for (let i = 0; i < numContainers; i++) {
|
|
3135
|
-
if (peek$(ctx, `containerItemKey${i}`) === itemKey) {
|
|
3136
|
-
needsRecalculate = true;
|
|
3137
|
-
break;
|
|
3138
|
-
}
|
|
3139
|
-
}
|
|
3140
|
-
}
|
|
3141
|
-
if (state.needsOtherAxisSize) {
|
|
3142
|
-
const otherAxisSize = horizontal ? sizeObj.height : sizeObj.width;
|
|
3143
|
-
maxOtherAxisSize = Math.max(maxOtherAxisSize, otherAxisSize);
|
|
3144
|
-
}
|
|
3145
|
-
if (prevSizeKnown !== void 0 && Math.abs(prevSizeKnown - size) > 5) {
|
|
3146
|
-
shouldMaintainScrollAtEnd = true;
|
|
3147
|
-
}
|
|
3148
|
-
onItemSizeChanged == null ? void 0 : onItemSizeChanged({
|
|
3149
|
-
index,
|
|
3150
|
-
itemData: state.props.data[index],
|
|
3151
|
-
itemKey,
|
|
3152
|
-
previous: size - diff,
|
|
3153
|
-
size
|
|
3154
|
-
});
|
|
3155
|
-
}
|
|
3156
|
-
if (minIndexSizeChanged !== void 0) {
|
|
3157
|
-
state.minIndexSizeChanged = state.minIndexSizeChanged !== void 0 ? Math.min(state.minIndexSizeChanged, minIndexSizeChanged) : minIndexSizeChanged;
|
|
3158
|
-
}
|
|
3159
|
-
if (IS_DEV && suggestEstimatedItemSize && minIndexSizeChanged !== void 0) {
|
|
3160
|
-
if (state.timeoutSizeMessage) clearTimeout(state.timeoutSizeMessage);
|
|
3161
|
-
state.timeoutSizeMessage = setTimeout(() => {
|
|
3162
|
-
var _a4;
|
|
3163
|
-
state.timeoutSizeMessage = void 0;
|
|
3164
|
-
const num = state.sizesKnown.size;
|
|
3165
|
-
const avg = (_a4 = state.averageSizes[""]) == null ? void 0 : _a4.avg;
|
|
3166
|
-
console.warn(
|
|
3167
|
-
`[legend-list] Based on the ${num} items rendered so far, the optimal estimated size is ${avg}.`
|
|
3168
|
-
);
|
|
3169
|
-
}, 1e3);
|
|
3170
|
-
}
|
|
3171
|
-
const cur = peek$(ctx, "otherAxisSize");
|
|
3172
|
-
if (!cur || maxOtherAxisSize > cur) {
|
|
3173
|
-
set$(ctx, "otherAxisSize", maxOtherAxisSize);
|
|
3174
|
-
}
|
|
3175
|
-
if (didContainersLayout || checkAllSizesKnown(state)) {
|
|
3176
|
-
if (needsRecalculate) {
|
|
3177
|
-
state.scrollForNextCalculateItemsInView = void 0;
|
|
3178
|
-
calculateItemsInView(ctx, { doMVCP: true });
|
|
3179
|
-
}
|
|
3180
|
-
if (shouldMaintainScrollAtEnd) {
|
|
3181
|
-
if (maintainScrollAtEnd === true || maintainScrollAtEnd.onItemLayout) {
|
|
3182
|
-
doMaintainScrollAtEnd(ctx, false);
|
|
3183
|
-
}
|
|
3184
|
-
}
|
|
3185
|
-
}
|
|
3186
|
-
}
|
|
3187
|
-
function updateOneItemSize(ctx, itemKey, sizeObj) {
|
|
3188
|
-
var _a3;
|
|
3189
|
-
const state = ctx.state;
|
|
3190
|
-
const {
|
|
3191
|
-
indexByKey,
|
|
3192
|
-
sizesKnown,
|
|
3193
|
-
averageSizes,
|
|
3194
|
-
props: { data, horizontal, getEstimatedItemSize, getItemType, getFixedItemSize }
|
|
3195
|
-
} = state;
|
|
3196
|
-
if (!data) return 0;
|
|
3197
|
-
const index = indexByKey.get(itemKey);
|
|
3198
|
-
const prevSize = getItemSize(ctx, itemKey, index, data[index]);
|
|
3199
|
-
const rawSize = horizontal ? sizeObj.width : sizeObj.height;
|
|
3200
|
-
const size = Math.round(rawSize) ;
|
|
3201
|
-
const prevSizeKnown = sizesKnown.get(itemKey);
|
|
3202
|
-
sizesKnown.set(itemKey, size);
|
|
3203
|
-
if (!getEstimatedItemSize && !getFixedItemSize && size > 0) {
|
|
3204
|
-
const itemType = getItemType ? (_a3 = getItemType(data[index], index)) != null ? _a3 : "" : "";
|
|
3205
|
-
let averages = averageSizes[itemType];
|
|
3206
|
-
if (!averages) {
|
|
3207
|
-
averages = averageSizes[itemType] = { avg: 0, num: 0 };
|
|
3208
|
-
}
|
|
3209
|
-
if (prevSizeKnown !== void 0 && prevSizeKnown > 0) {
|
|
3210
|
-
averages.avg += (size - prevSizeKnown) / averages.num;
|
|
3211
|
-
} else {
|
|
3212
|
-
averages.avg = (averages.avg * averages.num + size) / (averages.num + 1);
|
|
3213
|
-
averages.num++;
|
|
3214
|
-
}
|
|
3215
|
-
}
|
|
3216
|
-
if (!prevSize || Math.abs(prevSize - size) > 0.1) {
|
|
3217
|
-
setSize(ctx, itemKey, size);
|
|
3218
|
-
return size - prevSize;
|
|
3219
|
-
}
|
|
3220
|
-
return 0;
|
|
3221
|
-
}
|
|
3222
|
-
function useWrapIfItem(fn) {
|
|
3223
|
-
return useMemo(
|
|
3224
|
-
() => fn ? (arg1, arg2, arg3) => arg1 !== void 0 && arg2 !== void 0 ? fn(arg1, arg2, arg3) : void 0 : void 0,
|
|
3225
|
-
[fn]
|
|
3226
|
-
);
|
|
3227
|
-
}
|
|
3228
|
-
var useCombinedRef = (...refs) => {
|
|
3229
|
-
const callback = useCallback((element) => {
|
|
3230
|
-
for (const ref of refs) {
|
|
3231
|
-
if (!ref) {
|
|
3232
|
-
continue;
|
|
3233
|
-
}
|
|
3234
|
-
if (isFunction(ref)) {
|
|
3235
|
-
ref(element);
|
|
3236
|
-
} else {
|
|
3237
|
-
ref.current = element;
|
|
3238
|
-
}
|
|
3239
|
-
}
|
|
3240
|
-
}, refs);
|
|
3241
|
-
return callback;
|
|
3242
|
-
};
|
|
3243
|
-
|
|
3244
|
-
// src/platform/RefreshControl.tsx
|
|
3245
|
-
function RefreshControl(_props) {
|
|
3246
|
-
return null;
|
|
3247
|
-
}
|
|
3248
|
-
|
|
3249
|
-
// src/platform/useStickyScrollHandler.ts
|
|
3250
|
-
function useStickyScrollHandler(_stickyHeaderIndices, _horizontal, _ctx, onScroll2) {
|
|
3251
|
-
return onScroll2;
|
|
3252
|
-
}
|
|
3253
|
-
|
|
3254
|
-
// src/utils/createColumnWrapperStyle.ts
|
|
3255
|
-
function createColumnWrapperStyle(contentContainerStyle) {
|
|
3256
|
-
const { gap, columnGap, rowGap } = contentContainerStyle;
|
|
3257
|
-
if (gap || columnGap || rowGap) {
|
|
3258
|
-
contentContainerStyle.gap = void 0;
|
|
3259
|
-
contentContainerStyle.columnGap = void 0;
|
|
3260
|
-
contentContainerStyle.rowGap = void 0;
|
|
3261
|
-
return {
|
|
3262
|
-
columnGap,
|
|
3263
|
-
gap,
|
|
3264
|
-
rowGap
|
|
3265
|
-
};
|
|
3266
|
-
}
|
|
3267
|
-
}
|
|
3268
|
-
|
|
3269
|
-
// src/utils/createImperativeHandle.ts
|
|
3270
|
-
function createImperativeHandle(ctx) {
|
|
3271
|
-
const state = ctx.state;
|
|
3272
|
-
const scrollIndexIntoView = (options) => {
|
|
3273
|
-
if (state) {
|
|
3274
|
-
const { index, ...rest } = options;
|
|
3275
|
-
const { startNoBuffer, endNoBuffer } = state;
|
|
3276
|
-
if (index < startNoBuffer || index > endNoBuffer) {
|
|
3277
|
-
const viewPosition = index < startNoBuffer ? 0 : 1;
|
|
3278
|
-
scrollToIndex(ctx, {
|
|
3279
|
-
...rest,
|
|
3280
|
-
index,
|
|
3281
|
-
viewPosition
|
|
3282
|
-
});
|
|
3283
|
-
}
|
|
3284
|
-
}
|
|
3285
|
-
};
|
|
3286
|
-
const refScroller = state.refScroller;
|
|
3287
|
-
return {
|
|
3288
|
-
flashScrollIndicators: () => refScroller.current.flashScrollIndicators(),
|
|
3289
|
-
getNativeScrollRef: () => refScroller.current,
|
|
3290
|
-
getScrollableNode: () => refScroller.current.getScrollableNode(),
|
|
3291
|
-
getScrollResponder: () => refScroller.current.getScrollResponder(),
|
|
3292
|
-
getState: () => ({
|
|
3293
|
-
activeStickyIndex: peek$(ctx, "activeStickyIndex"),
|
|
3294
|
-
contentLength: state.totalSize,
|
|
3295
|
-
data: state.props.data,
|
|
3296
|
-
elementAtIndex: (index) => {
|
|
3297
|
-
var _a3;
|
|
3298
|
-
return (_a3 = ctx.viewRefs.get(findContainerId(ctx, getId(state, index)))) == null ? void 0 : _a3.current;
|
|
3299
|
-
},
|
|
3300
|
-
end: state.endNoBuffer,
|
|
3301
|
-
endBuffered: state.endBuffered,
|
|
3302
|
-
isAtEnd: state.isAtEnd,
|
|
3303
|
-
isAtStart: state.isAtStart,
|
|
3304
|
-
listen: (signalName, cb) => listen$(ctx, signalName, cb),
|
|
3305
|
-
listenToPosition: (key, cb) => listenPosition$(ctx, key, cb),
|
|
3306
|
-
positionAtIndex: (index) => state.positions.get(getId(state, index)),
|
|
3307
|
-
positions: state.positions,
|
|
3308
|
-
scroll: state.scroll,
|
|
3309
|
-
scrollLength: state.scrollLength,
|
|
3310
|
-
sizeAtIndex: (index) => state.sizesKnown.get(getId(state, index)),
|
|
3311
|
-
sizes: state.sizesKnown,
|
|
3312
|
-
start: state.startNoBuffer,
|
|
3313
|
-
startBuffered: state.startBuffered
|
|
3314
|
-
}),
|
|
3315
|
-
scrollIndexIntoView,
|
|
3316
|
-
scrollItemIntoView: ({ item, ...props }) => {
|
|
3317
|
-
const data = state.props.data;
|
|
3318
|
-
const index = data.indexOf(item);
|
|
3319
|
-
if (index !== -1) {
|
|
3320
|
-
scrollIndexIntoView({ index, ...props });
|
|
3321
|
-
}
|
|
3322
|
-
},
|
|
3323
|
-
scrollToEnd: (options) => {
|
|
3324
|
-
const data = state.props.data;
|
|
3325
|
-
const stylePaddingBottom = state.props.stylePaddingBottom;
|
|
3326
|
-
const index = data.length - 1;
|
|
3327
|
-
if (index !== -1) {
|
|
3328
|
-
const paddingBottom = stylePaddingBottom || 0;
|
|
3329
|
-
const footerSize = peek$(ctx, "footerSize") || 0;
|
|
3330
|
-
scrollToIndex(ctx, {
|
|
3331
|
-
...options,
|
|
3332
|
-
index,
|
|
3333
|
-
viewOffset: -paddingBottom - footerSize + ((options == null ? void 0 : options.viewOffset) || 0),
|
|
3334
|
-
viewPosition: 1
|
|
3335
|
-
});
|
|
3336
|
-
}
|
|
3337
|
-
},
|
|
3338
|
-
scrollToIndex: (params) => scrollToIndex(ctx, params),
|
|
3339
|
-
scrollToItem: ({ item, ...props }) => {
|
|
3340
|
-
const data = state.props.data;
|
|
3341
|
-
const index = data.indexOf(item);
|
|
3342
|
-
if (index !== -1) {
|
|
3343
|
-
scrollToIndex(ctx, { index, ...props });
|
|
3344
|
-
}
|
|
3345
|
-
},
|
|
3346
|
-
scrollToOffset: (params) => scrollTo(ctx, params),
|
|
3347
|
-
setScrollProcessingEnabled: (enabled) => {
|
|
3348
|
-
state.scrollProcessingEnabled = enabled;
|
|
3349
|
-
},
|
|
3350
|
-
setVisibleContentAnchorOffset: (value) => {
|
|
3351
|
-
const val = isFunction(value) ? value(peek$(ctx, "scrollAdjustUserOffset") || 0) : value;
|
|
3352
|
-
set$(ctx, "scrollAdjustUserOffset", val);
|
|
3353
|
-
}
|
|
3354
|
-
};
|
|
3355
|
-
}
|
|
3356
|
-
function getRenderedItem(ctx, key) {
|
|
3357
|
-
var _a3;
|
|
3358
|
-
const state = ctx.state;
|
|
3359
|
-
if (!state) {
|
|
3360
|
-
return null;
|
|
3361
|
-
}
|
|
3362
|
-
const {
|
|
3363
|
-
indexByKey,
|
|
3364
|
-
props: { data, getItemType, renderItem }
|
|
3365
|
-
} = state;
|
|
3366
|
-
const index = indexByKey.get(key);
|
|
3367
|
-
if (index === void 0) {
|
|
3368
|
-
return null;
|
|
3369
|
-
}
|
|
3370
|
-
let renderedItem = null;
|
|
3371
|
-
const extraData = peek$(ctx, "extraData");
|
|
3372
|
-
const item = data[index];
|
|
3373
|
-
if (renderItem && !isNullOrUndefined(item)) {
|
|
3374
|
-
const itemProps = {
|
|
3375
|
-
data,
|
|
3376
|
-
extraData,
|
|
3377
|
-
index,
|
|
3378
|
-
item,
|
|
3379
|
-
type: getItemType ? (_a3 = getItemType(item, index)) != null ? _a3 : "" : ""
|
|
3380
|
-
};
|
|
3381
|
-
renderedItem = isFunction(renderItem) ? renderItem(itemProps) : React3__default.createElement(renderItem, itemProps);
|
|
3382
|
-
}
|
|
3383
|
-
return { index, item: data[index], renderedItem };
|
|
3384
|
-
}
|
|
3385
|
-
|
|
3386
|
-
// src/utils/normalizeMaintainVisibleContentPosition.ts
|
|
3387
|
-
function normalizeMaintainVisibleContentPosition(value) {
|
|
3388
|
-
var _a3, _b;
|
|
3389
|
-
if (value === true) {
|
|
3390
|
-
return { data: true, size: true };
|
|
3391
|
-
}
|
|
3392
|
-
if (value && typeof value === "object") {
|
|
3393
|
-
return {
|
|
3394
|
-
data: (_a3 = value.data) != null ? _a3 : false,
|
|
3395
|
-
size: (_b = value.size) != null ? _b : true
|
|
3396
|
-
};
|
|
3397
|
-
}
|
|
3398
|
-
if (value === false) {
|
|
3399
|
-
return { data: false, size: false };
|
|
3400
|
-
}
|
|
3401
|
-
return { data: false, size: true };
|
|
3402
|
-
}
|
|
3403
|
-
function useThrottleDebounce(mode) {
|
|
3404
|
-
const timeoutRef = useRef(null);
|
|
3405
|
-
const lastCallTimeRef = useRef(0);
|
|
3406
|
-
const lastArgsRef = useRef(null);
|
|
3407
|
-
const clearTimeoutRef = () => {
|
|
3408
|
-
if (timeoutRef.current) {
|
|
3409
|
-
clearTimeout(timeoutRef.current);
|
|
3410
|
-
timeoutRef.current = null;
|
|
3411
|
-
}
|
|
3412
|
-
};
|
|
3413
|
-
const execute = useCallback(
|
|
3414
|
-
(callback, delay, ...args) => {
|
|
3415
|
-
{
|
|
3416
|
-
const now = Date.now();
|
|
3417
|
-
lastArgsRef.current = args;
|
|
3418
|
-
if (now - lastCallTimeRef.current >= delay) {
|
|
3419
|
-
lastCallTimeRef.current = now;
|
|
3420
|
-
callback(...args);
|
|
3421
|
-
clearTimeoutRef();
|
|
3422
|
-
} else {
|
|
3423
|
-
clearTimeoutRef();
|
|
3424
|
-
timeoutRef.current = setTimeout(
|
|
3425
|
-
() => {
|
|
3426
|
-
if (lastArgsRef.current) {
|
|
3427
|
-
lastCallTimeRef.current = Date.now();
|
|
3428
|
-
callback(...lastArgsRef.current);
|
|
3429
|
-
timeoutRef.current = null;
|
|
3430
|
-
lastArgsRef.current = null;
|
|
3431
|
-
}
|
|
3432
|
-
},
|
|
3433
|
-
delay - (now - lastCallTimeRef.current)
|
|
3434
|
-
);
|
|
3435
|
-
}
|
|
3436
|
-
}
|
|
3437
|
-
},
|
|
3438
|
-
[mode]
|
|
3439
|
-
);
|
|
3440
|
-
return execute;
|
|
3441
|
-
}
|
|
3442
|
-
|
|
3443
|
-
// src/utils/throttledOnScroll.ts
|
|
3444
|
-
function useThrottledOnScroll(originalHandler, scrollEventThrottle) {
|
|
3445
|
-
const throttle = useThrottleDebounce("throttle");
|
|
3446
|
-
return (event) => throttle(originalHandler, scrollEventThrottle, { nativeEvent: event.nativeEvent });
|
|
3447
|
-
}
|
|
3448
|
-
|
|
3449
|
-
// src/components/LegendList.tsx
|
|
3450
|
-
var DEFAULT_DRAW_DISTANCE = 250;
|
|
3451
|
-
var DEFAULT_ITEM_SIZE = 100;
|
|
3452
|
-
var LegendList = typedMemo(
|
|
3453
|
-
// biome-ignore lint/nursery/noShadow: const function name shadowing is intentional
|
|
3454
|
-
typedForwardRef(function LegendList2(props, forwardedRef) {
|
|
3455
|
-
const { children, data: dataProp, renderItem: renderItemProp, ...restProps } = props;
|
|
3456
|
-
const isChildrenMode = children !== void 0 && dataProp === void 0;
|
|
3457
|
-
const processedProps = isChildrenMode ? {
|
|
3458
|
-
...restProps,
|
|
3459
|
-
childrenMode: true,
|
|
3460
|
-
data: (isArray(children) ? children : React3.Children.toArray(children)).flat(1),
|
|
3461
|
-
renderItem: ({ item }) => item
|
|
3462
|
-
} : {
|
|
3463
|
-
...restProps,
|
|
3464
|
-
data: dataProp || [],
|
|
3465
|
-
renderItem: renderItemProp
|
|
3466
|
-
};
|
|
3467
|
-
return /* @__PURE__ */ React3.createElement(StateProvider, null, /* @__PURE__ */ React3.createElement(LegendListInner, { ...processedProps, ref: forwardedRef }));
|
|
3468
|
-
})
|
|
3469
|
-
);
|
|
3470
|
-
var LegendListInner = typedForwardRef(function LegendListInner2(props, forwardedRef) {
|
|
3471
|
-
var _a3, _b;
|
|
3472
|
-
const {
|
|
3473
|
-
alignItemsAtEnd = false,
|
|
3474
|
-
columnWrapperStyle,
|
|
3475
|
-
contentContainerStyle: contentContainerStyleProp,
|
|
3476
|
-
contentInset,
|
|
3477
|
-
data: dataProp = [],
|
|
3478
|
-
dataVersion,
|
|
3479
|
-
drawDistance = 250,
|
|
3480
|
-
estimatedItemSize: estimatedItemSizeProp,
|
|
3481
|
-
estimatedListSize,
|
|
3482
|
-
extraData,
|
|
3483
|
-
getEstimatedItemSize,
|
|
3484
|
-
getFixedItemSize,
|
|
3485
|
-
getItemType,
|
|
3486
|
-
horizontal,
|
|
3487
|
-
initialContainerPoolRatio = 2,
|
|
3488
|
-
initialScrollAtEnd = false,
|
|
3489
|
-
initialScrollIndex: initialScrollIndexProp,
|
|
3490
|
-
initialScrollOffset: initialScrollOffsetProp,
|
|
3491
|
-
itemsAreEqual,
|
|
3492
|
-
keyExtractor: keyExtractorProp,
|
|
3493
|
-
ListEmptyComponent,
|
|
3494
|
-
ListHeaderComponent,
|
|
3495
|
-
maintainScrollAtEnd = false,
|
|
3496
|
-
maintainScrollAtEndThreshold = 0.1,
|
|
3497
|
-
maintainVisibleContentPosition: maintainVisibleContentPositionProp,
|
|
3498
|
-
numColumns: numColumnsProp = 1,
|
|
3499
|
-
onEndReached,
|
|
3500
|
-
onEndReachedThreshold = 0.5,
|
|
3501
|
-
onItemSizeChanged,
|
|
3502
|
-
onLayout: onLayoutProp,
|
|
3503
|
-
onLoad,
|
|
3504
|
-
onMomentumScrollEnd,
|
|
3505
|
-
onRefresh,
|
|
3506
|
-
onScroll: onScrollProp,
|
|
3507
|
-
onStartReached,
|
|
3508
|
-
onStartReachedThreshold = 0.5,
|
|
3509
|
-
onStickyHeaderChange,
|
|
3510
|
-
onViewableItemsChanged,
|
|
3511
|
-
progressViewOffset,
|
|
3512
|
-
recycleItems = false,
|
|
3513
|
-
refreshControl,
|
|
3514
|
-
refreshing,
|
|
3515
|
-
refScrollView,
|
|
3516
|
-
renderItem,
|
|
3517
|
-
scrollEventThrottle,
|
|
3518
|
-
snapToIndices,
|
|
3519
|
-
stickyHeaderIndices: stickyHeaderIndicesProp,
|
|
3520
|
-
stickyIndices: stickyIndicesDeprecated,
|
|
3521
|
-
// TODOV3: Remove from v3 release
|
|
3522
|
-
style: styleProp,
|
|
3523
|
-
suggestEstimatedItemSize,
|
|
3524
|
-
viewabilityConfig,
|
|
3525
|
-
viewabilityConfigCallbackPairs,
|
|
3526
|
-
waitForInitialLayout = true,
|
|
3527
|
-
stickyHeaderConfig,
|
|
3528
|
-
...rest
|
|
3529
|
-
} = props;
|
|
3530
|
-
const animatedPropsInternal = props.animatedPropsInternal;
|
|
3531
|
-
const { childrenMode } = rest;
|
|
3532
|
-
const contentContainerStyle = { ...StyleSheet.flatten(contentContainerStyleProp) };
|
|
3533
|
-
const style = { ...StyleSheet.flatten(styleProp) };
|
|
3534
|
-
const stylePaddingTopState = extractPadding(style, contentContainerStyle, "Top");
|
|
3535
|
-
const stylePaddingBottomState = extractPadding(style, contentContainerStyle, "Bottom");
|
|
3536
|
-
const maintainVisibleContentPositionConfig = normalizeMaintainVisibleContentPosition(
|
|
3537
|
-
maintainVisibleContentPositionProp
|
|
3538
|
-
);
|
|
3539
|
-
const [renderNum, setRenderNum] = useState(0);
|
|
3540
|
-
const initialScrollProp = initialScrollAtEnd ? { index: Math.max(0, dataProp.length - 1), viewOffset: -stylePaddingBottomState } : initialScrollIndexProp || initialScrollOffsetProp ? typeof initialScrollIndexProp === "object" ? { index: initialScrollIndexProp.index || 0, viewOffset: initialScrollIndexProp.viewOffset || 0 } : { index: initialScrollIndexProp || 0, viewOffset: initialScrollOffsetProp || 0 } : void 0;
|
|
3541
|
-
const [canRender, setCanRender] = React3.useState(!IsNewArchitecture);
|
|
3542
|
-
const ctx = useStateContext();
|
|
3543
|
-
ctx.columnWrapperStyle = columnWrapperStyle || (contentContainerStyle ? createColumnWrapperStyle(contentContainerStyle) : void 0);
|
|
3544
|
-
const refScroller = useRef(null);
|
|
3545
|
-
const combinedRef = useCombinedRef(refScroller, refScrollView);
|
|
3546
|
-
const estimatedItemSize = estimatedItemSizeProp != null ? estimatedItemSizeProp : DEFAULT_ITEM_SIZE;
|
|
3547
|
-
const scrollBuffer = (drawDistance != null ? drawDistance : DEFAULT_DRAW_DISTANCE) || 1;
|
|
3548
|
-
const keyExtractor = keyExtractorProp != null ? keyExtractorProp : (_item, index) => index.toString();
|
|
3549
|
-
const stickyHeaderIndices = stickyHeaderIndicesProp != null ? stickyHeaderIndicesProp : stickyIndicesDeprecated;
|
|
3550
|
-
if (IS_DEV && stickyIndicesDeprecated && !stickyHeaderIndicesProp) {
|
|
3551
|
-
warnDevOnce(
|
|
3552
|
-
"stickyIndices",
|
|
3553
|
-
"stickyIndices has been renamed to stickyHeaderIndices. Please update your props to use stickyHeaderIndices."
|
|
3554
|
-
);
|
|
3555
|
-
}
|
|
3556
|
-
const refState = useRef();
|
|
3557
|
-
if (!refState.current) {
|
|
3558
|
-
if (!ctx.state) {
|
|
3559
|
-
const initialScrollLength = (estimatedListSize != null ? estimatedListSize : { height: 0, width: 0 } )[horizontal ? "width" : "height"];
|
|
3560
|
-
ctx.state = {
|
|
3561
|
-
activeStickyIndex: -1,
|
|
3562
|
-
averageSizes: {},
|
|
3563
|
-
columns: /* @__PURE__ */ new Map(),
|
|
3564
|
-
containerItemKeys: /* @__PURE__ */ new Set(),
|
|
3565
|
-
containerItemTypes: /* @__PURE__ */ new Map(),
|
|
3566
|
-
dataChangeNeedsScrollUpdate: false,
|
|
3567
|
-
didColumnsChange: false,
|
|
3568
|
-
didDataChange: false,
|
|
3569
|
-
enableScrollForNextCalculateItemsInView: true,
|
|
3570
|
-
endBuffered: -1,
|
|
3571
|
-
endNoBuffer: -1,
|
|
3572
|
-
endReachedSnapshot: void 0,
|
|
3573
|
-
firstFullyOnScreenIndex: -1,
|
|
3574
|
-
idCache: [],
|
|
3575
|
-
idsInView: [],
|
|
3576
|
-
indexByKey: /* @__PURE__ */ new Map(),
|
|
3577
|
-
initialAnchor: (initialScrollProp == null ? void 0 : initialScrollProp.index) !== void 0 && (initialScrollProp == null ? void 0 : initialScrollProp.viewPosition) !== void 0 ? {
|
|
3578
|
-
attempts: 0,
|
|
3579
|
-
index: initialScrollProp.index,
|
|
3580
|
-
settledTicks: 0,
|
|
3581
|
-
viewOffset: (_a3 = initialScrollProp.viewOffset) != null ? _a3 : 0,
|
|
3582
|
-
viewPosition: initialScrollProp.viewPosition
|
|
3583
|
-
} : void 0,
|
|
3584
|
-
initialScroll: initialScrollProp,
|
|
3585
|
-
isAtEnd: false,
|
|
3586
|
-
isAtStart: false,
|
|
3587
|
-
isEndReached: null,
|
|
3588
|
-
isFirst: true,
|
|
3589
|
-
isStartReached: null,
|
|
3590
|
-
lastBatchingAction: Date.now(),
|
|
3591
|
-
lastLayout: void 0,
|
|
3592
|
-
loadStartTime: Date.now(),
|
|
3593
|
-
minIndexSizeChanged: 0,
|
|
3594
|
-
nativeMarginTop: 0,
|
|
3595
|
-
positions: /* @__PURE__ */ new Map(),
|
|
3596
|
-
props: {},
|
|
3597
|
-
queuedCalculateItemsInView: 0,
|
|
3598
|
-
refScroller: void 0,
|
|
3599
|
-
scroll: 0,
|
|
3600
|
-
scrollAdjustHandler: new ScrollAdjustHandler(ctx),
|
|
3601
|
-
scrollForNextCalculateItemsInView: void 0,
|
|
3602
|
-
scrollHistory: [],
|
|
3603
|
-
scrollLength: initialScrollLength,
|
|
3604
|
-
scrollPending: 0,
|
|
3605
|
-
scrollPrev: 0,
|
|
3606
|
-
scrollPrevTime: 0,
|
|
3607
|
-
scrollProcessingEnabled: true,
|
|
3608
|
-
scrollTime: 0,
|
|
3609
|
-
sizes: /* @__PURE__ */ new Map(),
|
|
3610
|
-
sizesKnown: /* @__PURE__ */ new Map(),
|
|
3611
|
-
startBuffered: -1,
|
|
3612
|
-
startNoBuffer: -1,
|
|
3613
|
-
startReachedSnapshot: void 0,
|
|
3614
|
-
stickyContainerPool: /* @__PURE__ */ new Set(),
|
|
3615
|
-
stickyContainers: /* @__PURE__ */ new Map(),
|
|
3616
|
-
timeoutSizeMessage: 0,
|
|
3617
|
-
timeouts: /* @__PURE__ */ new Set(),
|
|
3618
|
-
totalSize: 0,
|
|
3619
|
-
viewabilityConfigCallbackPairs: void 0
|
|
3620
|
-
};
|
|
3621
|
-
const internalState = ctx.state;
|
|
3622
|
-
internalState.triggerCalculateItemsInView = (params) => calculateItemsInView(ctx, params);
|
|
3623
|
-
set$(ctx, "maintainVisibleContentPosition", maintainVisibleContentPositionConfig);
|
|
3624
|
-
set$(ctx, "extraData", extraData);
|
|
3625
|
-
}
|
|
3626
|
-
refState.current = ctx.state;
|
|
3627
|
-
}
|
|
3628
|
-
const state = refState.current;
|
|
3629
|
-
const isFirstLocal = state.isFirst;
|
|
3630
|
-
state.didColumnsChange = numColumnsProp !== state.props.numColumns;
|
|
3631
|
-
const didDataChangeLocal = state.props.dataVersion !== dataVersion || state.props.data !== dataProp && checkActualChange(state, dataProp, state.props.data);
|
|
3632
|
-
if (didDataChangeLocal) {
|
|
3633
|
-
state.dataChangeNeedsScrollUpdate = true;
|
|
3634
|
-
state.didDataChange = true;
|
|
3635
|
-
state.previousData = state.props.data;
|
|
3636
|
-
}
|
|
3637
|
-
const throttleScrollFn = scrollEventThrottle && onScrollProp ? useThrottledOnScroll(onScrollProp, scrollEventThrottle) : onScrollProp;
|
|
3638
|
-
state.props = {
|
|
3639
|
-
alignItemsAtEnd,
|
|
3640
|
-
animatedProps: animatedPropsInternal,
|
|
3641
|
-
contentInset,
|
|
3642
|
-
data: dataProp,
|
|
3643
|
-
dataVersion,
|
|
3644
|
-
estimatedItemSize,
|
|
3645
|
-
getEstimatedItemSize: useWrapIfItem(getEstimatedItemSize),
|
|
3646
|
-
getFixedItemSize: useWrapIfItem(getFixedItemSize),
|
|
3647
|
-
getItemType: useWrapIfItem(getItemType),
|
|
3648
|
-
horizontal: !!horizontal,
|
|
3649
|
-
initialContainerPoolRatio,
|
|
3650
|
-
itemsAreEqual,
|
|
3651
|
-
keyExtractor: useWrapIfItem(keyExtractor),
|
|
3652
|
-
maintainScrollAtEnd,
|
|
3653
|
-
maintainScrollAtEndThreshold,
|
|
3654
|
-
maintainVisibleContentPosition: maintainVisibleContentPositionConfig,
|
|
3655
|
-
numColumns: numColumnsProp,
|
|
3656
|
-
onEndReached,
|
|
3657
|
-
onEndReachedThreshold,
|
|
3658
|
-
onItemSizeChanged,
|
|
3659
|
-
onLoad,
|
|
3660
|
-
onScroll: throttleScrollFn,
|
|
3661
|
-
onStartReached,
|
|
3662
|
-
onStartReachedThreshold,
|
|
3663
|
-
onStickyHeaderChange,
|
|
3664
|
-
recycleItems: !!recycleItems,
|
|
3665
|
-
renderItem,
|
|
3666
|
-
scrollBuffer,
|
|
3667
|
-
snapToIndices,
|
|
3668
|
-
stickyIndicesArr: stickyHeaderIndices != null ? stickyHeaderIndices : [],
|
|
3669
|
-
stickyIndicesSet: useMemo(() => new Set(stickyHeaderIndices != null ? stickyHeaderIndices : []), [stickyHeaderIndices == null ? void 0 : stickyHeaderIndices.join(",")]),
|
|
3670
|
-
stylePaddingBottom: stylePaddingBottomState,
|
|
3671
|
-
stylePaddingTop: stylePaddingTopState,
|
|
3672
|
-
suggestEstimatedItemSize: !!suggestEstimatedItemSize
|
|
3673
|
-
};
|
|
3674
|
-
state.refScroller = refScroller;
|
|
3675
|
-
const memoizedLastItemKeys = useMemo(() => {
|
|
3676
|
-
if (!dataProp.length) return [];
|
|
3677
|
-
return Array.from(
|
|
3678
|
-
{ length: Math.min(numColumnsProp, dataProp.length) },
|
|
3679
|
-
(_, i) => getId(state, dataProp.length - 1 - i)
|
|
3680
|
-
);
|
|
3681
|
-
}, [dataProp, dataVersion, numColumnsProp]);
|
|
3682
|
-
const initializeStateVars = () => {
|
|
3683
|
-
set$(ctx, "lastItemKeys", memoizedLastItemKeys);
|
|
3684
|
-
set$(ctx, "numColumns", numColumnsProp);
|
|
3685
|
-
const prevPaddingTop = peek$(ctx, "stylePaddingTop");
|
|
3686
|
-
setPaddingTop(ctx, { stylePaddingTop: stylePaddingTopState });
|
|
3687
|
-
refState.current.props.stylePaddingBottom = stylePaddingBottomState;
|
|
3688
|
-
let paddingDiff = stylePaddingTopState - prevPaddingTop;
|
|
3689
|
-
if (maintainVisibleContentPositionConfig.size && paddingDiff && prevPaddingTop !== void 0 && Platform.OS === "ios") {
|
|
3690
|
-
if (state.scroll < 0) {
|
|
3691
|
-
paddingDiff += state.scroll;
|
|
3692
|
-
}
|
|
3693
|
-
requestAdjust(ctx, paddingDiff);
|
|
3694
|
-
}
|
|
3695
|
-
};
|
|
3696
|
-
if (isFirstLocal) {
|
|
3697
|
-
initializeStateVars();
|
|
3698
|
-
updateItemPositions(
|
|
3699
|
-
ctx,
|
|
3700
|
-
/*dataChanged*/
|
|
3701
|
-
true
|
|
3702
|
-
);
|
|
3703
|
-
}
|
|
3704
|
-
const initialContentOffset = useMemo(() => {
|
|
3705
|
-
let value;
|
|
3706
|
-
const { initialScroll, initialAnchor } = refState.current;
|
|
3707
|
-
if (initialScroll) {
|
|
3708
|
-
if (initialScroll.contentOffset !== void 0) {
|
|
3709
|
-
value = initialScroll.contentOffset;
|
|
3710
|
-
} else {
|
|
3711
|
-
const baseOffset = initialScroll.index !== void 0 ? calculateOffsetForIndex(ctx, initialScroll.index) : 0;
|
|
3712
|
-
const resolvedOffset = calculateOffsetWithOffsetPosition(ctx, baseOffset, initialScroll);
|
|
3713
|
-
const clampedOffset = clampScrollOffset(ctx, resolvedOffset);
|
|
3714
|
-
const updatedInitialScroll = { ...initialScroll, contentOffset: clampedOffset };
|
|
3715
|
-
refState.current.initialScroll = updatedInitialScroll;
|
|
3716
|
-
state.initialScroll = updatedInitialScroll;
|
|
3717
|
-
value = clampedOffset;
|
|
3718
|
-
}
|
|
3719
|
-
} else {
|
|
3720
|
-
refState.current.initialAnchor = void 0;
|
|
3721
|
-
value = 0;
|
|
3722
|
-
}
|
|
3723
|
-
if (!value) {
|
|
3724
|
-
setInitialRenderState(ctx, { didInitialScroll: true });
|
|
3725
|
-
}
|
|
3726
|
-
return value;
|
|
3727
|
-
}, [renderNum]);
|
|
3728
|
-
if (isFirstLocal || didDataChangeLocal || numColumnsProp !== peek$(ctx, "numColumns")) {
|
|
3729
|
-
refState.current.lastBatchingAction = Date.now();
|
|
3730
|
-
if (!keyExtractorProp && !isFirstLocal && didDataChangeLocal) {
|
|
3731
|
-
IS_DEV && !childrenMode && warnDevOnce(
|
|
3732
|
-
"keyExtractor",
|
|
3733
|
-
"Changing data without a keyExtractor can cause slow performance and resetting scroll. If your list data can change you should use a keyExtractor with a unique id for best performance and behavior."
|
|
3734
|
-
);
|
|
3735
|
-
refState.current.sizes.clear();
|
|
3736
|
-
refState.current.positions.clear();
|
|
3737
|
-
refState.current.totalSize = 0;
|
|
3738
|
-
set$(ctx, "totalSize", 0);
|
|
3739
|
-
}
|
|
3740
|
-
}
|
|
3741
|
-
const onLayoutHeader = useCallback((rect, fromLayoutEffect) => {
|
|
3742
|
-
const { initialScroll } = refState.current;
|
|
3743
|
-
const size = rect[horizontal ? "width" : "height"];
|
|
3744
|
-
set$(ctx, "headerSize", size);
|
|
3745
|
-
if ((initialScroll == null ? void 0 : initialScroll.index) !== void 0) {
|
|
3746
|
-
{
|
|
3747
|
-
if (fromLayoutEffect) {
|
|
3748
|
-
setRenderNum((v) => v + 1);
|
|
3749
|
-
}
|
|
3750
|
-
}
|
|
3751
|
-
}
|
|
3752
|
-
}, []);
|
|
3753
|
-
const doInitialScroll = useCallback(() => {
|
|
3754
|
-
const initialScroll = state.initialScroll;
|
|
3755
|
-
if (initialScroll) {
|
|
3756
|
-
scrollTo(ctx, {
|
|
3757
|
-
animated: false,
|
|
3758
|
-
index: initialScroll == null ? void 0 : initialScroll.index,
|
|
3759
|
-
isInitialScroll: true,
|
|
3760
|
-
offset: initialContentOffset,
|
|
3761
|
-
precomputedWithViewOffset: true
|
|
3762
|
-
});
|
|
3763
|
-
}
|
|
3764
|
-
}, [initialContentOffset]);
|
|
3765
|
-
const onLayoutChange = useCallback((layout) => {
|
|
3766
|
-
doInitialScroll();
|
|
3767
|
-
handleLayout(ctx, layout, setCanRender);
|
|
3768
|
-
}, []);
|
|
3769
|
-
const { onLayout } = useOnLayoutSync({
|
|
3770
|
-
onLayoutChange,
|
|
3771
|
-
onLayoutProp,
|
|
3772
|
-
ref: refScroller
|
|
3773
|
-
// the type of ScrollView doesn't include measure?
|
|
3774
|
-
});
|
|
3775
|
-
useLayoutEffect(() => {
|
|
3776
|
-
if (snapToIndices) {
|
|
3777
|
-
updateSnapToOffsets(ctx);
|
|
3778
|
-
}
|
|
3779
|
-
}, [snapToIndices]);
|
|
3780
|
-
useLayoutEffect(() => {
|
|
3781
|
-
const {
|
|
3782
|
-
didColumnsChange,
|
|
3783
|
-
didDataChange,
|
|
3784
|
-
isFirst,
|
|
3785
|
-
props: { data }
|
|
3786
|
-
} = state;
|
|
3787
|
-
const didAllocateContainers = data.length > 0 && doInitialAllocateContainers(ctx);
|
|
3788
|
-
if (!didAllocateContainers && !isFirst && (didDataChange || didColumnsChange)) {
|
|
3789
|
-
checkResetContainers(ctx, data);
|
|
3790
|
-
}
|
|
3791
|
-
state.didColumnsChange = false;
|
|
3792
|
-
state.didDataChange = false;
|
|
3793
|
-
state.isFirst = false;
|
|
3794
|
-
}, [dataProp, dataVersion, numColumnsProp]);
|
|
3795
|
-
useLayoutEffect(() => {
|
|
3796
|
-
set$(ctx, "extraData", extraData);
|
|
3797
|
-
}, [extraData]);
|
|
3798
|
-
useLayoutEffect(initializeStateVars, [
|
|
3799
|
-
dataVersion,
|
|
3800
|
-
memoizedLastItemKeys.join(","),
|
|
3801
|
-
numColumnsProp,
|
|
3802
|
-
stylePaddingBottomState,
|
|
3803
|
-
stylePaddingTopState
|
|
3804
|
-
]);
|
|
3805
|
-
useEffect(() => {
|
|
3806
|
-
const viewability = setupViewability({
|
|
3807
|
-
onViewableItemsChanged,
|
|
3808
|
-
viewabilityConfig,
|
|
3809
|
-
viewabilityConfigCallbackPairs
|
|
3810
|
-
});
|
|
3811
|
-
state.viewabilityConfigCallbackPairs = viewability;
|
|
3812
|
-
state.enableScrollForNextCalculateItemsInView = !viewability;
|
|
3813
|
-
}, [viewabilityConfig, viewabilityConfigCallbackPairs, onViewableItemsChanged]);
|
|
3814
|
-
useImperativeHandle(forwardedRef, () => createImperativeHandle(ctx), []);
|
|
3815
|
-
{
|
|
3816
|
-
useEffect(doInitialScroll, []);
|
|
3817
|
-
}
|
|
3818
|
-
const fns = useMemo(
|
|
3819
|
-
() => ({
|
|
3820
|
-
getRenderedItem: (key) => getRenderedItem(ctx, key),
|
|
3821
|
-
onMomentumScrollEnd: (event) => {
|
|
3822
|
-
checkFinishedScrollFallback(ctx);
|
|
3823
|
-
if (onMomentumScrollEnd) {
|
|
3824
|
-
onMomentumScrollEnd(event);
|
|
3825
|
-
}
|
|
3826
|
-
},
|
|
3827
|
-
onScroll: (event) => onScroll(ctx, event),
|
|
3828
|
-
updateItemSize: (itemKey, sizeObj) => updateItemSize(ctx, itemKey, sizeObj)
|
|
3829
|
-
}),
|
|
3830
|
-
[]
|
|
3831
|
-
);
|
|
3832
|
-
const onScrollHandler = useStickyScrollHandler(stickyHeaderIndices, horizontal, ctx, fns.onScroll);
|
|
3833
|
-
return /* @__PURE__ */ React3.createElement(React3.Fragment, null, /* @__PURE__ */ React3.createElement(
|
|
3834
|
-
ListComponent,
|
|
3835
|
-
{
|
|
3836
|
-
...rest,
|
|
3837
|
-
alignItemsAtEnd,
|
|
3838
|
-
canRender,
|
|
3839
|
-
contentContainerStyle,
|
|
3840
|
-
contentInset,
|
|
3841
|
-
getRenderedItem: fns.getRenderedItem,
|
|
3842
|
-
horizontal,
|
|
3843
|
-
initialContentOffset,
|
|
3844
|
-
ListEmptyComponent: dataProp.length === 0 ? ListEmptyComponent : void 0,
|
|
3845
|
-
ListHeaderComponent,
|
|
3846
|
-
onLayout,
|
|
3847
|
-
onLayoutHeader,
|
|
3848
|
-
onMomentumScrollEnd: fns.onMomentumScrollEnd,
|
|
3849
|
-
onScroll: onScrollHandler,
|
|
3850
|
-
recycleItems,
|
|
3851
|
-
refreshControl: refreshControl ? stylePaddingTopState > 0 ? React3.cloneElement(refreshControl, {
|
|
3852
|
-
progressViewOffset: (refreshControl.props.progressViewOffset || 0) + stylePaddingTopState
|
|
3853
|
-
}) : refreshControl : onRefresh && /* @__PURE__ */ React3.createElement(
|
|
3854
|
-
RefreshControl,
|
|
3855
|
-
{
|
|
3856
|
-
onRefresh,
|
|
3857
|
-
progressViewOffset: (progressViewOffset || 0) + stylePaddingTopState,
|
|
3858
|
-
refreshing: !!refreshing
|
|
3859
|
-
}
|
|
3860
|
-
),
|
|
3861
|
-
refScrollView: combinedRef,
|
|
3862
|
-
scrollAdjustHandler: (_b = refState.current) == null ? void 0 : _b.scrollAdjustHandler,
|
|
3863
|
-
scrollEventThrottle: 0,
|
|
3864
|
-
snapToIndices,
|
|
3865
|
-
stickyHeaderConfig,
|
|
3866
|
-
stickyHeaderIndices,
|
|
3867
|
-
style,
|
|
3868
|
-
updateItemSize: fns.updateItemSize,
|
|
3869
|
-
waitForInitialLayout
|
|
3870
|
-
}
|
|
3871
|
-
), IS_DEV && ENABLE_DEBUG_VIEW && /* @__PURE__ */ React3.createElement(DebugView, { state: refState.current }));
|
|
3872
|
-
});
|
|
3873
6
|
|
|
3874
7
|
// src/section-list/flattenSections.ts
|
|
3875
8
|
var defaultKeyExtractor = (item, index) => {
|
|
3876
|
-
var
|
|
3877
|
-
const key = (
|
|
9
|
+
var _a;
|
|
10
|
+
const key = (_a = item == null ? void 0 : item.key) != null ? _a : item == null ? void 0 : item.id;
|
|
3878
11
|
return key != null ? String(key) : String(index);
|
|
3879
12
|
};
|
|
3880
13
|
var getSectionKey = (section, sectionIndex) => {
|
|
3881
|
-
var
|
|
3882
|
-
return (
|
|
14
|
+
var _a;
|
|
15
|
+
return (_a = section.key) != null ? _a : `section-${sectionIndex}`;
|
|
3883
16
|
};
|
|
3884
17
|
function buildSectionListData({
|
|
3885
18
|
sections,
|
|
@@ -3890,14 +23,14 @@ function buildSectionListData({
|
|
|
3890
23
|
stickySectionHeadersEnabled,
|
|
3891
24
|
keyExtractor = defaultKeyExtractor
|
|
3892
25
|
}) {
|
|
3893
|
-
var
|
|
26
|
+
var _a, _b;
|
|
3894
27
|
const data = [];
|
|
3895
28
|
const sectionMeta = [];
|
|
3896
29
|
const stickyHeaderIndices = [];
|
|
3897
30
|
let absoluteItemIndex = 0;
|
|
3898
31
|
for (let sectionIndex = 0; sectionIndex < sections.length; sectionIndex++) {
|
|
3899
32
|
const section = sections[sectionIndex];
|
|
3900
|
-
const items = (
|
|
33
|
+
const items = (_a = section.data) != null ? _a : [];
|
|
3901
34
|
const meta = { items: [] };
|
|
3902
35
|
const sectionKey = getSectionKey(section, sectionIndex);
|
|
3903
36
|
const hasHeader = typeof renderSectionHeader === "function";
|
|
@@ -3978,11 +111,11 @@ var defaultSeparators = {
|
|
|
3978
111
|
};
|
|
3979
112
|
function resolveSeparatorComponent(component, props) {
|
|
3980
113
|
if (!component) return null;
|
|
3981
|
-
if (
|
|
114
|
+
if (React.isValidElement(component)) {
|
|
3982
115
|
return component;
|
|
3983
116
|
}
|
|
3984
117
|
const Component = component;
|
|
3985
|
-
return /* @__PURE__ */
|
|
118
|
+
return /* @__PURE__ */ React.createElement(Component, { ...props });
|
|
3986
119
|
}
|
|
3987
120
|
var SectionList = typedMemo(
|
|
3988
121
|
typedForwardRef(function SectionListInner(props, ref) {
|
|
@@ -3993,15 +126,15 @@ var SectionList = typedMemo(
|
|
|
3993
126
|
renderSectionFooter,
|
|
3994
127
|
ItemSeparatorComponent,
|
|
3995
128
|
SectionSeparatorComponent,
|
|
3996
|
-
stickySectionHeadersEnabled = Platform
|
|
129
|
+
stickySectionHeadersEnabled = Platform.OS === "ios",
|
|
3997
130
|
keyExtractor,
|
|
3998
131
|
extraData,
|
|
3999
132
|
onViewableItemsChanged,
|
|
4000
133
|
horizontal,
|
|
4001
134
|
...restProps
|
|
4002
135
|
} = props;
|
|
4003
|
-
const legendListRef =
|
|
4004
|
-
const flattened =
|
|
136
|
+
const legendListRef = React.useRef(null);
|
|
137
|
+
const flattened = React.useMemo(
|
|
4005
138
|
() => buildSectionListData({
|
|
4006
139
|
ItemSeparatorComponent,
|
|
4007
140
|
keyExtractor,
|
|
@@ -4024,7 +157,7 @@ var SectionList = typedMemo(
|
|
|
4024
157
|
]
|
|
4025
158
|
);
|
|
4026
159
|
const { data, sectionMeta, stickyHeaderIndices } = flattened;
|
|
4027
|
-
const handleViewableItemsChanged =
|
|
160
|
+
const handleViewableItemsChanged = React.useMemo(() => {
|
|
4028
161
|
if (!onViewableItemsChanged) return void 0;
|
|
4029
162
|
return ({
|
|
4030
163
|
viewableItems,
|
|
@@ -4045,16 +178,16 @@ var SectionList = typedMemo(
|
|
|
4045
178
|
onViewableItemsChanged({ changed: mappedChanged, viewableItems: mappedViewable });
|
|
4046
179
|
};
|
|
4047
180
|
}, [onViewableItemsChanged]);
|
|
4048
|
-
const renderItem =
|
|
181
|
+
const renderItem = React.useCallback(
|
|
4049
182
|
({ item }) => {
|
|
4050
|
-
var
|
|
183
|
+
var _a, _b;
|
|
4051
184
|
switch (item.kind) {
|
|
4052
185
|
case "header":
|
|
4053
186
|
return renderSectionHeader ? renderSectionHeader({ section: item.section }) : null;
|
|
4054
187
|
case "footer":
|
|
4055
188
|
return renderSectionFooter ? renderSectionFooter({ section: item.section }) : null;
|
|
4056
189
|
case "item": {
|
|
4057
|
-
const render = (
|
|
190
|
+
const render = (_a = item.section.renderItem) != null ? _a : renderItemProp;
|
|
4058
191
|
if (!render) return null;
|
|
4059
192
|
return render({
|
|
4060
193
|
index: item.itemIndex,
|
|
@@ -4093,12 +226,12 @@ var SectionList = typedMemo(
|
|
|
4093
226
|
renderSectionHeader
|
|
4094
227
|
]
|
|
4095
228
|
);
|
|
4096
|
-
const scrollToLocation =
|
|
229
|
+
const scrollToLocation = React.useCallback(
|
|
4097
230
|
({ sectionIndex, itemIndex, viewOffset, viewPosition, animated }) => {
|
|
4098
|
-
var
|
|
231
|
+
var _a, _b, _c;
|
|
4099
232
|
const meta = sectionMeta[sectionIndex];
|
|
4100
233
|
if (!meta) return;
|
|
4101
|
-
const target = itemIndex === -1 ? (_b = (
|
|
234
|
+
const target = itemIndex === -1 ? (_b = (_a = meta.header) != null ? _a : meta.items[0]) != null ? _b : meta.footer : meta.items[itemIndex];
|
|
4102
235
|
if (target === void 0) return;
|
|
4103
236
|
(_c = legendListRef.current) == null ? void 0 : _c.scrollToIndex({
|
|
4104
237
|
animated,
|
|
@@ -4109,7 +242,7 @@ var SectionList = typedMemo(
|
|
|
4109
242
|
},
|
|
4110
243
|
[sectionMeta]
|
|
4111
244
|
);
|
|
4112
|
-
|
|
245
|
+
React.useImperativeHandle(
|
|
4113
246
|
ref,
|
|
4114
247
|
() => ({
|
|
4115
248
|
...legendListRef.current,
|
|
@@ -4117,7 +250,7 @@ var SectionList = typedMemo(
|
|
|
4117
250
|
}),
|
|
4118
251
|
[scrollToLocation]
|
|
4119
252
|
);
|
|
4120
|
-
return /* @__PURE__ */
|
|
253
|
+
return /* @__PURE__ */ React.createElement(
|
|
4121
254
|
LegendList,
|
|
4122
255
|
{
|
|
4123
256
|
...restProps,
|