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