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