@legendapp/list 1.0.0-beta.11 → 1.0.0-beta.13
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 +46 -4
- package/animated.d.ts +46 -4
- package/index.d.mts +51 -8
- package/index.d.ts +51 -8
- package/index.js +252 -170
- package/index.mjs +218 -136
- package/package.json +3 -6
- package/reanimated.d.mts +4 -4
- package/reanimated.d.ts +4 -4
package/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var React6 = require('react');
|
|
4
4
|
var reactNative = require('react-native');
|
|
5
5
|
|
|
6
6
|
function _interopNamespace(e) {
|
|
@@ -21,12 +21,12 @@ function _interopNamespace(e) {
|
|
|
21
21
|
return Object.freeze(n);
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
var
|
|
24
|
+
var React6__namespace = /*#__PURE__*/_interopNamespace(React6);
|
|
25
25
|
|
|
26
26
|
// src/LegendList.tsx
|
|
27
|
-
var ContextState =
|
|
27
|
+
var ContextState = React6__namespace.createContext(null);
|
|
28
28
|
function StateProvider({ children }) {
|
|
29
|
-
const [value] =
|
|
29
|
+
const [value] = React6__namespace.useState(() => ({
|
|
30
30
|
listeners: /* @__PURE__ */ new Map(),
|
|
31
31
|
values: /* @__PURE__ */ new Map(),
|
|
32
32
|
mapViewabilityCallbacks: /* @__PURE__ */ new Map(),
|
|
@@ -34,10 +34,10 @@ function StateProvider({ children }) {
|
|
|
34
34
|
mapViewabilityAmountCallbacks: /* @__PURE__ */ new Map(),
|
|
35
35
|
mapViewabilityAmountValues: /* @__PURE__ */ new Map()
|
|
36
36
|
}));
|
|
37
|
-
return /* @__PURE__ */
|
|
37
|
+
return /* @__PURE__ */ React6__namespace.createElement(ContextState.Provider, { value }, children);
|
|
38
38
|
}
|
|
39
39
|
function useStateContext() {
|
|
40
|
-
return
|
|
40
|
+
return React6__namespace.useContext(ContextState);
|
|
41
41
|
}
|
|
42
42
|
function createSelectorFunctions(ctx, signalName) {
|
|
43
43
|
return {
|
|
@@ -46,9 +46,9 @@ function createSelectorFunctions(ctx, signalName) {
|
|
|
46
46
|
};
|
|
47
47
|
}
|
|
48
48
|
function use$(signalName) {
|
|
49
|
-
const ctx =
|
|
50
|
-
const { subscribe, get } =
|
|
51
|
-
const value =
|
|
49
|
+
const ctx = React6__namespace.useContext(ContextState);
|
|
50
|
+
const { subscribe, get } = React6__namespace.useMemo(() => createSelectorFunctions(ctx, signalName), []);
|
|
51
|
+
const value = React6.useSyncExternalStore(subscribe, get);
|
|
52
52
|
return value;
|
|
53
53
|
}
|
|
54
54
|
function listen$(ctx, signalName, cb) {
|
|
@@ -79,7 +79,7 @@ function set$(ctx, signalName, value) {
|
|
|
79
79
|
}
|
|
80
80
|
var symbolFirst = Symbol();
|
|
81
81
|
function useInit(cb) {
|
|
82
|
-
const refValue =
|
|
82
|
+
const refValue = React6.useRef(symbolFirst);
|
|
83
83
|
if (refValue.current === symbolFirst) {
|
|
84
84
|
refValue.current = cb();
|
|
85
85
|
}
|
|
@@ -87,10 +87,10 @@ function useInit(cb) {
|
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
// src/ContextContainer.ts
|
|
90
|
-
var ContextContainer =
|
|
90
|
+
var ContextContainer = React6.createContext(null);
|
|
91
91
|
function useViewability(configId, callback) {
|
|
92
92
|
const ctx = useStateContext();
|
|
93
|
-
const { containerId } =
|
|
93
|
+
const { containerId } = React6.useContext(ContextContainer);
|
|
94
94
|
const key = containerId + configId;
|
|
95
95
|
useInit(() => {
|
|
96
96
|
const value = ctx.mapViewabilityValues.get(key);
|
|
@@ -99,7 +99,7 @@ function useViewability(configId, callback) {
|
|
|
99
99
|
}
|
|
100
100
|
});
|
|
101
101
|
ctx.mapViewabilityCallbacks.set(key, callback);
|
|
102
|
-
|
|
102
|
+
React6.useEffect(
|
|
103
103
|
() => () => {
|
|
104
104
|
ctx.mapViewabilityCallbacks.delete(key);
|
|
105
105
|
},
|
|
@@ -108,7 +108,7 @@ function useViewability(configId, callback) {
|
|
|
108
108
|
}
|
|
109
109
|
function useViewabilityAmount(callback) {
|
|
110
110
|
const ctx = useStateContext();
|
|
111
|
-
const { containerId } =
|
|
111
|
+
const { containerId } = React6.useContext(ContextContainer);
|
|
112
112
|
useInit(() => {
|
|
113
113
|
const value = ctx.mapViewabilityAmountValues.get(containerId);
|
|
114
114
|
if (value) {
|
|
@@ -116,7 +116,7 @@ function useViewabilityAmount(callback) {
|
|
|
116
116
|
}
|
|
117
117
|
});
|
|
118
118
|
ctx.mapViewabilityAmountCallbacks.set(containerId, callback);
|
|
119
|
-
|
|
119
|
+
React6.useEffect(
|
|
120
120
|
() => () => {
|
|
121
121
|
ctx.mapViewabilityAmountCallbacks.delete(containerId);
|
|
122
122
|
},
|
|
@@ -124,12 +124,12 @@ function useViewabilityAmount(callback) {
|
|
|
124
124
|
);
|
|
125
125
|
}
|
|
126
126
|
function useRecyclingEffect(effect) {
|
|
127
|
-
const { index, value } =
|
|
128
|
-
const prevValues =
|
|
127
|
+
const { index, value } = React6.useContext(ContextContainer);
|
|
128
|
+
const prevValues = React6.useRef({
|
|
129
129
|
prevIndex: void 0,
|
|
130
130
|
prevItem: void 0
|
|
131
131
|
});
|
|
132
|
-
|
|
132
|
+
React6.useEffect(() => {
|
|
133
133
|
let ret = void 0;
|
|
134
134
|
if (prevValues.current.prevIndex !== void 0 && prevValues.current.prevItem !== void 0) {
|
|
135
135
|
ret = effect({
|
|
@@ -147,8 +147,8 @@ function useRecyclingEffect(effect) {
|
|
|
147
147
|
}, [index, value]);
|
|
148
148
|
}
|
|
149
149
|
function useRecyclingState(valueOrFun) {
|
|
150
|
-
const { index, value } =
|
|
151
|
-
const stateInfo =
|
|
150
|
+
const { index, value } = React6.useContext(ContextContainer);
|
|
151
|
+
const stateInfo = React6.useState(
|
|
152
152
|
() => typeof valueOrFun === "function" ? valueOrFun({
|
|
153
153
|
index,
|
|
154
154
|
item: value,
|
|
@@ -162,10 +162,40 @@ function useRecyclingState(valueOrFun) {
|
|
|
162
162
|
});
|
|
163
163
|
return stateInfo;
|
|
164
164
|
}
|
|
165
|
-
var
|
|
166
|
-
|
|
165
|
+
var DebugView = React6.memo(function DebugView2({ state }) {
|
|
166
|
+
const paddingTop = use$("paddingTop");
|
|
167
|
+
const [, forceUpdate] = React6.useReducer((x) => x + 1, 0);
|
|
168
|
+
useInterval(() => {
|
|
169
|
+
forceUpdate();
|
|
170
|
+
}, 100);
|
|
171
|
+
return /* @__PURE__ */ React.createElement(
|
|
172
|
+
reactNative.View,
|
|
173
|
+
{
|
|
174
|
+
style: {
|
|
175
|
+
position: "absolute",
|
|
176
|
+
top: 0,
|
|
177
|
+
right: 0,
|
|
178
|
+
paddingLeft: 4,
|
|
179
|
+
paddingBottom: 4,
|
|
180
|
+
// height: 100,
|
|
181
|
+
backgroundColor: "#FFFFFFCC"
|
|
182
|
+
}
|
|
183
|
+
},
|
|
184
|
+
/* @__PURE__ */ React.createElement(reactNative.Text, null, "PaddingTop: ", paddingTop),
|
|
185
|
+
/* @__PURE__ */ React.createElement(reactNative.Text, null, "At end: ", String(state.isAtBottom))
|
|
186
|
+
);
|
|
187
|
+
});
|
|
188
|
+
function useInterval(callback, delay) {
|
|
189
|
+
React6.useEffect(() => {
|
|
190
|
+
const interval = setInterval(callback, delay);
|
|
191
|
+
return () => clearInterval(interval);
|
|
192
|
+
}, [delay]);
|
|
193
|
+
}
|
|
194
|
+
var LeanViewComponent = React6__namespace.forwardRef((props, ref) => {
|
|
195
|
+
return React6__namespace.createElement("RCTView", { ...props, ref });
|
|
167
196
|
});
|
|
168
|
-
|
|
197
|
+
LeanViewComponent.displayName = "RCTView";
|
|
198
|
+
var LeanView = reactNative.Platform.OS === "android" || reactNative.Platform.OS === "ios" ? LeanViewComponent : reactNative.View;
|
|
169
199
|
|
|
170
200
|
// src/constants.ts
|
|
171
201
|
var POSITION_OUT_OF_VIEW = -1e7;
|
|
@@ -174,6 +204,8 @@ var ANCHORED_POSITION_OUT_OF_VIEW = {
|
|
|
174
204
|
relativeCoordinate: POSITION_OUT_OF_VIEW,
|
|
175
205
|
top: POSITION_OUT_OF_VIEW
|
|
176
206
|
};
|
|
207
|
+
var ENABLE_DEVMODE = __DEV__ && false;
|
|
208
|
+
var ENABLE_DEBUG_VIEW = __DEV__ && false;
|
|
177
209
|
|
|
178
210
|
// src/Container.tsx
|
|
179
211
|
var isNewArchitecture = global.nativeFabricUIManager != null;
|
|
@@ -185,7 +217,6 @@ var Container = ({
|
|
|
185
217
|
updateItemSize,
|
|
186
218
|
ItemSeparatorComponent
|
|
187
219
|
}) => {
|
|
188
|
-
useStateContext();
|
|
189
220
|
const maintainVisibleContentPosition = use$("maintainVisibleContentPosition");
|
|
190
221
|
const position = use$(`containerPosition${id}`) || ANCHORED_POSITION_OUT_OF_VIEW;
|
|
191
222
|
const column = use$(`containerColumn${id}`) || 0;
|
|
@@ -210,7 +241,7 @@ var Container = ({
|
|
|
210
241
|
const itemKey = use$(`containerItemKey${id}`);
|
|
211
242
|
const data = use$(`containerItemData${id}`);
|
|
212
243
|
const extraData = use$("extraData");
|
|
213
|
-
const renderedItemInfo =
|
|
244
|
+
const renderedItemInfo = React6.useMemo(
|
|
214
245
|
() => itemKey !== void 0 && getRenderedItem(itemKey),
|
|
215
246
|
[itemKey, data, extraData]
|
|
216
247
|
);
|
|
@@ -225,9 +256,9 @@ var Container = ({
|
|
|
225
256
|
updateItemSize(id, itemKey, size);
|
|
226
257
|
}
|
|
227
258
|
};
|
|
228
|
-
const ref =
|
|
259
|
+
const ref = React6.useRef(null);
|
|
229
260
|
if (isNewArchitecture) {
|
|
230
|
-
|
|
261
|
+
React6.useLayoutEffect(() => {
|
|
231
262
|
var _a, _b;
|
|
232
263
|
if (itemKey !== void 0) {
|
|
233
264
|
const measured = (_b = (_a = ref.current) == null ? void 0 : _a.unstable_getBoundingClientRect) == null ? void 0 : _b.call(_a);
|
|
@@ -240,25 +271,31 @@ var Container = ({
|
|
|
240
271
|
}
|
|
241
272
|
}, [itemKey]);
|
|
242
273
|
}
|
|
243
|
-
const contextValue =
|
|
274
|
+
const contextValue = React6.useMemo(
|
|
244
275
|
() => ({ containerId: id, itemKey, index, value: data }),
|
|
245
276
|
[id, itemKey, index, data]
|
|
246
277
|
);
|
|
247
|
-
const contentFragment = /* @__PURE__ */
|
|
278
|
+
const contentFragment = /* @__PURE__ */ React6__namespace.default.createElement(React6__namespace.default.Fragment, { key: recycleItems ? void 0 : itemKey }, /* @__PURE__ */ React6__namespace.default.createElement(ContextContainer.Provider, { value: contextValue }, renderedItem, renderedItem && ItemSeparatorComponent && itemKey !== lastItemKey && ItemSeparatorComponent));
|
|
248
279
|
if (maintainVisibleContentPosition) {
|
|
249
280
|
const anchorStyle = position.type === "top" ? { position: "absolute", top: 0, left: 0, right: 0 } : { position: "absolute", bottom: 0, left: 0, right: 0 };
|
|
250
|
-
|
|
281
|
+
if (ENABLE_DEVMODE) {
|
|
282
|
+
anchorStyle.borderColor = position.type === "top" ? "red" : "blue";
|
|
283
|
+
anchorStyle.borderWidth = 1;
|
|
284
|
+
}
|
|
285
|
+
return /* @__PURE__ */ React6__namespace.default.createElement(LeanView, { style }, /* @__PURE__ */ React6__namespace.default.createElement(LeanView, { style: anchorStyle, onLayout, ref }, contentFragment, ENABLE_DEVMODE && /* @__PURE__ */ React6__namespace.default.createElement(reactNative.Text, { style: { position: "absolute", top: 0, left: 0, zIndex: 1e3 } }, position.top)));
|
|
251
286
|
}
|
|
252
|
-
return /* @__PURE__ */
|
|
287
|
+
return /* @__PURE__ */ React6__namespace.default.createElement(LeanView, { style, onLayout, ref }, contentFragment);
|
|
253
288
|
};
|
|
254
289
|
var useAnimatedValue = reactNative.useAnimatedValue || ((initialValue) => {
|
|
255
|
-
return
|
|
290
|
+
return React6.useRef(new reactNative.Animated.Value(initialValue)).current;
|
|
256
291
|
});
|
|
292
|
+
|
|
293
|
+
// src/useValue$.ts
|
|
257
294
|
function useValue$(key, getValue, useMicrotask) {
|
|
258
295
|
var _a;
|
|
259
296
|
const ctx = useStateContext();
|
|
260
297
|
const animValue = useAnimatedValue((_a = getValue ? getValue(peek$(ctx, key)) : peek$(ctx, key)) != null ? _a : 0);
|
|
261
|
-
|
|
298
|
+
React6.useMemo(() => {
|
|
262
299
|
let newValue = void 0;
|
|
263
300
|
listen$(ctx, key, (v) => {
|
|
264
301
|
if (useMicrotask && newValue === void 0) {
|
|
@@ -277,7 +314,7 @@ function useValue$(key, getValue, useMicrotask) {
|
|
|
277
314
|
}
|
|
278
315
|
|
|
279
316
|
// src/Containers.tsx
|
|
280
|
-
var Containers =
|
|
317
|
+
var Containers = React6__namespace.memo(function Containers2({
|
|
281
318
|
horizontal,
|
|
282
319
|
recycleItems,
|
|
283
320
|
ItemSeparatorComponent,
|
|
@@ -296,7 +333,7 @@ var Containers = React5__namespace.memo(function Containers2({
|
|
|
296
333
|
const containers = [];
|
|
297
334
|
for (let i = 0; i < numContainers; i++) {
|
|
298
335
|
containers.push(
|
|
299
|
-
/* @__PURE__ */
|
|
336
|
+
/* @__PURE__ */ React6__namespace.createElement(
|
|
300
337
|
Container,
|
|
301
338
|
{
|
|
302
339
|
id: i,
|
|
@@ -311,20 +348,71 @@ var Containers = React5__namespace.memo(function Containers2({
|
|
|
311
348
|
);
|
|
312
349
|
}
|
|
313
350
|
const style = horizontal ? { width: animSize, opacity: animOpacity } : { height: animSize, opacity: animOpacity };
|
|
314
|
-
return /* @__PURE__ */
|
|
351
|
+
return /* @__PURE__ */ React6__namespace.createElement(reactNative.Animated.View, { style }, containers);
|
|
315
352
|
});
|
|
316
353
|
|
|
317
354
|
// src/ListComponent.tsx
|
|
318
355
|
var getComponent = (Component) => {
|
|
319
|
-
if (
|
|
356
|
+
if (React6__namespace.isValidElement(Component)) {
|
|
320
357
|
return Component;
|
|
321
358
|
}
|
|
322
359
|
if (Component) {
|
|
323
|
-
return /* @__PURE__ */
|
|
360
|
+
return /* @__PURE__ */ React6__namespace.createElement(Component, null);
|
|
324
361
|
}
|
|
325
362
|
return null;
|
|
326
363
|
};
|
|
327
|
-
var
|
|
364
|
+
var PaddingAndAdjust = () => {
|
|
365
|
+
const animPaddingTop = useValue$("paddingTop", (v) => v, true);
|
|
366
|
+
const animScrollAdjust = useValue$("scrollAdjust", (v) => v, true);
|
|
367
|
+
const additionalSize = { marginTop: animScrollAdjust, paddingTop: animPaddingTop };
|
|
368
|
+
return /* @__PURE__ */ React6__namespace.createElement(reactNative.Animated.View, { style: additionalSize });
|
|
369
|
+
};
|
|
370
|
+
var PaddingAndAdjustDevMode = () => {
|
|
371
|
+
const animPaddingTop = useValue$("paddingTop", (v) => v, true);
|
|
372
|
+
const animScrollAdjust = useValue$("scrollAdjust", (v) => v, true);
|
|
373
|
+
return /* @__PURE__ */ React6__namespace.createElement(React6__namespace.Fragment, null, /* @__PURE__ */ React6__namespace.createElement(reactNative.Animated.View, { style: { marginTop: animScrollAdjust } }), /* @__PURE__ */ React6__namespace.createElement(reactNative.Animated.View, { style: { paddingTop: animPaddingTop } }), /* @__PURE__ */ React6__namespace.createElement(
|
|
374
|
+
reactNative.Animated.View,
|
|
375
|
+
{
|
|
376
|
+
style: {
|
|
377
|
+
position: "absolute",
|
|
378
|
+
top: reactNative.Animated.add(animScrollAdjust, reactNative.Animated.multiply(animScrollAdjust, -1)),
|
|
379
|
+
height: animPaddingTop,
|
|
380
|
+
left: 0,
|
|
381
|
+
right: 0,
|
|
382
|
+
backgroundColor: "green"
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
), /* @__PURE__ */ React6__namespace.createElement(
|
|
386
|
+
reactNative.Animated.View,
|
|
387
|
+
{
|
|
388
|
+
style: {
|
|
389
|
+
position: "absolute",
|
|
390
|
+
top: animPaddingTop,
|
|
391
|
+
height: animScrollAdjust,
|
|
392
|
+
left: -16,
|
|
393
|
+
right: -16,
|
|
394
|
+
backgroundColor: "lightblue"
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
), /* @__PURE__ */ React6__namespace.createElement(
|
|
398
|
+
reactNative.Animated.View,
|
|
399
|
+
{
|
|
400
|
+
style: {
|
|
401
|
+
position: "absolute",
|
|
402
|
+
top: animPaddingTop,
|
|
403
|
+
height: reactNative.Animated.multiply(animScrollAdjust, -1),
|
|
404
|
+
width: 8,
|
|
405
|
+
right: 4,
|
|
406
|
+
borderStyle: "dashed",
|
|
407
|
+
borderColor: "blue",
|
|
408
|
+
borderWidth: 1,
|
|
409
|
+
backgroundColor: "lightblue"
|
|
410
|
+
//backgroundColor: "blue",
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
));
|
|
414
|
+
};
|
|
415
|
+
var ListComponent = React6__namespace.memo(function ListComponent2({
|
|
328
416
|
style,
|
|
329
417
|
contentContainerStyle,
|
|
330
418
|
horizontal,
|
|
@@ -348,14 +436,11 @@ var ListComponent = React5__namespace.memo(function ListComponent2({
|
|
|
348
436
|
...rest
|
|
349
437
|
}) {
|
|
350
438
|
const ctx = useStateContext();
|
|
351
|
-
const
|
|
352
|
-
|
|
353
|
-
const ScrollComponent = renderScrollComponent ? React5.useMemo(
|
|
354
|
-
() => React5__namespace.forwardRef((props, ref) => renderScrollComponent({ ...props, ref })),
|
|
439
|
+
const ScrollComponent = renderScrollComponent ? React6.useMemo(
|
|
440
|
+
() => React6__namespace.forwardRef((props, ref) => renderScrollComponent({ ...props, ref })),
|
|
355
441
|
[renderScrollComponent]
|
|
356
442
|
) : reactNative.ScrollView;
|
|
357
|
-
|
|
358
|
-
return /* @__PURE__ */ React5__namespace.createElement(
|
|
443
|
+
return /* @__PURE__ */ React6__namespace.createElement(
|
|
359
444
|
ScrollComponent,
|
|
360
445
|
{
|
|
361
446
|
...rest,
|
|
@@ -373,8 +458,8 @@ var ListComponent = React5__namespace.memo(function ListComponent2({
|
|
|
373
458
|
contentOffset: initialContentOffset ? horizontal ? { x: initialContentOffset, y: 0 } : { x: 0, y: initialContentOffset } : void 0,
|
|
374
459
|
ref: refScrollView
|
|
375
460
|
},
|
|
376
|
-
/* @__PURE__ */
|
|
377
|
-
ListHeaderComponent && /* @__PURE__ */
|
|
461
|
+
ENABLE_DEVMODE ? /* @__PURE__ */ React6__namespace.createElement(PaddingAndAdjustDevMode, null) : /* @__PURE__ */ React6__namespace.createElement(PaddingAndAdjust, null),
|
|
462
|
+
ListHeaderComponent && /* @__PURE__ */ React6__namespace.createElement(
|
|
378
463
|
reactNative.Animated.View,
|
|
379
464
|
{
|
|
380
465
|
style: ListHeaderComponentStyle,
|
|
@@ -389,7 +474,7 @@ var ListComponent = React5__namespace.memo(function ListComponent2({
|
|
|
389
474
|
getComponent(ListHeaderComponent)
|
|
390
475
|
),
|
|
391
476
|
ListEmptyComponent && getComponent(ListEmptyComponent),
|
|
392
|
-
/* @__PURE__ */
|
|
477
|
+
/* @__PURE__ */ React6__namespace.createElement(
|
|
393
478
|
Containers,
|
|
394
479
|
{
|
|
395
480
|
horizontal,
|
|
@@ -400,7 +485,7 @@ var ListComponent = React5__namespace.memo(function ListComponent2({
|
|
|
400
485
|
updateItemSize
|
|
401
486
|
}
|
|
402
487
|
),
|
|
403
|
-
ListFooterComponent && /* @__PURE__ */
|
|
488
|
+
ListFooterComponent && /* @__PURE__ */ React6__namespace.createElement(reactNative.View, { style: ListFooterComponentStyle }, getComponent(ListFooterComponent))
|
|
404
489
|
);
|
|
405
490
|
});
|
|
406
491
|
|
|
@@ -411,7 +496,6 @@ var ScrollAdjustHandler = class {
|
|
|
411
496
|
this.appliedAdjust = 0;
|
|
412
497
|
this.pendingAdjust = 0;
|
|
413
498
|
this.busy = false;
|
|
414
|
-
this.firstAdjust = true;
|
|
415
499
|
this.context = ctx;
|
|
416
500
|
}
|
|
417
501
|
requestAdjust(adjust, onAdjusted) {
|
|
@@ -428,20 +512,16 @@ var ScrollAdjustHandler = class {
|
|
|
428
512
|
};
|
|
429
513
|
if (!this.busy) {
|
|
430
514
|
this.busy = true;
|
|
431
|
-
|
|
432
|
-
this.firstAdjust = false;
|
|
433
|
-
setTimeout(doAjdust, 50);
|
|
434
|
-
} else {
|
|
435
|
-
doAjdust();
|
|
436
|
-
}
|
|
515
|
+
doAjdust();
|
|
437
516
|
}
|
|
438
517
|
}
|
|
439
518
|
getAppliedAdjust() {
|
|
440
519
|
return this.appliedAdjust;
|
|
441
520
|
}
|
|
442
521
|
};
|
|
522
|
+
var typedForwardRef = React6.forwardRef;
|
|
443
523
|
var useCombinedRef = (...refs) => {
|
|
444
|
-
const callback =
|
|
524
|
+
const callback = React6.useCallback((element) => {
|
|
445
525
|
for (const ref of refs) {
|
|
446
526
|
if (!ref) {
|
|
447
527
|
continue;
|
|
@@ -606,13 +686,13 @@ function maybeUpdateViewabilityCallback(ctx, configId, viewToken) {
|
|
|
606
686
|
// src/LegendList.tsx
|
|
607
687
|
var DEFAULT_DRAW_DISTANCE = 250;
|
|
608
688
|
var DEFAULT_ITEM_SIZE = 100;
|
|
609
|
-
var LegendList =
|
|
610
|
-
return /* @__PURE__ */
|
|
689
|
+
var LegendList = typedForwardRef(function LegendList2(props, forwardedRef) {
|
|
690
|
+
return /* @__PURE__ */ React6__namespace.createElement(StateProvider, null, /* @__PURE__ */ React6__namespace.createElement(LegendListInner, { ...props, ref: forwardedRef }));
|
|
611
691
|
});
|
|
612
|
-
var LegendListInner =
|
|
692
|
+
var LegendListInner = typedForwardRef(function LegendListInner2(props, forwardedRef) {
|
|
613
693
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
614
694
|
const {
|
|
615
|
-
data,
|
|
695
|
+
data: dataProp,
|
|
616
696
|
initialScrollIndex,
|
|
617
697
|
initialScrollOffset,
|
|
618
698
|
horizontal,
|
|
@@ -640,38 +720,39 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
|
|
|
640
720
|
...rest
|
|
641
721
|
} = props;
|
|
642
722
|
const { style, contentContainerStyle } = props;
|
|
643
|
-
const callbacks =
|
|
723
|
+
const callbacks = React6.useRef({
|
|
644
724
|
onStartReached: rest.onStartReached,
|
|
645
725
|
onEndReached: rest.onEndReached
|
|
646
726
|
});
|
|
647
727
|
callbacks.current.onStartReached = rest.onStartReached;
|
|
648
728
|
callbacks.current.onEndReached = rest.onEndReached;
|
|
649
729
|
const ctx = useStateContext();
|
|
650
|
-
const refScroller =
|
|
730
|
+
const refScroller = React6.useRef(null);
|
|
651
731
|
const combinedRef = useCombinedRef(refScroller, refScrollView);
|
|
652
732
|
const scrollBuffer = drawDistance != null ? drawDistance : DEFAULT_DRAW_DISTANCE;
|
|
653
733
|
const keyExtractor = keyExtractorProp != null ? keyExtractorProp : (item, index) => index.toString();
|
|
654
|
-
const refState =
|
|
734
|
+
const refState = React6.useRef();
|
|
655
735
|
const getId = (index) => {
|
|
656
736
|
var _a2;
|
|
657
|
-
const
|
|
658
|
-
if (!
|
|
737
|
+
const data = (_a2 = refState.current) == null ? void 0 : _a2.data;
|
|
738
|
+
if (!data) {
|
|
659
739
|
return "";
|
|
660
740
|
}
|
|
661
|
-
const ret = index <
|
|
741
|
+
const ret = index < data.length ? keyExtractor ? keyExtractor(data[index], index) : index : null;
|
|
662
742
|
return `${ret}`;
|
|
663
743
|
};
|
|
664
|
-
const getItemSize = (key, index,
|
|
744
|
+
const getItemSize = (key, index, data) => {
|
|
665
745
|
var _a2;
|
|
666
746
|
const sizeKnown = refState.current.sizes.get(key);
|
|
667
747
|
if (sizeKnown !== void 0) {
|
|
668
748
|
return sizeKnown;
|
|
669
749
|
}
|
|
670
|
-
const size = (_a2 = getEstimatedItemSize ? getEstimatedItemSize(index,
|
|
750
|
+
const size = (_a2 = getEstimatedItemSize ? getEstimatedItemSize(index, data) : estimatedItemSize) != null ? _a2 : DEFAULT_ITEM_SIZE;
|
|
671
751
|
refState.current.sizes.set(key, size);
|
|
672
752
|
return size;
|
|
673
753
|
};
|
|
674
754
|
const calculateInitialOffset = (index = initialScrollIndex) => {
|
|
755
|
+
const data = dataProp;
|
|
675
756
|
if (index) {
|
|
676
757
|
let offset = 0;
|
|
677
758
|
if (getEstimatedItemSize) {
|
|
@@ -685,7 +766,7 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
|
|
|
685
766
|
}
|
|
686
767
|
return 0;
|
|
687
768
|
};
|
|
688
|
-
const initialContentOffset = initialScrollOffset != null ? initialScrollOffset :
|
|
769
|
+
const initialContentOffset = initialScrollOffset != null ? initialScrollOffset : React6.useMemo(calculateInitialOffset, []);
|
|
689
770
|
if (!refState.current) {
|
|
690
771
|
const initialScrollLength = reactNative.Dimensions.get("window")[horizontal ? "width" : "height"];
|
|
691
772
|
refState.current = {
|
|
@@ -698,7 +779,7 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
|
|
|
698
779
|
isEndReached: false,
|
|
699
780
|
isAtBottom: false,
|
|
700
781
|
isAtTop: false,
|
|
701
|
-
data,
|
|
782
|
+
data: dataProp,
|
|
702
783
|
idsInFirstRender: void 0,
|
|
703
784
|
hasScrolled: false,
|
|
704
785
|
scrollLength: initialScrollLength,
|
|
@@ -730,14 +811,14 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
|
|
|
730
811
|
enableScrollForNextCalculateItemsInView: true,
|
|
731
812
|
minIndexSizeChanged: 0
|
|
732
813
|
};
|
|
733
|
-
refState.current.idsInFirstRender = new Set(
|
|
814
|
+
refState.current.idsInFirstRender = new Set(dataProp.map((_, i) => getId(i)));
|
|
734
815
|
if (maintainVisibleContentPosition) {
|
|
735
816
|
if (initialScrollIndex) {
|
|
736
817
|
refState.current.anchorElement = {
|
|
737
818
|
coordinate: initialContentOffset,
|
|
738
819
|
id: getId(initialScrollIndex)
|
|
739
820
|
};
|
|
740
|
-
} else if (
|
|
821
|
+
} else if (dataProp.length) {
|
|
741
822
|
refState.current.anchorElement = {
|
|
742
823
|
coordinate: initialContentOffset,
|
|
743
824
|
id: getId(0)
|
|
@@ -758,9 +839,9 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
|
|
|
758
839
|
}
|
|
759
840
|
return void 0;
|
|
760
841
|
};
|
|
761
|
-
const addTotalSize =
|
|
842
|
+
const addTotalSize = React6.useCallback((key, add, totalSizeBelowAnchor) => {
|
|
762
843
|
const state = refState.current;
|
|
763
|
-
const {
|
|
844
|
+
const { indexByKey, anchorElement } = state;
|
|
764
845
|
const index = key === null ? 0 : indexByKey.get(key);
|
|
765
846
|
let isAboveAnchor = false;
|
|
766
847
|
if (maintainVisibleContentPosition) {
|
|
@@ -777,10 +858,9 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
|
|
|
777
858
|
state.totalSizeBelowAnchor += add;
|
|
778
859
|
}
|
|
779
860
|
}
|
|
780
|
-
let applyAdjustValue =
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
if (maintainVisibleContentPosition) {
|
|
861
|
+
let applyAdjustValue = 0;
|
|
862
|
+
let resultSize = state.totalSize;
|
|
863
|
+
if (maintainVisibleContentPosition && anchorElement !== void 0) {
|
|
784
864
|
const newAdjust = anchorElement.coordinate - state.totalSizeBelowAnchor;
|
|
785
865
|
applyAdjustValue = -newAdjust;
|
|
786
866
|
state.belowAnchorElementPositions = buildElementPositionsBelowAnchor();
|
|
@@ -798,7 +878,7 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
|
|
|
798
878
|
}
|
|
799
879
|
}, []);
|
|
800
880
|
const getRowHeight = (n) => {
|
|
801
|
-
const { rowHeights } = refState.current;
|
|
881
|
+
const { rowHeights, data } = refState.current;
|
|
802
882
|
if (numColumnsProp === 1) {
|
|
803
883
|
const id = getId(n);
|
|
804
884
|
return getItemSize(id, n, data[n]);
|
|
@@ -848,10 +928,10 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
|
|
|
848
928
|
}
|
|
849
929
|
return res;
|
|
850
930
|
};
|
|
851
|
-
const calculateItemsInView =
|
|
931
|
+
const calculateItemsInView = React6.useCallback((speed) => {
|
|
852
932
|
const state = refState.current;
|
|
853
933
|
const {
|
|
854
|
-
data
|
|
934
|
+
data,
|
|
855
935
|
scrollLength,
|
|
856
936
|
scroll: scrollState,
|
|
857
937
|
startBufferedId: startBufferedIdOrig,
|
|
@@ -862,7 +942,7 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
|
|
|
862
942
|
if (state.waitingForMicrotask) {
|
|
863
943
|
state.waitingForMicrotask = false;
|
|
864
944
|
}
|
|
865
|
-
if (!
|
|
945
|
+
if (!data) {
|
|
866
946
|
return;
|
|
867
947
|
}
|
|
868
948
|
const topPad = (peek$(ctx, "stylePaddingTop") || 0) + (peek$(ctx, "headerSize") || 0);
|
|
@@ -908,7 +988,7 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
|
|
|
908
988
|
}
|
|
909
989
|
const top2 = newPosition || positions.get(id);
|
|
910
990
|
if (top2 !== void 0) {
|
|
911
|
-
const size = getItemSize(id, i,
|
|
991
|
+
const size = getItemSize(id, i, data[i]);
|
|
912
992
|
const bottom = top2 + size;
|
|
913
993
|
if (bottom > scroll - scrollBuffer) {
|
|
914
994
|
loopStart = i;
|
|
@@ -937,9 +1017,9 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
|
|
|
937
1017
|
}
|
|
938
1018
|
return topOffset;
|
|
939
1019
|
};
|
|
940
|
-
for (let i = loopStart; i <
|
|
1020
|
+
for (let i = loopStart; i < data.length; i++) {
|
|
941
1021
|
const id = getId(i);
|
|
942
|
-
const size = getItemSize(id, i,
|
|
1022
|
+
const size = getItemSize(id, i, data[i]);
|
|
943
1023
|
maxSizeInRow = Math.max(maxSizeInRow, size);
|
|
944
1024
|
if (top === void 0) {
|
|
945
1025
|
top = getInitialTop(i);
|
|
@@ -1027,13 +1107,13 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
|
|
|
1027
1107
|
if (furthestIndex >= 0) {
|
|
1028
1108
|
set$(ctx, `containerItemKey${furthestIndex}`, id);
|
|
1029
1109
|
const index = state.indexByKey.get(id);
|
|
1030
|
-
set$(ctx, `containerItemData${furthestIndex}`,
|
|
1110
|
+
set$(ctx, `containerItemData${furthestIndex}`, data[index]);
|
|
1031
1111
|
} else {
|
|
1032
1112
|
const containerId = numContainers;
|
|
1033
1113
|
numContainers++;
|
|
1034
1114
|
set$(ctx, `containerItemKey${containerId}`, id);
|
|
1035
1115
|
const index = state.indexByKey.get(id);
|
|
1036
|
-
set$(ctx, `containerItemData${containerId}`,
|
|
1116
|
+
set$(ctx, `containerItemData${containerId}`, data[index]);
|
|
1037
1117
|
set$(ctx, `containerPosition${containerId}`, ANCHORED_POSITION_OUT_OF_VIEW);
|
|
1038
1118
|
set$(ctx, `containerColumn${containerId}`, -1);
|
|
1039
1119
|
if (__DEV__ && numContainers > peek$(ctx, "numContainersPooled")) {
|
|
@@ -1054,13 +1134,13 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
|
|
|
1054
1134
|
for (let i = 0; i < numContainers; i++) {
|
|
1055
1135
|
const itemKey = peek$(ctx, `containerItemKey${i}`);
|
|
1056
1136
|
const itemIndex = state.indexByKey.get(itemKey);
|
|
1057
|
-
const item =
|
|
1137
|
+
const item = data[itemIndex];
|
|
1058
1138
|
if (item) {
|
|
1059
1139
|
const id = getId(itemIndex);
|
|
1060
1140
|
if (itemKey !== id || itemIndex < startBuffered || itemIndex > endBuffered) {
|
|
1061
1141
|
const prevPos = peek$(ctx, `containerPosition${i}`).top;
|
|
1062
1142
|
const pos = positions.get(id) || 0;
|
|
1063
|
-
const size = getItemSize(id, itemIndex,
|
|
1143
|
+
const size = getItemSize(id, itemIndex, data[i]);
|
|
1064
1144
|
if (pos + size >= scroll && pos <= scrollBottom || prevPos + size >= scroll && prevPos <= scrollBottom) {
|
|
1065
1145
|
set$(ctx, `containerPosition${i}`, ANCHORED_POSITION_OUT_OF_VIEW);
|
|
1066
1146
|
}
|
|
@@ -1074,7 +1154,7 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
|
|
|
1074
1154
|
if (maintainVisibleContentPosition && itemIndex < anchorElementIndex) {
|
|
1075
1155
|
const currentRow = Math.floor(itemIndex / numColumnsProp);
|
|
1076
1156
|
const rowHeight = getRowHeight(currentRow);
|
|
1077
|
-
const elementHeight = getItemSize(id, itemIndex,
|
|
1157
|
+
const elementHeight = getItemSize(id, itemIndex, data[i]);
|
|
1078
1158
|
const diff = rowHeight - elementHeight;
|
|
1079
1159
|
pos.relativeCoordinate = pos.top + getRowHeight(currentRow) - diff;
|
|
1080
1160
|
pos.type = "bottom";
|
|
@@ -1089,7 +1169,7 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
|
|
|
1089
1169
|
set$(ctx, `containerColumn${i}`, column2);
|
|
1090
1170
|
}
|
|
1091
1171
|
if (prevData !== item) {
|
|
1092
|
-
set$(ctx, `containerItemData${i}`,
|
|
1172
|
+
set$(ctx, `containerItemData${i}`, data[itemIndex]);
|
|
1093
1173
|
}
|
|
1094
1174
|
}
|
|
1095
1175
|
}
|
|
@@ -1119,7 +1199,10 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
|
|
|
1119
1199
|
const doMaintainScrollAtEnd = (animated) => {
|
|
1120
1200
|
const state = refState.current;
|
|
1121
1201
|
if ((state == null ? void 0 : state.isAtBottom) && maintainScrollAtEnd) {
|
|
1122
|
-
|
|
1202
|
+
const paddingTop = peek$(ctx, "paddingTop") || 0;
|
|
1203
|
+
if (paddingTop > 0) {
|
|
1204
|
+
state.scroll = 0;
|
|
1205
|
+
}
|
|
1123
1206
|
requestAnimationFrame(() => {
|
|
1124
1207
|
var _a2;
|
|
1125
1208
|
(_a2 = refScroller.current) == null ? void 0 : _a2.scrollToEnd({
|
|
@@ -1135,21 +1218,19 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
|
|
|
1135
1218
|
}
|
|
1136
1219
|
const { scrollLength, scroll, totalSize } = refState.current;
|
|
1137
1220
|
if (totalSize > 0) {
|
|
1138
|
-
const distanceFromEnd = totalSize - scroll - scrollLength;
|
|
1221
|
+
const distanceFromEnd = totalSize - scroll - scrollLength + (peek$(ctx, "paddingTop") || 0);
|
|
1139
1222
|
if (refState.current) {
|
|
1140
1223
|
refState.current.isAtBottom = distanceFromEnd < scrollLength * maintainScrollAtEndThreshold;
|
|
1141
1224
|
}
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
refState.current.isEndReached = false;
|
|
1152
|
-
}
|
|
1225
|
+
if (!refState.current.isEndReached) {
|
|
1226
|
+
if (distanceFromEnd < onEndReachedThreshold * scrollLength) {
|
|
1227
|
+
refState.current.isEndReached = true;
|
|
1228
|
+
const { onEndReached } = callbacks.current;
|
|
1229
|
+
onEndReached == null ? void 0 : onEndReached({ distanceFromEnd });
|
|
1230
|
+
}
|
|
1231
|
+
} else {
|
|
1232
|
+
if (distanceFromEnd >= onEndReachedThreshold * scrollLength) {
|
|
1233
|
+
refState.current.isEndReached = false;
|
|
1153
1234
|
}
|
|
1154
1235
|
}
|
|
1155
1236
|
}
|
|
@@ -1161,29 +1242,27 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
|
|
|
1161
1242
|
const { scrollLength, scroll } = refState.current;
|
|
1162
1243
|
const distanceFromTop = scroll;
|
|
1163
1244
|
refState.current.isAtTop = distanceFromTop < 0;
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
refState.current.isStartReached = false;
|
|
1178
|
-
}
|
|
1245
|
+
if (!refState.current.isStartReached && !refState.current.startReachedBlockedByTimer) {
|
|
1246
|
+
if (distanceFromTop < onStartReachedThreshold * scrollLength) {
|
|
1247
|
+
refState.current.isStartReached = true;
|
|
1248
|
+
const { onStartReached } = callbacks.current;
|
|
1249
|
+
onStartReached == null ? void 0 : onStartReached({ distanceFromStart: scroll });
|
|
1250
|
+
refState.current.startReachedBlockedByTimer = true;
|
|
1251
|
+
setTimeout(() => {
|
|
1252
|
+
refState.current.startReachedBlockedByTimer = false;
|
|
1253
|
+
}, 700);
|
|
1254
|
+
}
|
|
1255
|
+
} else {
|
|
1256
|
+
if (distanceFromTop >= 1.3 * onStartReachedThreshold * scrollLength) {
|
|
1257
|
+
refState.current.isStartReached = false;
|
|
1179
1258
|
}
|
|
1180
1259
|
}
|
|
1181
1260
|
};
|
|
1182
|
-
const checkResetContainers = (
|
|
1261
|
+
const checkResetContainers = (isFirst2) => {
|
|
1183
1262
|
const state = refState.current;
|
|
1184
1263
|
if (state) {
|
|
1185
|
-
state.data =
|
|
1186
|
-
if (
|
|
1264
|
+
state.data = dataProp;
|
|
1265
|
+
if (!isFirst2) {
|
|
1187
1266
|
refState.current.scrollForNextCalculateItemsInView = void 0;
|
|
1188
1267
|
const numContainers = peek$(ctx, "numContainers");
|
|
1189
1268
|
for (let i = 0; i < numContainers; i++) {
|
|
@@ -1199,28 +1278,28 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
|
|
|
1199
1278
|
state.positions.clear();
|
|
1200
1279
|
}
|
|
1201
1280
|
calculateItemsInView(state.scrollVelocity);
|
|
1281
|
+
const didMaintainScrollAtEnd = doMaintainScrollAtEnd(false);
|
|
1282
|
+
if (!didMaintainScrollAtEnd && dataProp.length > state.data.length) {
|
|
1283
|
+
state.isEndReached = false;
|
|
1284
|
+
}
|
|
1285
|
+
checkAtTop();
|
|
1286
|
+
checkAtBottom();
|
|
1202
1287
|
}
|
|
1203
|
-
const didMaintainScrollAtEnd = doMaintainScrollAtEnd(false);
|
|
1204
|
-
if (!didMaintainScrollAtEnd && data.length > state.data.length) {
|
|
1205
|
-
state.isEndReached = false;
|
|
1206
|
-
}
|
|
1207
|
-
checkAtTop();
|
|
1208
|
-
checkAtBottom();
|
|
1209
1288
|
}
|
|
1210
1289
|
};
|
|
1211
1290
|
const isFirst = !refState.current.renderItem;
|
|
1212
|
-
if (isFirst ||
|
|
1213
|
-
if (!keyExtractorProp && !isFirst &&
|
|
1291
|
+
if (isFirst || dataProp !== refState.current.data || numColumnsProp !== peek$(ctx, "numColumns")) {
|
|
1292
|
+
if (!keyExtractorProp && !isFirst && dataProp !== refState.current.data) {
|
|
1214
1293
|
refState.current.positions.clear();
|
|
1215
1294
|
}
|
|
1216
|
-
refState.current.data =
|
|
1295
|
+
refState.current.data = dataProp;
|
|
1217
1296
|
let totalSize = 0;
|
|
1218
1297
|
let totalSizeBelowIndex = 0;
|
|
1219
1298
|
const indexByKey = /* @__PURE__ */ new Map();
|
|
1220
1299
|
const newPositions = /* @__PURE__ */ new Map();
|
|
1221
1300
|
let column = 1;
|
|
1222
1301
|
let maxSizeInRow = 0;
|
|
1223
|
-
for (let i = 0; i <
|
|
1302
|
+
for (let i = 0; i < dataProp.length; i++) {
|
|
1224
1303
|
const key = getId(i);
|
|
1225
1304
|
if (__DEV__) {
|
|
1226
1305
|
if (indexByKey.has(key)) {
|
|
@@ -1239,7 +1318,7 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
|
|
|
1239
1318
|
if (!isFirst) {
|
|
1240
1319
|
if (maintainVisibleContentPosition) {
|
|
1241
1320
|
if (refState.current.anchorElement == null || indexByKey.get(refState.current.anchorElement.id) == null) {
|
|
1242
|
-
if (
|
|
1321
|
+
if (dataProp.length) {
|
|
1243
1322
|
const newAnchorElement = {
|
|
1244
1323
|
coordinate: 0,
|
|
1245
1324
|
id: getId(0)
|
|
@@ -1256,7 +1335,7 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
|
|
|
1256
1335
|
}
|
|
1257
1336
|
} else {
|
|
1258
1337
|
if (refState.current.startBufferedId != null && newPositions.get(refState.current.startBufferedId) == null) {
|
|
1259
|
-
if (
|
|
1338
|
+
if (dataProp.length) {
|
|
1260
1339
|
refState.current.startBufferedId = getId(0);
|
|
1261
1340
|
} else {
|
|
1262
1341
|
refState.current.startBufferedId = void 0;
|
|
@@ -1269,9 +1348,9 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
|
|
|
1269
1348
|
}
|
|
1270
1349
|
}
|
|
1271
1350
|
const anchorElementIndex = getAnchorElementIndex();
|
|
1272
|
-
for (let i = 0; i <
|
|
1351
|
+
for (let i = 0; i < dataProp.length; i++) {
|
|
1273
1352
|
const key = getId(i);
|
|
1274
|
-
const size = getItemSize(key, i,
|
|
1353
|
+
const size = getItemSize(key, i, dataProp[i]);
|
|
1275
1354
|
maxSizeInRow = Math.max(maxSizeInRow, size);
|
|
1276
1355
|
column++;
|
|
1277
1356
|
if (column > numColumnsProp) {
|
|
@@ -1288,17 +1367,17 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
|
|
|
1288
1367
|
}
|
|
1289
1368
|
addTotalSize(null, totalSize, totalSizeBelowIndex);
|
|
1290
1369
|
}
|
|
1291
|
-
|
|
1370
|
+
React6.useEffect(() => {
|
|
1292
1371
|
checkResetContainers(
|
|
1293
|
-
/*
|
|
1294
|
-
|
|
1372
|
+
/*isFirst*/
|
|
1373
|
+
isFirst
|
|
1295
1374
|
);
|
|
1296
|
-
}, [isFirst,
|
|
1297
|
-
|
|
1375
|
+
}, [isFirst, dataProp, numColumnsProp]);
|
|
1376
|
+
React6.useEffect(() => {
|
|
1298
1377
|
set$(ctx, "extraData", extraData);
|
|
1299
1378
|
}, [extraData]);
|
|
1300
1379
|
refState.current.renderItem = renderItem;
|
|
1301
|
-
const lastItemKey =
|
|
1380
|
+
const lastItemKey = dataProp.length > 0 ? getId(dataProp.length - 1) : void 0;
|
|
1302
1381
|
const stylePaddingTop = (_g = (_f = (_d = reactNative.StyleSheet.flatten(style)) == null ? void 0 : _d.paddingTop) != null ? _f : (_e = reactNative.StyleSheet.flatten(contentContainerStyle)) == null ? void 0 : _e.paddingTop) != null ? _g : 0;
|
|
1303
1382
|
const initalizeStateVars = () => {
|
|
1304
1383
|
set$(ctx, "lastItemKey", lastItemKey);
|
|
@@ -1308,14 +1387,14 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
|
|
|
1308
1387
|
if (isFirst) {
|
|
1309
1388
|
initalizeStateVars();
|
|
1310
1389
|
}
|
|
1311
|
-
|
|
1312
|
-
const getRenderedItem =
|
|
1390
|
+
React6.useEffect(initalizeStateVars, [lastItemKey, numColumnsProp, stylePaddingTop]);
|
|
1391
|
+
const getRenderedItem = React6.useCallback((key) => {
|
|
1313
1392
|
var _a2, _b2;
|
|
1314
1393
|
const state = refState.current;
|
|
1315
1394
|
if (!state) {
|
|
1316
1395
|
return null;
|
|
1317
1396
|
}
|
|
1318
|
-
const { data
|
|
1397
|
+
const { data, indexByKey } = state;
|
|
1319
1398
|
const index = indexByKey.get(key);
|
|
1320
1399
|
if (index === void 0) {
|
|
1321
1400
|
return null;
|
|
@@ -1333,7 +1412,7 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
|
|
|
1333
1412
|
return useRecyclingState(valueOrFun);
|
|
1334
1413
|
};
|
|
1335
1414
|
const renderedItem = (_b2 = (_a2 = refState.current).renderItem) == null ? void 0 : _b2.call(_a2, {
|
|
1336
|
-
item:
|
|
1415
|
+
item: data[index],
|
|
1337
1416
|
index,
|
|
1338
1417
|
useViewability: useViewability2,
|
|
1339
1418
|
useViewabilityAmount: useViewabilityAmount2,
|
|
@@ -1349,7 +1428,7 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
|
|
|
1349
1428
|
state.viewabilityConfigCallbackPairs = viewability;
|
|
1350
1429
|
state.enableScrollForNextCalculateItemsInView = !viewability;
|
|
1351
1430
|
const scrollLength = state.scrollLength;
|
|
1352
|
-
const averageItemSize = (_a2 = estimatedItemSize != null ? estimatedItemSize : getEstimatedItemSize == null ? void 0 : getEstimatedItemSize(0,
|
|
1431
|
+
const averageItemSize = (_a2 = estimatedItemSize != null ? estimatedItemSize : getEstimatedItemSize == null ? void 0 : getEstimatedItemSize(0, dataProp[0])) != null ? _a2 : DEFAULT_ITEM_SIZE;
|
|
1353
1432
|
const numContainers = Math.ceil((scrollLength + scrollBuffer * 2) / averageItemSize) * numColumnsProp;
|
|
1354
1433
|
for (let i = 0; i < numContainers; i++) {
|
|
1355
1434
|
set$(ctx, `containerPosition${i}`, ANCHORED_POSITION_OUT_OF_VIEW);
|
|
@@ -1357,31 +1436,33 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
|
|
|
1357
1436
|
}
|
|
1358
1437
|
set$(ctx, "numContainers", numContainers);
|
|
1359
1438
|
set$(ctx, "numContainersPooled", numContainers * 2);
|
|
1360
|
-
|
|
1439
|
+
if (initialScrollIndex) {
|
|
1440
|
+
requestAnimationFrame(() => {
|
|
1441
|
+
calculateItemsInView(state.scrollVelocity);
|
|
1442
|
+
});
|
|
1443
|
+
} else {
|
|
1444
|
+
calculateItemsInView(state.scrollVelocity);
|
|
1445
|
+
}
|
|
1361
1446
|
});
|
|
1362
|
-
const updateItemSize =
|
|
1447
|
+
const updateItemSize = React6.useCallback((containerId, itemKey, size) => {
|
|
1363
1448
|
const state = refState.current;
|
|
1364
|
-
const { sizes, indexByKey, columns, sizesLaidOut, data
|
|
1365
|
-
if (!
|
|
1449
|
+
const { sizes, indexByKey, columns, sizesLaidOut, data, rowHeights } = state;
|
|
1450
|
+
if (!data) {
|
|
1366
1451
|
return;
|
|
1367
1452
|
}
|
|
1368
1453
|
const index = indexByKey.get(itemKey);
|
|
1369
1454
|
const numColumns = peek$(ctx, "numColumns");
|
|
1370
1455
|
state.minIndexSizeChanged = state.minIndexSizeChanged !== void 0 ? Math.min(state.minIndexSizeChanged, index) : index;
|
|
1371
|
-
const prevSize = getItemSize(itemKey, index,
|
|
1456
|
+
const prevSize = getItemSize(itemKey, index, data);
|
|
1372
1457
|
if (!prevSize || Math.abs(prevSize - size) > 0.5) {
|
|
1373
1458
|
let diff;
|
|
1374
1459
|
if (numColumns > 1) {
|
|
1460
|
+
const rowNumber = Math.floor(index / numColumnsProp);
|
|
1461
|
+
const prevSizeInRow = getRowHeight(rowNumber);
|
|
1375
1462
|
sizes.set(itemKey, size);
|
|
1376
|
-
|
|
1377
|
-
const
|
|
1378
|
-
|
|
1379
|
-
for (let i = loopStart; i < loopStart + numColumns && i < data2.length; i++) {
|
|
1380
|
-
const id = getId(i);
|
|
1381
|
-
const size2 = getItemSize(id, i, data2[i]);
|
|
1382
|
-
nextMaxSizeInRow = Math.max(nextMaxSizeInRow, size2);
|
|
1383
|
-
}
|
|
1384
|
-
diff = nextMaxSizeInRow - prevSize;
|
|
1463
|
+
rowHeights.delete(rowNumber);
|
|
1464
|
+
const sizeInRow = getRowHeight(rowNumber);
|
|
1465
|
+
diff = sizeInRow - prevSizeInRow;
|
|
1385
1466
|
} else {
|
|
1386
1467
|
sizes.set(itemKey, size);
|
|
1387
1468
|
diff = size - prevSize;
|
|
@@ -1423,16 +1504,16 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
|
|
|
1423
1504
|
}
|
|
1424
1505
|
}
|
|
1425
1506
|
if (onItemSizeChanged) {
|
|
1426
|
-
onItemSizeChanged({ size, previous: prevSize, index, itemKey, itemData:
|
|
1507
|
+
onItemSizeChanged({ size, previous: prevSize, index, itemKey, itemData: data[index] });
|
|
1427
1508
|
}
|
|
1428
1509
|
}
|
|
1429
1510
|
}, []);
|
|
1430
|
-
const handleScrollDebounced =
|
|
1511
|
+
const handleScrollDebounced = React6.useCallback((velocity) => {
|
|
1431
1512
|
calculateItemsInView(velocity);
|
|
1432
1513
|
checkAtBottom();
|
|
1433
1514
|
checkAtTop();
|
|
1434
1515
|
}, []);
|
|
1435
|
-
const onLayout =
|
|
1516
|
+
const onLayout = React6.useCallback((event) => {
|
|
1436
1517
|
const scrollLength = event.nativeEvent.layout[horizontal ? "width" : "height"];
|
|
1437
1518
|
const didChange = scrollLength !== refState.current.scrollLength;
|
|
1438
1519
|
refState.current.scrollLength = scrollLength;
|
|
@@ -1456,7 +1537,7 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
|
|
|
1456
1537
|
onLayoutProp(event);
|
|
1457
1538
|
}
|
|
1458
1539
|
}, []);
|
|
1459
|
-
const handleScroll =
|
|
1540
|
+
const handleScroll = React6.useCallback(
|
|
1460
1541
|
(event, fromSelf) => {
|
|
1461
1542
|
var _a2, _b2, _c2;
|
|
1462
1543
|
if (((_b2 = (_a2 = event.nativeEvent) == null ? void 0 : _a2.contentSize) == null ? void 0 : _b2.height) === 0 && ((_c2 = event.nativeEvent.contentSize) == null ? void 0 : _c2.width) === 0) {
|
|
@@ -1498,7 +1579,7 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
|
|
|
1498
1579
|
},
|
|
1499
1580
|
[]
|
|
1500
1581
|
);
|
|
1501
|
-
|
|
1582
|
+
React6.useImperativeHandle(
|
|
1502
1583
|
forwardedRef,
|
|
1503
1584
|
() => {
|
|
1504
1585
|
const scrollToIndex = ({ index, animated }) => {
|
|
@@ -1517,6 +1598,7 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
|
|
|
1517
1598
|
refScroller.current.scrollTo({ ...offsetObj, animated });
|
|
1518
1599
|
},
|
|
1519
1600
|
scrollToItem: ({ item, animated }) => {
|
|
1601
|
+
const { data } = refState.current;
|
|
1520
1602
|
const index = data.indexOf(item);
|
|
1521
1603
|
if (index !== -1) {
|
|
1522
1604
|
scrollToIndex({ index, animated });
|
|
@@ -1527,7 +1609,7 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
|
|
|
1527
1609
|
},
|
|
1528
1610
|
[]
|
|
1529
1611
|
);
|
|
1530
|
-
return /* @__PURE__ */
|
|
1612
|
+
return /* @__PURE__ */ React6__namespace.createElement(React6__namespace.Fragment, null, /* @__PURE__ */ React6__namespace.createElement(
|
|
1531
1613
|
ListComponent,
|
|
1532
1614
|
{
|
|
1533
1615
|
...rest,
|
|
@@ -1540,13 +1622,13 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
|
|
|
1540
1622
|
onLayout,
|
|
1541
1623
|
recycleItems,
|
|
1542
1624
|
alignItemsAtEnd,
|
|
1543
|
-
ListEmptyComponent:
|
|
1625
|
+
ListEmptyComponent: dataProp.length === 0 ? ListEmptyComponent : void 0,
|
|
1544
1626
|
maintainVisibleContentPosition,
|
|
1545
1627
|
scrollEventThrottle: scrollEventThrottle != null ? scrollEventThrottle : reactNative.Platform.OS === "web" ? 16 : void 0,
|
|
1546
1628
|
waitForInitialLayout,
|
|
1547
1629
|
style
|
|
1548
1630
|
}
|
|
1549
|
-
);
|
|
1631
|
+
), __DEV__ && ENABLE_DEBUG_VIEW && /* @__PURE__ */ React6__namespace.createElement(DebugView, { state: refState.current }));
|
|
1550
1632
|
});
|
|
1551
1633
|
|
|
1552
1634
|
exports.LegendList = LegendList;
|