@legendapp/list 2.0.0-next.0 → 2.0.0-next.10
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/animated.d.mts +3 -2
- package/animated.d.ts +3 -2
- package/animated.js +2 -2
- package/animated.mjs +2 -2
- package/index.d.mts +102 -37
- package/index.d.ts +102 -37
- package/index.js +1547 -1319
- package/index.mjs +1550 -1322
- package/keyboard-controller.d.mts +8 -4
- package/keyboard-controller.d.ts +8 -4
- package/keyboard-controller.js +4 -4
- package/keyboard-controller.mjs +4 -4
- package/package.json +1 -1
- package/reanimated.d.mts +1 -1
- package/reanimated.d.ts +1 -1
- package/reanimated.js +7 -7
- package/reanimated.mjs +7 -7
package/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var React3 = require('react');
|
|
4
4
|
var reactNative = require('react-native');
|
|
5
5
|
var shim = require('use-sync-external-store/shim');
|
|
6
6
|
|
|
@@ -22,45 +22,36 @@ function _interopNamespace(e) {
|
|
|
22
22
|
return Object.freeze(n);
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
var
|
|
25
|
+
var React3__namespace = /*#__PURE__*/_interopNamespace(React3);
|
|
26
26
|
|
|
27
|
-
// src/
|
|
28
|
-
var ContextState =
|
|
27
|
+
// src/components/LazyLegendList.tsx
|
|
28
|
+
var ContextState = React3__namespace.createContext(null);
|
|
29
29
|
function StateProvider({ children }) {
|
|
30
|
-
const [value] =
|
|
30
|
+
const [value] = React3__namespace.useState(() => ({
|
|
31
|
+
columnWrapperStyle: void 0,
|
|
31
32
|
listeners: /* @__PURE__ */ new Map(),
|
|
33
|
+
mapViewabilityAmountCallbacks: /* @__PURE__ */ new Map(),
|
|
34
|
+
mapViewabilityAmountValues: /* @__PURE__ */ new Map(),
|
|
35
|
+
mapViewabilityCallbacks: /* @__PURE__ */ new Map(),
|
|
36
|
+
mapViewabilityValues: /* @__PURE__ */ new Map(),
|
|
32
37
|
values: /* @__PURE__ */ new Map([
|
|
33
38
|
["alignItemsPaddingTop", 0],
|
|
34
39
|
["stylePaddingTop", 0],
|
|
35
|
-
["headerSize", 0]
|
|
40
|
+
["headerSize", 0],
|
|
41
|
+
["numContainers", 0],
|
|
42
|
+
["totalSize", 0]
|
|
36
43
|
]),
|
|
37
|
-
mapViewabilityCallbacks: /* @__PURE__ */ new Map(),
|
|
38
|
-
mapViewabilityValues: /* @__PURE__ */ new Map(),
|
|
39
|
-
mapViewabilityAmountCallbacks: /* @__PURE__ */ new Map(),
|
|
40
|
-
mapViewabilityAmountValues: /* @__PURE__ */ new Map(),
|
|
41
|
-
columnWrapperStyle: void 0,
|
|
42
44
|
viewRefs: /* @__PURE__ */ new Map()
|
|
43
45
|
}));
|
|
44
|
-
return /* @__PURE__ */
|
|
46
|
+
return /* @__PURE__ */ React3__namespace.createElement(ContextState.Provider, { value }, children);
|
|
45
47
|
}
|
|
46
48
|
function useStateContext() {
|
|
47
|
-
return
|
|
49
|
+
return React3__namespace.useContext(ContextState);
|
|
48
50
|
}
|
|
49
51
|
function createSelectorFunctionsArr(ctx, signalNames) {
|
|
50
52
|
let lastValues = [];
|
|
51
53
|
let lastSignalValues = [];
|
|
52
54
|
return {
|
|
53
|
-
subscribe: (cb) => {
|
|
54
|
-
const listeners = [];
|
|
55
|
-
for (const signalName of signalNames) {
|
|
56
|
-
listeners.push(listen$(ctx, signalName, cb));
|
|
57
|
-
}
|
|
58
|
-
return () => {
|
|
59
|
-
for (const listener of listeners) {
|
|
60
|
-
listener();
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
},
|
|
64
55
|
get: () => {
|
|
65
56
|
const currentValues = [];
|
|
66
57
|
let hasChanged = false;
|
|
@@ -76,6 +67,17 @@ function createSelectorFunctionsArr(ctx, signalNames) {
|
|
|
76
67
|
lastValues = currentValues;
|
|
77
68
|
}
|
|
78
69
|
return lastValues;
|
|
70
|
+
},
|
|
71
|
+
subscribe: (cb) => {
|
|
72
|
+
const listeners = [];
|
|
73
|
+
for (const signalName of signalNames) {
|
|
74
|
+
listeners.push(listen$(ctx, signalName, cb));
|
|
75
|
+
}
|
|
76
|
+
return () => {
|
|
77
|
+
for (const listener of listeners) {
|
|
78
|
+
listener();
|
|
79
|
+
}
|
|
80
|
+
};
|
|
79
81
|
}
|
|
80
82
|
};
|
|
81
83
|
}
|
|
@@ -110,29 +112,29 @@ function getContentSize(ctx) {
|
|
|
110
112
|
const stylePaddingTop = values.get("stylePaddingTop") || 0;
|
|
111
113
|
const headerSize = values.get("headerSize") || 0;
|
|
112
114
|
const footerSize = values.get("footerSize") || 0;
|
|
113
|
-
const totalSize = values.get("totalSize")
|
|
115
|
+
const totalSize = values.get("totalSize");
|
|
114
116
|
return headerSize + footerSize + totalSize + stylePaddingTop;
|
|
115
117
|
}
|
|
116
118
|
function useArr$(signalNames) {
|
|
117
|
-
const ctx =
|
|
118
|
-
const { subscribe, get } =
|
|
119
|
+
const ctx = React3__namespace.useContext(ContextState);
|
|
120
|
+
const { subscribe, get } = React3__namespace.useMemo(() => createSelectorFunctionsArr(ctx, signalNames), [ctx, signalNames]);
|
|
119
121
|
const value = shim.useSyncExternalStore(subscribe, get);
|
|
120
122
|
return value;
|
|
121
123
|
}
|
|
122
124
|
function useSelector$(signalName, selector) {
|
|
123
|
-
const ctx =
|
|
124
|
-
const { subscribe, get } =
|
|
125
|
+
const ctx = React3__namespace.useContext(ContextState);
|
|
126
|
+
const { subscribe, get } = React3__namespace.useMemo(() => createSelectorFunctionsArr(ctx, [signalName]), [ctx, signalName]);
|
|
125
127
|
const value = shim.useSyncExternalStore(subscribe, () => selector(get()[0]));
|
|
126
128
|
return value;
|
|
127
129
|
}
|
|
128
130
|
|
|
129
|
-
// src/DebugView.tsx
|
|
131
|
+
// src/components/DebugView.tsx
|
|
130
132
|
var DebugRow = ({ children }) => {
|
|
131
|
-
return /* @__PURE__ */
|
|
133
|
+
return /* @__PURE__ */ React3__namespace.createElement(reactNative.View, { style: { alignItems: "center", flexDirection: "row", justifyContent: "space-between" } }, children);
|
|
132
134
|
};
|
|
133
|
-
var DebugView =
|
|
135
|
+
var DebugView = React3__namespace.memo(function DebugView2({ state }) {
|
|
134
136
|
const ctx = useStateContext();
|
|
135
|
-
const [totalSize = 0, scrollAdjust = 0, rawScroll = 0, scroll = 0,
|
|
137
|
+
const [totalSize = 0, scrollAdjust = 0, rawScroll = 0, scroll = 0, _numContainers = 0, _numContainersPooled = 0] = useArr$([
|
|
136
138
|
"totalSize",
|
|
137
139
|
"scrollAdjust",
|
|
138
140
|
"debugRawScroll",
|
|
@@ -141,44 +143,70 @@ var DebugView = React2__namespace.memo(function DebugView2({ state }) {
|
|
|
141
143
|
"numContainersPooled"
|
|
142
144
|
]);
|
|
143
145
|
const contentSize = getContentSize(ctx);
|
|
144
|
-
const [, forceUpdate] =
|
|
146
|
+
const [, forceUpdate] = React3.useReducer((x) => x + 1, 0);
|
|
145
147
|
useInterval(() => {
|
|
146
148
|
forceUpdate();
|
|
147
149
|
}, 100);
|
|
148
|
-
return /* @__PURE__ */
|
|
150
|
+
return /* @__PURE__ */ React3__namespace.createElement(
|
|
149
151
|
reactNative.View,
|
|
150
152
|
{
|
|
153
|
+
pointerEvents: "none",
|
|
151
154
|
style: {
|
|
152
|
-
position: "absolute",
|
|
153
|
-
top: 0,
|
|
154
|
-
right: 0,
|
|
155
|
-
paddingLeft: 4,
|
|
156
|
-
paddingBottom: 4,
|
|
157
155
|
// height: 100,
|
|
158
156
|
backgroundColor: "#FFFFFFCC",
|
|
157
|
+
borderRadius: 4,
|
|
159
158
|
padding: 4,
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
159
|
+
paddingBottom: 4,
|
|
160
|
+
paddingLeft: 4,
|
|
161
|
+
position: "absolute",
|
|
162
|
+
right: 0,
|
|
163
|
+
top: 0
|
|
164
|
+
}
|
|
163
165
|
},
|
|
164
|
-
/* @__PURE__ */
|
|
165
|
-
/* @__PURE__ */
|
|
166
|
-
/* @__PURE__ */
|
|
167
|
-
/* @__PURE__ */
|
|
168
|
-
/* @__PURE__ */
|
|
169
|
-
/* @__PURE__ */
|
|
170
|
-
/* @__PURE__ */
|
|
171
|
-
/* @__PURE__ */
|
|
166
|
+
/* @__PURE__ */ React3__namespace.createElement(DebugRow, null, /* @__PURE__ */ React3__namespace.createElement(reactNative.Text, null, "TotalSize:"), /* @__PURE__ */ React3__namespace.createElement(reactNative.Text, null, totalSize.toFixed(2))),
|
|
167
|
+
/* @__PURE__ */ React3__namespace.createElement(DebugRow, null, /* @__PURE__ */ React3__namespace.createElement(reactNative.Text, null, "ContentSize:"), /* @__PURE__ */ React3__namespace.createElement(reactNative.Text, null, contentSize.toFixed(2))),
|
|
168
|
+
/* @__PURE__ */ React3__namespace.createElement(DebugRow, null, /* @__PURE__ */ React3__namespace.createElement(reactNative.Text, null, "At end:"), /* @__PURE__ */ React3__namespace.createElement(reactNative.Text, null, String(state.isAtEnd))),
|
|
169
|
+
/* @__PURE__ */ React3__namespace.createElement(reactNative.Text, null),
|
|
170
|
+
/* @__PURE__ */ React3__namespace.createElement(DebugRow, null, /* @__PURE__ */ React3__namespace.createElement(reactNative.Text, null, "ScrollAdjust:"), /* @__PURE__ */ React3__namespace.createElement(reactNative.Text, null, scrollAdjust.toFixed(2))),
|
|
171
|
+
/* @__PURE__ */ React3__namespace.createElement(reactNative.Text, null),
|
|
172
|
+
/* @__PURE__ */ React3__namespace.createElement(DebugRow, null, /* @__PURE__ */ React3__namespace.createElement(reactNative.Text, null, "RawScroll: "), /* @__PURE__ */ React3__namespace.createElement(reactNative.Text, null, rawScroll.toFixed(2))),
|
|
173
|
+
/* @__PURE__ */ React3__namespace.createElement(DebugRow, null, /* @__PURE__ */ React3__namespace.createElement(reactNative.Text, null, "ComputedScroll: "), /* @__PURE__ */ React3__namespace.createElement(reactNative.Text, null, scroll.toFixed(2)))
|
|
172
174
|
);
|
|
173
175
|
});
|
|
174
176
|
function useInterval(callback, delay) {
|
|
175
|
-
|
|
177
|
+
React3.useEffect(() => {
|
|
176
178
|
const interval = setInterval(callback, delay);
|
|
177
179
|
return () => clearInterval(interval);
|
|
178
180
|
}, [delay]);
|
|
179
181
|
}
|
|
182
|
+
var LeanViewComponent = React3__namespace.forwardRef((props, ref) => {
|
|
183
|
+
return React3__namespace.createElement("RCTView", { ...props, ref });
|
|
184
|
+
});
|
|
185
|
+
LeanViewComponent.displayName = "RCTView";
|
|
186
|
+
var LeanView = reactNative.Platform.OS === "android" || reactNative.Platform.OS === "ios" ? LeanViewComponent : reactNative.View;
|
|
187
|
+
|
|
188
|
+
// src/components/Separator.tsx
|
|
189
|
+
function Separator({ ItemSeparatorComponent, itemKey, leadingItem }) {
|
|
190
|
+
const [lastItemKeys] = useArr$(["lastItemKeys"]);
|
|
191
|
+
const isALastItem = lastItemKeys.includes(itemKey);
|
|
192
|
+
return isALastItem ? null : /* @__PURE__ */ React.createElement(ItemSeparatorComponent, { leadingItem });
|
|
193
|
+
}
|
|
180
194
|
|
|
181
|
-
// src/
|
|
195
|
+
// src/constants.ts
|
|
196
|
+
var POSITION_OUT_OF_VIEW = -1e7;
|
|
197
|
+
var ENABLE_DEVMODE = __DEV__ && false;
|
|
198
|
+
var ENABLE_DEBUG_VIEW = __DEV__ && false;
|
|
199
|
+
var IsNewArchitecture = global.nativeFabricUIManager != null;
|
|
200
|
+
var symbolFirst = Symbol();
|
|
201
|
+
function useInit(cb) {
|
|
202
|
+
const refValue = React3.useRef(symbolFirst);
|
|
203
|
+
if (refValue.current === symbolFirst) {
|
|
204
|
+
refValue.current = cb();
|
|
205
|
+
}
|
|
206
|
+
return refValue.current;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// src/utils/helpers.ts
|
|
182
210
|
function isFunction(obj) {
|
|
183
211
|
return typeof obj === "function";
|
|
184
212
|
}
|
|
@@ -192,12 +220,12 @@ function warnDevOnce(id, text) {
|
|
|
192
220
|
console.warn(`[legend-list] ${text}`);
|
|
193
221
|
}
|
|
194
222
|
}
|
|
223
|
+
function roundSize(size) {
|
|
224
|
+
return Math.floor(size * 8) / 8;
|
|
225
|
+
}
|
|
195
226
|
function isNullOrUndefined(value) {
|
|
196
227
|
return value === null || value === void 0;
|
|
197
228
|
}
|
|
198
|
-
function comparatorByDistance(a, b) {
|
|
199
|
-
return b.distance - a.distance;
|
|
200
|
-
}
|
|
201
229
|
function comparatorDefault(a, b) {
|
|
202
230
|
return a - b;
|
|
203
231
|
}
|
|
@@ -208,20 +236,12 @@ function getPadding(s, type) {
|
|
|
208
236
|
function extractPadding(style, contentContainerStyle, type) {
|
|
209
237
|
return getPadding(style, type) + getPadding(contentContainerStyle, type);
|
|
210
238
|
}
|
|
211
|
-
var symbolFirst = Symbol();
|
|
212
|
-
function useInit(cb) {
|
|
213
|
-
const refValue = React2.useRef(symbolFirst);
|
|
214
|
-
if (refValue.current === symbolFirst) {
|
|
215
|
-
refValue.current = cb();
|
|
216
|
-
}
|
|
217
|
-
return refValue.current;
|
|
218
|
-
}
|
|
219
239
|
|
|
220
|
-
// src/ContextContainer.ts
|
|
221
|
-
var ContextContainer =
|
|
240
|
+
// src/state/ContextContainer.ts
|
|
241
|
+
var ContextContainer = React3.createContext(null);
|
|
222
242
|
function useViewability(callback, configId) {
|
|
223
243
|
const ctx = useStateContext();
|
|
224
|
-
const { containerId } =
|
|
244
|
+
const { containerId } = React3.useContext(ContextContainer);
|
|
225
245
|
const key = containerId + (configId != null ? configId : "");
|
|
226
246
|
useInit(() => {
|
|
227
247
|
const value = ctx.mapViewabilityValues.get(key);
|
|
@@ -230,7 +250,7 @@ function useViewability(callback, configId) {
|
|
|
230
250
|
}
|
|
231
251
|
});
|
|
232
252
|
ctx.mapViewabilityCallbacks.set(key, callback);
|
|
233
|
-
|
|
253
|
+
React3.useEffect(
|
|
234
254
|
() => () => {
|
|
235
255
|
ctx.mapViewabilityCallbacks.delete(key);
|
|
236
256
|
},
|
|
@@ -239,7 +259,7 @@ function useViewability(callback, configId) {
|
|
|
239
259
|
}
|
|
240
260
|
function useViewabilityAmount(callback) {
|
|
241
261
|
const ctx = useStateContext();
|
|
242
|
-
const { containerId } =
|
|
262
|
+
const { containerId } = React3.useContext(ContextContainer);
|
|
243
263
|
useInit(() => {
|
|
244
264
|
const value = ctx.mapViewabilityAmountValues.get(containerId);
|
|
245
265
|
if (value) {
|
|
@@ -247,7 +267,7 @@ function useViewabilityAmount(callback) {
|
|
|
247
267
|
}
|
|
248
268
|
});
|
|
249
269
|
ctx.mapViewabilityAmountCallbacks.set(containerId, callback);
|
|
250
|
-
|
|
270
|
+
React3.useEffect(
|
|
251
271
|
() => () => {
|
|
252
272
|
ctx.mapViewabilityAmountCallbacks.delete(containerId);
|
|
253
273
|
},
|
|
@@ -255,13 +275,13 @@ function useViewabilityAmount(callback) {
|
|
|
255
275
|
);
|
|
256
276
|
}
|
|
257
277
|
function useRecyclingEffect(effect) {
|
|
258
|
-
const { index, value } =
|
|
259
|
-
const prevValues =
|
|
278
|
+
const { index, value } = React3.useContext(ContextContainer);
|
|
279
|
+
const prevValues = React3.useRef({
|
|
260
280
|
prevIndex: void 0,
|
|
261
281
|
prevItem: void 0
|
|
262
282
|
});
|
|
263
|
-
|
|
264
|
-
let ret
|
|
283
|
+
React3.useEffect(() => {
|
|
284
|
+
let ret;
|
|
265
285
|
if (prevValues.current.prevIndex !== void 0 && prevValues.current.prevItem !== void 0) {
|
|
266
286
|
ret = effect({
|
|
267
287
|
index,
|
|
@@ -275,36 +295,37 @@ function useRecyclingEffect(effect) {
|
|
|
275
295
|
prevItem: value
|
|
276
296
|
};
|
|
277
297
|
return ret;
|
|
278
|
-
}, [index, value]);
|
|
298
|
+
}, [index, value, effect]);
|
|
279
299
|
}
|
|
280
300
|
function useRecyclingState(valueOrFun) {
|
|
281
|
-
const { index, value, itemKey, triggerLayout } =
|
|
282
|
-
const refState =
|
|
301
|
+
const { index, value, itemKey, triggerLayout } = React3.useContext(ContextContainer);
|
|
302
|
+
const refState = React3.useRef({
|
|
283
303
|
itemKey: null,
|
|
284
304
|
value: null
|
|
285
305
|
});
|
|
286
|
-
const [_, setRenderNum] =
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
306
|
+
const [_, setRenderNum] = React3.useState(0);
|
|
307
|
+
const state = refState.current;
|
|
308
|
+
if (state.itemKey !== itemKey) {
|
|
309
|
+
state.itemKey = itemKey;
|
|
310
|
+
state.value = isFunction(valueOrFun) ? valueOrFun({
|
|
290
311
|
index,
|
|
291
312
|
item: value,
|
|
292
313
|
prevIndex: void 0,
|
|
293
314
|
prevItem: void 0
|
|
294
315
|
}) : valueOrFun;
|
|
295
316
|
}
|
|
296
|
-
const setState =
|
|
317
|
+
const setState = React3.useCallback(
|
|
297
318
|
(newState) => {
|
|
298
|
-
|
|
319
|
+
state.value = isFunction(newState) ? newState(state.value) : newState;
|
|
299
320
|
setRenderNum((v) => v + 1);
|
|
300
321
|
triggerLayout();
|
|
301
322
|
},
|
|
302
|
-
[triggerLayout]
|
|
323
|
+
[triggerLayout, state]
|
|
303
324
|
);
|
|
304
|
-
return [
|
|
325
|
+
return [state.value, setState];
|
|
305
326
|
}
|
|
306
327
|
function useIsLastItem() {
|
|
307
|
-
const { itemKey } =
|
|
328
|
+
const { itemKey } = React3.useContext(ContextContainer);
|
|
308
329
|
const isLast = useSelector$("lastItemKeys", (lastItemKeys) => (lastItemKeys == null ? void 0 : lastItemKeys.includes(itemKey)) || false);
|
|
309
330
|
return isLast;
|
|
310
331
|
}
|
|
@@ -312,86 +333,80 @@ function useListScrollSize() {
|
|
|
312
333
|
const [scrollSize] = useArr$(["scrollSize"]);
|
|
313
334
|
return scrollSize;
|
|
314
335
|
}
|
|
315
|
-
var
|
|
316
|
-
|
|
317
|
-
});
|
|
318
|
-
LeanViewComponent.displayName = "RCTView";
|
|
319
|
-
var LeanView = reactNative.Platform.OS === "android" || reactNative.Platform.OS === "ios" ? LeanViewComponent : reactNative.View;
|
|
320
|
-
|
|
321
|
-
// src/constants.ts
|
|
322
|
-
var POSITION_OUT_OF_VIEW = -1e7;
|
|
323
|
-
var ENABLE_DEVMODE = __DEV__ && false;
|
|
324
|
-
var ENABLE_DEBUG_VIEW = __DEV__ && false;
|
|
325
|
-
var IsNewArchitecture = global.nativeFabricUIManager != null;
|
|
336
|
+
var typedForwardRef = React3.forwardRef;
|
|
337
|
+
var typedMemo = React3.memo;
|
|
326
338
|
|
|
327
|
-
// src/Container.tsx
|
|
328
|
-
var Container = ({
|
|
339
|
+
// src/components/Container.tsx
|
|
340
|
+
var Container = typedMemo(function Container2({
|
|
329
341
|
id,
|
|
330
342
|
recycleItems,
|
|
331
343
|
horizontal,
|
|
332
|
-
getRenderedItem,
|
|
333
|
-
updateItemSize,
|
|
344
|
+
getRenderedItem: getRenderedItem2,
|
|
345
|
+
updateItemSize: updateItemSize2,
|
|
334
346
|
ItemSeparatorComponent
|
|
335
|
-
})
|
|
347
|
+
}) {
|
|
336
348
|
const ctx = useStateContext();
|
|
337
349
|
const columnWrapperStyle = ctx.columnWrapperStyle;
|
|
338
|
-
const [column = 0, data, itemKey, position = POSITION_OUT_OF_VIEW, numColumns,
|
|
350
|
+
const [column = 0, data, itemKey, position = POSITION_OUT_OF_VIEW, numColumns, extraData] = useArr$([
|
|
339
351
|
`containerColumn${id}`,
|
|
340
352
|
`containerItemData${id}`,
|
|
341
353
|
`containerItemKey${id}`,
|
|
342
354
|
`containerPosition${id}`,
|
|
343
355
|
"numColumns",
|
|
344
|
-
"lastItemKeys",
|
|
345
356
|
"extraData"
|
|
346
357
|
]);
|
|
347
|
-
const refLastSize =
|
|
348
|
-
const ref =
|
|
349
|
-
const [layoutRenderCount, forceLayoutRender] =
|
|
358
|
+
const refLastSize = React3.useRef();
|
|
359
|
+
const ref = React3.useRef(null);
|
|
360
|
+
const [layoutRenderCount, forceLayoutRender] = React3.useState(0);
|
|
350
361
|
const otherAxisPos = numColumns > 1 ? `${(column - 1) / numColumns * 100}%` : 0;
|
|
351
362
|
const otherAxisSize = numColumns > 1 ? `${1 / numColumns * 100}%` : void 0;
|
|
352
|
-
const isALastItem = lastItemKeys.includes(itemKey);
|
|
353
363
|
let didLayout = false;
|
|
354
364
|
let paddingStyles;
|
|
355
365
|
if (columnWrapperStyle) {
|
|
356
366
|
const { columnGap, rowGap, gap } = columnWrapperStyle;
|
|
357
367
|
if (horizontal) {
|
|
358
368
|
paddingStyles = {
|
|
359
|
-
paddingRight:
|
|
369
|
+
paddingRight: columnGap || gap || void 0,
|
|
360
370
|
paddingVertical: numColumns > 1 ? (rowGap || gap || 0) / 2 : void 0
|
|
361
371
|
};
|
|
362
372
|
} else {
|
|
363
373
|
paddingStyles = {
|
|
364
|
-
paddingBottom:
|
|
374
|
+
paddingBottom: rowGap || gap || void 0,
|
|
365
375
|
paddingHorizontal: numColumns > 1 ? (columnGap || gap || 0) / 2 : void 0
|
|
366
376
|
};
|
|
367
377
|
}
|
|
368
378
|
}
|
|
369
379
|
const style = horizontal ? {
|
|
370
380
|
flexDirection: ItemSeparatorComponent ? "row" : void 0,
|
|
371
|
-
position: "absolute",
|
|
372
|
-
top: otherAxisPos,
|
|
373
381
|
height: otherAxisSize,
|
|
374
382
|
left: position,
|
|
383
|
+
position: "absolute",
|
|
384
|
+
top: otherAxisPos,
|
|
375
385
|
...paddingStyles || {}
|
|
376
386
|
} : {
|
|
377
|
-
position: "absolute",
|
|
378
387
|
left: otherAxisPos,
|
|
388
|
+
position: "absolute",
|
|
379
389
|
right: numColumns > 1 ? null : 0,
|
|
380
|
-
width: otherAxisSize,
|
|
381
390
|
top: position,
|
|
391
|
+
width: otherAxisSize,
|
|
382
392
|
...paddingStyles || {}
|
|
383
393
|
};
|
|
384
|
-
const renderedItemInfo =
|
|
385
|
-
() => itemKey !== void 0 ?
|
|
394
|
+
const renderedItemInfo = React3.useMemo(
|
|
395
|
+
() => itemKey !== void 0 ? getRenderedItem2(itemKey) : null,
|
|
386
396
|
[itemKey, data, extraData]
|
|
387
397
|
);
|
|
388
398
|
const { index, renderedItem } = renderedItemInfo || {};
|
|
389
|
-
const
|
|
390
|
-
forceLayoutRender((v) => v + 1);
|
|
391
|
-
}, []);
|
|
392
|
-
const contextValue = React2.useMemo(() => {
|
|
399
|
+
const contextValue = React3.useMemo(() => {
|
|
393
400
|
ctx.viewRefs.set(id, ref);
|
|
394
|
-
return {
|
|
401
|
+
return {
|
|
402
|
+
containerId: id,
|
|
403
|
+
index,
|
|
404
|
+
itemKey,
|
|
405
|
+
triggerLayout: () => {
|
|
406
|
+
forceLayoutRender((v) => v + 1);
|
|
407
|
+
},
|
|
408
|
+
value: data
|
|
409
|
+
};
|
|
395
410
|
}, [id, itemKey, index, data]);
|
|
396
411
|
const onLayout = (event) => {
|
|
397
412
|
var _a, _b;
|
|
@@ -400,38 +415,38 @@ var Container = ({
|
|
|
400
415
|
let layout = event.nativeEvent.layout;
|
|
401
416
|
const size = layout[horizontal ? "width" : "height"];
|
|
402
417
|
const doUpdate = () => {
|
|
403
|
-
refLastSize.current = {
|
|
404
|
-
|
|
418
|
+
refLastSize.current = { height: layout.height, width: layout.width };
|
|
419
|
+
updateItemSize2(itemKey, layout);
|
|
405
420
|
};
|
|
406
421
|
if (IsNewArchitecture || size > 0) {
|
|
407
422
|
doUpdate();
|
|
408
423
|
} else {
|
|
409
|
-
(_b = (_a = ref.current) == null ? void 0 : _a.measure) == null ? void 0 : _b.call(_a, (
|
|
410
|
-
layout = {
|
|
424
|
+
(_b = (_a = ref.current) == null ? void 0 : _a.measure) == null ? void 0 : _b.call(_a, (_x, _y, width, height) => {
|
|
425
|
+
layout = { height, width };
|
|
411
426
|
doUpdate();
|
|
412
427
|
});
|
|
413
428
|
}
|
|
414
429
|
}
|
|
415
430
|
};
|
|
416
431
|
if (IsNewArchitecture) {
|
|
417
|
-
|
|
432
|
+
React3.useLayoutEffect(() => {
|
|
418
433
|
var _a, _b;
|
|
419
434
|
if (!isNullOrUndefined(itemKey)) {
|
|
420
435
|
const measured = (_b = (_a = ref.current) == null ? void 0 : _a.unstable_getBoundingClientRect) == null ? void 0 : _b.call(_a);
|
|
421
436
|
if (measured) {
|
|
422
437
|
const size = Math.floor(measured[horizontal ? "width" : "height"] * 8) / 8;
|
|
423
438
|
if (size) {
|
|
424
|
-
|
|
439
|
+
updateItemSize2(itemKey, measured);
|
|
425
440
|
}
|
|
426
441
|
}
|
|
427
442
|
}
|
|
428
|
-
}, [itemKey, layoutRenderCount
|
|
443
|
+
}, [itemKey, layoutRenderCount]);
|
|
429
444
|
} else {
|
|
430
|
-
|
|
445
|
+
React3.useEffect(() => {
|
|
431
446
|
if (!isNullOrUndefined(itemKey)) {
|
|
432
447
|
const timeout = setTimeout(() => {
|
|
433
448
|
if (!didLayout && refLastSize.current) {
|
|
434
|
-
|
|
449
|
+
updateItemSize2(itemKey, refLastSize.current);
|
|
435
450
|
}
|
|
436
451
|
}, 16);
|
|
437
452
|
return () => {
|
|
@@ -440,23 +455,28 @@ var Container = ({
|
|
|
440
455
|
}
|
|
441
456
|
}, [itemKey]);
|
|
442
457
|
}
|
|
443
|
-
return /* @__PURE__ */
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
458
|
+
return /* @__PURE__ */ React3__namespace.createElement(LeanView, { key: recycleItems ? void 0 : itemKey, onLayout, ref, style }, /* @__PURE__ */ React3__namespace.createElement(ContextContainer.Provider, { value: contextValue }, renderedItem, renderedItemInfo && ItemSeparatorComponent && /* @__PURE__ */ React3__namespace.createElement(
|
|
459
|
+
Separator,
|
|
460
|
+
{
|
|
461
|
+
ItemSeparatorComponent,
|
|
462
|
+
itemKey,
|
|
463
|
+
leadingItem: renderedItemInfo.item
|
|
464
|
+
}
|
|
465
|
+
)));
|
|
466
|
+
});
|
|
447
467
|
var useAnimatedValue = (initialValue) => {
|
|
448
|
-
return
|
|
468
|
+
return React3.useRef(new reactNative.Animated.Value(initialValue)).current;
|
|
449
469
|
};
|
|
450
470
|
|
|
451
|
-
// src/useValue$.ts
|
|
471
|
+
// src/hooks/useValue$.ts
|
|
452
472
|
function useValue$(key, params) {
|
|
453
473
|
var _a;
|
|
454
474
|
const { getValue, delay } = params || {};
|
|
455
475
|
const ctx = useStateContext();
|
|
456
476
|
const animValue = useAnimatedValue((_a = getValue ? getValue(peek$(ctx, key)) : peek$(ctx, key)) != null ? _a : 0);
|
|
457
|
-
|
|
458
|
-
let newValue
|
|
459
|
-
let prevValue
|
|
477
|
+
React3.useMemo(() => {
|
|
478
|
+
let newValue;
|
|
479
|
+
let prevValue;
|
|
460
480
|
let didQueueTask = false;
|
|
461
481
|
listen$(ctx, key, (v) => {
|
|
462
482
|
newValue = getValue ? getValue(v) : v;
|
|
@@ -485,14 +505,14 @@ function useValue$(key, params) {
|
|
|
485
505
|
return animValue;
|
|
486
506
|
}
|
|
487
507
|
|
|
488
|
-
// src/Containers.tsx
|
|
508
|
+
// src/components/Containers.tsx
|
|
489
509
|
var Containers = typedMemo(function Containers2({
|
|
490
510
|
horizontal,
|
|
491
511
|
recycleItems,
|
|
492
512
|
ItemSeparatorComponent,
|
|
493
513
|
waitForInitialLayout,
|
|
494
|
-
updateItemSize,
|
|
495
|
-
getRenderedItem
|
|
514
|
+
updateItemSize: updateItemSize2,
|
|
515
|
+
getRenderedItem: getRenderedItem2
|
|
496
516
|
}) {
|
|
497
517
|
const ctx = useStateContext();
|
|
498
518
|
const columnWrapperStyle = ctx.columnWrapperStyle;
|
|
@@ -506,100 +526,114 @@ var Containers = typedMemo(function Containers2({
|
|
|
506
526
|
const containers = [];
|
|
507
527
|
for (let i = 0; i < numContainers; i++) {
|
|
508
528
|
containers.push(
|
|
509
|
-
/* @__PURE__ */
|
|
529
|
+
/* @__PURE__ */ React3__namespace.createElement(
|
|
510
530
|
Container,
|
|
511
531
|
{
|
|
532
|
+
getRenderedItem: getRenderedItem2,
|
|
533
|
+
horizontal,
|
|
534
|
+
ItemSeparatorComponent,
|
|
512
535
|
id: i,
|
|
513
536
|
key: i,
|
|
514
537
|
recycleItems,
|
|
515
|
-
|
|
516
|
-
getRenderedItem,
|
|
517
|
-
updateItemSize,
|
|
518
|
-
ItemSeparatorComponent
|
|
538
|
+
updateItemSize: updateItemSize2
|
|
519
539
|
}
|
|
520
540
|
)
|
|
521
541
|
);
|
|
522
542
|
}
|
|
523
|
-
const style = horizontal ? {
|
|
543
|
+
const style = horizontal ? { minHeight: otherAxisSize, opacity: animOpacity, width: animSize } : { height: animSize, minWidth: otherAxisSize, opacity: animOpacity };
|
|
524
544
|
if (columnWrapperStyle && numColumns > 1) {
|
|
525
545
|
const { columnGap, rowGap, gap } = columnWrapperStyle;
|
|
546
|
+
const gapX = columnGap || gap || 0;
|
|
547
|
+
const gapY = rowGap || gap || 0;
|
|
526
548
|
if (horizontal) {
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
549
|
+
if (gapY) {
|
|
550
|
+
style.marginVertical = -gapY / 2;
|
|
551
|
+
}
|
|
552
|
+
if (gapX) {
|
|
553
|
+
style.marginRight = -gapX;
|
|
530
554
|
}
|
|
531
555
|
} else {
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
556
|
+
if (gapX) {
|
|
557
|
+
style.marginHorizontal = -gapX;
|
|
558
|
+
}
|
|
559
|
+
if (gapY) {
|
|
560
|
+
style.marginBottom = -gapY;
|
|
535
561
|
}
|
|
536
562
|
}
|
|
537
563
|
}
|
|
538
|
-
return /* @__PURE__ */
|
|
564
|
+
return /* @__PURE__ */ React3__namespace.createElement(reactNative.Animated.View, { style }, containers);
|
|
539
565
|
});
|
|
540
566
|
function ScrollAdjust() {
|
|
541
567
|
const bias = 1e7;
|
|
542
568
|
const [scrollAdjust, scrollAdjustUserOffset] = useArr$(["scrollAdjust", "scrollAdjustUserOffset"]);
|
|
543
569
|
const scrollOffset = (scrollAdjust || 0) + (scrollAdjustUserOffset || 0) + bias;
|
|
544
|
-
return /* @__PURE__ */
|
|
570
|
+
return /* @__PURE__ */ React3__namespace.createElement(
|
|
545
571
|
reactNative.View,
|
|
546
572
|
{
|
|
547
573
|
style: {
|
|
548
|
-
position: "absolute",
|
|
549
574
|
height: 0,
|
|
550
|
-
|
|
575
|
+
left: 0,
|
|
576
|
+
position: "absolute",
|
|
551
577
|
top: scrollOffset,
|
|
552
|
-
|
|
578
|
+
width: 0
|
|
553
579
|
}
|
|
554
580
|
}
|
|
555
581
|
);
|
|
556
582
|
}
|
|
583
|
+
|
|
584
|
+
// src/components/SnapWrapper.tsx
|
|
585
|
+
function SnapWrapper({ ScrollComponent, ...props }) {
|
|
586
|
+
const [snapToOffsets] = useArr$(["snapToOffsets"]);
|
|
587
|
+
return /* @__PURE__ */ React.createElement(ScrollComponent, { ...props, snapToOffsets });
|
|
588
|
+
}
|
|
557
589
|
function useSyncLayout({
|
|
558
590
|
onChange
|
|
559
591
|
}) {
|
|
560
|
-
const ref =
|
|
561
|
-
const onLayout =
|
|
592
|
+
const ref = React3.useRef(null);
|
|
593
|
+
const onLayout = React3.useCallback(
|
|
562
594
|
(event) => {
|
|
563
595
|
onChange(event.nativeEvent.layout, false);
|
|
564
596
|
},
|
|
565
597
|
[onChange]
|
|
566
598
|
);
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
ref.current
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
599
|
+
if (IsNewArchitecture) {
|
|
600
|
+
React3.useLayoutEffect(() => {
|
|
601
|
+
if (ref.current) {
|
|
602
|
+
ref.current.measure((x, y, width, height) => {
|
|
603
|
+
onChange({ height, width, x, y }, true);
|
|
604
|
+
});
|
|
605
|
+
}
|
|
606
|
+
}, []);
|
|
607
|
+
}
|
|
574
608
|
return { onLayout, ref };
|
|
575
609
|
}
|
|
576
610
|
|
|
577
|
-
// src/ListComponent.tsx
|
|
611
|
+
// src/components/ListComponent.tsx
|
|
578
612
|
var getComponent = (Component) => {
|
|
579
|
-
if (
|
|
613
|
+
if (React3__namespace.isValidElement(Component)) {
|
|
580
614
|
return Component;
|
|
581
615
|
}
|
|
582
616
|
if (Component) {
|
|
583
|
-
return /* @__PURE__ */
|
|
617
|
+
return /* @__PURE__ */ React3__namespace.createElement(Component, null);
|
|
584
618
|
}
|
|
585
619
|
return null;
|
|
586
620
|
};
|
|
587
621
|
var Padding = () => {
|
|
588
622
|
const animPaddingTop = useValue$("alignItemsPaddingTop", { delay: 0 });
|
|
589
|
-
return /* @__PURE__ */
|
|
623
|
+
return /* @__PURE__ */ React3__namespace.createElement(reactNative.Animated.View, { style: { paddingTop: animPaddingTop } });
|
|
590
624
|
};
|
|
591
625
|
var PaddingDevMode = () => {
|
|
592
626
|
const animPaddingTop = useValue$("alignItemsPaddingTop", { delay: 0 });
|
|
593
|
-
return /* @__PURE__ */
|
|
627
|
+
return /* @__PURE__ */ React3__namespace.createElement(React3__namespace.Fragment, null, /* @__PURE__ */ React3__namespace.createElement(reactNative.Animated.View, { style: { paddingTop: animPaddingTop } }), /* @__PURE__ */ React3__namespace.createElement(
|
|
594
628
|
reactNative.Animated.View,
|
|
595
629
|
{
|
|
596
630
|
style: {
|
|
597
|
-
|
|
598
|
-
top: 0,
|
|
631
|
+
backgroundColor: "green",
|
|
599
632
|
height: animPaddingTop,
|
|
600
633
|
left: 0,
|
|
634
|
+
position: "absolute",
|
|
601
635
|
right: 0,
|
|
602
|
-
|
|
636
|
+
top: 0
|
|
603
637
|
}
|
|
604
638
|
}
|
|
605
639
|
));
|
|
@@ -614,122 +648,449 @@ var ListComponent = typedMemo(function ListComponent2({
|
|
|
614
648
|
ItemSeparatorComponent,
|
|
615
649
|
alignItemsAtEnd,
|
|
616
650
|
waitForInitialLayout,
|
|
617
|
-
|
|
651
|
+
onScroll: onScroll2,
|
|
618
652
|
onLayout,
|
|
619
653
|
ListHeaderComponent,
|
|
620
654
|
ListHeaderComponentStyle,
|
|
621
655
|
ListFooterComponent,
|
|
622
656
|
ListFooterComponentStyle,
|
|
623
657
|
ListEmptyComponent,
|
|
624
|
-
getRenderedItem,
|
|
625
|
-
updateItemSize,
|
|
658
|
+
getRenderedItem: getRenderedItem2,
|
|
659
|
+
updateItemSize: updateItemSize2,
|
|
626
660
|
refScrollView,
|
|
627
661
|
maintainVisibleContentPosition,
|
|
628
662
|
renderScrollComponent,
|
|
629
663
|
scrollAdjustHandler,
|
|
630
664
|
onLayoutHeader,
|
|
665
|
+
snapToIndices,
|
|
631
666
|
...rest
|
|
632
667
|
}) {
|
|
633
668
|
const ctx = useStateContext();
|
|
634
669
|
const { onLayout: onLayoutHeaderSync, ref: refHeader } = useSyncLayout({
|
|
635
670
|
onChange: onLayoutHeader
|
|
636
671
|
});
|
|
637
|
-
const ScrollComponent = renderScrollComponent ?
|
|
638
|
-
() =>
|
|
672
|
+
const ScrollComponent = renderScrollComponent ? React3.useMemo(
|
|
673
|
+
() => React3__namespace.forwardRef((props, ref) => renderScrollComponent({ ...props, ref })),
|
|
639
674
|
[renderScrollComponent]
|
|
640
675
|
) : reactNative.ScrollView;
|
|
641
|
-
|
|
676
|
+
React3__namespace.useEffect(() => {
|
|
642
677
|
if (canRender) {
|
|
643
678
|
setTimeout(() => {
|
|
644
679
|
scrollAdjustHandler.setMounted();
|
|
645
680
|
}, 0);
|
|
646
681
|
}
|
|
647
682
|
}, [canRender]);
|
|
648
|
-
|
|
649
|
-
|
|
683
|
+
const SnapOrScroll = snapToIndices ? SnapWrapper : ScrollComponent;
|
|
684
|
+
return /* @__PURE__ */ React3__namespace.createElement(
|
|
685
|
+
SnapOrScroll,
|
|
650
686
|
{
|
|
651
687
|
...rest,
|
|
652
|
-
style,
|
|
653
|
-
maintainVisibleContentPosition: maintainVisibleContentPosition && !ListEmptyComponent ? { minIndexForVisible: 0 } : void 0,
|
|
654
688
|
contentContainerStyle: [
|
|
655
689
|
contentContainerStyle,
|
|
656
690
|
horizontal ? {
|
|
657
691
|
height: "100%"
|
|
658
692
|
} : {}
|
|
659
693
|
],
|
|
660
|
-
onScroll: handleScroll,
|
|
661
|
-
onLayout,
|
|
662
|
-
horizontal,
|
|
663
694
|
contentOffset: initialContentOffset ? horizontal ? { x: initialContentOffset, y: 0 } : { x: 0, y: initialContentOffset } : void 0,
|
|
664
|
-
|
|
695
|
+
horizontal,
|
|
696
|
+
maintainVisibleContentPosition: maintainVisibleContentPosition && !ListEmptyComponent ? { minIndexForVisible: 0 } : void 0,
|
|
697
|
+
onLayout,
|
|
698
|
+
onScroll: onScroll2,
|
|
699
|
+
ref: refScrollView,
|
|
700
|
+
ScrollComponent: snapToIndices ? ScrollComponent : void 0,
|
|
701
|
+
style
|
|
665
702
|
},
|
|
666
|
-
maintainVisibleContentPosition && /* @__PURE__ */
|
|
667
|
-
ENABLE_DEVMODE ? /* @__PURE__ */
|
|
668
|
-
ListHeaderComponent && /* @__PURE__ */
|
|
703
|
+
maintainVisibleContentPosition && /* @__PURE__ */ React3__namespace.createElement(ScrollAdjust, null),
|
|
704
|
+
ENABLE_DEVMODE ? /* @__PURE__ */ React3__namespace.createElement(PaddingDevMode, null) : /* @__PURE__ */ React3__namespace.createElement(Padding, null),
|
|
705
|
+
ListHeaderComponent && /* @__PURE__ */ React3__namespace.createElement(reactNative.View, { onLayout: onLayoutHeaderSync, ref: refHeader, style: ListHeaderComponentStyle }, getComponent(ListHeaderComponent)),
|
|
669
706
|
ListEmptyComponent && getComponent(ListEmptyComponent),
|
|
670
|
-
canRender && /* @__PURE__ */
|
|
707
|
+
canRender && /* @__PURE__ */ React3__namespace.createElement(
|
|
671
708
|
Containers,
|
|
672
709
|
{
|
|
710
|
+
getRenderedItem: getRenderedItem2,
|
|
673
711
|
horizontal,
|
|
674
|
-
recycleItems,
|
|
675
|
-
waitForInitialLayout,
|
|
676
|
-
getRenderedItem,
|
|
677
712
|
ItemSeparatorComponent,
|
|
678
|
-
|
|
713
|
+
recycleItems,
|
|
714
|
+
updateItemSize: updateItemSize2,
|
|
715
|
+
waitForInitialLayout
|
|
679
716
|
}
|
|
680
717
|
),
|
|
681
|
-
ListFooterComponent && /* @__PURE__ */
|
|
718
|
+
ListFooterComponent && /* @__PURE__ */ React3__namespace.createElement(
|
|
682
719
|
reactNative.View,
|
|
683
720
|
{
|
|
684
|
-
style: ListFooterComponentStyle,
|
|
685
721
|
onLayout: (event) => {
|
|
686
722
|
const size = event.nativeEvent.layout[horizontal ? "width" : "height"];
|
|
687
723
|
set$(ctx, "footerSize", size);
|
|
688
|
-
}
|
|
724
|
+
},
|
|
725
|
+
style: ListFooterComponentStyle
|
|
689
726
|
},
|
|
690
727
|
getComponent(ListFooterComponent)
|
|
691
728
|
)
|
|
692
729
|
);
|
|
693
730
|
});
|
|
694
731
|
|
|
695
|
-
// src/
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
this.context = ctx;
|
|
732
|
+
// src/utils/getId.ts
|
|
733
|
+
function getId(state, index) {
|
|
734
|
+
const { data, keyExtractor } = state.props;
|
|
735
|
+
if (!data) {
|
|
736
|
+
return "";
|
|
701
737
|
}
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
738
|
+
const ret = index < data.length ? keyExtractor ? keyExtractor(data[index], index) : index : null;
|
|
739
|
+
const id = ret;
|
|
740
|
+
state.idCache.set(index, id);
|
|
741
|
+
return id;
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
// src/core/calculateOffsetForIndex.ts
|
|
745
|
+
function calculateOffsetForIndex(ctx, state, index) {
|
|
746
|
+
let position = 0;
|
|
747
|
+
if (index !== void 0) {
|
|
748
|
+
position = (state == null ? void 0 : state.positions.get(getId(state, index))) || 0;
|
|
749
|
+
}
|
|
750
|
+
const paddingTop = peek$(ctx, "stylePaddingTop");
|
|
751
|
+
if (paddingTop) {
|
|
752
|
+
position += paddingTop;
|
|
753
|
+
}
|
|
754
|
+
const headerSize = peek$(ctx, "headerSize");
|
|
755
|
+
if (headerSize) {
|
|
756
|
+
position += headerSize;
|
|
757
|
+
}
|
|
758
|
+
return position;
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
// src/utils/getItemSize.ts
|
|
762
|
+
function getItemSize(state, key, index, data, useAverageSize) {
|
|
763
|
+
const {
|
|
764
|
+
sizesKnown,
|
|
765
|
+
sizes,
|
|
766
|
+
scrollingTo,
|
|
767
|
+
props: { estimatedItemSize, getEstimatedItemSize }
|
|
768
|
+
} = state;
|
|
769
|
+
const sizeKnown = sizesKnown.get(key);
|
|
770
|
+
if (sizeKnown !== void 0) {
|
|
771
|
+
return sizeKnown;
|
|
772
|
+
}
|
|
773
|
+
let size;
|
|
774
|
+
if (useAverageSize !== void 0 && sizeKnown === void 0 && !getEstimatedItemSize && !scrollingTo) {
|
|
775
|
+
size = useAverageSize;
|
|
776
|
+
}
|
|
777
|
+
if (size === void 0) {
|
|
778
|
+
size = sizes.get(key);
|
|
779
|
+
if (size !== void 0) {
|
|
780
|
+
return size;
|
|
710
781
|
}
|
|
711
782
|
}
|
|
712
|
-
|
|
713
|
-
|
|
783
|
+
if (size === void 0) {
|
|
784
|
+
size = getEstimatedItemSize ? getEstimatedItemSize(index, data) : estimatedItemSize;
|
|
714
785
|
}
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
786
|
+
sizes.set(key, size);
|
|
787
|
+
return size;
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
// src/core/calculateOffsetWithOffsetPosition.ts
|
|
791
|
+
function calculateOffsetWithOffsetPosition(state, offsetParam, params) {
|
|
792
|
+
const { index, viewOffset, viewPosition } = params;
|
|
793
|
+
let offset = offsetParam;
|
|
794
|
+
if (viewOffset) {
|
|
795
|
+
offset -= viewOffset;
|
|
796
|
+
}
|
|
797
|
+
if (viewPosition !== void 0 && index !== void 0) {
|
|
798
|
+
offset -= viewPosition * (state.scrollLength - getItemSize(state, getId(state, index), index, state.props.data[index]));
|
|
799
|
+
}
|
|
800
|
+
return offset;
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
// src/utils/requestAdjust.ts
|
|
804
|
+
function requestAdjust(ctx, state, positionDiff) {
|
|
805
|
+
if (Math.abs(positionDiff) > 0.1) {
|
|
806
|
+
const doit = () => {
|
|
807
|
+
state.scrollAdjustHandler.requestAdjust(positionDiff);
|
|
808
|
+
};
|
|
809
|
+
state.scroll += positionDiff;
|
|
810
|
+
state.scrollForNextCalculateItemsInView = void 0;
|
|
811
|
+
const didLayout = peek$(ctx, "containersDidLayout");
|
|
812
|
+
if (didLayout) {
|
|
813
|
+
doit();
|
|
814
|
+
const threshold = state.scroll - positionDiff / 2;
|
|
815
|
+
if (!state.ignoreScrollFromMVCP) {
|
|
816
|
+
state.ignoreScrollFromMVCP = {};
|
|
721
817
|
}
|
|
722
|
-
if (
|
|
723
|
-
|
|
818
|
+
if (positionDiff > 0) {
|
|
819
|
+
state.ignoreScrollFromMVCP.lt = threshold;
|
|
724
820
|
} else {
|
|
725
|
-
|
|
821
|
+
state.ignoreScrollFromMVCP.gt = threshold;
|
|
822
|
+
}
|
|
823
|
+
if (state.ignoreScrollFromMVCPTimeout) {
|
|
824
|
+
clearTimeout(state.ignoreScrollFromMVCPTimeout);
|
|
726
825
|
}
|
|
826
|
+
state.ignoreScrollFromMVCPTimeout = setTimeout(() => {
|
|
827
|
+
state.ignoreScrollFromMVCP = void 0;
|
|
828
|
+
}, 100);
|
|
829
|
+
} else {
|
|
830
|
+
requestAnimationFrame(doit);
|
|
727
831
|
}
|
|
728
|
-
}
|
|
729
|
-
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
// src/core/prepareMVCP.ts
|
|
836
|
+
function prepareMVCP(ctx, state) {
|
|
837
|
+
const {
|
|
838
|
+
positions,
|
|
839
|
+
scrollingTo,
|
|
840
|
+
props: { maintainVisibleContentPosition }
|
|
841
|
+
} = state;
|
|
842
|
+
let prevPosition;
|
|
843
|
+
let targetId;
|
|
844
|
+
let targetIndex;
|
|
845
|
+
const scrollTarget = scrollingTo == null ? void 0 : scrollingTo.index;
|
|
846
|
+
if (maintainVisibleContentPosition) {
|
|
847
|
+
const indexByKey = state.indexByKey;
|
|
848
|
+
if (scrollTarget !== void 0) {
|
|
849
|
+
targetId = getId(state, scrollTarget);
|
|
850
|
+
targetIndex = scrollTarget;
|
|
851
|
+
} else if (state.idsInView.length > 0 && peek$(ctx, "containersDidLayout")) {
|
|
852
|
+
targetId = state.idsInView.find((id) => indexByKey.get(id) !== void 0);
|
|
853
|
+
targetIndex = indexByKey.get(targetId);
|
|
854
|
+
}
|
|
855
|
+
if (targetId !== void 0 && targetIndex !== void 0) {
|
|
856
|
+
prevPosition = positions.get(targetId);
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
return () => {
|
|
860
|
+
if (targetId !== void 0 && prevPosition !== void 0) {
|
|
861
|
+
const newPosition = positions.get(targetId);
|
|
862
|
+
if (newPosition !== void 0) {
|
|
863
|
+
const positionDiff = newPosition - prevPosition;
|
|
864
|
+
if (Math.abs(positionDiff) > 0.1) {
|
|
865
|
+
requestAdjust(ctx, state, positionDiff);
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
};
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
// src/utils/setPaddingTop.ts
|
|
873
|
+
function setPaddingTop(ctx, state, { stylePaddingTop, alignItemsPaddingTop }) {
|
|
874
|
+
if (stylePaddingTop !== void 0) {
|
|
875
|
+
const prevStylePaddingTop = peek$(ctx, "stylePaddingTop") || 0;
|
|
876
|
+
if (stylePaddingTop < prevStylePaddingTop) {
|
|
877
|
+
let prevTotalSize = peek$(ctx, "totalSize");
|
|
878
|
+
set$(ctx, "totalSize", prevTotalSize + prevStylePaddingTop);
|
|
879
|
+
state.timeoutSetPaddingTop = setTimeout(() => {
|
|
880
|
+
prevTotalSize = peek$(ctx, "totalSize");
|
|
881
|
+
set$(ctx, "totalSize", prevTotalSize - prevStylePaddingTop);
|
|
882
|
+
}, 16);
|
|
883
|
+
}
|
|
884
|
+
set$(ctx, "stylePaddingTop", stylePaddingTop);
|
|
885
|
+
}
|
|
886
|
+
if (alignItemsPaddingTop !== void 0) {
|
|
887
|
+
set$(ctx, "alignItemsPaddingTop", alignItemsPaddingTop);
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
// src/utils/updateAlignItemsPaddingTop.ts
|
|
892
|
+
function updateAlignItemsPaddingTop(ctx, state) {
|
|
893
|
+
const {
|
|
894
|
+
scrollLength,
|
|
895
|
+
props: { alignItemsAtEnd, data }
|
|
896
|
+
} = state;
|
|
897
|
+
if (alignItemsAtEnd) {
|
|
898
|
+
let alignItemsPaddingTop = 0;
|
|
899
|
+
if ((data == null ? void 0 : data.length) > 0) {
|
|
900
|
+
const contentSize = getContentSize(ctx);
|
|
901
|
+
alignItemsPaddingTop = Math.max(0, Math.floor(scrollLength - contentSize));
|
|
902
|
+
}
|
|
903
|
+
setPaddingTop(ctx, state, { alignItemsPaddingTop });
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
|
|
907
|
+
// src/core/updateTotalSize.ts
|
|
908
|
+
function updateTotalSize(ctx, state) {
|
|
909
|
+
const {
|
|
910
|
+
positions,
|
|
911
|
+
props: { data }
|
|
912
|
+
} = state;
|
|
913
|
+
if (data.length === 0) {
|
|
914
|
+
addTotalSize(ctx, state, null, 0);
|
|
915
|
+
} else {
|
|
916
|
+
const lastId = getId(state, data.length - 1);
|
|
917
|
+
if (lastId !== void 0) {
|
|
918
|
+
const lastPosition = positions.get(lastId);
|
|
919
|
+
if (lastPosition !== void 0) {
|
|
920
|
+
const lastSize = getItemSize(state, lastId, data.length - 1, data[data.length - 1]);
|
|
921
|
+
if (lastSize !== void 0) {
|
|
922
|
+
const totalSize = lastPosition + lastSize;
|
|
923
|
+
addTotalSize(ctx, state, null, totalSize);
|
|
924
|
+
}
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
function addTotalSize(ctx, state, key, add) {
|
|
930
|
+
const { alignItemsAtEnd } = state.props;
|
|
931
|
+
{
|
|
932
|
+
state.totalSize = add;
|
|
933
|
+
if (state.timeoutSetPaddingTop) {
|
|
934
|
+
clearTimeout(state.timeoutSetPaddingTop);
|
|
935
|
+
state.timeoutSetPaddingTop = void 0;
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
set$(ctx, "totalSize", state.totalSize);
|
|
939
|
+
if (alignItemsAtEnd) {
|
|
940
|
+
updateAlignItemsPaddingTop(ctx, state);
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
// src/utils/getScrollVelocity.ts
|
|
945
|
+
var getScrollVelocity = (state) => {
|
|
946
|
+
const { scrollHistory } = state;
|
|
947
|
+
let velocity = 0;
|
|
948
|
+
if (scrollHistory.length >= 1) {
|
|
949
|
+
const newest = scrollHistory[scrollHistory.length - 1];
|
|
950
|
+
let oldest;
|
|
951
|
+
let start = 0;
|
|
952
|
+
for (let i = 0; i < scrollHistory.length - 1; i++) {
|
|
953
|
+
const entry = scrollHistory[i];
|
|
954
|
+
const nextEntry = scrollHistory[i + 1];
|
|
955
|
+
if (i > 0) {
|
|
956
|
+
const prevEntry = scrollHistory[i - 1];
|
|
957
|
+
const prevDirection = entry.scroll - prevEntry.scroll;
|
|
958
|
+
const currentDirection = nextEntry.scroll - entry.scroll;
|
|
959
|
+
if (prevDirection > 0 && currentDirection < 0 || prevDirection < 0 && currentDirection > 0) {
|
|
960
|
+
start = i;
|
|
961
|
+
break;
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
for (let i = start; i < scrollHistory.length - 1; i++) {
|
|
966
|
+
const entry = scrollHistory[i];
|
|
967
|
+
if (newest.time - entry.time <= 1e3) {
|
|
968
|
+
oldest = entry;
|
|
969
|
+
break;
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
if (oldest) {
|
|
973
|
+
const scrollDiff = newest.scroll - oldest.scroll;
|
|
974
|
+
const timeDiff = newest.time - oldest.time;
|
|
975
|
+
velocity = timeDiff > 0 ? scrollDiff / timeDiff : 0;
|
|
976
|
+
}
|
|
977
|
+
}
|
|
978
|
+
return velocity;
|
|
730
979
|
};
|
|
731
980
|
|
|
732
|
-
// src/
|
|
981
|
+
// src/utils/updateSnapToOffsets.ts
|
|
982
|
+
function updateSnapToOffsets(ctx, state) {
|
|
983
|
+
const {
|
|
984
|
+
positions,
|
|
985
|
+
props: { snapToIndices }
|
|
986
|
+
} = state;
|
|
987
|
+
const snapToOffsets = Array(snapToIndices.length);
|
|
988
|
+
for (let i = 0; i < snapToIndices.length; i++) {
|
|
989
|
+
const idx = snapToIndices[i];
|
|
990
|
+
const key = getId(state, idx);
|
|
991
|
+
snapToOffsets[i] = positions.get(key);
|
|
992
|
+
}
|
|
993
|
+
set$(ctx, "snapToOffsets", snapToOffsets);
|
|
994
|
+
}
|
|
995
|
+
|
|
996
|
+
// src/core/updateAllPositions.ts
|
|
997
|
+
function updateAllPositions(ctx, state, dataChanged) {
|
|
998
|
+
var _a, _b, _c, _d, _e;
|
|
999
|
+
const {
|
|
1000
|
+
averageSizes,
|
|
1001
|
+
columns,
|
|
1002
|
+
indexByKey,
|
|
1003
|
+
positions,
|
|
1004
|
+
firstFullyOnScreenIndex,
|
|
1005
|
+
idCache,
|
|
1006
|
+
sizesKnown,
|
|
1007
|
+
props: { snapToIndices }
|
|
1008
|
+
} = state;
|
|
1009
|
+
const data = state.props.data;
|
|
1010
|
+
const numColumns = peek$(ctx, "numColumns");
|
|
1011
|
+
const indexByKeyForChecking = __DEV__ ? /* @__PURE__ */ new Map() : void 0;
|
|
1012
|
+
const scrollVelocity = getScrollVelocity(state);
|
|
1013
|
+
if (dataChanged) {
|
|
1014
|
+
indexByKey.clear();
|
|
1015
|
+
idCache.clear();
|
|
1016
|
+
}
|
|
1017
|
+
const itemType = "";
|
|
1018
|
+
let averageSize = (_a = averageSizes[itemType]) == null ? void 0 : _a.avg;
|
|
1019
|
+
if (averageSize !== void 0) {
|
|
1020
|
+
averageSize = roundSize(averageSize);
|
|
1021
|
+
}
|
|
1022
|
+
const shouldUseBackwards = !dataChanged && scrollVelocity < 0 && firstFullyOnScreenIndex > 5 && firstFullyOnScreenIndex < data.length;
|
|
1023
|
+
if (shouldUseBackwards && firstFullyOnScreenIndex !== void 0) {
|
|
1024
|
+
const anchorId = getId(state, firstFullyOnScreenIndex);
|
|
1025
|
+
const anchorPosition = positions.get(anchorId);
|
|
1026
|
+
if (anchorPosition !== void 0) {
|
|
1027
|
+
let currentRowTop2 = anchorPosition;
|
|
1028
|
+
let maxSizeInRow2 = 0;
|
|
1029
|
+
let bailout = false;
|
|
1030
|
+
for (let i = firstFullyOnScreenIndex - 1; i >= 0; i--) {
|
|
1031
|
+
const id = (_b = idCache.get(i)) != null ? _b : getId(state, i);
|
|
1032
|
+
const size = (_c = sizesKnown.get(id)) != null ? _c : getItemSize(state, id, i, data[i], averageSize);
|
|
1033
|
+
const itemColumn = columns.get(id);
|
|
1034
|
+
maxSizeInRow2 = Math.max(maxSizeInRow2, size);
|
|
1035
|
+
if (itemColumn === 1) {
|
|
1036
|
+
currentRowTop2 -= maxSizeInRow2;
|
|
1037
|
+
maxSizeInRow2 = 0;
|
|
1038
|
+
}
|
|
1039
|
+
if (currentRowTop2 < -2e3) {
|
|
1040
|
+
bailout = true;
|
|
1041
|
+
break;
|
|
1042
|
+
}
|
|
1043
|
+
positions.set(id, currentRowTop2);
|
|
1044
|
+
}
|
|
1045
|
+
if (!bailout) {
|
|
1046
|
+
updateTotalSize(ctx, state);
|
|
1047
|
+
return;
|
|
1048
|
+
}
|
|
1049
|
+
}
|
|
1050
|
+
}
|
|
1051
|
+
let currentRowTop = 0;
|
|
1052
|
+
let column = 1;
|
|
1053
|
+
let maxSizeInRow = 0;
|
|
1054
|
+
const hasColumns = numColumns > 1;
|
|
1055
|
+
const needsIndexByKey = dataChanged || indexByKey.size === 0;
|
|
1056
|
+
const dataLength = data.length;
|
|
1057
|
+
for (let i = 0; i < dataLength; i++) {
|
|
1058
|
+
const id = (_d = idCache.get(i)) != null ? _d : getId(state, i);
|
|
1059
|
+
const size = (_e = sizesKnown.get(id)) != null ? _e : getItemSize(state, id, i, data[i], averageSize);
|
|
1060
|
+
if (__DEV__ && needsIndexByKey) {
|
|
1061
|
+
if (indexByKeyForChecking.has(id)) {
|
|
1062
|
+
console.error(
|
|
1063
|
+
`[legend-list] Error: Detected overlapping key (${id}) which causes missing items and gaps and other terrrible things. Check that keyExtractor returns unique values.`
|
|
1064
|
+
);
|
|
1065
|
+
}
|
|
1066
|
+
indexByKeyForChecking.set(id, i);
|
|
1067
|
+
}
|
|
1068
|
+
positions.set(id, currentRowTop);
|
|
1069
|
+
if (needsIndexByKey) {
|
|
1070
|
+
indexByKey.set(id, i);
|
|
1071
|
+
}
|
|
1072
|
+
columns.set(id, column);
|
|
1073
|
+
if (hasColumns) {
|
|
1074
|
+
if (size > maxSizeInRow) {
|
|
1075
|
+
maxSizeInRow = size;
|
|
1076
|
+
}
|
|
1077
|
+
column++;
|
|
1078
|
+
if (column > numColumns) {
|
|
1079
|
+
currentRowTop += maxSizeInRow;
|
|
1080
|
+
column = 1;
|
|
1081
|
+
maxSizeInRow = 0;
|
|
1082
|
+
}
|
|
1083
|
+
} else {
|
|
1084
|
+
currentRowTop += size;
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
updateTotalSize(ctx, state);
|
|
1088
|
+
if (snapToIndices) {
|
|
1089
|
+
updateSnapToOffsets(ctx, state);
|
|
1090
|
+
}
|
|
1091
|
+
}
|
|
1092
|
+
|
|
1093
|
+
// src/core/viewability.ts
|
|
733
1094
|
var mapViewabilityConfigCallbackPairs = /* @__PURE__ */ new Map();
|
|
734
1095
|
function setupViewability(props) {
|
|
735
1096
|
let { viewabilityConfig, viewabilityConfigCallbackPairs, onViewableItemsChanged } = props;
|
|
@@ -737,27 +1098,31 @@ function setupViewability(props) {
|
|
|
737
1098
|
viewabilityConfigCallbackPairs = [
|
|
738
1099
|
...viewabilityConfigCallbackPairs || [],
|
|
739
1100
|
{
|
|
1101
|
+
onViewableItemsChanged,
|
|
740
1102
|
viewabilityConfig: viewabilityConfig || {
|
|
741
1103
|
viewAreaCoveragePercentThreshold: 0
|
|
742
|
-
}
|
|
743
|
-
onViewableItemsChanged
|
|
1104
|
+
}
|
|
744
1105
|
}
|
|
745
1106
|
];
|
|
746
1107
|
}
|
|
747
1108
|
if (viewabilityConfigCallbackPairs) {
|
|
748
1109
|
for (const pair of viewabilityConfigCallbackPairs) {
|
|
749
1110
|
mapViewabilityConfigCallbackPairs.set(pair.viewabilityConfig.id, {
|
|
750
|
-
viewableItems: [],
|
|
751
|
-
start: -1,
|
|
752
1111
|
end: -1,
|
|
1112
|
+
previousEnd: -1,
|
|
753
1113
|
previousStart: -1,
|
|
754
|
-
|
|
1114
|
+
start: -1,
|
|
1115
|
+
viewableItems: []
|
|
755
1116
|
});
|
|
756
1117
|
}
|
|
757
1118
|
}
|
|
758
1119
|
return viewabilityConfigCallbackPairs;
|
|
759
1120
|
}
|
|
760
|
-
function updateViewableItems(state, ctx, viewabilityConfigCallbackPairs,
|
|
1121
|
+
function updateViewableItems(state, ctx, viewabilityConfigCallbackPairs, scrollSize, start, end) {
|
|
1122
|
+
const {
|
|
1123
|
+
timeouts,
|
|
1124
|
+
props: { data }
|
|
1125
|
+
} = state;
|
|
761
1126
|
for (const viewabilityConfigCallbackPair of viewabilityConfigCallbackPairs) {
|
|
762
1127
|
const viewabilityState = mapViewabilityConfigCallbackPairs.get(
|
|
763
1128
|
viewabilityConfigCallbackPair.viewabilityConfig.id
|
|
@@ -766,16 +1131,16 @@ function updateViewableItems(state, ctx, viewabilityConfigCallbackPairs, getId,
|
|
|
766
1131
|
viewabilityState.end = end;
|
|
767
1132
|
if (viewabilityConfigCallbackPair.viewabilityConfig.minimumViewTime) {
|
|
768
1133
|
const timer = setTimeout(() => {
|
|
769
|
-
|
|
770
|
-
updateViewableItemsWithConfig(
|
|
1134
|
+
timeouts.delete(timer);
|
|
1135
|
+
updateViewableItemsWithConfig(data, viewabilityConfigCallbackPair, state, ctx, scrollSize);
|
|
771
1136
|
}, viewabilityConfigCallbackPair.viewabilityConfig.minimumViewTime);
|
|
772
|
-
|
|
1137
|
+
timeouts.add(timer);
|
|
773
1138
|
} else {
|
|
774
|
-
updateViewableItemsWithConfig(
|
|
1139
|
+
updateViewableItemsWithConfig(data, viewabilityConfigCallbackPair, state, ctx, scrollSize);
|
|
775
1140
|
}
|
|
776
1141
|
}
|
|
777
1142
|
}
|
|
778
|
-
function updateViewableItemsWithConfig(data, viewabilityConfigCallbackPair,
|
|
1143
|
+
function updateViewableItemsWithConfig(data, viewabilityConfigCallbackPair, state, ctx, scrollSize) {
|
|
779
1144
|
const { viewabilityConfig, onViewableItemsChanged } = viewabilityConfigCallbackPair;
|
|
780
1145
|
const configId = viewabilityConfig.id;
|
|
781
1146
|
const viewabilityState = mapViewabilityConfigCallbackPairs.get(configId);
|
|
@@ -819,15 +1184,15 @@ function updateViewableItemsWithConfig(data, viewabilityConfigCallbackPair, getI
|
|
|
819
1184
|
for (let i = start; i <= end; i++) {
|
|
820
1185
|
const item = data[i];
|
|
821
1186
|
if (item) {
|
|
822
|
-
const key = getId(i);
|
|
1187
|
+
const key = getId(state, i);
|
|
823
1188
|
const containerId = findContainerId(ctx, key);
|
|
824
1189
|
if (isViewable(state, ctx, viewabilityConfig, containerId, key, scrollSize, item, i)) {
|
|
825
1190
|
const viewToken = {
|
|
826
|
-
|
|
827
|
-
key,
|
|
1191
|
+
containerId,
|
|
828
1192
|
index: i,
|
|
829
1193
|
isViewable: true,
|
|
830
|
-
|
|
1194
|
+
item,
|
|
1195
|
+
key
|
|
831
1196
|
};
|
|
832
1197
|
viewableItems.push(viewToken);
|
|
833
1198
|
if (!(previousViewableItems == null ? void 0 : previousViewableItems.find((v) => v.key === viewToken.key))) {
|
|
@@ -837,9 +1202,9 @@ function updateViewableItemsWithConfig(data, viewabilityConfigCallbackPair, getI
|
|
|
837
1202
|
}
|
|
838
1203
|
}
|
|
839
1204
|
Object.assign(viewabilityState, {
|
|
840
|
-
|
|
1205
|
+
previousEnd: end,
|
|
841
1206
|
previousStart: start,
|
|
842
|
-
|
|
1207
|
+
viewableItems
|
|
843
1208
|
});
|
|
844
1209
|
if (changed.length > 0) {
|
|
845
1210
|
viewabilityState.viewableItems = viewableItems;
|
|
@@ -848,7 +1213,7 @@ function updateViewableItemsWithConfig(data, viewabilityConfigCallbackPair, getI
|
|
|
848
1213
|
maybeUpdateViewabilityCallback(ctx, configId, change.containerId, change);
|
|
849
1214
|
}
|
|
850
1215
|
if (onViewableItemsChanged) {
|
|
851
|
-
onViewableItemsChanged({
|
|
1216
|
+
onViewableItemsChanged({ changed, viewableItems });
|
|
852
1217
|
}
|
|
853
1218
|
}
|
|
854
1219
|
for (const [containerId, value] of ctx.mapViewabilityAmountValues) {
|
|
@@ -874,16 +1239,16 @@ function computeViewability(state, ctx, viewabilityConfig, containerId, key, scr
|
|
|
874
1239
|
const percent = isEntirelyVisible ? 100 : viewAreaMode ? percentOfScroller : percentVisible;
|
|
875
1240
|
const isViewable2 = percent >= viewablePercentThreshold;
|
|
876
1241
|
const value = {
|
|
1242
|
+
containerId,
|
|
877
1243
|
index,
|
|
878
1244
|
isViewable: isViewable2,
|
|
879
1245
|
item,
|
|
880
1246
|
key,
|
|
881
|
-
percentVisible,
|
|
882
1247
|
percentOfScroller,
|
|
883
|
-
|
|
884
|
-
size,
|
|
1248
|
+
percentVisible,
|
|
885
1249
|
scrollSize,
|
|
886
|
-
|
|
1250
|
+
size,
|
|
1251
|
+
sizeVisible
|
|
887
1252
|
};
|
|
888
1253
|
if (JSON.stringify(value) !== JSON.stringify(ctx.mapViewabilityAmountValues.get(containerId))) {
|
|
889
1254
|
ctx.mapViewabilityAmountValues.set(containerId, value);
|
|
@@ -915,427 +1280,221 @@ function maybeUpdateViewabilityCallback(ctx, configId, containerId, viewToken) {
|
|
|
915
1280
|
cb == null ? void 0 : cb(viewToken);
|
|
916
1281
|
}
|
|
917
1282
|
|
|
918
|
-
// src/
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
return
|
|
928
|
-
gap,
|
|
929
|
-
columnGap,
|
|
930
|
-
rowGap
|
|
931
|
-
};
|
|
1283
|
+
// src/utils/checkAllSizesKnown.ts
|
|
1284
|
+
function checkAllSizesKnown(state) {
|
|
1285
|
+
const { startBuffered, endBuffered, sizesKnown } = state;
|
|
1286
|
+
if (endBuffered !== null) {
|
|
1287
|
+
let areAllKnown = true;
|
|
1288
|
+
for (let i = startBuffered; areAllKnown && i <= endBuffered; i++) {
|
|
1289
|
+
const key = getId(state, i);
|
|
1290
|
+
areAllKnown && (areAllKnown = sizesKnown.has(key));
|
|
1291
|
+
}
|
|
1292
|
+
return areAllKnown;
|
|
932
1293
|
}
|
|
1294
|
+
return false;
|
|
933
1295
|
}
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
const
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
maintainScrollAtEndThreshold = 0.1,
|
|
950
|
-
alignItemsAtEnd = false,
|
|
951
|
-
maintainVisibleContentPosition = false,
|
|
952
|
-
onScroll: onScrollProp,
|
|
953
|
-
onMomentumScrollEnd,
|
|
954
|
-
numColumns: numColumnsProp = 1,
|
|
955
|
-
columnWrapperStyle,
|
|
956
|
-
keyExtractor: keyExtractorProp,
|
|
957
|
-
renderItem: renderItem2,
|
|
958
|
-
estimatedListSize,
|
|
959
|
-
estimatedItemSize: estimatedItemSizeProp,
|
|
960
|
-
getEstimatedItemSize,
|
|
961
|
-
suggestEstimatedItemSize,
|
|
962
|
-
ListHeaderComponent,
|
|
963
|
-
ListEmptyComponent,
|
|
964
|
-
onItemSizeChanged,
|
|
965
|
-
refScrollView,
|
|
966
|
-
waitForInitialLayout = true,
|
|
967
|
-
extraData,
|
|
968
|
-
contentContainerStyle: contentContainerStyleProp,
|
|
969
|
-
style: styleProp,
|
|
970
|
-
onLayout: onLayoutProp,
|
|
971
|
-
onRefresh,
|
|
972
|
-
refreshing,
|
|
973
|
-
progressViewOffset,
|
|
974
|
-
refreshControl,
|
|
975
|
-
initialContainerPoolRatio = 2,
|
|
976
|
-
viewabilityConfig,
|
|
977
|
-
viewabilityConfigCallbackPairs,
|
|
978
|
-
onViewableItemsChanged,
|
|
979
|
-
...rest
|
|
980
|
-
} = props;
|
|
981
|
-
const [renderNum, setRenderNum] = React2.useState(0);
|
|
982
|
-
const initialScroll = typeof initialScrollIndexProp === "number" ? { index: initialScrollIndexProp } : initialScrollIndexProp;
|
|
983
|
-
const initialScrollIndex = initialScroll == null ? void 0 : initialScroll.index;
|
|
984
|
-
const refLoadStartTime = React2.useRef(Date.now());
|
|
985
|
-
const [canRender, setCanRender] = React2__namespace.useState(!IsNewArchitecture);
|
|
986
|
-
const callbacks = React2.useRef({
|
|
987
|
-
onStartReached: rest.onStartReached,
|
|
988
|
-
onEndReached: rest.onEndReached
|
|
989
|
-
});
|
|
990
|
-
callbacks.current.onStartReached = rest.onStartReached;
|
|
991
|
-
callbacks.current.onEndReached = rest.onEndReached;
|
|
992
|
-
const contentContainerStyle = { ...reactNative.StyleSheet.flatten(contentContainerStyleProp) };
|
|
993
|
-
const style = { ...reactNative.StyleSheet.flatten(styleProp) };
|
|
994
|
-
const stylePaddingTopState = extractPadding(style, contentContainerStyle, "Top");
|
|
995
|
-
const stylePaddingBottomState = extractPadding(style, contentContainerStyle, "Bottom");
|
|
996
|
-
const ctx = useStateContext();
|
|
997
|
-
ctx.columnWrapperStyle = columnWrapperStyle || (contentContainerStyle ? createColumnWrapperStyle(contentContainerStyle) : void 0);
|
|
998
|
-
const refScroller = React2.useRef(null);
|
|
999
|
-
const combinedRef = useCombinedRef(refScroller, refScrollView);
|
|
1000
|
-
const estimatedItemSize = estimatedItemSizeProp != null ? estimatedItemSizeProp : DEFAULT_ITEM_SIZE;
|
|
1001
|
-
const scrollBuffer = (drawDistance != null ? drawDistance : DEFAULT_DRAW_DISTANCE) || 1;
|
|
1002
|
-
const keyExtractor = keyExtractorProp != null ? keyExtractorProp : (item, index) => index.toString();
|
|
1003
|
-
const refState = React2.useRef();
|
|
1004
|
-
const getId = (index) => {
|
|
1005
|
-
const state = refState.current;
|
|
1006
|
-
if (!(state == null ? void 0 : state.data)) {
|
|
1007
|
-
return "";
|
|
1008
|
-
}
|
|
1009
|
-
const data = state.data;
|
|
1010
|
-
const ret = index < data.length ? keyExtractor ? keyExtractor(data[index], index) : index : null;
|
|
1011
|
-
const id = ret;
|
|
1012
|
-
state.idCache.set(index, id);
|
|
1013
|
-
return id;
|
|
1014
|
-
};
|
|
1015
|
-
const getItemSize = (key, index, data, useAverageSize = false) => {
|
|
1016
|
-
const state = refState.current;
|
|
1017
|
-
const sizeKnown = state.sizesKnown.get(key);
|
|
1018
|
-
if (sizeKnown !== void 0) {
|
|
1019
|
-
return sizeKnown;
|
|
1020
|
-
}
|
|
1021
|
-
const sizePrevious = state.sizes.get(key);
|
|
1022
|
-
if (sizePrevious !== void 0) {
|
|
1023
|
-
return sizePrevious;
|
|
1024
|
-
}
|
|
1025
|
-
const size = getEstimatedItemSize ? getEstimatedItemSize(index, data) : estimatedItemSize;
|
|
1026
|
-
state.sizes.set(key, size);
|
|
1027
|
-
return size;
|
|
1028
|
-
};
|
|
1029
|
-
const calculateOffsetForIndex = (index) => {
|
|
1030
|
-
var _a2;
|
|
1031
|
-
let position = 0;
|
|
1032
|
-
if (index !== void 0) {
|
|
1033
|
-
position = ((_a2 = refState.current) == null ? void 0 : _a2.positions.get(getId(index))) || 0;
|
|
1034
|
-
}
|
|
1035
|
-
const paddingTop = peek$(ctx, "stylePaddingTop");
|
|
1036
|
-
if (paddingTop) {
|
|
1037
|
-
position += paddingTop;
|
|
1038
|
-
}
|
|
1039
|
-
const headerSize = peek$(ctx, "headerSize");
|
|
1040
|
-
if (headerSize) {
|
|
1041
|
-
position += headerSize;
|
|
1042
|
-
}
|
|
1043
|
-
return position;
|
|
1044
|
-
};
|
|
1045
|
-
const calculateOffsetWithOffsetPosition = (offsetParam, params) => {
|
|
1046
|
-
const { index, viewOffset, viewPosition } = params;
|
|
1047
|
-
let offset = offsetParam;
|
|
1048
|
-
const state = refState.current;
|
|
1049
|
-
if (viewOffset) {
|
|
1050
|
-
offset -= viewOffset;
|
|
1296
|
+
|
|
1297
|
+
// src/utils/findAvailableContainers.ts
|
|
1298
|
+
function findAvailableContainers(ctx, state, numNeeded, startBuffered, endBuffered, pendingRemoval) {
|
|
1299
|
+
const numContainers = peek$(ctx, "numContainers");
|
|
1300
|
+
const result = [];
|
|
1301
|
+
const availableContainers = [];
|
|
1302
|
+
for (let u = 0; u < numContainers; u++) {
|
|
1303
|
+
const key = peek$(ctx, `containerItemKey${u}`);
|
|
1304
|
+
let isOk = key === void 0;
|
|
1305
|
+
if (!isOk) {
|
|
1306
|
+
const index = pendingRemoval.indexOf(u);
|
|
1307
|
+
if (index !== -1) {
|
|
1308
|
+
pendingRemoval.splice(index, 1);
|
|
1309
|
+
isOk = true;
|
|
1310
|
+
}
|
|
1051
1311
|
}
|
|
1052
|
-
if (
|
|
1053
|
-
|
|
1312
|
+
if (isOk) {
|
|
1313
|
+
result.push(u);
|
|
1314
|
+
if (result.length >= numNeeded) {
|
|
1315
|
+
return result;
|
|
1316
|
+
}
|
|
1054
1317
|
}
|
|
1055
|
-
return offset;
|
|
1056
|
-
};
|
|
1057
|
-
if (!refState.current) {
|
|
1058
|
-
const initialScrollLength = (estimatedListSize != null ? estimatedListSize : IsNewArchitecture ? { width: 0, height: 0 } : reactNative.Dimensions.get("window"))[horizontal ? "width" : "height"];
|
|
1059
|
-
refState.current = {
|
|
1060
|
-
sizes: /* @__PURE__ */ new Map(),
|
|
1061
|
-
positions: /* @__PURE__ */ new Map(),
|
|
1062
|
-
columns: /* @__PURE__ */ new Map(),
|
|
1063
|
-
pendingAdjust: 0,
|
|
1064
|
-
isStartReached: false,
|
|
1065
|
-
isEndReached: false,
|
|
1066
|
-
isAtEnd: false,
|
|
1067
|
-
isAtStart: false,
|
|
1068
|
-
data: dataProp,
|
|
1069
|
-
scrollLength: initialScrollLength,
|
|
1070
|
-
startBuffered: -1,
|
|
1071
|
-
startNoBuffer: -1,
|
|
1072
|
-
endBuffered: -1,
|
|
1073
|
-
endNoBuffer: -1,
|
|
1074
|
-
firstFullyOnScreenIndex: -1,
|
|
1075
|
-
scroll: 0,
|
|
1076
|
-
totalSize: 0,
|
|
1077
|
-
timeouts: /* @__PURE__ */ new Set(),
|
|
1078
|
-
viewabilityConfigCallbackPairs: void 0,
|
|
1079
|
-
renderItem: void 0,
|
|
1080
|
-
scrollAdjustHandler: new ScrollAdjustHandler(ctx),
|
|
1081
|
-
nativeMarginTop: 0,
|
|
1082
|
-
scrollPrev: 0,
|
|
1083
|
-
scrollPrevTime: 0,
|
|
1084
|
-
scrollTime: 0,
|
|
1085
|
-
scrollPending: 0,
|
|
1086
|
-
indexByKey: /* @__PURE__ */ new Map(),
|
|
1087
|
-
scrollHistory: [],
|
|
1088
|
-
sizesKnown: /* @__PURE__ */ new Map(),
|
|
1089
|
-
timeoutSizeMessage: 0,
|
|
1090
|
-
startReachedBlockedByTimer: false,
|
|
1091
|
-
endReachedBlockedByTimer: false,
|
|
1092
|
-
scrollForNextCalculateItemsInView: void 0,
|
|
1093
|
-
enableScrollForNextCalculateItemsInView: true,
|
|
1094
|
-
minIndexSizeChanged: 0,
|
|
1095
|
-
queuedCalculateItemsInView: 0,
|
|
1096
|
-
lastBatchingAction: Date.now(),
|
|
1097
|
-
averageSizes: {},
|
|
1098
|
-
onScroll: onScrollProp,
|
|
1099
|
-
idsInView: [],
|
|
1100
|
-
containerItemKeys: /* @__PURE__ */ new Set(),
|
|
1101
|
-
idCache: /* @__PURE__ */ new Map()
|
|
1102
|
-
};
|
|
1103
|
-
set$(ctx, "maintainVisibleContentPosition", maintainVisibleContentPosition);
|
|
1104
|
-
set$(ctx, "extraData", extraData);
|
|
1105
1318
|
}
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
if (
|
|
1113
|
-
|
|
1114
|
-
let oldest;
|
|
1115
|
-
for (let i = 0; i < scrollHistory.length - 1; i++) {
|
|
1116
|
-
const entry = scrollHistory[i];
|
|
1117
|
-
const nextEntry = scrollHistory[i + 1];
|
|
1118
|
-
if (i > 0) {
|
|
1119
|
-
const prevEntry = scrollHistory[i - 1];
|
|
1120
|
-
const prevDirection = entry.scroll - prevEntry.scroll;
|
|
1121
|
-
const currentDirection = nextEntry.scroll - entry.scroll;
|
|
1122
|
-
if (prevDirection > 0 && currentDirection < 0 || prevDirection < 0 && currentDirection > 0) {
|
|
1123
|
-
break;
|
|
1124
|
-
}
|
|
1125
|
-
}
|
|
1126
|
-
}
|
|
1127
|
-
for (let i = 0; i < scrollHistory.length - 1; i++) {
|
|
1128
|
-
const entry = scrollHistory[i];
|
|
1129
|
-
if (newest.time - entry.time <= 1e3) {
|
|
1130
|
-
oldest = entry;
|
|
1131
|
-
break;
|
|
1132
|
-
}
|
|
1133
|
-
}
|
|
1134
|
-
if (oldest) {
|
|
1135
|
-
const scrollDiff = newest.scroll - oldest.scroll;
|
|
1136
|
-
const timeDiff = newest.time - oldest.time;
|
|
1137
|
-
velocity = timeDiff > 0 ? scrollDiff / timeDiff : 0;
|
|
1138
|
-
}
|
|
1319
|
+
for (let u = 0; u < numContainers; u++) {
|
|
1320
|
+
const key = peek$(ctx, `containerItemKey${u}`);
|
|
1321
|
+
if (key === void 0) continue;
|
|
1322
|
+
const index = state.indexByKey.get(key);
|
|
1323
|
+
if (index < startBuffered) {
|
|
1324
|
+
availableContainers.push({ distance: startBuffered - index, index: u });
|
|
1325
|
+
} else if (index > endBuffered) {
|
|
1326
|
+
availableContainers.push({ distance: index - endBuffered, index: u });
|
|
1139
1327
|
}
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
}
|
|
1152
|
-
const
|
|
1153
|
-
if (
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
maxSizeInRow2 = 0;
|
|
1168
|
-
}
|
|
1169
|
-
if (currentRowTop2 < -2e3) {
|
|
1170
|
-
bailout = true;
|
|
1171
|
-
break;
|
|
1328
|
+
}
|
|
1329
|
+
const remaining = numNeeded - result.length;
|
|
1330
|
+
if (remaining > 0) {
|
|
1331
|
+
if (availableContainers.length > 0) {
|
|
1332
|
+
if (availableContainers.length > remaining) {
|
|
1333
|
+
availableContainers.sort(comparatorByDistance);
|
|
1334
|
+
availableContainers.length = remaining;
|
|
1335
|
+
}
|
|
1336
|
+
for (const container of availableContainers) {
|
|
1337
|
+
result.push(container.index);
|
|
1338
|
+
}
|
|
1339
|
+
}
|
|
1340
|
+
const stillNeeded = numNeeded - result.length;
|
|
1341
|
+
if (stillNeeded > 0) {
|
|
1342
|
+
for (let i = 0; i < stillNeeded; i++) {
|
|
1343
|
+
result.push(numContainers + i);
|
|
1344
|
+
}
|
|
1345
|
+
if (__DEV__ && numContainers + stillNeeded > peek$(ctx, "numContainersPooled")) {
|
|
1346
|
+
console.warn(
|
|
1347
|
+
"[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.",
|
|
1348
|
+
{
|
|
1349
|
+
debugInfo: {
|
|
1350
|
+
numContainers,
|
|
1351
|
+
numContainersPooled: peek$(ctx, "numContainersPooled"),
|
|
1352
|
+
numNeeded,
|
|
1353
|
+
stillNeeded
|
|
1354
|
+
}
|
|
1172
1355
|
}
|
|
1173
|
-
|
|
1174
|
-
}
|
|
1175
|
-
if (!bailout) {
|
|
1176
|
-
updateTotalSize();
|
|
1177
|
-
return;
|
|
1178
|
-
}
|
|
1179
|
-
}
|
|
1180
|
-
}
|
|
1181
|
-
let currentRowTop = 0;
|
|
1182
|
-
let column = 1;
|
|
1183
|
-
let maxSizeInRow = 0;
|
|
1184
|
-
const hasColumns = numColumns > 1;
|
|
1185
|
-
const needsIndexByKey = dataChanged || indexByKey.size === 0;
|
|
1186
|
-
const dataLength = data.length;
|
|
1187
|
-
for (let i = 0; i < dataLength; i++) {
|
|
1188
|
-
const id = (_b = idCache.get(i)) != null ? _b : getId(i);
|
|
1189
|
-
const size = (_c = sizes.get(id)) != null ? _c : getItemSize(id, i, data[i], false);
|
|
1190
|
-
if (__DEV__ && needsIndexByKey) {
|
|
1191
|
-
if (indexByKeyForChecking.has(id)) {
|
|
1192
|
-
console.error(
|
|
1193
|
-
`[legend-list] Error: Detected overlapping key (${id}) which causes missing items and gaps and other terrrible things. Check that keyExtractor returns unique values.`
|
|
1194
|
-
);
|
|
1195
|
-
}
|
|
1196
|
-
indexByKeyForChecking.set(id, i);
|
|
1197
|
-
}
|
|
1198
|
-
positions.set(id, currentRowTop);
|
|
1199
|
-
if (needsIndexByKey) {
|
|
1200
|
-
indexByKey.set(id, i);
|
|
1201
|
-
}
|
|
1202
|
-
columns.set(id, column);
|
|
1203
|
-
if (hasColumns) {
|
|
1204
|
-
if (size > maxSizeInRow) {
|
|
1205
|
-
maxSizeInRow = size;
|
|
1206
|
-
}
|
|
1207
|
-
column++;
|
|
1208
|
-
if (column > numColumns) {
|
|
1209
|
-
currentRowTop += maxSizeInRow;
|
|
1210
|
-
column = 1;
|
|
1211
|
-
maxSizeInRow = 0;
|
|
1212
|
-
}
|
|
1213
|
-
} else {
|
|
1214
|
-
currentRowTop += size;
|
|
1356
|
+
);
|
|
1215
1357
|
}
|
|
1216
1358
|
}
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1359
|
+
}
|
|
1360
|
+
return result.sort(comparatorDefault);
|
|
1361
|
+
}
|
|
1362
|
+
function comparatorByDistance(a, b) {
|
|
1363
|
+
return b.distance - a.distance;
|
|
1364
|
+
}
|
|
1365
|
+
|
|
1366
|
+
// src/core/finishScrollTo.ts
|
|
1367
|
+
var finishScrollTo = (state) => {
|
|
1368
|
+
if (state) {
|
|
1369
|
+
state.scrollingTo = void 0;
|
|
1370
|
+
state.scrollHistory.length = 0;
|
|
1371
|
+
}
|
|
1372
|
+
};
|
|
1373
|
+
|
|
1374
|
+
// src/core/scrollTo.ts
|
|
1375
|
+
function scrollTo(state, params = {}) {
|
|
1376
|
+
var _a;
|
|
1377
|
+
const { animated } = params;
|
|
1378
|
+
const {
|
|
1379
|
+
refScroller,
|
|
1380
|
+
props: { horizontal }
|
|
1381
|
+
} = state;
|
|
1382
|
+
const offset = calculateOffsetWithOffsetPosition(state, params.offset, params);
|
|
1383
|
+
state.scrollHistory.length = 0;
|
|
1384
|
+
state.scrollingTo = params;
|
|
1385
|
+
state.scrollPending = offset;
|
|
1386
|
+
(_a = refScroller.current) == null ? void 0 : _a.scrollTo({
|
|
1387
|
+
animated: !!animated,
|
|
1388
|
+
x: horizontal ? offset : 0,
|
|
1389
|
+
y: horizontal ? 0 : offset
|
|
1390
|
+
});
|
|
1391
|
+
if (!animated) {
|
|
1392
|
+
state.scroll = offset;
|
|
1393
|
+
setTimeout(() => finishScrollTo(state), 100);
|
|
1394
|
+
}
|
|
1395
|
+
}
|
|
1396
|
+
|
|
1397
|
+
// src/core/scrollToIndex.ts
|
|
1398
|
+
function scrollToIndex(ctx, state, { index, viewOffset = 0, animated = true, viewPosition }) {
|
|
1399
|
+
if (index >= state.props.data.length) {
|
|
1400
|
+
index = state.props.data.length - 1;
|
|
1401
|
+
} else if (index < 0) {
|
|
1402
|
+
index = 0;
|
|
1403
|
+
}
|
|
1404
|
+
const firstIndexOffset = calculateOffsetForIndex(ctx, state, index);
|
|
1405
|
+
const isLast = index === state.props.data.length - 1;
|
|
1406
|
+
if (isLast && viewPosition === void 0) {
|
|
1407
|
+
viewPosition = 1;
|
|
1408
|
+
}
|
|
1409
|
+
const firstIndexScrollPostion = firstIndexOffset - viewOffset;
|
|
1410
|
+
state.scrollForNextCalculateItemsInView = void 0;
|
|
1411
|
+
scrollTo(state, {
|
|
1412
|
+
animated,
|
|
1220
1413
|
index,
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
viewPosition
|
|
1224
|
-
})
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
};
|
|
1240
|
-
const setDidLayout = () => {
|
|
1241
|
-
refState.current.queuedInitialLayout = true;
|
|
1242
|
-
checkAtBottom();
|
|
1243
|
-
set$(ctx, "containersDidLayout", true);
|
|
1244
|
-
if (props.onLoad) {
|
|
1245
|
-
props.onLoad({ elapsedTimeInMs: Date.now() - refLoadStartTime.current });
|
|
1246
|
-
}
|
|
1247
|
-
};
|
|
1248
|
-
const addTotalSize = React2.useCallback((key, add) => {
|
|
1249
|
-
const state = refState.current;
|
|
1250
|
-
if (key === null) {
|
|
1251
|
-
state.totalSize = add;
|
|
1252
|
-
} else {
|
|
1253
|
-
state.totalSize += add;
|
|
1254
|
-
}
|
|
1255
|
-
set$(ctx, "totalSize", state.totalSize);
|
|
1256
|
-
if (alignItemsAtEnd) {
|
|
1257
|
-
updateAlignItemsPaddingTop();
|
|
1258
|
-
}
|
|
1259
|
-
}, []);
|
|
1260
|
-
const checkAllSizesKnown = React2.useCallback(() => {
|
|
1261
|
-
const { startBuffered, endBuffered, sizesKnown } = refState.current;
|
|
1262
|
-
if (endBuffered !== null) {
|
|
1263
|
-
let areAllKnown = true;
|
|
1264
|
-
for (let i = startBuffered; areAllKnown && i <= endBuffered; i++) {
|
|
1265
|
-
const key = getId(i);
|
|
1266
|
-
areAllKnown && (areAllKnown = sizesKnown.has(key));
|
|
1267
|
-
}
|
|
1268
|
-
return areAllKnown;
|
|
1414
|
+
offset: firstIndexScrollPostion,
|
|
1415
|
+
viewOffset,
|
|
1416
|
+
viewPosition: viewPosition != null ? viewPosition : 0
|
|
1417
|
+
});
|
|
1418
|
+
}
|
|
1419
|
+
|
|
1420
|
+
// src/utils/checkThreshold.ts
|
|
1421
|
+
var checkThreshold = (distance, atThreshold, threshold, isReached, isBlockedByTimer, onReached, blockTimer) => {
|
|
1422
|
+
const distanceAbs = Math.abs(distance);
|
|
1423
|
+
const isAtThreshold = atThreshold || distanceAbs < threshold;
|
|
1424
|
+
if (!isReached && !isBlockedByTimer) {
|
|
1425
|
+
if (isAtThreshold) {
|
|
1426
|
+
onReached == null ? void 0 : onReached(distance);
|
|
1427
|
+
blockTimer == null ? void 0 : blockTimer(true);
|
|
1428
|
+
setTimeout(() => {
|
|
1429
|
+
blockTimer == null ? void 0 : blockTimer(false);
|
|
1430
|
+
}, 700);
|
|
1431
|
+
return true;
|
|
1269
1432
|
}
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
if (Math.abs(positionDiff) > 0.1) {
|
|
1274
|
-
const state = refState.current;
|
|
1275
|
-
const doit = () => {
|
|
1276
|
-
state.scrollAdjustHandler.requestAdjust(positionDiff);
|
|
1277
|
-
};
|
|
1278
|
-
state.scroll += positionDiff;
|
|
1279
|
-
state.scrollForNextCalculateItemsInView = void 0;
|
|
1280
|
-
if (peek$(ctx, "containersDidLayout")) {
|
|
1281
|
-
doit();
|
|
1282
|
-
} else {
|
|
1283
|
-
requestAnimationFrame(doit);
|
|
1284
|
-
}
|
|
1285
|
-
const threshold = state.scroll - positionDiff / 2;
|
|
1286
|
-
if (!state.ignoreScrollFromMVCP) {
|
|
1287
|
-
state.ignoreScrollFromMVCP = {};
|
|
1288
|
-
}
|
|
1289
|
-
if (positionDiff > 0) {
|
|
1290
|
-
state.ignoreScrollFromMVCP.lt = threshold;
|
|
1291
|
-
} else {
|
|
1292
|
-
state.ignoreScrollFromMVCP.gt = threshold;
|
|
1293
|
-
}
|
|
1294
|
-
if (state.ignoreScrollFromMVCPTimeout) {
|
|
1295
|
-
clearTimeout(state.ignoreScrollFromMVCPTimeout);
|
|
1296
|
-
}
|
|
1297
|
-
state.ignoreScrollFromMVCPTimeout = setTimeout(() => {
|
|
1298
|
-
state.ignoreScrollFromMVCP = void 0;
|
|
1299
|
-
}, 100);
|
|
1433
|
+
} else {
|
|
1434
|
+
if (distance >= 1.3 * threshold) {
|
|
1435
|
+
return false;
|
|
1300
1436
|
}
|
|
1301
|
-
}
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
}
|
|
1437
|
+
}
|
|
1438
|
+
return isReached;
|
|
1439
|
+
};
|
|
1440
|
+
|
|
1441
|
+
// src/utils/checkAtBottom.ts
|
|
1442
|
+
function checkAtBottom(ctx, state) {
|
|
1443
|
+
if (!state) {
|
|
1444
|
+
return;
|
|
1445
|
+
}
|
|
1446
|
+
const {
|
|
1447
|
+
queuedInitialLayout,
|
|
1448
|
+
scrollLength,
|
|
1449
|
+
scroll,
|
|
1450
|
+
maintainingScrollAtEnd,
|
|
1451
|
+
props: { maintainScrollAtEndThreshold, onEndReachedThreshold }
|
|
1452
|
+
} = state;
|
|
1453
|
+
const contentSize = getContentSize(ctx);
|
|
1454
|
+
if (contentSize > 0 && queuedInitialLayout && !maintainingScrollAtEnd) {
|
|
1455
|
+
const distanceFromEnd = contentSize - scroll - scrollLength;
|
|
1456
|
+
const isContentLess = contentSize < scrollLength;
|
|
1457
|
+
state.isAtEnd = isContentLess || distanceFromEnd < scrollLength * maintainScrollAtEndThreshold;
|
|
1458
|
+
state.isEndReached = checkThreshold(
|
|
1459
|
+
distanceFromEnd,
|
|
1460
|
+
isContentLess,
|
|
1461
|
+
onEndReachedThreshold * scrollLength,
|
|
1462
|
+
state.isEndReached,
|
|
1463
|
+
state.endReachedBlockedByTimer,
|
|
1464
|
+
(distance) => {
|
|
1465
|
+
var _a, _b;
|
|
1466
|
+
return (_b = (_a = state.props).onEndReached) == null ? void 0 : _b.call(_a, { distanceFromEnd: distance });
|
|
1467
|
+
},
|
|
1468
|
+
(block) => {
|
|
1469
|
+
state.endReachedBlockedByTimer = block;
|
|
1331
1470
|
}
|
|
1332
|
-
|
|
1333
|
-
}
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1471
|
+
);
|
|
1472
|
+
}
|
|
1473
|
+
}
|
|
1474
|
+
|
|
1475
|
+
// src/utils/setDidLayout.ts
|
|
1476
|
+
function setDidLayout(ctx, state) {
|
|
1477
|
+
const {
|
|
1478
|
+
loadStartTime,
|
|
1479
|
+
initialScroll,
|
|
1480
|
+
props: { onLoad }
|
|
1481
|
+
} = state;
|
|
1482
|
+
state.queuedInitialLayout = true;
|
|
1483
|
+
checkAtBottom(ctx, state);
|
|
1484
|
+
if (!IsNewArchitecture && initialScroll) {
|
|
1485
|
+
scrollToIndex(ctx, state, { ...initialScroll, animated: false });
|
|
1486
|
+
}
|
|
1487
|
+
set$(ctx, "containersDidLayout", true);
|
|
1488
|
+
if (onLoad) {
|
|
1489
|
+
onLoad({ elapsedTimeInMs: Date.now() - loadStartTime });
|
|
1490
|
+
}
|
|
1491
|
+
}
|
|
1492
|
+
|
|
1493
|
+
// src/core/calculateItemsInView.ts
|
|
1494
|
+
function calculateItemsInView(ctx, state, params = {}) {
|
|
1495
|
+
reactNative.unstable_batchedUpdates(() => {
|
|
1496
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
1337
1497
|
const {
|
|
1338
|
-
data,
|
|
1339
1498
|
scrollLength,
|
|
1340
1499
|
startBufferedId: startBufferedIdOrig,
|
|
1341
1500
|
positions,
|
|
@@ -1348,7 +1507,9 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
|
|
|
1348
1507
|
enableScrollForNextCalculateItemsInView,
|
|
1349
1508
|
minIndexSizeChanged
|
|
1350
1509
|
} = state;
|
|
1351
|
-
|
|
1510
|
+
const data = state.props.data;
|
|
1511
|
+
const prevNumContainers = peek$(ctx, "numContainers");
|
|
1512
|
+
if (!data || scrollLength === 0 || !prevNumContainers) {
|
|
1352
1513
|
return;
|
|
1353
1514
|
}
|
|
1354
1515
|
const totalSize = peek$(ctx, "totalSize");
|
|
@@ -1356,19 +1517,20 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
|
|
|
1356
1517
|
const numColumns = peek$(ctx, "numColumns");
|
|
1357
1518
|
const previousScrollAdjust = 0;
|
|
1358
1519
|
const { dataChanged, doMVCP } = params;
|
|
1359
|
-
const speed = getScrollVelocity();
|
|
1520
|
+
const speed = getScrollVelocity(state);
|
|
1360
1521
|
if (doMVCP || dataChanged) {
|
|
1361
|
-
const checkMVCP = doMVCP ? prepareMVCP() : void 0;
|
|
1362
|
-
updateAllPositions(dataChanged);
|
|
1522
|
+
const checkMVCP = doMVCP ? prepareMVCP(ctx, state) : void 0;
|
|
1523
|
+
updateAllPositions(ctx, state, dataChanged);
|
|
1363
1524
|
checkMVCP == null ? void 0 : checkMVCP();
|
|
1364
1525
|
}
|
|
1365
1526
|
const scrollExtra = 0;
|
|
1366
|
-
const useAverageSize = false;
|
|
1367
1527
|
const { queuedInitialLayout } = state;
|
|
1368
1528
|
let { scroll: scrollState } = state;
|
|
1529
|
+
const initialScroll = state.props.initialScroll;
|
|
1369
1530
|
if (!queuedInitialLayout && initialScroll) {
|
|
1370
1531
|
const updatedOffset = calculateOffsetWithOffsetPosition(
|
|
1371
|
-
|
|
1532
|
+
state,
|
|
1533
|
+
calculateOffsetForIndex(ctx, state, initialScroll.index),
|
|
1372
1534
|
initialScroll
|
|
1373
1535
|
);
|
|
1374
1536
|
scrollState = updatedOffset;
|
|
@@ -1382,6 +1544,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
|
|
|
1382
1544
|
set$(ctx, "debugRawScroll", scrollState);
|
|
1383
1545
|
set$(ctx, "debugComputedScroll", scroll);
|
|
1384
1546
|
}
|
|
1547
|
+
const scrollBuffer = state.props.scrollBuffer;
|
|
1385
1548
|
let scrollBufferTop = scrollBuffer;
|
|
1386
1549
|
let scrollBufferBottom = scrollBuffer;
|
|
1387
1550
|
if (speed > 0) {
|
|
@@ -1411,9 +1574,9 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
|
|
|
1411
1574
|
state.minIndexSizeChanged = void 0;
|
|
1412
1575
|
}
|
|
1413
1576
|
for (let i = loopStart; i >= 0; i--) {
|
|
1414
|
-
const id = (
|
|
1577
|
+
const id = (_a = idCache.get(i)) != null ? _a : getId(state, i);
|
|
1415
1578
|
const top = positions.get(id);
|
|
1416
|
-
const size = (_b = sizes.get(id)) != null ? _b : getItemSize(id, i, data[i]
|
|
1579
|
+
const size = (_b = sizes.get(id)) != null ? _b : getItemSize(state, id, i, data[i]);
|
|
1417
1580
|
const bottom = top + size;
|
|
1418
1581
|
if (bottom > scroll - scrollBuffer) {
|
|
1419
1582
|
loopStart = i;
|
|
@@ -1428,7 +1591,6 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
|
|
|
1428
1591
|
let foundEnd = false;
|
|
1429
1592
|
let nextTop;
|
|
1430
1593
|
let nextBottom;
|
|
1431
|
-
const prevNumContainers = ctx.values.get("numContainers");
|
|
1432
1594
|
let maxIndexRendered = 0;
|
|
1433
1595
|
for (let i = 0; i < prevNumContainers; i++) {
|
|
1434
1596
|
const key = peek$(ctx, `containerItemKey${i}`);
|
|
@@ -1440,8 +1602,8 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
|
|
|
1440
1602
|
let firstFullyOnScreenIndex;
|
|
1441
1603
|
const dataLength = data.length;
|
|
1442
1604
|
for (let i = Math.max(0, loopStart); i < dataLength && (!foundEnd || i <= maxIndexRendered); i++) {
|
|
1443
|
-
const id = (_c = idCache.get(i)) != null ? _c : getId(i);
|
|
1444
|
-
const size = (_d = sizes.get(id)) != null ? _d : getItemSize(id, i, data[i]
|
|
1605
|
+
const id = (_c = idCache.get(i)) != null ? _c : getId(state, i);
|
|
1606
|
+
const size = (_d = sizes.get(id)) != null ? _d : getItemSize(state, id, i, data[i]);
|
|
1445
1607
|
const top = positions.get(id);
|
|
1446
1608
|
if (!foundEnd) {
|
|
1447
1609
|
if (startNoBuffer === null && top + size > scroll) {
|
|
@@ -1470,22 +1632,22 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
|
|
|
1470
1632
|
}
|
|
1471
1633
|
const idsInView = [];
|
|
1472
1634
|
for (let i = firstFullyOnScreenIndex; i <= endNoBuffer; i++) {
|
|
1473
|
-
const id = (_e = idCache.get(i)) != null ? _e : getId(i);
|
|
1635
|
+
const id = (_e = idCache.get(i)) != null ? _e : getId(state, i);
|
|
1474
1636
|
idsInView.push(id);
|
|
1475
1637
|
}
|
|
1476
1638
|
Object.assign(state, {
|
|
1477
|
-
startBuffered,
|
|
1478
|
-
startBufferedId,
|
|
1479
|
-
startNoBuffer,
|
|
1480
1639
|
endBuffered,
|
|
1481
1640
|
endNoBuffer,
|
|
1641
|
+
firstFullyOnScreenIndex,
|
|
1482
1642
|
idsInView,
|
|
1483
|
-
|
|
1643
|
+
startBuffered,
|
|
1644
|
+
startBufferedId,
|
|
1645
|
+
startNoBuffer
|
|
1484
1646
|
});
|
|
1485
1647
|
if (enableScrollForNextCalculateItemsInView && nextTop !== void 0 && nextBottom !== void 0) {
|
|
1486
1648
|
state.scrollForNextCalculateItemsInView = nextTop !== void 0 && nextBottom !== void 0 ? {
|
|
1487
|
-
|
|
1488
|
-
|
|
1649
|
+
bottom: nextBottom,
|
|
1650
|
+
top: nextTop
|
|
1489
1651
|
} : void 0;
|
|
1490
1652
|
}
|
|
1491
1653
|
const numContainers = peek$(ctx, "numContainers");
|
|
@@ -1493,7 +1655,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
|
|
|
1493
1655
|
if (dataChanged) {
|
|
1494
1656
|
for (let i = 0; i < numContainers; i++) {
|
|
1495
1657
|
const itemKey = peek$(ctx, `containerItemKey${i}`);
|
|
1496
|
-
if (!
|
|
1658
|
+
if (!state.props.keyExtractor || itemKey && indexByKey.get(itemKey) === void 0) {
|
|
1497
1659
|
pendingRemoval.push(i);
|
|
1498
1660
|
}
|
|
1499
1661
|
}
|
|
@@ -1502,13 +1664,15 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
|
|
|
1502
1664
|
let numContainers2 = prevNumContainers;
|
|
1503
1665
|
const needNewContainers = [];
|
|
1504
1666
|
for (let i = startBuffered; i <= endBuffered; i++) {
|
|
1505
|
-
const id = (_f = idCache.get(i)) != null ? _f : getId(i);
|
|
1667
|
+
const id = (_f = idCache.get(i)) != null ? _f : getId(state, i);
|
|
1506
1668
|
if (!containerItemKeys.has(id)) {
|
|
1507
1669
|
needNewContainers.push(i);
|
|
1508
1670
|
}
|
|
1509
1671
|
}
|
|
1510
1672
|
if (needNewContainers.length > 0) {
|
|
1511
1673
|
const availableContainers = findAvailableContainers(
|
|
1674
|
+
ctx,
|
|
1675
|
+
state,
|
|
1512
1676
|
needNewContainers.length,
|
|
1513
1677
|
startBuffered,
|
|
1514
1678
|
endBuffered,
|
|
@@ -1517,7 +1681,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
|
|
|
1517
1681
|
for (let idx = 0; idx < needNewContainers.length; idx++) {
|
|
1518
1682
|
const i = needNewContainers[idx];
|
|
1519
1683
|
const containerIndex = availableContainers[idx];
|
|
1520
|
-
const id = (_g = idCache.get(i)) != null ? _g : getId(i);
|
|
1684
|
+
const id = (_g = idCache.get(i)) != null ? _g : getId(state, i);
|
|
1521
1685
|
const oldKey = peek$(ctx, `containerItemKey${containerIndex}`);
|
|
1522
1686
|
if (oldKey && oldKey !== id) {
|
|
1523
1687
|
containerItemKeys.delete(oldKey);
|
|
@@ -1536,334 +1700,629 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
|
|
|
1536
1700
|
}
|
|
1537
1701
|
}
|
|
1538
1702
|
}
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
}
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
}
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
}
|
|
1703
|
+
}
|
|
1704
|
+
for (let i = 0; i < numContainers; i++) {
|
|
1705
|
+
const itemKey = peek$(ctx, `containerItemKey${i}`);
|
|
1706
|
+
if (pendingRemoval.includes(i)) {
|
|
1707
|
+
if (itemKey) {
|
|
1708
|
+
containerItemKeys.delete(itemKey);
|
|
1709
|
+
}
|
|
1710
|
+
set$(ctx, `containerItemKey${i}`, void 0);
|
|
1711
|
+
set$(ctx, `containerItemData${i}`, void 0);
|
|
1712
|
+
set$(ctx, `containerPosition${i}`, POSITION_OUT_OF_VIEW);
|
|
1713
|
+
set$(ctx, `containerColumn${i}`, -1);
|
|
1714
|
+
} else {
|
|
1715
|
+
const itemIndex = indexByKey.get(itemKey);
|
|
1716
|
+
const item = data[itemIndex];
|
|
1717
|
+
if (item !== void 0) {
|
|
1718
|
+
const id = (_h = idCache.get(itemIndex)) != null ? _h : getId(state, itemIndex);
|
|
1719
|
+
const position = positions.get(id);
|
|
1720
|
+
if (position === void 0) {
|
|
1721
|
+
set$(ctx, `containerPosition${i}`, POSITION_OUT_OF_VIEW);
|
|
1722
|
+
} else {
|
|
1723
|
+
const column = columns.get(id) || 1;
|
|
1724
|
+
const prevPos = peek$(ctx, `containerPosition${i}`);
|
|
1725
|
+
const prevColumn = peek$(ctx, `containerColumn${i}`);
|
|
1726
|
+
const prevData = peek$(ctx, `containerItemData${i}`);
|
|
1727
|
+
if (position > POSITION_OUT_OF_VIEW && position !== prevPos) {
|
|
1728
|
+
set$(ctx, `containerPosition${i}`, position);
|
|
1729
|
+
}
|
|
1730
|
+
if (column >= 0 && column !== prevColumn) {
|
|
1731
|
+
set$(ctx, `containerColumn${i}`, column);
|
|
1732
|
+
}
|
|
1733
|
+
if (prevData !== item) {
|
|
1734
|
+
set$(ctx, `containerItemData${i}`, data[itemIndex]);
|
|
1572
1735
|
}
|
|
1573
1736
|
}
|
|
1574
1737
|
}
|
|
1575
1738
|
}
|
|
1576
1739
|
}
|
|
1577
1740
|
if (!queuedInitialLayout && endBuffered !== null) {
|
|
1578
|
-
if (checkAllSizesKnown()) {
|
|
1579
|
-
setDidLayout();
|
|
1741
|
+
if (checkAllSizesKnown(state)) {
|
|
1742
|
+
setDidLayout(ctx, state);
|
|
1580
1743
|
}
|
|
1581
1744
|
}
|
|
1582
|
-
if (viewabilityConfigCallbackPairs) {
|
|
1745
|
+
if (state.viewabilityConfigCallbackPairs) {
|
|
1583
1746
|
updateViewableItems(
|
|
1584
1747
|
state,
|
|
1585
1748
|
ctx,
|
|
1586
|
-
viewabilityConfigCallbackPairs,
|
|
1587
|
-
getId,
|
|
1749
|
+
state.viewabilityConfigCallbackPairs,
|
|
1588
1750
|
scrollLength,
|
|
1589
1751
|
startNoBuffer,
|
|
1590
1752
|
endNoBuffer
|
|
1591
1753
|
);
|
|
1592
1754
|
}
|
|
1593
|
-
}
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
set$(ctx,
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
let alignItemsPaddingTop = 0;
|
|
1617
|
-
if ((data == null ? void 0 : data.length) > 0) {
|
|
1618
|
-
const contentSize = getContentSize(ctx);
|
|
1619
|
-
alignItemsPaddingTop = Math.max(0, Math.floor(scrollLength - contentSize));
|
|
1620
|
-
}
|
|
1621
|
-
setPaddingTop({ alignItemsPaddingTop });
|
|
1622
|
-
}
|
|
1623
|
-
};
|
|
1624
|
-
const finishScrollTo = () => {
|
|
1625
|
-
const state = refState.current;
|
|
1626
|
-
if (state) {
|
|
1627
|
-
state.scrollingTo = void 0;
|
|
1628
|
-
state.scrollHistory.length = 0;
|
|
1629
|
-
}
|
|
1630
|
-
};
|
|
1631
|
-
const scrollTo = (params = {}) => {
|
|
1632
|
-
var _a2;
|
|
1633
|
-
const state = refState.current;
|
|
1634
|
-
const { animated } = params;
|
|
1635
|
-
const offset = calculateOffsetWithOffsetPosition(params.offset, params);
|
|
1636
|
-
state.scrollHistory.length = 0;
|
|
1637
|
-
state.scrollingTo = params;
|
|
1638
|
-
state.scrollPending = offset;
|
|
1639
|
-
(_a2 = refScroller.current) == null ? void 0 : _a2.scrollTo({
|
|
1640
|
-
x: horizontal ? offset : 0,
|
|
1641
|
-
y: horizontal ? 0 : offset,
|
|
1642
|
-
animated: !!animated
|
|
1643
|
-
});
|
|
1644
|
-
if (!animated) {
|
|
1645
|
-
refState.current.scroll = offset;
|
|
1646
|
-
setTimeout(finishScrollTo, 100);
|
|
1647
|
-
}
|
|
1648
|
-
};
|
|
1649
|
-
const doMaintainScrollAtEnd = (animated) => {
|
|
1650
|
-
const state = refState.current;
|
|
1651
|
-
if ((state == null ? void 0 : state.isAtEnd) && maintainScrollAtEnd && peek$(ctx, "containersDidLayout")) {
|
|
1652
|
-
const paddingTop = peek$(ctx, "alignItemsPaddingTop");
|
|
1653
|
-
if (paddingTop > 0) {
|
|
1654
|
-
state.scroll = 0;
|
|
1655
|
-
}
|
|
1656
|
-
requestAnimationFrame(() => {
|
|
1657
|
-
var _a2;
|
|
1658
|
-
state.maintainingScrollAtEnd = true;
|
|
1659
|
-
(_a2 = refScroller.current) == null ? void 0 : _a2.scrollToEnd({
|
|
1660
|
-
animated
|
|
1755
|
+
});
|
|
1756
|
+
}
|
|
1757
|
+
|
|
1758
|
+
// src/core/doInitialAllocateContainers.ts
|
|
1759
|
+
function doInitialAllocateContainers(ctx, state) {
|
|
1760
|
+
const { scrollLength } = state;
|
|
1761
|
+
const data = state.props.data;
|
|
1762
|
+
if (scrollLength > 0 && data.length > 0 && !peek$(ctx, "numContainers")) {
|
|
1763
|
+
const averageItemSize = state.props.getEstimatedItemSize ? state.props.getEstimatedItemSize(0, data[0]) : state.props.estimatedItemSize;
|
|
1764
|
+
const Extra = 1.5;
|
|
1765
|
+
const numContainers = Math.ceil(
|
|
1766
|
+
(scrollLength + state.props.scrollBuffer * 2) / averageItemSize * state.props.numColumns * Extra
|
|
1767
|
+
);
|
|
1768
|
+
for (let i = 0; i < numContainers; i++) {
|
|
1769
|
+
set$(ctx, `containerPosition${i}`, POSITION_OUT_OF_VIEW);
|
|
1770
|
+
set$(ctx, `containerColumn${i}`, -1);
|
|
1771
|
+
}
|
|
1772
|
+
set$(ctx, "numContainers", numContainers);
|
|
1773
|
+
set$(ctx, "numContainersPooled", numContainers * state.props.initialContainerPoolRatio);
|
|
1774
|
+
if (!IsNewArchitecture) {
|
|
1775
|
+
if (state.props.initialScroll) {
|
|
1776
|
+
requestAnimationFrame(() => {
|
|
1777
|
+
calculateItemsInView(ctx, state);
|
|
1661
1778
|
});
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
state.maintainingScrollAtEnd = false;
|
|
1665
|
-
},
|
|
1666
|
-
0
|
|
1667
|
-
);
|
|
1668
|
-
});
|
|
1669
|
-
return true;
|
|
1670
|
-
}
|
|
1671
|
-
};
|
|
1672
|
-
const checkThreshold = (distance, atThreshold, threshold, isReached, isBlockedByTimer, onReached, blockTimer) => {
|
|
1673
|
-
const distanceAbs = Math.abs(distance);
|
|
1674
|
-
const isAtThreshold = atThreshold || distanceAbs < threshold;
|
|
1675
|
-
if (!isReached && !isBlockedByTimer) {
|
|
1676
|
-
if (isAtThreshold) {
|
|
1677
|
-
onReached == null ? void 0 : onReached(distance);
|
|
1678
|
-
blockTimer == null ? void 0 : blockTimer(true);
|
|
1679
|
-
setTimeout(() => {
|
|
1680
|
-
blockTimer == null ? void 0 : blockTimer(false);
|
|
1681
|
-
}, 700);
|
|
1682
|
-
return true;
|
|
1683
|
-
}
|
|
1684
|
-
} else {
|
|
1685
|
-
if (distance >= 1.3 * threshold) {
|
|
1686
|
-
return false;
|
|
1779
|
+
} else {
|
|
1780
|
+
calculateItemsInView(ctx, state);
|
|
1687
1781
|
}
|
|
1688
1782
|
}
|
|
1689
|
-
return
|
|
1690
|
-
}
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1783
|
+
return true;
|
|
1784
|
+
}
|
|
1785
|
+
}
|
|
1786
|
+
|
|
1787
|
+
// src/core/doMaintainScrollAtEnd.ts
|
|
1788
|
+
function doMaintainScrollAtEnd(ctx, state, animated) {
|
|
1789
|
+
const {
|
|
1790
|
+
refScroller,
|
|
1791
|
+
props: { maintainScrollAtEnd }
|
|
1792
|
+
} = state;
|
|
1793
|
+
if ((state == null ? void 0 : state.isAtEnd) && maintainScrollAtEnd && peek$(ctx, "containersDidLayout")) {
|
|
1794
|
+
const paddingTop = peek$(ctx, "alignItemsPaddingTop");
|
|
1795
|
+
if (paddingTop > 0) {
|
|
1796
|
+
state.scroll = 0;
|
|
1797
|
+
}
|
|
1798
|
+
requestAnimationFrame(() => {
|
|
1799
|
+
var _a;
|
|
1800
|
+
state.maintainingScrollAtEnd = true;
|
|
1801
|
+
(_a = refScroller.current) == null ? void 0 : _a.scrollToEnd({
|
|
1802
|
+
animated
|
|
1803
|
+
});
|
|
1804
|
+
setTimeout(
|
|
1805
|
+
() => {
|
|
1806
|
+
state.maintainingScrollAtEnd = false;
|
|
1710
1807
|
},
|
|
1711
|
-
|
|
1712
|
-
refState.current.endReachedBlockedByTimer = block;
|
|
1713
|
-
}
|
|
1808
|
+
0
|
|
1714
1809
|
);
|
|
1810
|
+
});
|
|
1811
|
+
return true;
|
|
1812
|
+
}
|
|
1813
|
+
}
|
|
1814
|
+
|
|
1815
|
+
// src/utils/checkAtTop.ts
|
|
1816
|
+
function checkAtTop(state) {
|
|
1817
|
+
if (!state) {
|
|
1818
|
+
return;
|
|
1819
|
+
}
|
|
1820
|
+
const {
|
|
1821
|
+
scrollLength,
|
|
1822
|
+
scroll,
|
|
1823
|
+
props: { onStartReachedThreshold }
|
|
1824
|
+
} = state;
|
|
1825
|
+
const distanceFromTop = scroll;
|
|
1826
|
+
state.isAtStart = distanceFromTop <= 0;
|
|
1827
|
+
state.isStartReached = checkThreshold(
|
|
1828
|
+
distanceFromTop,
|
|
1829
|
+
false,
|
|
1830
|
+
onStartReachedThreshold * scrollLength,
|
|
1831
|
+
state.isStartReached,
|
|
1832
|
+
state.startReachedBlockedByTimer,
|
|
1833
|
+
(distance) => {
|
|
1834
|
+
var _a, _b;
|
|
1835
|
+
return (_b = (_a = state.props).onStartReached) == null ? void 0 : _b.call(_a, { distanceFromStart: distance });
|
|
1836
|
+
},
|
|
1837
|
+
(block) => {
|
|
1838
|
+
state.startReachedBlockedByTimer = block;
|
|
1715
1839
|
}
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1840
|
+
);
|
|
1841
|
+
}
|
|
1842
|
+
|
|
1843
|
+
// src/core/handleLayout.ts
|
|
1844
|
+
function handleLayout(ctx, state, layout, setCanRender) {
|
|
1845
|
+
const { maintainScrollAtEnd } = state.props;
|
|
1846
|
+
const scrollLength = layout[state.props.horizontal ? "width" : "height"];
|
|
1847
|
+
const otherAxisSize = layout[state.props.horizontal ? "height" : "width"];
|
|
1848
|
+
const needsCalculate = !state.lastLayout || scrollLength > state.scrollLength || state.lastLayout.x !== layout.x || state.lastLayout.y !== layout.y;
|
|
1849
|
+
state.lastLayout = layout;
|
|
1850
|
+
const didChange = scrollLength !== state.scrollLength;
|
|
1851
|
+
const prevOtherAxisSize = state.otherAxisSize;
|
|
1852
|
+
state.scrollLength = scrollLength;
|
|
1853
|
+
state.otherAxisSize = otherAxisSize;
|
|
1854
|
+
state.lastBatchingAction = Date.now();
|
|
1855
|
+
state.scrollForNextCalculateItemsInView = void 0;
|
|
1856
|
+
doInitialAllocateContainers(ctx, state);
|
|
1857
|
+
if (needsCalculate) {
|
|
1858
|
+
calculateItemsInView(ctx, state, { doMVCP: true });
|
|
1859
|
+
}
|
|
1860
|
+
if (didChange || otherAxisSize !== prevOtherAxisSize) {
|
|
1861
|
+
set$(ctx, "scrollSize", { height: layout.height, width: layout.width });
|
|
1862
|
+
}
|
|
1863
|
+
if (maintainScrollAtEnd === true || maintainScrollAtEnd.onLayout) {
|
|
1864
|
+
doMaintainScrollAtEnd(ctx, state, false);
|
|
1865
|
+
}
|
|
1866
|
+
updateAlignItemsPaddingTop(ctx, state);
|
|
1867
|
+
checkAtBottom(ctx, state);
|
|
1868
|
+
checkAtTop(state);
|
|
1869
|
+
if (state) {
|
|
1870
|
+
state.needsOtherAxisSize = otherAxisSize - (state.props.stylePaddingTop || 0) < 10;
|
|
1871
|
+
}
|
|
1872
|
+
if (__DEV__ && scrollLength === 0) {
|
|
1873
|
+
warnDevOnce(
|
|
1874
|
+
"height0",
|
|
1875
|
+
`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.`
|
|
1737
1876
|
);
|
|
1738
|
-
}
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1877
|
+
}
|
|
1878
|
+
setCanRender(true);
|
|
1879
|
+
}
|
|
1880
|
+
|
|
1881
|
+
// src/core/onScroll.ts
|
|
1882
|
+
function onScroll(ctx, state, event) {
|
|
1883
|
+
var _a, _b, _c, _d, _e;
|
|
1884
|
+
if (((_b = (_a = event.nativeEvent) == null ? void 0 : _a.contentSize) == null ? void 0 : _b.height) === 0 && ((_c = event.nativeEvent.contentSize) == null ? void 0 : _c.width) === 0) {
|
|
1885
|
+
return;
|
|
1886
|
+
}
|
|
1887
|
+
const newScroll = event.nativeEvent.contentOffset[state.props.horizontal ? "x" : "y"];
|
|
1888
|
+
const ignoreScrollFromMVCP = state.ignoreScrollFromMVCP;
|
|
1889
|
+
if (ignoreScrollFromMVCP && !state.scrollingTo) {
|
|
1890
|
+
const { lt, gt } = ignoreScrollFromMVCP;
|
|
1891
|
+
if (lt && newScroll < lt || gt && newScroll > gt) {
|
|
1892
|
+
return;
|
|
1754
1893
|
}
|
|
1755
|
-
}
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1894
|
+
}
|
|
1895
|
+
state.scrollPending = newScroll;
|
|
1896
|
+
updateScroll(ctx, state, newScroll);
|
|
1897
|
+
(_e = (_d = state.props).onScroll) == null ? void 0 : _e.call(_d, event);
|
|
1898
|
+
}
|
|
1899
|
+
function updateScroll(ctx, state, newScroll) {
|
|
1900
|
+
const scrollingTo = state.scrollingTo;
|
|
1901
|
+
state.hasScrolled = true;
|
|
1902
|
+
state.lastBatchingAction = Date.now();
|
|
1903
|
+
const currentTime = performance.now();
|
|
1904
|
+
if (scrollingTo === void 0 && !(state.scrollHistory.length === 0 && newScroll === state.scroll)) {
|
|
1905
|
+
state.scrollHistory.push({ scroll: newScroll, time: currentTime });
|
|
1906
|
+
}
|
|
1907
|
+
if (state.scrollHistory.length > 5) {
|
|
1908
|
+
state.scrollHistory.shift();
|
|
1909
|
+
}
|
|
1910
|
+
state.scrollPrev = state.scroll;
|
|
1911
|
+
state.scrollPrevTime = state.scrollTime;
|
|
1912
|
+
state.scroll = newScroll;
|
|
1913
|
+
state.scrollTime = currentTime;
|
|
1914
|
+
calculateItemsInView(ctx, state);
|
|
1915
|
+
checkAtBottom(ctx, state);
|
|
1916
|
+
checkAtTop(state);
|
|
1917
|
+
}
|
|
1918
|
+
|
|
1919
|
+
// src/core/ScrollAdjustHandler.ts
|
|
1920
|
+
var ScrollAdjustHandler = class {
|
|
1921
|
+
constructor(ctx) {
|
|
1922
|
+
this.appliedAdjust = 0;
|
|
1923
|
+
this.mounted = false;
|
|
1924
|
+
this.context = ctx;
|
|
1925
|
+
}
|
|
1926
|
+
requestAdjust(add) {
|
|
1927
|
+
const oldAdjustTop = peek$(this.context, "scrollAdjust") || 0;
|
|
1928
|
+
this.appliedAdjust = add + oldAdjustTop;
|
|
1929
|
+
const set = () => set$(this.context, "scrollAdjust", this.appliedAdjust);
|
|
1930
|
+
if (this.mounted) {
|
|
1931
|
+
set();
|
|
1760
1932
|
} else {
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1933
|
+
requestAnimationFrame(set);
|
|
1934
|
+
}
|
|
1935
|
+
}
|
|
1936
|
+
setMounted() {
|
|
1937
|
+
this.mounted = true;
|
|
1938
|
+
}
|
|
1939
|
+
};
|
|
1940
|
+
|
|
1941
|
+
// src/core/updateItemSize.ts
|
|
1942
|
+
function updateItemSizes(ctx, state, itemUpdates) {
|
|
1943
|
+
var _a;
|
|
1944
|
+
const {
|
|
1945
|
+
props: {
|
|
1946
|
+
horizontal,
|
|
1947
|
+
maintainVisibleContentPosition,
|
|
1948
|
+
suggestEstimatedItemSize,
|
|
1949
|
+
onItemSizeChanged,
|
|
1950
|
+
data,
|
|
1951
|
+
maintainScrollAtEnd
|
|
1952
|
+
}
|
|
1953
|
+
} = state;
|
|
1954
|
+
if (!data) return;
|
|
1955
|
+
const containersDidLayout = peek$(ctx, "containersDidLayout");
|
|
1956
|
+
let needsRecalculate = !containersDidLayout;
|
|
1957
|
+
let shouldMaintainScrollAtEnd = false;
|
|
1958
|
+
let minIndexSizeChanged;
|
|
1959
|
+
let maxOtherAxisSize = peek$(ctx, "otherAxisSize") || 0;
|
|
1960
|
+
for (const { itemKey, sizeObj } of itemUpdates) {
|
|
1961
|
+
const index = state.indexByKey.get(itemKey);
|
|
1962
|
+
const prevSizeKnown = state.sizesKnown.get(itemKey);
|
|
1963
|
+
const diff = updateOneItemSize(state, itemKey, sizeObj);
|
|
1964
|
+
const size = Math.floor((horizontal ? sizeObj.width : sizeObj.height) * 8) / 8;
|
|
1965
|
+
if (diff !== 0) {
|
|
1966
|
+
minIndexSizeChanged = minIndexSizeChanged !== void 0 ? Math.min(minIndexSizeChanged, index) : index;
|
|
1967
|
+
if (((_a = state.scrollingTo) == null ? void 0 : _a.viewPosition) && maintainVisibleContentPosition && index === state.scrollingTo.index && diff > 0) {
|
|
1968
|
+
requestAdjust(ctx, state, diff * state.scrollingTo.viewPosition);
|
|
1969
|
+
}
|
|
1970
|
+
const { startBuffered, endBuffered } = state;
|
|
1971
|
+
needsRecalculate || (needsRecalculate = index >= startBuffered && index <= endBuffered);
|
|
1972
|
+
if (!needsRecalculate) {
|
|
1973
|
+
const numContainers = ctx.values.get("numContainers");
|
|
1974
|
+
for (let i = 0; i < numContainers; i++) {
|
|
1975
|
+
if (peek$(ctx, `containerItemKey${i}`) === itemKey) {
|
|
1976
|
+
needsRecalculate = true;
|
|
1977
|
+
break;
|
|
1769
1978
|
}
|
|
1770
1979
|
}
|
|
1771
1980
|
}
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
const state = refState.current;
|
|
1776
|
-
const numContainers = peek$(ctx, "numContainers");
|
|
1777
|
-
const result = [];
|
|
1778
|
-
const availableContainers = [];
|
|
1779
|
-
for (let u = 0; u < numContainers; u++) {
|
|
1780
|
-
const key = peek$(ctx, `containerItemKey${u}`);
|
|
1781
|
-
let isOk = key === void 0;
|
|
1782
|
-
if (!isOk) {
|
|
1783
|
-
const index = pendingRemoval.indexOf(u);
|
|
1784
|
-
if (index !== -1) {
|
|
1785
|
-
pendingRemoval.splice(index, 1);
|
|
1786
|
-
isOk = true;
|
|
1787
|
-
}
|
|
1981
|
+
if (state.needsOtherAxisSize) {
|
|
1982
|
+
const otherAxisSize = horizontal ? sizeObj.height : sizeObj.width;
|
|
1983
|
+
maxOtherAxisSize = Math.max(maxOtherAxisSize, otherAxisSize);
|
|
1788
1984
|
}
|
|
1789
|
-
if (
|
|
1790
|
-
|
|
1791
|
-
if (result.length >= numNeeded) {
|
|
1792
|
-
return result;
|
|
1793
|
-
}
|
|
1985
|
+
if (prevSizeKnown !== void 0 && Math.abs(prevSizeKnown - size) > 5) {
|
|
1986
|
+
shouldMaintainScrollAtEnd = true;
|
|
1794
1987
|
}
|
|
1988
|
+
onItemSizeChanged == null ? void 0 : onItemSizeChanged({
|
|
1989
|
+
index,
|
|
1990
|
+
itemData: state.props.data[index],
|
|
1991
|
+
itemKey,
|
|
1992
|
+
previous: size - diff,
|
|
1993
|
+
size
|
|
1994
|
+
});
|
|
1995
|
+
}
|
|
1996
|
+
}
|
|
1997
|
+
if (minIndexSizeChanged !== void 0) {
|
|
1998
|
+
state.minIndexSizeChanged = state.minIndexSizeChanged !== void 0 ? Math.min(state.minIndexSizeChanged, minIndexSizeChanged) : minIndexSizeChanged;
|
|
1999
|
+
}
|
|
2000
|
+
if (__DEV__ && suggestEstimatedItemSize && minIndexSizeChanged !== void 0) {
|
|
2001
|
+
if (state.timeoutSizeMessage) clearTimeout(state.timeoutSizeMessage);
|
|
2002
|
+
state.timeoutSizeMessage = setTimeout(() => {
|
|
2003
|
+
var _a2;
|
|
2004
|
+
state.timeoutSizeMessage = void 0;
|
|
2005
|
+
const num = state.sizesKnown.size;
|
|
2006
|
+
const avg = (_a2 = state.averageSizes[""]) == null ? void 0 : _a2.avg;
|
|
2007
|
+
console.warn(
|
|
2008
|
+
`[legend-list] Based on the ${num} items rendered so far, the optimal estimated size is ${avg}.`
|
|
2009
|
+
);
|
|
2010
|
+
}, 1e3);
|
|
2011
|
+
}
|
|
2012
|
+
const cur = peek$(ctx, "otherAxisSize");
|
|
2013
|
+
if (!cur || maxOtherAxisSize > cur) {
|
|
2014
|
+
set$(ctx, "otherAxisSize", maxOtherAxisSize);
|
|
2015
|
+
}
|
|
2016
|
+
if (containersDidLayout || checkAllSizesKnown(state)) {
|
|
2017
|
+
if (needsRecalculate) {
|
|
2018
|
+
state.scrollForNextCalculateItemsInView = void 0;
|
|
2019
|
+
calculateItemsInView(ctx, state, { doMVCP: true });
|
|
1795
2020
|
}
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
const index = state.indexByKey.get(key);
|
|
1800
|
-
if (index < startBuffered) {
|
|
1801
|
-
availableContainers.push({ index: u, distance: startBuffered - index });
|
|
1802
|
-
} else if (index > endBuffered) {
|
|
1803
|
-
availableContainers.push({ index: u, distance: index - endBuffered });
|
|
2021
|
+
if (shouldMaintainScrollAtEnd) {
|
|
2022
|
+
if (maintainScrollAtEnd === true || maintainScrollAtEnd.onItemLayout) {
|
|
2023
|
+
doMaintainScrollAtEnd(ctx, state, false);
|
|
1804
2024
|
}
|
|
1805
2025
|
}
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
2026
|
+
}
|
|
2027
|
+
}
|
|
2028
|
+
function updateItemSize(ctx, state, itemKey, sizeObj) {
|
|
2029
|
+
const { queuedItemSizeUpdates, queuedItemSizeUpdatesWaiting } = state;
|
|
2030
|
+
const containersDidLayout = peek$(ctx, "containersDidLayout");
|
|
2031
|
+
if (!containersDidLayout || !queuedItemSizeUpdatesWaiting) {
|
|
2032
|
+
updateItemSizes(ctx, state, [{ itemKey, sizeObj }]);
|
|
2033
|
+
if (containersDidLayout) {
|
|
2034
|
+
state.queuedItemSizeUpdatesWaiting = true;
|
|
2035
|
+
requestAnimationFrame(() => {
|
|
2036
|
+
state.queuedItemSizeUpdatesWaiting = false;
|
|
2037
|
+
updateItemSizes(ctx, state, queuedItemSizeUpdates);
|
|
2038
|
+
queuedItemSizeUpdates.length = 0;
|
|
2039
|
+
});
|
|
2040
|
+
}
|
|
2041
|
+
} else {
|
|
2042
|
+
queuedItemSizeUpdates.push({ itemKey, sizeObj });
|
|
2043
|
+
}
|
|
2044
|
+
}
|
|
2045
|
+
function updateOneItemSize(state, itemKey, sizeObj) {
|
|
2046
|
+
const {
|
|
2047
|
+
sizes,
|
|
2048
|
+
indexByKey,
|
|
2049
|
+
sizesKnown,
|
|
2050
|
+
averageSizes,
|
|
2051
|
+
props: { data, horizontal }
|
|
2052
|
+
} = state;
|
|
2053
|
+
if (!data) return 0;
|
|
2054
|
+
const index = indexByKey.get(itemKey);
|
|
2055
|
+
const prevSize = getItemSize(state, itemKey, index, data);
|
|
2056
|
+
const size = Math.floor((horizontal ? sizeObj.width : sizeObj.height) * 8) / 8;
|
|
2057
|
+
sizesKnown.set(itemKey, size);
|
|
2058
|
+
const itemType = "";
|
|
2059
|
+
let averages = averageSizes[itemType];
|
|
2060
|
+
if (!averages) {
|
|
2061
|
+
averages = averageSizes[itemType] = { avg: 0, num: 0 };
|
|
2062
|
+
}
|
|
2063
|
+
averages.avg = (averages.avg * averages.num + size) / (averages.num + 1);
|
|
2064
|
+
averages.num++;
|
|
2065
|
+
if (!prevSize || Math.abs(prevSize - size) > 0.1) {
|
|
2066
|
+
sizes.set(itemKey, size);
|
|
2067
|
+
return size - prevSize;
|
|
2068
|
+
}
|
|
2069
|
+
return 0;
|
|
2070
|
+
}
|
|
2071
|
+
var useCombinedRef = (...refs) => {
|
|
2072
|
+
const callback = React3.useCallback((element) => {
|
|
2073
|
+
for (const ref of refs) {
|
|
2074
|
+
if (!ref) {
|
|
2075
|
+
continue;
|
|
1816
2076
|
}
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
2077
|
+
if (isFunction(ref)) {
|
|
2078
|
+
ref(element);
|
|
2079
|
+
} else {
|
|
2080
|
+
ref.current = element;
|
|
2081
|
+
}
|
|
2082
|
+
}
|
|
2083
|
+
}, refs);
|
|
2084
|
+
return callback;
|
|
2085
|
+
};
|
|
2086
|
+
|
|
2087
|
+
// src/utils/createColumnWrapperStyle.ts
|
|
2088
|
+
function createColumnWrapperStyle(contentContainerStyle) {
|
|
2089
|
+
const { gap, columnGap, rowGap } = contentContainerStyle;
|
|
2090
|
+
if (gap || columnGap || rowGap) {
|
|
2091
|
+
contentContainerStyle.gap = void 0;
|
|
2092
|
+
contentContainerStyle.columnGap = void 0;
|
|
2093
|
+
contentContainerStyle.rowGap = void 0;
|
|
2094
|
+
return {
|
|
2095
|
+
columnGap,
|
|
2096
|
+
gap,
|
|
2097
|
+
rowGap
|
|
2098
|
+
};
|
|
2099
|
+
}
|
|
2100
|
+
}
|
|
2101
|
+
function getRenderedItem(ctx, state, key) {
|
|
2102
|
+
if (!state) {
|
|
2103
|
+
return null;
|
|
2104
|
+
}
|
|
2105
|
+
const {
|
|
2106
|
+
indexByKey,
|
|
2107
|
+
props: { data, renderItem: renderItem2 }
|
|
2108
|
+
} = state;
|
|
2109
|
+
const index = indexByKey.get(key);
|
|
2110
|
+
if (index === void 0) {
|
|
2111
|
+
return null;
|
|
2112
|
+
}
|
|
2113
|
+
let renderedItem = null;
|
|
2114
|
+
if (renderItem2) {
|
|
2115
|
+
const itemProps = {
|
|
2116
|
+
extraData: peek$(ctx, "extraData"),
|
|
2117
|
+
index,
|
|
2118
|
+
item: data[index]
|
|
2119
|
+
};
|
|
2120
|
+
renderedItem = React3__namespace.default.createElement(renderItem2, itemProps);
|
|
2121
|
+
}
|
|
2122
|
+
return { index, item: data[index], renderedItem };
|
|
2123
|
+
}
|
|
2124
|
+
|
|
2125
|
+
// src/components/LegendList.tsx
|
|
2126
|
+
var DEFAULT_DRAW_DISTANCE = 250;
|
|
2127
|
+
var DEFAULT_ITEM_SIZE = 100;
|
|
2128
|
+
var LegendList = typedForwardRef(function LegendList2(props, forwardedRef) {
|
|
2129
|
+
return /* @__PURE__ */ React3__namespace.createElement(StateProvider, null, /* @__PURE__ */ React3__namespace.createElement(LegendListInner, { ...props, ref: forwardedRef }));
|
|
2130
|
+
});
|
|
2131
|
+
var LegendListInner = typedForwardRef(function LegendListInner2(props, forwardedRef) {
|
|
2132
|
+
var _a;
|
|
2133
|
+
const {
|
|
2134
|
+
data: dataProp = [],
|
|
2135
|
+
initialScrollIndex: initialScrollIndexProp,
|
|
2136
|
+
initialScrollOffset,
|
|
2137
|
+
horizontal,
|
|
2138
|
+
drawDistance = 250,
|
|
2139
|
+
recycleItems = false,
|
|
2140
|
+
onEndReachedThreshold = 0.5,
|
|
2141
|
+
onStartReachedThreshold = 0.5,
|
|
2142
|
+
maintainScrollAtEnd = false,
|
|
2143
|
+
maintainScrollAtEndThreshold = 0.1,
|
|
2144
|
+
alignItemsAtEnd = false,
|
|
2145
|
+
maintainVisibleContentPosition = false,
|
|
2146
|
+
onScroll: onScrollProp,
|
|
2147
|
+
onMomentumScrollEnd,
|
|
2148
|
+
numColumns: numColumnsProp = 1,
|
|
2149
|
+
columnWrapperStyle,
|
|
2150
|
+
keyExtractor: keyExtractorProp,
|
|
2151
|
+
renderItem: renderItem2,
|
|
2152
|
+
estimatedListSize,
|
|
2153
|
+
estimatedItemSize: estimatedItemSizeProp,
|
|
2154
|
+
getEstimatedItemSize,
|
|
2155
|
+
suggestEstimatedItemSize,
|
|
2156
|
+
ListHeaderComponent,
|
|
2157
|
+
ListEmptyComponent,
|
|
2158
|
+
onItemSizeChanged,
|
|
2159
|
+
refScrollView,
|
|
2160
|
+
waitForInitialLayout = true,
|
|
2161
|
+
extraData,
|
|
2162
|
+
contentContainerStyle: contentContainerStyleProp,
|
|
2163
|
+
style: styleProp,
|
|
2164
|
+
onLayout: onLayoutProp,
|
|
2165
|
+
onRefresh,
|
|
2166
|
+
refreshing,
|
|
2167
|
+
progressViewOffset,
|
|
2168
|
+
refreshControl,
|
|
2169
|
+
initialContainerPoolRatio = 2,
|
|
2170
|
+
viewabilityConfig,
|
|
2171
|
+
viewabilityConfigCallbackPairs,
|
|
2172
|
+
snapToIndices,
|
|
2173
|
+
onViewableItemsChanged,
|
|
2174
|
+
onStartReached,
|
|
2175
|
+
onEndReached,
|
|
2176
|
+
onLoad,
|
|
2177
|
+
...rest
|
|
2178
|
+
} = props;
|
|
2179
|
+
const [renderNum, setRenderNum] = React3.useState(0);
|
|
2180
|
+
const initialScroll = typeof initialScrollIndexProp === "number" ? { index: initialScrollIndexProp } : initialScrollIndexProp;
|
|
2181
|
+
const initialScrollIndex = initialScroll == null ? void 0 : initialScroll.index;
|
|
2182
|
+
const [canRender, setCanRender] = React3__namespace.useState(!IsNewArchitecture);
|
|
2183
|
+
const contentContainerStyle = { ...reactNative.StyleSheet.flatten(contentContainerStyleProp) };
|
|
2184
|
+
const style = { ...reactNative.StyleSheet.flatten(styleProp) };
|
|
2185
|
+
const stylePaddingTopState = extractPadding(style, contentContainerStyle, "Top");
|
|
2186
|
+
const stylePaddingBottomState = extractPadding(style, contentContainerStyle, "Bottom");
|
|
2187
|
+
const ctx = useStateContext();
|
|
2188
|
+
ctx.columnWrapperStyle = columnWrapperStyle || (contentContainerStyle ? createColumnWrapperStyle(contentContainerStyle) : void 0);
|
|
2189
|
+
const refScroller = React3.useRef(null);
|
|
2190
|
+
const combinedRef = useCombinedRef(refScroller, refScrollView);
|
|
2191
|
+
const estimatedItemSize = estimatedItemSizeProp != null ? estimatedItemSizeProp : DEFAULT_ITEM_SIZE;
|
|
2192
|
+
const scrollBuffer = (drawDistance != null ? drawDistance : DEFAULT_DRAW_DISTANCE) || 1;
|
|
2193
|
+
const keyExtractor = keyExtractorProp != null ? keyExtractorProp : (_item, index) => index.toString();
|
|
2194
|
+
const refState = React3.useRef();
|
|
2195
|
+
if (!refState.current) {
|
|
2196
|
+
const initialScrollLength = (estimatedListSize != null ? estimatedListSize : IsNewArchitecture ? { height: 0, width: 0 } : reactNative.Dimensions.get("window"))[horizontal ? "width" : "height"];
|
|
2197
|
+
refState.current = {
|
|
2198
|
+
averageSizes: {},
|
|
2199
|
+
columns: /* @__PURE__ */ new Map(),
|
|
2200
|
+
containerItemKeys: /* @__PURE__ */ new Set(),
|
|
2201
|
+
enableScrollForNextCalculateItemsInView: true,
|
|
2202
|
+
endBuffered: -1,
|
|
2203
|
+
endNoBuffer: -1,
|
|
2204
|
+
endReachedBlockedByTimer: false,
|
|
2205
|
+
firstFullyOnScreenIndex: -1,
|
|
2206
|
+
idCache: /* @__PURE__ */ new Map(),
|
|
2207
|
+
idsInView: [],
|
|
2208
|
+
indexByKey: /* @__PURE__ */ new Map(),
|
|
2209
|
+
initialScroll,
|
|
2210
|
+
isAtEnd: false,
|
|
2211
|
+
isAtStart: false,
|
|
2212
|
+
isEndReached: false,
|
|
2213
|
+
isStartReached: false,
|
|
2214
|
+
lastBatchingAction: Date.now(),
|
|
2215
|
+
lastLayout: void 0,
|
|
2216
|
+
loadStartTime: Date.now(),
|
|
2217
|
+
minIndexSizeChanged: 0,
|
|
2218
|
+
nativeMarginTop: 0,
|
|
2219
|
+
pendingAdjust: 0,
|
|
2220
|
+
positions: /* @__PURE__ */ new Map(),
|
|
2221
|
+
props: {},
|
|
2222
|
+
queuedCalculateItemsInView: 0,
|
|
2223
|
+
queuedItemSizeUpdates: [],
|
|
2224
|
+
refScroller: void 0,
|
|
2225
|
+
scroll: 0,
|
|
2226
|
+
scrollAdjustHandler: new ScrollAdjustHandler(ctx),
|
|
2227
|
+
scrollForNextCalculateItemsInView: void 0,
|
|
2228
|
+
scrollHistory: [],
|
|
2229
|
+
scrollLength: initialScrollLength,
|
|
2230
|
+
scrollPending: 0,
|
|
2231
|
+
scrollPrev: 0,
|
|
2232
|
+
scrollPrevTime: 0,
|
|
2233
|
+
scrollTime: 0,
|
|
2234
|
+
sizes: /* @__PURE__ */ new Map(),
|
|
2235
|
+
sizesKnown: /* @__PURE__ */ new Map(),
|
|
2236
|
+
startBuffered: -1,
|
|
2237
|
+
startNoBuffer: -1,
|
|
2238
|
+
startReachedBlockedByTimer: false,
|
|
2239
|
+
timeoutSizeMessage: 0,
|
|
2240
|
+
timeouts: /* @__PURE__ */ new Set(),
|
|
2241
|
+
totalSize: 0,
|
|
2242
|
+
viewabilityConfigCallbackPairs: void 0
|
|
2243
|
+
};
|
|
2244
|
+
set$(ctx, "maintainVisibleContentPosition", maintainVisibleContentPosition);
|
|
2245
|
+
set$(ctx, "extraData", extraData);
|
|
2246
|
+
}
|
|
2247
|
+
const state = refState.current;
|
|
2248
|
+
const isFirst = !state.props.renderItem;
|
|
2249
|
+
const didDataChange = state.props.data !== dataProp;
|
|
2250
|
+
state.props = {
|
|
2251
|
+
alignItemsAtEnd,
|
|
2252
|
+
data: dataProp,
|
|
2253
|
+
estimatedItemSize,
|
|
2254
|
+
getEstimatedItemSize,
|
|
2255
|
+
horizontal: !!horizontal,
|
|
2256
|
+
initialContainerPoolRatio,
|
|
2257
|
+
initialScroll,
|
|
2258
|
+
keyExtractor,
|
|
2259
|
+
maintainScrollAtEnd,
|
|
2260
|
+
maintainScrollAtEndThreshold,
|
|
2261
|
+
maintainVisibleContentPosition,
|
|
2262
|
+
numColumns: numColumnsProp,
|
|
2263
|
+
onEndReached,
|
|
2264
|
+
onEndReachedThreshold,
|
|
2265
|
+
onItemSizeChanged,
|
|
2266
|
+
onLoad,
|
|
2267
|
+
onScroll: onScrollProp,
|
|
2268
|
+
onStartReached,
|
|
2269
|
+
onStartReachedThreshold,
|
|
2270
|
+
renderItem: renderItem2,
|
|
2271
|
+
scrollBuffer,
|
|
2272
|
+
snapToIndices,
|
|
2273
|
+
stylePaddingBottom: stylePaddingBottomState,
|
|
2274
|
+
stylePaddingTop: stylePaddingTopState,
|
|
2275
|
+
suggestEstimatedItemSize: !!suggestEstimatedItemSize
|
|
2276
|
+
};
|
|
2277
|
+
state.refScroller = refScroller;
|
|
2278
|
+
const checkResetContainers = (isFirst2) => {
|
|
2279
|
+
const state2 = refState.current;
|
|
2280
|
+
if (state2) {
|
|
2281
|
+
state2.props.data = dataProp;
|
|
2282
|
+
if (!isFirst2) {
|
|
2283
|
+
calculateItemsInView(ctx, state2, { dataChanged: true, doMVCP: true });
|
|
2284
|
+
const shouldMaintainScrollAtEnd = maintainScrollAtEnd === true || maintainScrollAtEnd.onDataChange;
|
|
2285
|
+
const didMaintainScrollAtEnd = shouldMaintainScrollAtEnd && doMaintainScrollAtEnd(ctx, state2, false);
|
|
2286
|
+
if (!didMaintainScrollAtEnd && dataProp.length > state2.props.data.length) {
|
|
2287
|
+
state2.isEndReached = false;
|
|
1821
2288
|
}
|
|
1822
|
-
if (
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
{
|
|
1826
|
-
debugInfo: {
|
|
1827
|
-
numContainers,
|
|
1828
|
-
numNeeded,
|
|
1829
|
-
stillNeeded,
|
|
1830
|
-
numContainersPooled: peek$(ctx, "numContainersPooled")
|
|
1831
|
-
}
|
|
1832
|
-
}
|
|
1833
|
-
);
|
|
2289
|
+
if (!didMaintainScrollAtEnd) {
|
|
2290
|
+
checkAtTop(state2);
|
|
2291
|
+
checkAtBottom(ctx, state2);
|
|
1834
2292
|
}
|
|
1835
2293
|
}
|
|
1836
2294
|
}
|
|
1837
|
-
return result.sort(comparatorDefault);
|
|
1838
2295
|
};
|
|
1839
|
-
const
|
|
1840
|
-
const memoizedLastItemKeys = React2.useMemo(() => {
|
|
2296
|
+
const memoizedLastItemKeys = React3.useMemo(() => {
|
|
1841
2297
|
if (!dataProp.length) return [];
|
|
1842
2298
|
return Array.from(
|
|
1843
2299
|
{ length: Math.min(numColumnsProp, dataProp.length) },
|
|
1844
|
-
(_, i) => getId(dataProp.length - 1 - i)
|
|
2300
|
+
(_, i) => getId(state, dataProp.length - 1 - i)
|
|
1845
2301
|
);
|
|
1846
2302
|
}, [dataProp, numColumnsProp]);
|
|
1847
|
-
const
|
|
2303
|
+
const initializeStateVars = () => {
|
|
1848
2304
|
set$(ctx, "lastItemKeys", memoizedLastItemKeys);
|
|
1849
2305
|
set$(ctx, "numColumns", numColumnsProp);
|
|
1850
2306
|
const prevPaddingTop = peek$(ctx, "stylePaddingTop");
|
|
1851
|
-
setPaddingTop({ stylePaddingTop: stylePaddingTopState });
|
|
1852
|
-
refState.current.stylePaddingBottom = stylePaddingBottomState;
|
|
1853
|
-
|
|
1854
|
-
if (paddingDiff && prevPaddingTop !== void 0 && reactNative.Platform.OS === "ios") {
|
|
1855
|
-
|
|
2307
|
+
setPaddingTop(ctx, state, { stylePaddingTop: stylePaddingTopState });
|
|
2308
|
+
refState.current.props.stylePaddingBottom = stylePaddingBottomState;
|
|
2309
|
+
let paddingDiff = stylePaddingTopState - prevPaddingTop;
|
|
2310
|
+
if (maintainVisibleContentPosition && paddingDiff && prevPaddingTop !== void 0 && reactNative.Platform.OS === "ios") {
|
|
2311
|
+
if (state.scroll < 0) {
|
|
2312
|
+
paddingDiff += state.scroll;
|
|
2313
|
+
}
|
|
2314
|
+
requestAdjust(ctx, state, paddingDiff);
|
|
1856
2315
|
}
|
|
1857
2316
|
};
|
|
1858
2317
|
if (isFirst) {
|
|
1859
|
-
|
|
1860
|
-
updateAllPositions();
|
|
2318
|
+
initializeStateVars();
|
|
2319
|
+
updateAllPositions(ctx, state);
|
|
1861
2320
|
}
|
|
1862
|
-
const initialContentOffset =
|
|
1863
|
-
const initialContentOffset2 = initialScrollOffset || calculateOffsetForIndex(initialScrollIndex);
|
|
2321
|
+
const initialContentOffset = React3.useMemo(() => {
|
|
2322
|
+
const initialContentOffset2 = initialScrollOffset || calculateOffsetForIndex(ctx, state, initialScrollIndex);
|
|
1864
2323
|
refState.current.isStartReached = initialContentOffset2 < refState.current.scrollLength * onStartReachedThreshold;
|
|
1865
2324
|
if (initialContentOffset2 > 0) {
|
|
1866
|
-
scrollTo({
|
|
2325
|
+
scrollTo(state, { animated: false, index: initialScrollIndex, offset: initialContentOffset2 });
|
|
1867
2326
|
}
|
|
1868
2327
|
return initialContentOffset2;
|
|
1869
2328
|
}, [renderNum]);
|
|
@@ -1878,22 +2337,24 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
|
|
|
1878
2337
|
refState.current.positions.clear();
|
|
1879
2338
|
}
|
|
1880
2339
|
}
|
|
1881
|
-
|
|
1882
|
-
var _a2, _b;
|
|
2340
|
+
React3.useLayoutEffect(() => {
|
|
1883
2341
|
if (IsNewArchitecture) {
|
|
1884
|
-
|
|
2342
|
+
let measured;
|
|
2343
|
+
refScroller.current.measure((x, y, width, height) => {
|
|
2344
|
+
measured = { height, width, x, y };
|
|
2345
|
+
});
|
|
1885
2346
|
if (measured) {
|
|
1886
2347
|
const size = Math.floor(measured[horizontal ? "width" : "height"] * 8) / 8;
|
|
1887
2348
|
if (size) {
|
|
1888
|
-
handleLayout(measured);
|
|
2349
|
+
handleLayout(ctx, state, measured, setCanRender);
|
|
1889
2350
|
}
|
|
1890
2351
|
}
|
|
1891
2352
|
}
|
|
1892
2353
|
if (!isFirst) {
|
|
1893
|
-
calculateItemsInView({ doMVCP: true });
|
|
2354
|
+
calculateItemsInView(ctx, state, { doMVCP: true });
|
|
1894
2355
|
}
|
|
1895
2356
|
}, [dataProp]);
|
|
1896
|
-
const onLayoutHeader =
|
|
2357
|
+
const onLayoutHeader = React3.useCallback((rect, fromLayoutEffect) => {
|
|
1897
2358
|
const size = rect[horizontal ? "width" : "height"];
|
|
1898
2359
|
set$(ctx, "headerSize", size);
|
|
1899
2360
|
if (initialScroll) {
|
|
@@ -1903,13 +2364,18 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
|
|
|
1903
2364
|
}
|
|
1904
2365
|
} else {
|
|
1905
2366
|
setTimeout(() => {
|
|
1906
|
-
scrollToIndex({ ...initialScroll, animated: false });
|
|
2367
|
+
scrollToIndex(ctx, state, { ...initialScroll, animated: false });
|
|
1907
2368
|
}, 17);
|
|
1908
2369
|
}
|
|
1909
2370
|
}
|
|
1910
2371
|
}, []);
|
|
1911
|
-
|
|
1912
|
-
|
|
2372
|
+
React3.useLayoutEffect(() => {
|
|
2373
|
+
if (snapToIndices) {
|
|
2374
|
+
updateSnapToOffsets(ctx, state);
|
|
2375
|
+
}
|
|
2376
|
+
}, [snapToIndices]);
|
|
2377
|
+
React3.useLayoutEffect(() => {
|
|
2378
|
+
const didAllocateContainers = doInitialAllocateContainersCallback();
|
|
1913
2379
|
if (!didAllocateContainers) {
|
|
1914
2380
|
checkResetContainers(
|
|
1915
2381
|
/*isFirst*/
|
|
@@ -1917,424 +2383,186 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
|
|
|
1917
2383
|
);
|
|
1918
2384
|
}
|
|
1919
2385
|
}, [dataProp, numColumnsProp]);
|
|
1920
|
-
|
|
2386
|
+
React3.useLayoutEffect(() => {
|
|
1921
2387
|
set$(ctx, "extraData", extraData);
|
|
1922
2388
|
}, [extraData]);
|
|
1923
|
-
|
|
1924
|
-
React2.useLayoutEffect(initalizeStateVars, [
|
|
2389
|
+
React3.useLayoutEffect(initializeStateVars, [
|
|
1925
2390
|
memoizedLastItemKeys.join(","),
|
|
1926
2391
|
numColumnsProp,
|
|
1927
2392
|
stylePaddingTopState,
|
|
1928
2393
|
stylePaddingBottomState
|
|
1929
2394
|
]);
|
|
1930
|
-
const
|
|
1931
|
-
|
|
1932
|
-
if (!state) {
|
|
1933
|
-
return null;
|
|
1934
|
-
}
|
|
1935
|
-
const { data, indexByKey } = state;
|
|
1936
|
-
const index = indexByKey.get(key);
|
|
1937
|
-
if (index === void 0) {
|
|
1938
|
-
return null;
|
|
1939
|
-
}
|
|
1940
|
-
const renderItemProp = refState.current.renderItem;
|
|
1941
|
-
let renderedItem = null;
|
|
1942
|
-
if (renderItemProp) {
|
|
1943
|
-
const itemProps = {
|
|
1944
|
-
item: data[index],
|
|
1945
|
-
index,
|
|
1946
|
-
extraData: peek$(ctx, "extraData")
|
|
1947
|
-
};
|
|
1948
|
-
renderedItem = React2__namespace.createElement(renderItemProp, itemProps);
|
|
1949
|
-
}
|
|
1950
|
-
return { index, item: data[index], renderedItem };
|
|
1951
|
-
}, []);
|
|
1952
|
-
const doInitialAllocateContainers = () => {
|
|
1953
|
-
const state = refState.current;
|
|
1954
|
-
const { scrollLength, data } = state;
|
|
1955
|
-
if (scrollLength > 0 && data.length > 0 && !peek$(ctx, "numContainers")) {
|
|
1956
|
-
const averageItemSize = getEstimatedItemSize ? getEstimatedItemSize(0, data[0]) : estimatedItemSize;
|
|
1957
|
-
const Extra = 1.5;
|
|
1958
|
-
const numContainers = Math.ceil(
|
|
1959
|
-
(scrollLength + scrollBuffer * 2) / averageItemSize * numColumnsProp * Extra
|
|
1960
|
-
);
|
|
1961
|
-
for (let i = 0; i < numContainers; i++) {
|
|
1962
|
-
set$(ctx, `containerPosition${i}`, POSITION_OUT_OF_VIEW);
|
|
1963
|
-
set$(ctx, `containerColumn${i}`, -1);
|
|
1964
|
-
}
|
|
1965
|
-
set$(ctx, "numContainers", numContainers);
|
|
1966
|
-
set$(ctx, "numContainersPooled", numContainers * initialContainerPoolRatio);
|
|
1967
|
-
if (!IsNewArchitecture) {
|
|
1968
|
-
if (initialScroll) {
|
|
1969
|
-
requestAnimationFrame(() => {
|
|
1970
|
-
calculateItemsInView();
|
|
1971
|
-
});
|
|
1972
|
-
} else {
|
|
1973
|
-
calculateItemsInView();
|
|
1974
|
-
}
|
|
1975
|
-
}
|
|
1976
|
-
return true;
|
|
1977
|
-
}
|
|
2395
|
+
const doInitialAllocateContainersCallback = () => {
|
|
2396
|
+
return doInitialAllocateContainers(ctx, state);
|
|
1978
2397
|
};
|
|
1979
|
-
|
|
1980
|
-
const state = refState.current;
|
|
2398
|
+
React3.useEffect(() => {
|
|
1981
2399
|
const viewability = setupViewability({
|
|
2400
|
+
onViewableItemsChanged,
|
|
1982
2401
|
viewabilityConfig,
|
|
1983
|
-
viewabilityConfigCallbackPairs
|
|
1984
|
-
onViewableItemsChanged
|
|
2402
|
+
viewabilityConfigCallbackPairs
|
|
1985
2403
|
});
|
|
1986
2404
|
state.viewabilityConfigCallbackPairs = viewability;
|
|
1987
2405
|
state.enableScrollForNextCalculateItemsInView = !viewability;
|
|
1988
2406
|
}, [viewabilityConfig, viewabilityConfigCallbackPairs, onViewableItemsChanged]);
|
|
1989
2407
|
if (!IsNewArchitecture) {
|
|
1990
2408
|
useInit(() => {
|
|
1991
|
-
|
|
2409
|
+
doInitialAllocateContainersCallback();
|
|
1992
2410
|
});
|
|
1993
2411
|
}
|
|
1994
|
-
const
|
|
1995
|
-
const
|
|
1996
|
-
|
|
1997
|
-
if (
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
const size = Math.floor((horizontal ? sizeObj.width : sizeObj.height) * 8) / 8;
|
|
2001
|
-
sizesKnown.set(itemKey, size);
|
|
2002
|
-
const itemType = "";
|
|
2003
|
-
let averages = averageSizes[itemType];
|
|
2004
|
-
if (!averages) {
|
|
2005
|
-
averages = averageSizes[itemType] = { num: 0, avg: 0 };
|
|
2006
|
-
}
|
|
2007
|
-
averages.avg = (averages.avg * averages.num + size) / (averages.num + 1);
|
|
2008
|
-
averages.num++;
|
|
2009
|
-
if (!prevSize || Math.abs(prevSize - size) > 0.1) {
|
|
2010
|
-
sizes.set(itemKey, size);
|
|
2011
|
-
return size - prevSize;
|
|
2012
|
-
}
|
|
2013
|
-
return 0;
|
|
2412
|
+
const onLayout = React3.useCallback((event) => {
|
|
2413
|
+
const layout = event.nativeEvent.layout;
|
|
2414
|
+
handleLayout(ctx, state, layout, setCanRender);
|
|
2415
|
+
if (onLayoutProp) {
|
|
2416
|
+
onLayoutProp(event);
|
|
2417
|
+
}
|
|
2014
2418
|
}, []);
|
|
2015
|
-
|
|
2016
|
-
(
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
const index = state.indexByKey.get(itemKey);
|
|
2026
|
-
const prevSizeKnown = state.sizesKnown.get(itemKey);
|
|
2027
|
-
const diff = updateOneItemSize(itemKey, sizeObj);
|
|
2028
|
-
const size = Math.floor((horizontal ? sizeObj.width : sizeObj.height) * 8) / 8;
|
|
2029
|
-
if (diff !== 0) {
|
|
2030
|
-
minIndexSizeChanged = minIndexSizeChanged !== void 0 ? Math.min(minIndexSizeChanged, index) : index;
|
|
2031
|
-
if (((_a2 = state.scrollingTo) == null ? void 0 : _a2.viewPosition) && maintainVisibleContentPosition && index === state.scrollingTo.index) {
|
|
2032
|
-
requestAdjust(diff * state.scrollingTo.viewPosition);
|
|
2033
|
-
}
|
|
2034
|
-
const { startBuffered, endBuffered } = state;
|
|
2035
|
-
needsRecalculate || (needsRecalculate = index >= startBuffered && index <= endBuffered);
|
|
2036
|
-
if (!needsRecalculate) {
|
|
2037
|
-
const numContainers = ctx.values.get("numContainers");
|
|
2038
|
-
for (let i = 0; i < numContainers; i++) {
|
|
2039
|
-
if (peek$(ctx, `containerItemKey${i}`) === itemKey) {
|
|
2040
|
-
needsRecalculate = true;
|
|
2041
|
-
break;
|
|
2042
|
-
}
|
|
2043
|
-
}
|
|
2044
|
-
}
|
|
2045
|
-
if (state.needsOtherAxisSize) {
|
|
2046
|
-
const otherAxisSize = horizontal ? sizeObj.height : sizeObj.width;
|
|
2047
|
-
maxOtherAxisSize = Math.max(maxOtherAxisSize, otherAxisSize);
|
|
2048
|
-
}
|
|
2049
|
-
if (prevSizeKnown !== void 0 && Math.abs(prevSizeKnown - size) > 5) {
|
|
2050
|
-
shouldMaintainScrollAtEnd = true;
|
|
2051
|
-
}
|
|
2052
|
-
onItemSizeChanged == null ? void 0 : onItemSizeChanged({
|
|
2053
|
-
size,
|
|
2054
|
-
previous: size - diff,
|
|
2419
|
+
React3.useImperativeHandle(forwardedRef, () => {
|
|
2420
|
+
const scrollIndexIntoView = (options) => {
|
|
2421
|
+
const state2 = refState.current;
|
|
2422
|
+
if (state2) {
|
|
2423
|
+
const { index, ...rest2 } = options;
|
|
2424
|
+
const { startNoBuffer, endNoBuffer } = state2;
|
|
2425
|
+
if (index < startNoBuffer || index > endNoBuffer) {
|
|
2426
|
+
const viewPosition = index < startNoBuffer ? 0 : 1;
|
|
2427
|
+
scrollToIndex(ctx, state2, {
|
|
2428
|
+
...rest2,
|
|
2055
2429
|
index,
|
|
2056
|
-
|
|
2057
|
-
itemData: state.data[index]
|
|
2430
|
+
viewPosition
|
|
2058
2431
|
});
|
|
2059
2432
|
}
|
|
2060
2433
|
}
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2434
|
+
};
|
|
2435
|
+
return {
|
|
2436
|
+
flashScrollIndicators: () => refScroller.current.flashScrollIndicators(),
|
|
2437
|
+
getNativeScrollRef: () => refScroller.current,
|
|
2438
|
+
getScrollableNode: () => refScroller.current.getScrollableNode(),
|
|
2439
|
+
getScrollResponder: () => refScroller.current.getScrollResponder(),
|
|
2440
|
+
getState: () => {
|
|
2441
|
+
const state2 = refState.current;
|
|
2442
|
+
return state2 ? {
|
|
2443
|
+
contentLength: state2.totalSize,
|
|
2444
|
+
end: state2.endNoBuffer,
|
|
2445
|
+
endBuffered: state2.endBuffered,
|
|
2446
|
+
isAtEnd: state2.isAtEnd,
|
|
2447
|
+
isAtStart: state2.isAtStart,
|
|
2448
|
+
positions: state2.positions,
|
|
2449
|
+
scroll: state2.scroll,
|
|
2450
|
+
scrollLength: state2.scrollLength,
|
|
2451
|
+
sizeAtIndex: (index) => state2.sizesKnown.get(getId(state2, index)),
|
|
2452
|
+
sizes: state2.sizesKnown,
|
|
2453
|
+
start: state2.startNoBuffer,
|
|
2454
|
+
startBuffered: state2.startBuffered
|
|
2455
|
+
} : {};
|
|
2456
|
+
},
|
|
2457
|
+
scrollIndexIntoView,
|
|
2458
|
+
scrollItemIntoView: ({ item, ...props2 }) => {
|
|
2459
|
+
const data = refState.current.props.data;
|
|
2460
|
+
const index = data.indexOf(item);
|
|
2461
|
+
if (index !== -1) {
|
|
2462
|
+
scrollIndexIntoView({ index, ...props2 });
|
|
2088
2463
|
}
|
|
2089
|
-
}
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
} else if (!sizesKnown.has(containerItemKey) && containerItemKey !== void 0) {
|
|
2104
|
-
const containerRef = ctx.viewRefs.get(i);
|
|
2105
|
-
if (containerRef) {
|
|
2106
|
-
const measured = (_b = (_a2 = containerRef.current) == null ? void 0 : _a2.unstable_getBoundingClientRect) == null ? void 0 : _b.call(_a2);
|
|
2107
|
-
if (measured) {
|
|
2108
|
-
changes.push({ itemKey: containerItemKey, sizeObj: measured });
|
|
2109
|
-
}
|
|
2110
|
-
}
|
|
2464
|
+
},
|
|
2465
|
+
scrollToEnd: (options) => {
|
|
2466
|
+
const data = refState.current.props.data;
|
|
2467
|
+
const stylePaddingBottom = refState.current.props.stylePaddingBottom;
|
|
2468
|
+
const index = data.length - 1;
|
|
2469
|
+
if (index !== -1) {
|
|
2470
|
+
const paddingBottom = stylePaddingBottom || 0;
|
|
2471
|
+
const footerSize = peek$(ctx, "footerSize") || 0;
|
|
2472
|
+
scrollToIndex(ctx, state, {
|
|
2473
|
+
index,
|
|
2474
|
+
viewOffset: -paddingBottom - footerSize + ((options == null ? void 0 : options.viewOffset) || 0),
|
|
2475
|
+
viewPosition: 1,
|
|
2476
|
+
...options
|
|
2477
|
+
});
|
|
2111
2478
|
}
|
|
2112
|
-
}
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
}, []);
|
|
2120
|
-
const handleLayout = React2.useCallback((size) => {
|
|
2121
|
-
const scrollLength = size[horizontal ? "width" : "height"];
|
|
2122
|
-
const otherAxisSize = size[horizontal ? "height" : "width"];
|
|
2123
|
-
const state = refState.current;
|
|
2124
|
-
const didChange = scrollLength !== state.scrollLength;
|
|
2125
|
-
const prevOtherAxisSize = state.otherAxisSize;
|
|
2126
|
-
state.scrollLength = scrollLength;
|
|
2127
|
-
state.otherAxisSize = otherAxisSize;
|
|
2128
|
-
state.lastBatchingAction = Date.now();
|
|
2129
|
-
state.scrollForNextCalculateItemsInView = void 0;
|
|
2130
|
-
doInitialAllocateContainers();
|
|
2131
|
-
if (didChange) {
|
|
2132
|
-
calculateItemsInView({ doMVCP: true });
|
|
2133
|
-
}
|
|
2134
|
-
if (didChange || otherAxisSize !== prevOtherAxisSize) {
|
|
2135
|
-
set$(ctx, "scrollSize", { width: size.width, height: size.height });
|
|
2136
|
-
}
|
|
2137
|
-
doMaintainScrollAtEnd(false);
|
|
2138
|
-
updateAlignItemsPaddingTop();
|
|
2139
|
-
checkAtBottom();
|
|
2140
|
-
checkAtTop();
|
|
2141
|
-
if (refState.current) {
|
|
2142
|
-
refState.current.needsOtherAxisSize = otherAxisSize - (stylePaddingTopState || 0) < 10;
|
|
2143
|
-
}
|
|
2144
|
-
if (__DEV__ && scrollLength === 0) {
|
|
2145
|
-
warnDevOnce(
|
|
2146
|
-
"height0",
|
|
2147
|
-
`List ${horizontal ? "width" : "height"} is 0. You may need to set a style or \`flex: \` for the list, because children are absolutely positioned.`
|
|
2148
|
-
);
|
|
2149
|
-
}
|
|
2150
|
-
calculateItemsInView({ doMVCP: true });
|
|
2151
|
-
setCanRender(true);
|
|
2152
|
-
}, []);
|
|
2153
|
-
const onLayout = React2.useCallback((event) => {
|
|
2154
|
-
const layout = event.nativeEvent.layout;
|
|
2155
|
-
handleLayout(layout);
|
|
2156
|
-
if (onLayoutProp) {
|
|
2157
|
-
onLayoutProp(event);
|
|
2158
|
-
}
|
|
2159
|
-
}, []);
|
|
2160
|
-
const handleScroll = React2.useCallback(
|
|
2161
|
-
(event) => {
|
|
2162
|
-
var _a2, _b, _c, _d;
|
|
2163
|
-
if (((_b = (_a2 = event.nativeEvent) == null ? void 0 : _a2.contentSize) == null ? void 0 : _b.height) === 0 && ((_c = event.nativeEvent.contentSize) == null ? void 0 : _c.width) === 0) {
|
|
2164
|
-
return;
|
|
2165
|
-
}
|
|
2166
|
-
const state = refState.current;
|
|
2167
|
-
const newScroll = event.nativeEvent.contentOffset[horizontal ? "x" : "y"];
|
|
2168
|
-
const ignoreScrollFromMVCP = state.ignoreScrollFromMVCP;
|
|
2169
|
-
if (ignoreScrollFromMVCP && !state.scrollingTo) {
|
|
2170
|
-
const { lt, gt } = ignoreScrollFromMVCP;
|
|
2171
|
-
if (lt && newScroll < lt || gt && newScroll > gt) {
|
|
2172
|
-
return;
|
|
2479
|
+
},
|
|
2480
|
+
scrollToIndex: (params) => scrollToIndex(ctx, state, params),
|
|
2481
|
+
scrollToItem: ({ item, ...props2 }) => {
|
|
2482
|
+
const data = refState.current.props.data;
|
|
2483
|
+
const index = data.indexOf(item);
|
|
2484
|
+
if (index !== -1) {
|
|
2485
|
+
scrollToIndex(ctx, state, { index, ...props2 });
|
|
2173
2486
|
}
|
|
2487
|
+
},
|
|
2488
|
+
scrollToOffset: (params) => scrollTo(state, params),
|
|
2489
|
+
setVisibleContentAnchorOffset: (value) => {
|
|
2490
|
+
const val = typeof value === "function" ? value(peek$(ctx, "scrollAdjustUserOffset") || 0) : value;
|
|
2491
|
+
set$(ctx, "scrollAdjustUserOffset", val);
|
|
2174
2492
|
}
|
|
2175
|
-
|
|
2176
|
-
updateScroll(newScroll);
|
|
2177
|
-
(_d = state.onScroll) == null ? void 0 : _d.call(state, event);
|
|
2178
|
-
},
|
|
2179
|
-
[]
|
|
2180
|
-
);
|
|
2181
|
-
const updateScroll = React2.useCallback((newScroll) => {
|
|
2182
|
-
const state = refState.current;
|
|
2183
|
-
const scrollingTo = state.scrollingTo;
|
|
2184
|
-
state.hasScrolled = true;
|
|
2185
|
-
state.lastBatchingAction = Date.now();
|
|
2186
|
-
const currentTime = performance.now();
|
|
2187
|
-
if (scrollingTo === void 0 && !(state.scrollHistory.length === 0 && newScroll === state.scroll)) {
|
|
2188
|
-
state.scrollHistory.push({ scroll: newScroll, time: currentTime });
|
|
2189
|
-
}
|
|
2190
|
-
if (state.scrollHistory.length > 5) {
|
|
2191
|
-
state.scrollHistory.shift();
|
|
2192
|
-
}
|
|
2193
|
-
state.scrollPrev = state.scroll;
|
|
2194
|
-
state.scrollPrevTime = state.scrollTime;
|
|
2195
|
-
state.scroll = newScroll;
|
|
2196
|
-
state.scrollTime = currentTime;
|
|
2197
|
-
calculateItemsInView();
|
|
2198
|
-
checkAtBottom();
|
|
2199
|
-
checkAtTop();
|
|
2493
|
+
};
|
|
2200
2494
|
}, []);
|
|
2201
|
-
React2.useImperativeHandle(
|
|
2202
|
-
forwardedRef,
|
|
2203
|
-
() => {
|
|
2204
|
-
const scrollIndexIntoView = (options) => {
|
|
2205
|
-
if (refState.current) {
|
|
2206
|
-
const { index, ...rest2 } = options;
|
|
2207
|
-
const { startNoBuffer, endNoBuffer } = refState.current;
|
|
2208
|
-
if (index < startNoBuffer || index > endNoBuffer) {
|
|
2209
|
-
const viewPosition = index < startNoBuffer ? 0 : 1;
|
|
2210
|
-
scrollToIndex({
|
|
2211
|
-
...rest2,
|
|
2212
|
-
viewPosition,
|
|
2213
|
-
index
|
|
2214
|
-
});
|
|
2215
|
-
}
|
|
2216
|
-
}
|
|
2217
|
-
};
|
|
2218
|
-
return {
|
|
2219
|
-
flashScrollIndicators: () => refScroller.current.flashScrollIndicators(),
|
|
2220
|
-
getNativeScrollRef: () => refScroller.current,
|
|
2221
|
-
getScrollableNode: () => refScroller.current.getScrollableNode(),
|
|
2222
|
-
getScrollResponder: () => refScroller.current.getScrollResponder(),
|
|
2223
|
-
getState: () => {
|
|
2224
|
-
const state = refState.current;
|
|
2225
|
-
return state ? {
|
|
2226
|
-
contentLength: state.totalSize,
|
|
2227
|
-
end: state.endNoBuffer,
|
|
2228
|
-
endBuffered: state.endBuffered,
|
|
2229
|
-
isAtEnd: state.isAtEnd,
|
|
2230
|
-
isAtStart: state.isAtStart,
|
|
2231
|
-
scroll: state.scroll,
|
|
2232
|
-
scrollLength: state.scrollLength,
|
|
2233
|
-
start: state.startNoBuffer,
|
|
2234
|
-
startBuffered: state.startBuffered,
|
|
2235
|
-
sizes: state.sizesKnown,
|
|
2236
|
-
sizeAtIndex: (index) => state.sizesKnown.get(getId(index))
|
|
2237
|
-
} : {};
|
|
2238
|
-
},
|
|
2239
|
-
scrollIndexIntoView,
|
|
2240
|
-
scrollItemIntoView: ({ item, ...props2 }) => {
|
|
2241
|
-
const { data } = refState.current;
|
|
2242
|
-
const index = data.indexOf(item);
|
|
2243
|
-
if (index !== -1) {
|
|
2244
|
-
scrollIndexIntoView({ index, ...props2 });
|
|
2245
|
-
}
|
|
2246
|
-
},
|
|
2247
|
-
scrollToIndex,
|
|
2248
|
-
scrollToItem: ({ item, ...props2 }) => {
|
|
2249
|
-
const { data } = refState.current;
|
|
2250
|
-
const index = data.indexOf(item);
|
|
2251
|
-
if (index !== -1) {
|
|
2252
|
-
scrollToIndex({ index, ...props2 });
|
|
2253
|
-
}
|
|
2254
|
-
},
|
|
2255
|
-
scrollToOffset: (params) => scrollTo(params),
|
|
2256
|
-
scrollToEnd: (options) => {
|
|
2257
|
-
const { data, stylePaddingBottom } = refState.current;
|
|
2258
|
-
const index = data.length - 1;
|
|
2259
|
-
if (index !== -1) {
|
|
2260
|
-
const paddingBottom = stylePaddingBottom || 0;
|
|
2261
|
-
const footerSize = peek$(ctx, "footerSize") || 0;
|
|
2262
|
-
scrollToIndex({
|
|
2263
|
-
index,
|
|
2264
|
-
viewPosition: 1,
|
|
2265
|
-
viewOffset: -paddingBottom - footerSize,
|
|
2266
|
-
...options
|
|
2267
|
-
});
|
|
2268
|
-
}
|
|
2269
|
-
},
|
|
2270
|
-
setVisibleContentAnchorOffset: (value) => {
|
|
2271
|
-
const val = typeof value === "function" ? value(peek$(ctx, "scrollAdjustUserOffset") || 0) : value;
|
|
2272
|
-
set$(ctx, "scrollAdjustUserOffset", val);
|
|
2273
|
-
}
|
|
2274
|
-
};
|
|
2275
|
-
},
|
|
2276
|
-
[]
|
|
2277
|
-
);
|
|
2278
2495
|
if (reactNative.Platform.OS === "web") {
|
|
2279
|
-
|
|
2496
|
+
React3.useEffect(() => {
|
|
2280
2497
|
if (initialContentOffset) {
|
|
2281
|
-
scrollTo({
|
|
2498
|
+
scrollTo(state, { animated: false, offset: initialContentOffset });
|
|
2282
2499
|
}
|
|
2283
2500
|
}, []);
|
|
2284
2501
|
}
|
|
2285
|
-
|
|
2502
|
+
const fns = React3.useMemo(
|
|
2503
|
+
() => ({
|
|
2504
|
+
getRenderedItem: (key) => getRenderedItem(ctx, state, key),
|
|
2505
|
+
onScroll: (event) => onScroll(ctx, state, event),
|
|
2506
|
+
updateItemSize: (itemKey, sizeObj) => updateItemSize(ctx, state, itemKey, sizeObj)
|
|
2507
|
+
}),
|
|
2508
|
+
[]
|
|
2509
|
+
);
|
|
2510
|
+
return /* @__PURE__ */ React3__namespace.createElement(React3__namespace.Fragment, null, /* @__PURE__ */ React3__namespace.createElement(
|
|
2286
2511
|
ListComponent,
|
|
2287
2512
|
{
|
|
2288
2513
|
...rest,
|
|
2514
|
+
alignItemsAtEnd,
|
|
2289
2515
|
canRender,
|
|
2516
|
+
contentContainerStyle,
|
|
2517
|
+
getRenderedItem: fns.getRenderedItem,
|
|
2290
2518
|
horizontal,
|
|
2291
|
-
refScrollView: combinedRef,
|
|
2292
2519
|
initialContentOffset,
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2520
|
+
ListEmptyComponent: dataProp.length === 0 ? ListEmptyComponent : void 0,
|
|
2521
|
+
ListHeaderComponent,
|
|
2522
|
+
maintainVisibleContentPosition,
|
|
2523
|
+
onLayout,
|
|
2524
|
+
onLayoutHeader,
|
|
2296
2525
|
onMomentumScrollEnd: (event) => {
|
|
2297
2526
|
requestAnimationFrame(() => {
|
|
2298
|
-
finishScrollTo();
|
|
2527
|
+
finishScrollTo(refState.current);
|
|
2299
2528
|
});
|
|
2300
2529
|
if (onMomentumScrollEnd) {
|
|
2301
2530
|
onMomentumScrollEnd(event);
|
|
2302
2531
|
}
|
|
2303
2532
|
},
|
|
2304
|
-
|
|
2533
|
+
onScroll: fns.onScroll,
|
|
2305
2534
|
recycleItems,
|
|
2306
|
-
|
|
2307
|
-
ListEmptyComponent: dataProp.length === 0 ? ListEmptyComponent : void 0,
|
|
2308
|
-
ListHeaderComponent,
|
|
2309
|
-
maintainVisibleContentPosition,
|
|
2310
|
-
scrollEventThrottle: reactNative.Platform.OS === "web" ? 16 : void 0,
|
|
2311
|
-
waitForInitialLayout,
|
|
2312
|
-
refreshControl: refreshControl ? stylePaddingTopState > 0 ? React2__namespace.cloneElement(refreshControl, {
|
|
2535
|
+
refreshControl: refreshControl ? stylePaddingTopState > 0 ? React3__namespace.cloneElement(refreshControl, {
|
|
2313
2536
|
progressViewOffset: (refreshControl.props.progressViewOffset || 0) + stylePaddingTopState
|
|
2314
|
-
}) : refreshControl : onRefresh && /* @__PURE__ */
|
|
2537
|
+
}) : refreshControl : onRefresh && /* @__PURE__ */ React3__namespace.createElement(
|
|
2315
2538
|
reactNative.RefreshControl,
|
|
2316
2539
|
{
|
|
2317
|
-
refreshing: !!refreshing,
|
|
2318
2540
|
onRefresh,
|
|
2319
|
-
progressViewOffset: (progressViewOffset || 0) + stylePaddingTopState
|
|
2541
|
+
progressViewOffset: (progressViewOffset || 0) + stylePaddingTopState,
|
|
2542
|
+
refreshing: !!refreshing
|
|
2320
2543
|
}
|
|
2321
2544
|
),
|
|
2322
|
-
|
|
2323
|
-
contentContainerStyle,
|
|
2545
|
+
refScrollView: combinedRef,
|
|
2324
2546
|
scrollAdjustHandler: (_a = refState.current) == null ? void 0 : _a.scrollAdjustHandler,
|
|
2325
|
-
|
|
2547
|
+
scrollEventThrottle: reactNative.Platform.OS === "web" ? 16 : void 0,
|
|
2548
|
+
snapToIndices,
|
|
2549
|
+
style,
|
|
2550
|
+
updateItemSize: fns.updateItemSize,
|
|
2551
|
+
waitForInitialLayout
|
|
2326
2552
|
}
|
|
2327
|
-
), __DEV__ && ENABLE_DEBUG_VIEW && /* @__PURE__ */
|
|
2553
|
+
), __DEV__ && ENABLE_DEBUG_VIEW && /* @__PURE__ */ React3__namespace.createElement(DebugView, { state: refState.current }));
|
|
2328
2554
|
});
|
|
2329
|
-
|
|
2555
|
+
|
|
2556
|
+
// src/components/LazyLegendList.tsx
|
|
2557
|
+
var typedForwardRef2 = React3.forwardRef;
|
|
2330
2558
|
var renderItem = ({ item }) => item;
|
|
2331
2559
|
var LazyLegendList = typedForwardRef2(function LazyLegendList2(props, forwardedRef) {
|
|
2332
2560
|
const { LegendList: LegendListProp, children, ...rest } = props;
|
|
2333
2561
|
const LegendListComponent = LegendListProp != null ? LegendListProp : LegendList;
|
|
2334
|
-
const data = (isArray(children) ? children :
|
|
2562
|
+
const data = (isArray(children) ? children : React3__namespace.Children.toArray(children)).flat(1);
|
|
2335
2563
|
return (
|
|
2336
2564
|
// @ts-expect-error TODO: Fix this type
|
|
2337
|
-
/* @__PURE__ */
|
|
2565
|
+
/* @__PURE__ */ React3__namespace.createElement(LegendListComponent, { ...rest, data, ref: forwardedRef, renderItem })
|
|
2338
2566
|
);
|
|
2339
2567
|
});
|
|
2340
2568
|
|