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