@legendapp/list 0.5.8 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.mts +23 -2
- package/index.d.ts +23 -2
- package/index.js +310 -191
- package/index.mjs +293 -174
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var React4 = require('react');
|
|
4
4
|
var reactNative = require('react-native');
|
|
5
5
|
|
|
6
6
|
function _interopNamespace(e) {
|
|
@@ -21,13 +21,12 @@ function _interopNamespace(e) {
|
|
|
21
21
|
return Object.freeze(n);
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
var
|
|
24
|
+
var React4__namespace = /*#__PURE__*/_interopNamespace(React4);
|
|
25
25
|
|
|
26
26
|
// src/LegendList.tsx
|
|
27
|
-
var
|
|
28
|
-
var ContextState = React5__namespace.createContext(null);
|
|
27
|
+
var ContextState = React4__namespace.createContext(null);
|
|
29
28
|
function StateProvider({ children }) {
|
|
30
|
-
const [value] =
|
|
29
|
+
const [value] = React4__namespace.useState(() => ({
|
|
31
30
|
listeners: /* @__PURE__ */ new Map(),
|
|
32
31
|
values: /* @__PURE__ */ new Map(),
|
|
33
32
|
mapViewabilityCallbacks: /* @__PURE__ */ new Map(),
|
|
@@ -35,18 +34,18 @@ function StateProvider({ children }) {
|
|
|
35
34
|
mapViewabilityAmountCallbacks: /* @__PURE__ */ new Map(),
|
|
36
35
|
mapViewabilityAmountValues: /* @__PURE__ */ new Map()
|
|
37
36
|
}));
|
|
38
|
-
return /* @__PURE__ */
|
|
37
|
+
return /* @__PURE__ */ React4__namespace.createElement(ContextState.Provider, { value }, children);
|
|
39
38
|
}
|
|
40
39
|
function useStateContext() {
|
|
41
|
-
return
|
|
40
|
+
return React4__namespace.useContext(ContextState);
|
|
42
41
|
}
|
|
43
42
|
function use$(signalName) {
|
|
44
|
-
const ctx =
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
return
|
|
43
|
+
const ctx = React4__namespace.useContext(ContextState);
|
|
44
|
+
const value = React4.useSyncExternalStore(
|
|
45
|
+
(onStoreChange) => listen$(ctx, signalName, onStoreChange),
|
|
46
|
+
() => ctx.values.get(signalName)
|
|
47
|
+
);
|
|
48
|
+
return value;
|
|
50
49
|
}
|
|
51
50
|
function listen$(ctx, signalName, cb) {
|
|
52
51
|
const { listeners } = ctx;
|
|
@@ -74,25 +73,6 @@ function set$(ctx, signalName, value) {
|
|
|
74
73
|
}
|
|
75
74
|
}
|
|
76
75
|
}
|
|
77
|
-
|
|
78
|
-
// src/$ScrollView.tsx
|
|
79
|
-
var OFFSET_TEST = 0;
|
|
80
|
-
var $ScrollView = React5__namespace.forwardRef(function $ScrollView2(props, ref) {
|
|
81
|
-
const { style, horizontal, ...rest } = props;
|
|
82
|
-
const scrollAdjust = use$("scrollAdjust");
|
|
83
|
-
const adjustProps = {};
|
|
84
|
-
if (scrollAdjust !== 0) {
|
|
85
|
-
if (USE_CONTENT_INSET) {
|
|
86
|
-
adjustProps.contentInset = horizontal ? { left: -scrollAdjust } : { top: -scrollAdjust + OFFSET_TEST };
|
|
87
|
-
} else {
|
|
88
|
-
adjustProps.style = horizontal ? { marginLeft: -scrollAdjust } : { marginTop: -scrollAdjust };
|
|
89
|
-
if (style) {
|
|
90
|
-
adjustProps.style = reactNative.StyleSheet.compose(style, adjustProps.style);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
return /* @__PURE__ */ React5__namespace.createElement(reactNative.ScrollView, { ...rest, style, horizontal, ...adjustProps, ref });
|
|
95
|
-
});
|
|
96
76
|
var Container = ({
|
|
97
77
|
id,
|
|
98
78
|
recycleItems,
|
|
@@ -108,31 +88,34 @@ var Container = ({
|
|
|
108
88
|
const numColumns = use$("numColumns");
|
|
109
89
|
const otherAxisPos = numColumns > 1 ? `${(column - 1) / numColumns * 100}%` : 0;
|
|
110
90
|
const otherAxisSize = numColumns > 1 ? `${1 / numColumns * 100}%` : void 0;
|
|
111
|
-
|
|
91
|
+
let style = horizontal ? {
|
|
112
92
|
flexDirection: "row",
|
|
113
93
|
position: "absolute",
|
|
114
|
-
top:
|
|
94
|
+
top: otherAxisPos,
|
|
115
95
|
bottom: numColumns > 1 ? null : 0,
|
|
116
96
|
height: otherAxisSize,
|
|
117
97
|
left: position
|
|
118
98
|
} : {
|
|
119
99
|
position: "absolute",
|
|
120
|
-
left:
|
|
100
|
+
left: otherAxisPos,
|
|
121
101
|
right: numColumns > 1 ? null : 0,
|
|
122
102
|
width: otherAxisSize,
|
|
123
103
|
top: position
|
|
124
104
|
};
|
|
105
|
+
{
|
|
106
|
+
style.opacity = visible ? 1 : 0;
|
|
107
|
+
}
|
|
125
108
|
const lastItemKey = use$("lastItemKey");
|
|
126
109
|
const itemKey = use$(`containerItemKey${id}`);
|
|
127
|
-
const renderedItem =
|
|
128
|
-
return /* @__PURE__ */
|
|
110
|
+
const renderedItem = React4.useMemo(() => itemKey !== void 0 && getRenderedItem(itemKey, id), [itemKey]);
|
|
111
|
+
return /* @__PURE__ */ React4__namespace.default.createElement(
|
|
129
112
|
reactNative.View,
|
|
130
113
|
{
|
|
131
114
|
style,
|
|
132
115
|
onLayout: (event) => {
|
|
133
116
|
const key = peek$(ctx, `containerItemKey${id}`);
|
|
134
117
|
if (key !== void 0) {
|
|
135
|
-
const size = event.nativeEvent.layout[horizontal ? "width" : "height"];
|
|
118
|
+
const size = Math.floor(event.nativeEvent.layout[horizontal ? "width" : "height"] * 8) / 8;
|
|
136
119
|
updateItemSize(id, key, size);
|
|
137
120
|
const otherAxisSize2 = horizontal ? event.nativeEvent.layout.width : event.nativeEvent.layout.height;
|
|
138
121
|
set$(ctx, "otherAxisSize", Math.max(otherAxisSize2, peek$(ctx, "otherAxisSize") || 0));
|
|
@@ -145,34 +128,36 @@ var Container = ({
|
|
|
145
128
|
}
|
|
146
129
|
}
|
|
147
130
|
},
|
|
148
|
-
/* @__PURE__ */
|
|
131
|
+
/* @__PURE__ */ React4__namespace.default.createElement(React4__namespace.default.Fragment, { key: recycleItems ? void 0 : itemKey }, renderedItem, renderedItem && ItemSeparatorComponent && itemKey !== lastItemKey && ItemSeparatorComponent)
|
|
149
132
|
);
|
|
150
133
|
};
|
|
134
|
+
var useAnimatedValue = reactNative.useAnimatedValue || ((initialValue) => {
|
|
135
|
+
return React4.useRef(new reactNative.Animated.Value(initialValue)).current;
|
|
136
|
+
});
|
|
151
137
|
function useValue$(key, getValue, key2) {
|
|
152
138
|
var _a;
|
|
153
139
|
const ctx = useStateContext();
|
|
154
|
-
const animValue =
|
|
155
|
-
|
|
156
|
-
listen$(ctx, key, (v) => animValue.setValue(
|
|
140
|
+
const animValue = useAnimatedValue((_a = peek$(ctx, key)) != null ? _a : 0);
|
|
141
|
+
React4.useMemo(() => {
|
|
142
|
+
listen$(ctx, key, (v) => animValue.setValue(v));
|
|
157
143
|
}, []);
|
|
158
144
|
return animValue;
|
|
159
145
|
}
|
|
160
146
|
|
|
161
147
|
// src/Containers.tsx
|
|
162
|
-
var Containers =
|
|
148
|
+
var Containers = React4__namespace.memo(function Containers2({
|
|
163
149
|
horizontal,
|
|
164
150
|
recycleItems,
|
|
165
151
|
ItemSeparatorComponent,
|
|
166
152
|
updateItemSize,
|
|
167
153
|
getRenderedItem
|
|
168
154
|
}) {
|
|
169
|
-
const ctx = useStateContext();
|
|
170
155
|
const numContainers = use$("numContainersPooled");
|
|
171
|
-
const animSize = useValue$("totalSize"
|
|
156
|
+
const animSize = useValue$("totalSize");
|
|
172
157
|
const containers = [];
|
|
173
158
|
for (let i = 0; i < numContainers; i++) {
|
|
174
159
|
containers.push(
|
|
175
|
-
/* @__PURE__ */
|
|
160
|
+
/* @__PURE__ */ React4__namespace.createElement(
|
|
176
161
|
Container,
|
|
177
162
|
{
|
|
178
163
|
id: i,
|
|
@@ -187,20 +172,20 @@ var Containers = React5__namespace.memo(function Containers2({
|
|
|
187
172
|
);
|
|
188
173
|
}
|
|
189
174
|
const style = horizontal ? { width: animSize } : { height: animSize };
|
|
190
|
-
return /* @__PURE__ */
|
|
175
|
+
return /* @__PURE__ */ React4__namespace.createElement(reactNative.Animated.View, { style }, containers);
|
|
191
176
|
});
|
|
192
177
|
|
|
193
178
|
// src/ListComponent.tsx
|
|
194
179
|
var getComponent = (Component) => {
|
|
195
|
-
if (
|
|
180
|
+
if (React4__namespace.isValidElement(Component)) {
|
|
196
181
|
return Component;
|
|
197
182
|
}
|
|
198
183
|
if (Component) {
|
|
199
|
-
return /* @__PURE__ */
|
|
184
|
+
return /* @__PURE__ */ React4__namespace.createElement(Component, null);
|
|
200
185
|
}
|
|
201
186
|
return null;
|
|
202
187
|
};
|
|
203
|
-
var ListComponent =
|
|
188
|
+
var ListComponent = React4__namespace.memo(function ListComponent2({
|
|
204
189
|
style,
|
|
205
190
|
contentContainerStyle,
|
|
206
191
|
horizontal,
|
|
@@ -218,18 +203,20 @@ var ListComponent = React5__namespace.memo(function ListComponent2({
|
|
|
218
203
|
ListEmptyComponentStyle,
|
|
219
204
|
getRenderedItem,
|
|
220
205
|
updateItemSize,
|
|
221
|
-
addTotalSize,
|
|
222
206
|
refScroller,
|
|
207
|
+
maintainVisibleContentPosition,
|
|
223
208
|
...rest
|
|
224
209
|
}) {
|
|
225
210
|
const ctx = useStateContext();
|
|
226
211
|
const animPaddingTop = useValue$("paddingTop");
|
|
227
212
|
const animScrollAdjust = useValue$("scrollAdjust");
|
|
228
|
-
|
|
229
|
-
|
|
213
|
+
const additionalSize = { marginTop: animScrollAdjust, paddingTop: animPaddingTop };
|
|
214
|
+
return /* @__PURE__ */ React4__namespace.createElement(
|
|
215
|
+
reactNative.ScrollView,
|
|
230
216
|
{
|
|
231
217
|
...rest,
|
|
232
218
|
style,
|
|
219
|
+
maintainVisibleContentPosition: maintainVisibleContentPosition ? { minIndexForVisible: 0 } : void 0,
|
|
233
220
|
contentContainerStyle: [
|
|
234
221
|
contentContainerStyle,
|
|
235
222
|
horizontal ? {
|
|
@@ -242,13 +229,11 @@ var ListComponent = React5__namespace.memo(function ListComponent2({
|
|
|
242
229
|
contentOffset: initialContentOffset ? horizontal ? { x: initialContentOffset, y: 0 } : { x: 0, y: initialContentOffset } : void 0,
|
|
243
230
|
ref: refScroller
|
|
244
231
|
},
|
|
245
|
-
|
|
246
|
-
ListHeaderComponent && /* @__PURE__ */
|
|
232
|
+
/* @__PURE__ */ React4__namespace.createElement(reactNative.Animated.View, { style: additionalSize }),
|
|
233
|
+
ListHeaderComponent && /* @__PURE__ */ React4__namespace.createElement(
|
|
247
234
|
reactNative.Animated.View,
|
|
248
235
|
{
|
|
249
|
-
style:
|
|
250
|
-
top: animScrollAdjust
|
|
251
|
-
}),
|
|
236
|
+
style: ListHeaderComponentStyle,
|
|
252
237
|
onLayout: (event) => {
|
|
253
238
|
const size = event.nativeEvent.layout[horizontal ? "width" : "height"];
|
|
254
239
|
const prevSize = peek$(ctx, "headerSize") || 0;
|
|
@@ -259,16 +244,8 @@ var ListComponent = React5__namespace.memo(function ListComponent2({
|
|
|
259
244
|
},
|
|
260
245
|
getComponent(ListHeaderComponent)
|
|
261
246
|
),
|
|
262
|
-
ListEmptyComponent && /* @__PURE__ */
|
|
263
|
-
|
|
264
|
-
{
|
|
265
|
-
style: reactNative.StyleSheet.compose(ListEmptyComponentStyle, {
|
|
266
|
-
top: animScrollAdjust
|
|
267
|
-
})
|
|
268
|
-
},
|
|
269
|
-
getComponent(ListEmptyComponent)
|
|
270
|
-
),
|
|
271
|
-
/* @__PURE__ */ React5__namespace.createElement(
|
|
247
|
+
ListEmptyComponent && /* @__PURE__ */ React4__namespace.createElement(reactNative.Animated.View, { style: ListEmptyComponentStyle }, getComponent(ListEmptyComponent)),
|
|
248
|
+
/* @__PURE__ */ React4__namespace.createElement(
|
|
272
249
|
Containers,
|
|
273
250
|
{
|
|
274
251
|
horizontal,
|
|
@@ -278,12 +255,49 @@ var ListComponent = React5__namespace.memo(function ListComponent2({
|
|
|
278
255
|
updateItemSize
|
|
279
256
|
}
|
|
280
257
|
),
|
|
281
|
-
ListFooterComponent && /* @__PURE__ */
|
|
258
|
+
ListFooterComponent && /* @__PURE__ */ React4__namespace.createElement(reactNative.View, { style: ListFooterComponentStyle }, getComponent(ListFooterComponent))
|
|
282
259
|
);
|
|
283
260
|
});
|
|
261
|
+
|
|
262
|
+
// src/ScrollAdjustHandler.ts
|
|
263
|
+
var ScrollAdjustHandler = class {
|
|
264
|
+
constructor(ctx) {
|
|
265
|
+
this.ctx = ctx;
|
|
266
|
+
this.appliedAdjust = 0;
|
|
267
|
+
this.pendingAdjust = 0;
|
|
268
|
+
this.busy = false;
|
|
269
|
+
this.firstAdjust = true;
|
|
270
|
+
this.context = ctx;
|
|
271
|
+
}
|
|
272
|
+
requestAdjust(adjust, onAdjusted) {
|
|
273
|
+
const oldAdjustTop = peek$(this.context, "scrollAdjust");
|
|
274
|
+
if (oldAdjustTop === adjust) {
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
this.appliedAdjust = adjust;
|
|
278
|
+
this.pendingAdjust = adjust;
|
|
279
|
+
const doAjdust = () => {
|
|
280
|
+
set$(this.context, "scrollAdjust", this.pendingAdjust);
|
|
281
|
+
onAdjusted(oldAdjustTop - this.pendingAdjust);
|
|
282
|
+
this.busy = false;
|
|
283
|
+
};
|
|
284
|
+
if (!this.busy) {
|
|
285
|
+
this.busy = true;
|
|
286
|
+
if (this.firstAdjust) {
|
|
287
|
+
this.firstAdjust = false;
|
|
288
|
+
setTimeout(doAjdust, 50);
|
|
289
|
+
} else {
|
|
290
|
+
doAjdust();
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
getAppliedAdjust() {
|
|
295
|
+
return this.appliedAdjust;
|
|
296
|
+
}
|
|
297
|
+
};
|
|
284
298
|
var symbolFirst = Symbol();
|
|
285
299
|
function useInit(cb) {
|
|
286
|
-
const refValue =
|
|
300
|
+
const refValue = React4.useRef(symbolFirst);
|
|
287
301
|
if (refValue.current === symbolFirst) {
|
|
288
302
|
refValue.current = cb();
|
|
289
303
|
}
|
|
@@ -439,14 +453,13 @@ function maybeUpdateViewabilityCallback(ctx, configId, viewToken) {
|
|
|
439
453
|
|
|
440
454
|
// src/LegendList.tsx
|
|
441
455
|
var DEFAULT_DRAW_DISTANCE = 250;
|
|
442
|
-
var INITIAL_SCROLL_ADJUST = 1e4;
|
|
443
456
|
var POSITION_OUT_OF_VIEW = -1e7;
|
|
444
457
|
var DEFAULT_ITEM_SIZE = 100;
|
|
445
|
-
var LegendList =
|
|
446
|
-
return /* @__PURE__ */
|
|
458
|
+
var LegendList = React4.forwardRef(function LegendList2(props, forwardedRef) {
|
|
459
|
+
return /* @__PURE__ */ React4__namespace.createElement(StateProvider, null, /* @__PURE__ */ React4__namespace.createElement(LegendListInner, { ...props, ref: forwardedRef }));
|
|
447
460
|
});
|
|
448
|
-
var LegendListInner =
|
|
449
|
-
var _a, _b, _c, _d, _e
|
|
461
|
+
var LegendListInner = React4.forwardRef(function LegendListInner2(props, forwardedRef) {
|
|
462
|
+
var _a, _b, _c, _d, _e;
|
|
450
463
|
const {
|
|
451
464
|
data,
|
|
452
465
|
initialScrollIndex,
|
|
@@ -474,11 +487,11 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
|
|
|
474
487
|
} = props;
|
|
475
488
|
const { style, contentContainerStyle } = props;
|
|
476
489
|
const ctx = useStateContext();
|
|
477
|
-
const internalRef =
|
|
490
|
+
const internalRef = React4.useRef(null);
|
|
478
491
|
const refScroller = internalRef;
|
|
479
492
|
const scrollBuffer = drawDistance != null ? drawDistance : DEFAULT_DRAW_DISTANCE;
|
|
480
493
|
const keyExtractor = keyExtractorProp != null ? keyExtractorProp : (item, index) => index.toString();
|
|
481
|
-
const refState =
|
|
494
|
+
const refState = React4.useRef();
|
|
482
495
|
const getId = (index) => {
|
|
483
496
|
var _a2;
|
|
484
497
|
const data2 = (_a2 = refState.current) == null ? void 0 : _a2.data;
|
|
@@ -508,37 +521,38 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
|
|
|
508
521
|
} else if (estimatedItemSize) {
|
|
509
522
|
offset = index * estimatedItemSize;
|
|
510
523
|
}
|
|
511
|
-
return offset
|
|
524
|
+
return offset / numColumnsProp;
|
|
512
525
|
}
|
|
513
|
-
return
|
|
526
|
+
return 0;
|
|
514
527
|
};
|
|
515
|
-
const initialContentOffset = initialScrollOffset != null ? initialScrollOffset :
|
|
528
|
+
const initialContentOffset = initialScrollOffset != null ? initialScrollOffset : React4.useMemo(calculateInitialOffset, []);
|
|
516
529
|
if (!refState.current) {
|
|
530
|
+
const initialScrollLength = reactNative.Dimensions.get("window")[horizontal ? "width" : "height"];
|
|
517
531
|
refState.current = {
|
|
518
532
|
sizes: /* @__PURE__ */ new Map(),
|
|
519
533
|
positions: /* @__PURE__ */ new Map(),
|
|
520
534
|
columns: /* @__PURE__ */ new Map(),
|
|
521
535
|
pendingAdjust: 0,
|
|
522
536
|
animFrameLayout: null,
|
|
523
|
-
|
|
524
|
-
isStartReached: true,
|
|
537
|
+
isStartReached: initialContentOffset < initialScrollLength * onStartReachedThreshold,
|
|
525
538
|
isEndReached: false,
|
|
526
539
|
isAtBottom: false,
|
|
527
540
|
isAtTop: false,
|
|
528
541
|
data,
|
|
529
542
|
idsInFirstRender: void 0,
|
|
530
543
|
hasScrolled: false,
|
|
531
|
-
scrollLength:
|
|
544
|
+
scrollLength: initialScrollLength,
|
|
532
545
|
startBuffered: 0,
|
|
533
546
|
startNoBuffer: 0,
|
|
534
547
|
endBuffered: 0,
|
|
535
548
|
endNoBuffer: 0,
|
|
536
549
|
scroll: initialContentOffset || 0,
|
|
537
550
|
totalSize: 0,
|
|
551
|
+
totalSizeBelowAnchor: 0,
|
|
538
552
|
timeouts: /* @__PURE__ */ new Set(),
|
|
539
553
|
viewabilityConfigCallbackPairs: void 0,
|
|
540
554
|
renderItem: void 0,
|
|
541
|
-
|
|
555
|
+
scrollAdjustHandler: new ScrollAdjustHandler(ctx),
|
|
542
556
|
nativeMarginTop: 0,
|
|
543
557
|
scrollPrev: 0,
|
|
544
558
|
scrollPrevTime: 0,
|
|
@@ -548,54 +562,142 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
|
|
|
548
562
|
scrollVelocity: 0,
|
|
549
563
|
contentSize: { width: 0, height: 0 },
|
|
550
564
|
sizesLaidOut: __DEV__ ? /* @__PURE__ */ new Map() : void 0,
|
|
551
|
-
timeoutSizeMessage: 0
|
|
565
|
+
timeoutSizeMessage: 0,
|
|
566
|
+
scrollTimer: void 0,
|
|
567
|
+
belowAnchorElementPositions: void 0,
|
|
568
|
+
rowHeights: /* @__PURE__ */ new Map(),
|
|
569
|
+
startReachedBlockedByTimer: false
|
|
552
570
|
};
|
|
553
571
|
refState.current.idsInFirstRender = new Set(data.map((_, i) => getId(i)));
|
|
554
|
-
|
|
572
|
+
if (maintainVisibleContentPosition) {
|
|
573
|
+
if (initialScrollIndex) {
|
|
574
|
+
refState.current.anchorElement = {
|
|
575
|
+
coordinate: initialContentOffset,
|
|
576
|
+
id: getId(initialScrollIndex)
|
|
577
|
+
};
|
|
578
|
+
} else if (data.length) {
|
|
579
|
+
refState.current.anchorElement = {
|
|
580
|
+
coordinate: initialContentOffset,
|
|
581
|
+
id: getId(0)
|
|
582
|
+
};
|
|
583
|
+
} else {
|
|
584
|
+
console.warn("[legend-list] maintainVisibleContentPosition was not able to find an anchor element");
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
set$(ctx, "scrollAdjust", 0);
|
|
555
588
|
}
|
|
556
|
-
const
|
|
557
|
-
|
|
558
|
-
|
|
589
|
+
const getAnchorElementIndex = () => {
|
|
590
|
+
const state = refState.current;
|
|
591
|
+
if (state.anchorElement) {
|
|
592
|
+
const el = state.indexByKey.get(state.anchorElement.id);
|
|
593
|
+
return el;
|
|
559
594
|
}
|
|
595
|
+
return void 0;
|
|
560
596
|
};
|
|
561
|
-
const addTotalSize =
|
|
597
|
+
const addTotalSize = React4.useCallback((key, add, totalSizeBelowAnchor) => {
|
|
562
598
|
const state = refState.current;
|
|
563
599
|
const index = key === null ? 0 : state.indexByKey.get(key);
|
|
564
|
-
|
|
565
|
-
|
|
600
|
+
let isAboveAnchor = false;
|
|
601
|
+
if (maintainVisibleContentPosition) {
|
|
602
|
+
if (state.anchorElement && index < getAnchorElementIndex()) {
|
|
603
|
+
isAboveAnchor = true;
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
state.totalSize;
|
|
566
607
|
if (key === null) {
|
|
567
608
|
state.totalSize = add;
|
|
609
|
+
state.totalSizeBelowAnchor = totalSizeBelowAnchor;
|
|
568
610
|
} else {
|
|
569
611
|
state.totalSize += add;
|
|
612
|
+
if (isAboveAnchor) {
|
|
613
|
+
state.totalSizeBelowAnchor += add;
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
let applyAdjustValue = void 0;
|
|
617
|
+
if (maintainVisibleContentPosition) {
|
|
618
|
+
const newAdjust = state.anchorElement.coordinate - state.totalSizeBelowAnchor;
|
|
619
|
+
applyAdjustValue = -newAdjust;
|
|
620
|
+
state.belowAnchorElementPositions = buildElementPositionsBelowAnchor();
|
|
621
|
+
state.rowHeights.clear();
|
|
570
622
|
}
|
|
571
623
|
const doAdd = () => {
|
|
572
624
|
const totalSize = state.totalSize;
|
|
573
|
-
|
|
574
|
-
|
|
625
|
+
let resultSize = totalSize;
|
|
626
|
+
if (applyAdjustValue !== void 0) {
|
|
627
|
+
resultSize -= applyAdjustValue;
|
|
628
|
+
refState.current.scrollAdjustHandler.requestAdjust(applyAdjustValue, (diff) => {
|
|
629
|
+
state.scroll -= diff;
|
|
630
|
+
});
|
|
631
|
+
}
|
|
632
|
+
set$(ctx, "totalSize", resultSize);
|
|
575
633
|
if (alignItemsAtEnd) {
|
|
576
634
|
doUpdatePaddingTop();
|
|
577
635
|
}
|
|
578
636
|
};
|
|
579
|
-
|
|
580
|
-
|
|
637
|
+
doAdd();
|
|
638
|
+
}, []);
|
|
639
|
+
const getRowHeight = (n) => {
|
|
640
|
+
const { rowHeights } = refState.current;
|
|
641
|
+
if (numColumnsProp === 1) {
|
|
642
|
+
const id = getId(n);
|
|
643
|
+
return getItemSize(id, n, data[n]);
|
|
581
644
|
}
|
|
582
|
-
if (
|
|
583
|
-
|
|
584
|
-
} else if (!state.animFrameTotalSize) {
|
|
585
|
-
state.animFrameTotalSize = requestAnimationFrame(doAdd);
|
|
645
|
+
if (rowHeights.has(n)) {
|
|
646
|
+
return rowHeights.get(n) || 0;
|
|
586
647
|
}
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
648
|
+
let rowHeight = 0;
|
|
649
|
+
const startEl = n * numColumnsProp;
|
|
650
|
+
for (let i = startEl; i < startEl + numColumnsProp; i++) {
|
|
651
|
+
const id = getId(i);
|
|
652
|
+
const size = getItemSize(id, i, data[i]);
|
|
653
|
+
rowHeight = Math.max(rowHeight, size);
|
|
654
|
+
}
|
|
655
|
+
rowHeights.set(n, rowHeight);
|
|
656
|
+
return rowHeight;
|
|
657
|
+
};
|
|
658
|
+
const buildElementPositionsBelowAnchor = () => {
|
|
659
|
+
const state = refState.current;
|
|
660
|
+
if (!state.anchorElement) {
|
|
661
|
+
return /* @__PURE__ */ new Map();
|
|
662
|
+
}
|
|
663
|
+
let top = state.anchorElement.coordinate;
|
|
664
|
+
const anchorIndex = state.indexByKey.get(state.anchorElement.id);
|
|
665
|
+
if (anchorIndex === 0) {
|
|
666
|
+
return /* @__PURE__ */ new Map();
|
|
667
|
+
}
|
|
668
|
+
const map = state.belowAnchorElementPositions || /* @__PURE__ */ new Map();
|
|
669
|
+
for (let i = anchorIndex - 1; i >= 0; i--) {
|
|
670
|
+
const id = getId(i);
|
|
671
|
+
const rowNumber = Math.floor(i / numColumnsProp);
|
|
672
|
+
if (i % numColumnsProp === 0) {
|
|
673
|
+
top -= getRowHeight(rowNumber);
|
|
674
|
+
}
|
|
675
|
+
map.set(id, top);
|
|
676
|
+
}
|
|
677
|
+
return map;
|
|
678
|
+
};
|
|
679
|
+
const getElementPositionBelowAchor = (id) => {
|
|
680
|
+
const state = refState.current;
|
|
681
|
+
if (!refState.current.belowAnchorElementPositions) {
|
|
682
|
+
state.belowAnchorElementPositions = buildElementPositionsBelowAnchor();
|
|
683
|
+
}
|
|
684
|
+
const res = state.belowAnchorElementPositions.get(id);
|
|
685
|
+
if (res === void 0) {
|
|
686
|
+
throw new Error("Undefined position below achor");
|
|
687
|
+
}
|
|
688
|
+
return res;
|
|
689
|
+
};
|
|
690
|
+
const calculateItemsInView = React4.useCallback((speed) => {
|
|
691
|
+
var _a2, _b2;
|
|
590
692
|
const state = refState.current;
|
|
591
693
|
const {
|
|
592
694
|
data: data2,
|
|
593
695
|
scrollLength,
|
|
594
696
|
scroll: scrollState,
|
|
595
|
-
|
|
697
|
+
startBufferedId: startBufferedIdOrig,
|
|
596
698
|
positions,
|
|
597
|
-
|
|
598
|
-
|
|
699
|
+
columns,
|
|
700
|
+
scrollAdjustHandler
|
|
599
701
|
} = state;
|
|
600
702
|
if (state.animFrameLayout) {
|
|
601
703
|
cancelAnimationFrame(state.animFrameLayout);
|
|
@@ -605,30 +707,35 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
|
|
|
605
707
|
return;
|
|
606
708
|
}
|
|
607
709
|
const topPad = (peek$(ctx, "stylePaddingTop") || 0) + (peek$(ctx, "headerSize") || 0);
|
|
608
|
-
const
|
|
710
|
+
const previousScrollAdjust = scrollAdjustHandler.getAppliedAdjust();
|
|
609
711
|
const scrollExtra = Math.max(-16, Math.min(16, speed)) * 16;
|
|
610
|
-
const scroll =
|
|
611
|
-
0,
|
|
612
|
-
scrollState - topPad - (USE_CONTENT_INSET ? scrollAdjustPending : 0) + scrollExtra
|
|
613
|
-
);
|
|
712
|
+
const scroll = scrollState - previousScrollAdjust - topPad - scrollExtra;
|
|
614
713
|
const scrollBottom = scroll + scrollLength;
|
|
615
714
|
let startNoBuffer = null;
|
|
616
715
|
let startBuffered = null;
|
|
716
|
+
let startBufferedId = null;
|
|
617
717
|
let endNoBuffer = null;
|
|
618
718
|
let endBuffered = null;
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
719
|
+
const originalStartId = startBufferedIdOrig && state.indexByKey.get(startBufferedIdOrig);
|
|
720
|
+
let loopStart = originalStartId || 0;
|
|
721
|
+
const anchorElementIndex = getAnchorElementIndex();
|
|
722
|
+
for (let i = loopStart; i >= 0; i--) {
|
|
723
|
+
const id = getId(i);
|
|
724
|
+
let newPosition;
|
|
725
|
+
if (maintainVisibleContentPosition && anchorElementIndex && i < anchorElementIndex) {
|
|
726
|
+
newPosition = getElementPositionBelowAchor(id);
|
|
727
|
+
if (newPosition !== void 0) {
|
|
728
|
+
positions.set(id, newPosition);
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
const top2 = newPosition || positions.get(id);
|
|
732
|
+
if (top2 !== void 0) {
|
|
733
|
+
const size = getItemSize(id, i, data2[i]);
|
|
734
|
+
const bottom = top2 + size;
|
|
735
|
+
if (bottom > scroll - scrollBuffer) {
|
|
736
|
+
loopStart = i;
|
|
737
|
+
} else {
|
|
738
|
+
break;
|
|
632
739
|
}
|
|
633
740
|
}
|
|
634
741
|
}
|
|
@@ -637,13 +744,28 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
|
|
|
637
744
|
if (loopStartMod > 0) {
|
|
638
745
|
loopStart -= loopStartMod;
|
|
639
746
|
}
|
|
640
|
-
let top =
|
|
747
|
+
let top = void 0;
|
|
641
748
|
let column = 1;
|
|
642
749
|
let maxSizeInRow = 0;
|
|
750
|
+
const getInitialTop = (i) => {
|
|
751
|
+
var _a3;
|
|
752
|
+
const id = getId(i);
|
|
753
|
+
let topOffset = 0;
|
|
754
|
+
if (positions.get(id)) {
|
|
755
|
+
topOffset = positions.get(id);
|
|
756
|
+
}
|
|
757
|
+
if (id === ((_a3 = state.anchorElement) == null ? void 0 : _a3.id)) {
|
|
758
|
+
topOffset = initialContentOffset || 0;
|
|
759
|
+
}
|
|
760
|
+
return topOffset;
|
|
761
|
+
};
|
|
643
762
|
for (let i = loopStart; i < data2.length; i++) {
|
|
644
763
|
const id = getId(i);
|
|
645
764
|
const size = getItemSize(id, i, data2[i]);
|
|
646
765
|
maxSizeInRow = Math.max(maxSizeInRow, size);
|
|
766
|
+
if (top === void 0) {
|
|
767
|
+
top = getInitialTop(i);
|
|
768
|
+
}
|
|
647
769
|
if (positions.get(id) !== top) {
|
|
648
770
|
positions.set(id, top);
|
|
649
771
|
}
|
|
@@ -655,6 +777,7 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
|
|
|
655
777
|
}
|
|
656
778
|
if (startBuffered === null && top + size > scroll - scrollBuffer) {
|
|
657
779
|
startBuffered = i;
|
|
780
|
+
startBufferedId = id;
|
|
658
781
|
}
|
|
659
782
|
if (startNoBuffer !== null) {
|
|
660
783
|
if (top <= scrollBottom) {
|
|
@@ -675,6 +798,7 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
|
|
|
675
798
|
}
|
|
676
799
|
Object.assign(refState.current, {
|
|
677
800
|
startBuffered,
|
|
801
|
+
startBufferedId,
|
|
678
802
|
startNoBuffer,
|
|
679
803
|
endBuffered,
|
|
680
804
|
endNoBuffer
|
|
@@ -693,7 +817,7 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
|
|
|
693
817
|
}
|
|
694
818
|
}
|
|
695
819
|
if (!isContained) {
|
|
696
|
-
const top2 =
|
|
820
|
+
const top2 = positions.get(id) || 0;
|
|
697
821
|
let furthestIndex = -1;
|
|
698
822
|
let furthestDistance = 0;
|
|
699
823
|
for (let u = 0; u < numContainers; u++) {
|
|
@@ -702,7 +826,7 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
|
|
|
702
826
|
furthestIndex = u;
|
|
703
827
|
break;
|
|
704
828
|
}
|
|
705
|
-
const index = (
|
|
829
|
+
const index = (_a2 = refState.current) == null ? void 0 : _a2.indexByKey.get(key);
|
|
706
830
|
const pos = peek$(ctx, `containerPosition${u}`);
|
|
707
831
|
if (index < startBuffered || index > endBuffered) {
|
|
708
832
|
const distance = Math.abs(pos - top2);
|
|
@@ -737,23 +861,23 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
|
|
|
737
861
|
}
|
|
738
862
|
for (let i = 0; i < numContainers; i++) {
|
|
739
863
|
const itemKey = peek$(ctx, `containerItemKey${i}`);
|
|
740
|
-
const itemIndex = (
|
|
864
|
+
const itemIndex = (_b2 = refState.current) == null ? void 0 : _b2.indexByKey.get(itemKey);
|
|
741
865
|
const item = data2[itemIndex];
|
|
742
866
|
if (item) {
|
|
743
867
|
const id = getId(itemIndex);
|
|
744
868
|
if (itemKey !== id || itemIndex < startBuffered || itemIndex > endBuffered) {
|
|
745
|
-
const prevPos = peek$(ctx, `containerPosition${i}`)
|
|
869
|
+
const prevPos = peek$(ctx, `containerPosition${i}`);
|
|
746
870
|
const pos = positions.get(id) || 0;
|
|
747
|
-
const size =
|
|
871
|
+
const size = getItemSize(id, itemIndex, data2[i]);
|
|
748
872
|
if (pos + size >= scroll && pos <= scrollBottom || prevPos + size >= scroll && prevPos <= scrollBottom) {
|
|
749
873
|
set$(ctx, `containerPosition${i}`, POSITION_OUT_OF_VIEW);
|
|
750
874
|
}
|
|
751
875
|
} else {
|
|
752
|
-
const pos =
|
|
876
|
+
const pos = positions.get(id) || 0;
|
|
753
877
|
const column2 = columns.get(id) || 1;
|
|
754
878
|
const prevPos = peek$(ctx, `containerPosition${i}`);
|
|
755
879
|
const prevColumn = peek$(ctx, `containerColumn${i}`);
|
|
756
|
-
if (pos
|
|
880
|
+
if (pos > POSITION_OUT_OF_VIEW && pos !== prevPos) {
|
|
757
881
|
set$(ctx, `containerPosition${i}`, pos);
|
|
758
882
|
}
|
|
759
883
|
if (column2 >= 0 && column2 !== prevColumn) {
|
|
@@ -825,17 +949,20 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
|
|
|
825
949
|
return;
|
|
826
950
|
}
|
|
827
951
|
const { scrollLength, scroll } = refState.current;
|
|
828
|
-
const
|
|
829
|
-
const distanceFromTop = scroll - scrollAdjust;
|
|
952
|
+
const distanceFromTop = scroll;
|
|
830
953
|
refState.current.isAtTop = distanceFromTop < 0;
|
|
831
954
|
if (onStartReached) {
|
|
832
|
-
if (!refState.current.isStartReached) {
|
|
955
|
+
if (!refState.current.isStartReached && !refState.current.startReachedBlockedByTimer) {
|
|
833
956
|
if (distanceFromTop < onStartReachedThreshold * scrollLength) {
|
|
834
957
|
refState.current.isStartReached = true;
|
|
835
958
|
onStartReached({ distanceFromStart: scroll });
|
|
959
|
+
refState.current.startReachedBlockedByTimer = true;
|
|
960
|
+
setTimeout(() => {
|
|
961
|
+
refState.current.startReachedBlockedByTimer = false;
|
|
962
|
+
}, 700);
|
|
836
963
|
}
|
|
837
964
|
} else {
|
|
838
|
-
if (distanceFromTop >= onStartReachedThreshold * scrollLength) {
|
|
965
|
+
if (distanceFromTop >= 1.3 * onStartReachedThreshold * scrollLength) {
|
|
839
966
|
refState.current.isStartReached = false;
|
|
840
967
|
}
|
|
841
968
|
}
|
|
@@ -849,43 +976,36 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
|
|
|
849
976
|
}
|
|
850
977
|
refState.current.data = data;
|
|
851
978
|
let totalSize = 0;
|
|
979
|
+
let totalSizeBelowIndex = 0;
|
|
852
980
|
const indexByKey = /* @__PURE__ */ new Map();
|
|
853
981
|
let column = 1;
|
|
854
982
|
let maxSizeInRow = 0;
|
|
855
983
|
for (let i = 0; i < data.length; i++) {
|
|
856
984
|
const key = getId(i);
|
|
857
985
|
indexByKey.set(key, i);
|
|
986
|
+
}
|
|
987
|
+
refState.current.indexByKey = indexByKey;
|
|
988
|
+
const anchorElementIndex = getAnchorElementIndex();
|
|
989
|
+
for (let i = 0; i < data.length; i++) {
|
|
990
|
+
const key = getId(i);
|
|
858
991
|
const size = getItemSize(key, i, data[i]);
|
|
859
992
|
maxSizeInRow = Math.max(maxSizeInRow, size);
|
|
860
|
-
if (maintainVisibleContentPosition && i < refState.current.startNoBuffer && !refState.current.indexByKey.has(key)) {
|
|
861
|
-
const size2 = getItemSize(key, i, data[i]);
|
|
862
|
-
adjustScroll(size2);
|
|
863
|
-
}
|
|
864
993
|
column++;
|
|
865
994
|
if (column > numColumnsProp) {
|
|
995
|
+
if (maintainVisibleContentPosition && anchorElementIndex !== void 0 && i < anchorElementIndex) {
|
|
996
|
+
totalSizeBelowIndex += maxSizeInRow;
|
|
997
|
+
}
|
|
866
998
|
totalSize += maxSizeInRow;
|
|
867
999
|
column = 1;
|
|
868
1000
|
maxSizeInRow = 0;
|
|
869
1001
|
}
|
|
870
1002
|
}
|
|
871
|
-
addTotalSize(null, totalSize);
|
|
872
|
-
if (maintainVisibleContentPosition) {
|
|
873
|
-
for (const [key, index] of refState.current.indexByKey) {
|
|
874
|
-
if (index < refState.current.startNoBuffer && !indexByKey.has(key)) {
|
|
875
|
-
const size = (_a = refState.current.sizes.get(key)) != null ? _a : 0;
|
|
876
|
-
if (size) {
|
|
877
|
-
adjustScroll(-size);
|
|
878
|
-
}
|
|
879
|
-
}
|
|
880
|
-
}
|
|
881
|
-
}
|
|
882
|
-
refState.current.indexByKey = indexByKey;
|
|
1003
|
+
addTotalSize(null, totalSize, totalSizeBelowIndex);
|
|
883
1004
|
if (!isFirst) {
|
|
884
|
-
refState.current.isEndReached = false;
|
|
885
1005
|
const numContainers = peek$(ctx, "numContainers");
|
|
886
1006
|
for (let i = 0; i < numContainers; i++) {
|
|
887
1007
|
const itemKey = peek$(ctx, `containerItemKey${i}`);
|
|
888
|
-
if (!keyExtractorProp || itemKey && ((
|
|
1008
|
+
if (!keyExtractorProp || itemKey && ((_a = refState.current) == null ? void 0 : _a.indexByKey.get(itemKey)) === void 0) {
|
|
889
1009
|
set$(ctx, `containerItemKey${i}`, void 0);
|
|
890
1010
|
set$(ctx, `containerPosition${i}`, POSITION_OUT_OF_VIEW);
|
|
891
1011
|
set$(ctx, `containerColumn${i}`, -1);
|
|
@@ -895,10 +1015,12 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
|
|
|
895
1015
|
refState.current.sizes.clear();
|
|
896
1016
|
refState.current.positions;
|
|
897
1017
|
}
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
1018
|
+
setTimeout(() => {
|
|
1019
|
+
calculateItemsInView(refState.current.scrollVelocity);
|
|
1020
|
+
doMaintainScrollAtEnd(false);
|
|
1021
|
+
checkAtTop();
|
|
1022
|
+
checkAtBottom();
|
|
1023
|
+
}, 0);
|
|
902
1024
|
}
|
|
903
1025
|
}
|
|
904
1026
|
refState.current.renderItem = renderItem;
|
|
@@ -907,9 +1029,9 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
|
|
|
907
1029
|
set$(
|
|
908
1030
|
ctx,
|
|
909
1031
|
"stylePaddingTop",
|
|
910
|
-
(
|
|
1032
|
+
(_e = (_d = (_b = reactNative.StyleSheet.flatten(style)) == null ? void 0 : _b.paddingTop) != null ? _d : (_c = reactNative.StyleSheet.flatten(contentContainerStyle)) == null ? void 0 : _c.paddingTop) != null ? _e : 0
|
|
911
1033
|
);
|
|
912
|
-
const getRenderedItem =
|
|
1034
|
+
const getRenderedItem = React4.useCallback((key, containerId) => {
|
|
913
1035
|
var _a2, _b2;
|
|
914
1036
|
const state = refState.current;
|
|
915
1037
|
if (!state) {
|
|
@@ -929,7 +1051,7 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
|
|
|
929
1051
|
}
|
|
930
1052
|
});
|
|
931
1053
|
ctx.mapViewabilityCallbacks.set(key2, callback);
|
|
932
|
-
|
|
1054
|
+
React4.useEffect(
|
|
933
1055
|
() => () => {
|
|
934
1056
|
ctx.mapViewabilityCallbacks.delete(key2);
|
|
935
1057
|
},
|
|
@@ -944,7 +1066,7 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
|
|
|
944
1066
|
}
|
|
945
1067
|
});
|
|
946
1068
|
ctx.mapViewabilityAmountCallbacks.set(containerId, callback);
|
|
947
|
-
|
|
1069
|
+
React4.useEffect(
|
|
948
1070
|
() => () => {
|
|
949
1071
|
ctx.mapViewabilityAmountCallbacks.delete(containerId);
|
|
950
1072
|
},
|
|
@@ -952,7 +1074,7 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
|
|
|
952
1074
|
);
|
|
953
1075
|
};
|
|
954
1076
|
const useRecyclingEffect = (effect) => {
|
|
955
|
-
|
|
1077
|
+
React4.useEffect(() => {
|
|
956
1078
|
const state2 = refState.current;
|
|
957
1079
|
let prevIndex = index;
|
|
958
1080
|
let prevItem = state2.data[index];
|
|
@@ -980,7 +1102,7 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
|
|
|
980
1102
|
}, []);
|
|
981
1103
|
};
|
|
982
1104
|
const useRecyclingState = (valueOrFun) => {
|
|
983
|
-
const stateInfo =
|
|
1105
|
+
const stateInfo = React4.useState(
|
|
984
1106
|
() => typeof valueOrFun === "function" ? valueOrFun({
|
|
985
1107
|
index,
|
|
986
1108
|
item: refState.current.data[index],
|
|
@@ -1016,9 +1138,9 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
|
|
|
1016
1138
|
}
|
|
1017
1139
|
set$(ctx, "numContainers", numContainers);
|
|
1018
1140
|
set$(ctx, "numContainersPooled", numContainers * 2);
|
|
1019
|
-
calculateItemsInView();
|
|
1141
|
+
calculateItemsInView(refState.current.scrollVelocity);
|
|
1020
1142
|
});
|
|
1021
|
-
const updateItemSize =
|
|
1143
|
+
const updateItemSize = React4.useCallback((containerId, itemKey, size) => {
|
|
1022
1144
|
var _a2;
|
|
1023
1145
|
const data2 = (_a2 = refState.current) == null ? void 0 : _a2.data;
|
|
1024
1146
|
if (!data2) {
|
|
@@ -1027,21 +1149,16 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
|
|
|
1027
1149
|
const state = refState.current;
|
|
1028
1150
|
const { sizes, indexByKey, idsInFirstRender, columns, sizesLaidOut } = state;
|
|
1029
1151
|
const index = indexByKey.get(itemKey);
|
|
1030
|
-
const
|
|
1031
|
-
const
|
|
1152
|
+
const numColumns = peek$(ctx, "numColumns");
|
|
1153
|
+
const row = Math.floor(index / numColumns);
|
|
1154
|
+
const prevSize = getRowHeight(row);
|
|
1032
1155
|
if (!prevSize || Math.abs(prevSize - size) > 0.5) {
|
|
1033
1156
|
let diff;
|
|
1034
|
-
const numColumns = peek$(ctx, "numColumns");
|
|
1035
1157
|
if (numColumns > 1) {
|
|
1158
|
+
const prevMaxSizeInRow = getRowHeight(row);
|
|
1159
|
+
sizes.set(itemKey, size);
|
|
1036
1160
|
const column = columns.get(itemKey);
|
|
1037
1161
|
const loopStart = index - (column - 1);
|
|
1038
|
-
let prevMaxSizeInRow = 0;
|
|
1039
|
-
for (let i = loopStart; i < loopStart + numColumns; i++) {
|
|
1040
|
-
const id = getId(i);
|
|
1041
|
-
const size2 = getItemSize(id, i, data2[i]);
|
|
1042
|
-
prevMaxSizeInRow = Math.max(prevMaxSizeInRow, size2);
|
|
1043
|
-
}
|
|
1044
|
-
sizes.set(itemKey, size);
|
|
1045
1162
|
let nextMaxSizeInRow = 0;
|
|
1046
1163
|
for (let i = loopStart; i < loopStart + numColumns; i++) {
|
|
1047
1164
|
const id = getId(i);
|
|
@@ -1072,7 +1189,7 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
|
|
|
1072
1189
|
);
|
|
1073
1190
|
}, 1e3);
|
|
1074
1191
|
}
|
|
1075
|
-
addTotalSize(itemKey, diff);
|
|
1192
|
+
addTotalSize(itemKey, diff, 0);
|
|
1076
1193
|
doMaintainScrollAtEnd(true);
|
|
1077
1194
|
const scrollVelocity = state.scrollVelocity;
|
|
1078
1195
|
if (!state.animFrameLayout && (Number.isNaN(scrollVelocity) || Math.abs(scrollVelocity) < 1)) {
|
|
@@ -1087,19 +1204,13 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
|
|
|
1087
1204
|
}
|
|
1088
1205
|
}
|
|
1089
1206
|
}, []);
|
|
1090
|
-
const handleScrollDebounced =
|
|
1091
|
-
var _a2, _b2;
|
|
1092
|
-
const scrollAdjustPending = (_b2 = (_a2 = refState.current) == null ? void 0 : _a2.scrollAdjustPending) != null ? _b2 : 0;
|
|
1093
|
-
set$(ctx, "scrollAdjust", scrollAdjustPending);
|
|
1207
|
+
const handleScrollDebounced = React4.useCallback((velocity) => {
|
|
1094
1208
|
calculateItemsInView(velocity);
|
|
1095
1209
|
checkAtBottom();
|
|
1096
1210
|
checkAtTop();
|
|
1097
1211
|
}, []);
|
|
1098
|
-
const onLayout =
|
|
1099
|
-
|
|
1100
|
-
if (!USE_CONTENT_INSET) {
|
|
1101
|
-
scrollLength += event.nativeEvent.layout[horizontal ? "x" : "y"];
|
|
1102
|
-
}
|
|
1212
|
+
const onLayout = React4.useCallback((event) => {
|
|
1213
|
+
const scrollLength = event.nativeEvent.layout[horizontal ? "width" : "height"];
|
|
1103
1214
|
refState.current.scrollLength = scrollLength;
|
|
1104
1215
|
if (refState.current.hasScrolled) {
|
|
1105
1216
|
doMaintainScrollAtEnd(false);
|
|
@@ -1117,7 +1228,7 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
|
|
|
1117
1228
|
}
|
|
1118
1229
|
}
|
|
1119
1230
|
}, []);
|
|
1120
|
-
const handleScroll =
|
|
1231
|
+
const handleScroll = React4.useCallback(
|
|
1121
1232
|
(event, fromSelf) => {
|
|
1122
1233
|
var _a2, _b2, _c2;
|
|
1123
1234
|
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) {
|
|
@@ -1128,10 +1239,18 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
|
|
|
1128
1239
|
state.contentSize = event.nativeEvent.contentSize;
|
|
1129
1240
|
const currentTime = performance.now();
|
|
1130
1241
|
const newScroll = event.nativeEvent.contentOffset[horizontal ? "x" : "y"];
|
|
1131
|
-
state.scrollHistory.
|
|
1242
|
+
if (!(state.scrollHistory.length === 0 && newScroll === initialContentOffset)) {
|
|
1243
|
+
state.scrollHistory.push({ scroll: newScroll, time: currentTime });
|
|
1244
|
+
}
|
|
1132
1245
|
if (state.scrollHistory.length > 5) {
|
|
1133
1246
|
state.scrollHistory.shift();
|
|
1134
1247
|
}
|
|
1248
|
+
if (state.scrollTimer !== void 0) {
|
|
1249
|
+
clearTimeout(state.scrollTimer);
|
|
1250
|
+
}
|
|
1251
|
+
state.scrollTimer = setTimeout(() => {
|
|
1252
|
+
state.scrollVelocity = 0;
|
|
1253
|
+
}, 500);
|
|
1135
1254
|
let velocity = 0;
|
|
1136
1255
|
if (state.scrollHistory.length >= 2) {
|
|
1137
1256
|
const newest = state.scrollHistory[state.scrollHistory.length - 1];
|
|
@@ -1152,7 +1271,7 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
|
|
|
1152
1271
|
},
|
|
1153
1272
|
[]
|
|
1154
1273
|
);
|
|
1155
|
-
|
|
1274
|
+
React4.useImperativeHandle(
|
|
1156
1275
|
forwardedRef,
|
|
1157
1276
|
() => {
|
|
1158
1277
|
const scrollToIndex = ({ index, animated }) => {
|
|
@@ -1181,7 +1300,7 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
|
|
|
1181
1300
|
},
|
|
1182
1301
|
[]
|
|
1183
1302
|
);
|
|
1184
|
-
return /* @__PURE__ */
|
|
1303
|
+
return /* @__PURE__ */ React4__namespace.createElement(
|
|
1185
1304
|
ListComponent,
|
|
1186
1305
|
{
|
|
1187
1306
|
...rest,
|
|
@@ -1194,8 +1313,8 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
|
|
|
1194
1313
|
onLayout,
|
|
1195
1314
|
recycleItems,
|
|
1196
1315
|
alignItemsAtEnd,
|
|
1197
|
-
addTotalSize,
|
|
1198
1316
|
ListEmptyComponent: data.length === 0 ? ListEmptyComponent : void 0,
|
|
1317
|
+
maintainVisibleContentPosition,
|
|
1199
1318
|
style
|
|
1200
1319
|
}
|
|
1201
1320
|
);
|