@legendapp/list 1.0.0-beta.1 → 1.0.0-beta.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 -3
- package/animated.d.ts +3 -3
- package/index.d.mts +17 -6
- package/index.d.ts +17 -6
- package/index.js +375 -229
- package/index.mjs +354 -212
- package/package.json +1 -1
- package/reanimated.d.mts +6 -3
- package/reanimated.d.ts +6 -3
package/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var React5 = 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 React5__namespace = /*#__PURE__*/_interopNamespace(React5);
|
|
25
25
|
|
|
26
26
|
// src/LegendList.tsx
|
|
27
|
-
var ContextState =
|
|
27
|
+
var ContextState = React5__namespace.createContext(null);
|
|
28
28
|
function StateProvider({ children }) {
|
|
29
|
-
const [value] =
|
|
29
|
+
const [value] = React5__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__ */ React5__namespace.createElement(ContextState.Provider, { value }, children);
|
|
38
38
|
}
|
|
39
39
|
function useStateContext() {
|
|
40
|
-
return
|
|
40
|
+
return React5__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 = React5__namespace.useContext(ContextState);
|
|
50
|
+
const { subscribe, get } = React5__namespace.useMemo(() => createSelectorFunctions(ctx, signalName), []);
|
|
51
|
+
const value = React5.useSyncExternalStore(subscribe, get);
|
|
52
52
|
return value;
|
|
53
53
|
}
|
|
54
54
|
function listen$(ctx, signalName, cb) {
|
|
@@ -77,75 +77,207 @@ function set$(ctx, signalName, value) {
|
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
|
+
var symbolFirst = Symbol();
|
|
81
|
+
function useInit(cb) {
|
|
82
|
+
const refValue = React5.useRef(symbolFirst);
|
|
83
|
+
if (refValue.current === symbolFirst) {
|
|
84
|
+
refValue.current = cb();
|
|
85
|
+
}
|
|
86
|
+
return refValue.current;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// src/ContextContainer.ts
|
|
90
|
+
var ContextContainer = React5.createContext(null);
|
|
91
|
+
function useViewability(configId, callback) {
|
|
92
|
+
const ctx = useStateContext();
|
|
93
|
+
const { containerId } = React5.useContext(ContextContainer);
|
|
94
|
+
const key = containerId + configId;
|
|
95
|
+
useInit(() => {
|
|
96
|
+
const value = ctx.mapViewabilityValues.get(key);
|
|
97
|
+
if (value) {
|
|
98
|
+
callback(value);
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
ctx.mapViewabilityCallbacks.set(key, callback);
|
|
102
|
+
React5.useEffect(
|
|
103
|
+
() => () => {
|
|
104
|
+
ctx.mapViewabilityCallbacks.delete(key);
|
|
105
|
+
},
|
|
106
|
+
[]
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
function useViewabilityAmount(callback) {
|
|
110
|
+
const ctx = useStateContext();
|
|
111
|
+
const { containerId } = React5.useContext(ContextContainer);
|
|
112
|
+
useInit(() => {
|
|
113
|
+
const value = ctx.mapViewabilityAmountValues.get(containerId);
|
|
114
|
+
if (value) {
|
|
115
|
+
callback(value);
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
ctx.mapViewabilityAmountCallbacks.set(containerId, callback);
|
|
119
|
+
React5.useEffect(
|
|
120
|
+
() => () => {
|
|
121
|
+
ctx.mapViewabilityAmountCallbacks.delete(containerId);
|
|
122
|
+
},
|
|
123
|
+
[]
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
function useRecyclingEffect(effect) {
|
|
127
|
+
const { index, value } = React5.useContext(ContextContainer);
|
|
128
|
+
const prevValues = React5.useRef({
|
|
129
|
+
prevIndex: void 0,
|
|
130
|
+
prevItem: void 0
|
|
131
|
+
});
|
|
132
|
+
React5.useEffect(() => {
|
|
133
|
+
let ret = void 0;
|
|
134
|
+
if (prevValues.current.prevIndex !== void 0 && prevValues.current.prevItem !== void 0) {
|
|
135
|
+
ret = effect({
|
|
136
|
+
index,
|
|
137
|
+
item: value,
|
|
138
|
+
prevIndex: prevValues.current.prevIndex,
|
|
139
|
+
prevItem: prevValues.current.prevItem
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
prevValues.current = {
|
|
143
|
+
prevIndex: index,
|
|
144
|
+
prevItem: value
|
|
145
|
+
};
|
|
146
|
+
return ret;
|
|
147
|
+
}, [index, value]);
|
|
148
|
+
}
|
|
149
|
+
function useRecyclingState(valueOrFun) {
|
|
150
|
+
const { index, value } = React5.useContext(ContextContainer);
|
|
151
|
+
const stateInfo = React5.useState(
|
|
152
|
+
() => typeof valueOrFun === "function" ? valueOrFun({
|
|
153
|
+
index,
|
|
154
|
+
item: value,
|
|
155
|
+
prevIndex: void 0,
|
|
156
|
+
prevItem: void 0
|
|
157
|
+
}) : valueOrFun
|
|
158
|
+
);
|
|
159
|
+
useRecyclingEffect((state) => {
|
|
160
|
+
const newState = typeof valueOrFun === "function" ? valueOrFun(state) : valueOrFun;
|
|
161
|
+
stateInfo[1](newState);
|
|
162
|
+
});
|
|
163
|
+
return stateInfo;
|
|
164
|
+
}
|
|
165
|
+
var LeanView = React5__namespace.forwardRef((props, ref) => {
|
|
166
|
+
return React5__namespace.createElement("RCTView", { ...props, ref });
|
|
167
|
+
});
|
|
168
|
+
LeanView.displayName = "RCTView";
|
|
169
|
+
|
|
170
|
+
// src/constants.ts
|
|
171
|
+
var POSITION_OUT_OF_VIEW = -1e7;
|
|
172
|
+
var ANCHORED_POSITION_OUT_OF_VIEW = {
|
|
173
|
+
type: "top",
|
|
174
|
+
relativeCoordinate: POSITION_OUT_OF_VIEW,
|
|
175
|
+
top: POSITION_OUT_OF_VIEW
|
|
176
|
+
};
|
|
80
177
|
|
|
81
178
|
// src/Container.tsx
|
|
179
|
+
var isNewArchitecture = global.nativeFabricUIManager != null;
|
|
82
180
|
var Container = ({
|
|
83
181
|
id,
|
|
84
182
|
recycleItems,
|
|
85
183
|
horizontal,
|
|
86
|
-
waitForInitialLayout,
|
|
87
184
|
getRenderedItem,
|
|
88
185
|
updateItemSize,
|
|
89
186
|
ItemSeparatorComponent
|
|
90
187
|
}) => {
|
|
91
|
-
|
|
92
|
-
const
|
|
188
|
+
useStateContext();
|
|
189
|
+
const maintainVisibleContentPosition = use$("maintainVisibleContentPosition");
|
|
190
|
+
const position = use$(`containerPosition${id}`) || ANCHORED_POSITION_OUT_OF_VIEW;
|
|
93
191
|
const column = use$(`containerColumn${id}`) || 0;
|
|
94
192
|
const numColumns = use$("numColumns");
|
|
95
193
|
const otherAxisPos = numColumns > 1 ? `${(column - 1) / numColumns * 100}%` : 0;
|
|
96
194
|
const otherAxisSize = numColumns > 1 ? `${1 / numColumns * 100}%` : void 0;
|
|
97
195
|
const style = horizontal ? {
|
|
98
|
-
flexDirection: "row",
|
|
196
|
+
flexDirection: ItemSeparatorComponent ? "row" : void 0,
|
|
99
197
|
position: "absolute",
|
|
100
198
|
top: otherAxisPos,
|
|
101
199
|
bottom: numColumns > 1 ? null : 0,
|
|
102
200
|
height: otherAxisSize,
|
|
103
|
-
left: position
|
|
201
|
+
left: position.relativeCoordinate
|
|
104
202
|
} : {
|
|
105
203
|
position: "absolute",
|
|
106
204
|
left: otherAxisPos,
|
|
107
205
|
right: numColumns > 1 ? null : 0,
|
|
108
206
|
width: otherAxisSize,
|
|
109
|
-
top: position
|
|
207
|
+
top: position.relativeCoordinate
|
|
110
208
|
};
|
|
111
|
-
if (waitForInitialLayout) {
|
|
112
|
-
const visible = use$(`containerDidLayout${id}`);
|
|
113
|
-
style.opacity = visible ? 1 : 0;
|
|
114
|
-
}
|
|
115
209
|
const lastItemKey = use$("lastItemKey");
|
|
116
210
|
const itemKey = use$(`containerItemKey${id}`);
|
|
117
211
|
const data = use$(`containerItemData${id}`);
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
212
|
+
const extraData = use$("extraData");
|
|
213
|
+
const renderedItemInfo = React5.useMemo(
|
|
214
|
+
() => itemKey !== void 0 && getRenderedItem(itemKey),
|
|
215
|
+
[itemKey, data, extraData]
|
|
216
|
+
);
|
|
217
|
+
const { index, renderedItem } = renderedItemInfo || {};
|
|
218
|
+
const onLayout = (event) => {
|
|
219
|
+
if (itemKey !== void 0) {
|
|
220
|
+
const size = Math.floor(event.nativeEvent.layout[horizontal ? "width" : "height"] * 8) / 8;
|
|
221
|
+
if (size === 0) {
|
|
222
|
+
console.log("[WARN] Container 0 height reported, possible bug in LegendList", id, itemKey);
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
updateItemSize(id, itemKey, size);
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
const ref = React5.useRef(null);
|
|
229
|
+
if (isNewArchitecture) {
|
|
230
|
+
React5.useLayoutEffect(() => {
|
|
231
|
+
var _a, _b;
|
|
232
|
+
if (itemKey !== void 0) {
|
|
233
|
+
const measured = (_b = (_a = ref.current) == null ? void 0 : _a.unstable_getBoundingClientRect) == null ? void 0 : _b.call(_a);
|
|
234
|
+
if (measured) {
|
|
235
|
+
const size = Math.floor(measured[horizontal ? "width" : "height"] * 8) / 8;
|
|
236
|
+
if (size) {
|
|
237
|
+
updateItemSize(id, itemKey, size);
|
|
238
|
+
}
|
|
128
239
|
}
|
|
129
240
|
}
|
|
130
|
-
},
|
|
131
|
-
|
|
241
|
+
}, [itemKey]);
|
|
242
|
+
}
|
|
243
|
+
const contextValue = React5.useMemo(
|
|
244
|
+
() => ({ containerId: id, itemKey, index, value: data }),
|
|
245
|
+
[id, itemKey, index, data]
|
|
132
246
|
);
|
|
247
|
+
const contentFragment = /* @__PURE__ */ React5__namespace.default.createElement(React5__namespace.default.Fragment, { key: recycleItems ? void 0 : itemKey }, /* @__PURE__ */ React5__namespace.default.createElement(ContextContainer.Provider, { value: contextValue }, renderedItem, renderedItem && ItemSeparatorComponent && itemKey !== lastItemKey && ItemSeparatorComponent));
|
|
248
|
+
if (maintainVisibleContentPosition) {
|
|
249
|
+
const anchorStyle = position.type === "top" ? { position: "absolute", top: 0, left: 0, right: 0 } : { position: "absolute", bottom: 0, left: 0, right: 0 };
|
|
250
|
+
return /* @__PURE__ */ React5__namespace.default.createElement(LeanView, { style }, /* @__PURE__ */ React5__namespace.default.createElement(LeanView, { style: anchorStyle, onLayout, ref }, contentFragment));
|
|
251
|
+
}
|
|
252
|
+
return /* @__PURE__ */ React5__namespace.default.createElement(LeanView, { style, onLayout, ref }, contentFragment);
|
|
133
253
|
};
|
|
134
254
|
var useAnimatedValue = reactNative.useAnimatedValue || ((initialValue) => {
|
|
135
|
-
return
|
|
255
|
+
return React5.useRef(new reactNative.Animated.Value(initialValue)).current;
|
|
136
256
|
});
|
|
137
|
-
function useValue$(key, getValue,
|
|
257
|
+
function useValue$(key, getValue, useMicrotask) {
|
|
138
258
|
var _a;
|
|
139
259
|
const ctx = useStateContext();
|
|
140
|
-
const animValue = useAnimatedValue((_a = peek$(ctx, key)) != null ? _a : 0);
|
|
141
|
-
|
|
142
|
-
|
|
260
|
+
const animValue = useAnimatedValue((_a = getValue ? getValue(peek$(ctx, key)) : peek$(ctx, key)) != null ? _a : 0);
|
|
261
|
+
React5.useMemo(() => {
|
|
262
|
+
let newValue = void 0;
|
|
263
|
+
listen$(ctx, key, (v) => {
|
|
264
|
+
if (useMicrotask && newValue === void 0) {
|
|
265
|
+
queueMicrotask(() => {
|
|
266
|
+
animValue.setValue(newValue);
|
|
267
|
+
newValue = void 0;
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
newValue = getValue ? getValue(v) : v;
|
|
271
|
+
if (!useMicrotask) {
|
|
272
|
+
animValue.setValue(newValue);
|
|
273
|
+
}
|
|
274
|
+
});
|
|
143
275
|
}, []);
|
|
144
276
|
return animValue;
|
|
145
277
|
}
|
|
146
278
|
|
|
147
279
|
// src/Containers.tsx
|
|
148
|
-
var Containers =
|
|
280
|
+
var Containers = React5__namespace.memo(function Containers2({
|
|
149
281
|
horizontal,
|
|
150
282
|
recycleItems,
|
|
151
283
|
ItemSeparatorComponent,
|
|
@@ -154,18 +286,23 @@ var Containers = React4__namespace.memo(function Containers2({
|
|
|
154
286
|
getRenderedItem
|
|
155
287
|
}) {
|
|
156
288
|
const numContainers = use$("numContainersPooled");
|
|
157
|
-
const animSize = useValue$(
|
|
289
|
+
const animSize = useValue$(
|
|
290
|
+
"totalSize",
|
|
291
|
+
void 0,
|
|
292
|
+
/*useMicrotask*/
|
|
293
|
+
true
|
|
294
|
+
);
|
|
295
|
+
const animOpacity = waitForInitialLayout ? useValue$("containersDidLayout", (value) => value ? 1 : 0) : void 0;
|
|
158
296
|
const containers = [];
|
|
159
297
|
for (let i = 0; i < numContainers; i++) {
|
|
160
298
|
containers.push(
|
|
161
|
-
/* @__PURE__ */
|
|
299
|
+
/* @__PURE__ */ React5__namespace.createElement(
|
|
162
300
|
Container,
|
|
163
301
|
{
|
|
164
302
|
id: i,
|
|
165
303
|
key: i,
|
|
166
304
|
recycleItems,
|
|
167
305
|
horizontal,
|
|
168
|
-
waitForInitialLayout,
|
|
169
306
|
getRenderedItem,
|
|
170
307
|
updateItemSize,
|
|
171
308
|
ItemSeparatorComponent
|
|
@@ -173,21 +310,21 @@ var Containers = React4__namespace.memo(function Containers2({
|
|
|
173
310
|
)
|
|
174
311
|
);
|
|
175
312
|
}
|
|
176
|
-
const style = horizontal ? { width: animSize } : { height: animSize };
|
|
177
|
-
return /* @__PURE__ */
|
|
313
|
+
const style = horizontal ? { width: animSize, opacity: animOpacity } : { height: animSize, opacity: animOpacity };
|
|
314
|
+
return /* @__PURE__ */ React5__namespace.createElement(reactNative.Animated.View, { style }, containers);
|
|
178
315
|
});
|
|
179
316
|
|
|
180
317
|
// src/ListComponent.tsx
|
|
181
318
|
var getComponent = (Component) => {
|
|
182
|
-
if (
|
|
319
|
+
if (React5__namespace.isValidElement(Component)) {
|
|
183
320
|
return Component;
|
|
184
321
|
}
|
|
185
322
|
if (Component) {
|
|
186
|
-
return /* @__PURE__ */
|
|
323
|
+
return /* @__PURE__ */ React5__namespace.createElement(Component, null);
|
|
187
324
|
}
|
|
188
325
|
return null;
|
|
189
326
|
};
|
|
190
|
-
var ListComponent =
|
|
327
|
+
var ListComponent = React5__namespace.memo(function ListComponent2({
|
|
191
328
|
style,
|
|
192
329
|
contentContainerStyle,
|
|
193
330
|
horizontal,
|
|
@@ -203,7 +340,6 @@ var ListComponent = React4__namespace.memo(function ListComponent2({
|
|
|
203
340
|
ListFooterComponent,
|
|
204
341
|
ListFooterComponentStyle,
|
|
205
342
|
ListEmptyComponent,
|
|
206
|
-
ListEmptyComponentStyle,
|
|
207
343
|
getRenderedItem,
|
|
208
344
|
updateItemSize,
|
|
209
345
|
refScrollView,
|
|
@@ -214,17 +350,17 @@ var ListComponent = React4__namespace.memo(function ListComponent2({
|
|
|
214
350
|
const ctx = useStateContext();
|
|
215
351
|
const animPaddingTop = useValue$("paddingTop");
|
|
216
352
|
const animScrollAdjust = useValue$("scrollAdjust");
|
|
217
|
-
const ScrollComponent = renderScrollComponent ?
|
|
218
|
-
() =>
|
|
353
|
+
const ScrollComponent = renderScrollComponent ? React5.useMemo(
|
|
354
|
+
() => React5__namespace.forwardRef((props, ref) => renderScrollComponent({ ...props, ref })),
|
|
219
355
|
[renderScrollComponent]
|
|
220
356
|
) : reactNative.ScrollView;
|
|
221
357
|
const additionalSize = { marginTop: animScrollAdjust, paddingTop: animPaddingTop };
|
|
222
|
-
return /* @__PURE__ */
|
|
358
|
+
return /* @__PURE__ */ React5__namespace.createElement(
|
|
223
359
|
ScrollComponent,
|
|
224
360
|
{
|
|
225
361
|
...rest,
|
|
226
362
|
style,
|
|
227
|
-
maintainVisibleContentPosition: maintainVisibleContentPosition ? { minIndexForVisible: 0 } : void 0,
|
|
363
|
+
maintainVisibleContentPosition: maintainVisibleContentPosition && !ListEmptyComponent ? { minIndexForVisible: 0 } : void 0,
|
|
228
364
|
contentContainerStyle: [
|
|
229
365
|
contentContainerStyle,
|
|
230
366
|
horizontal ? {
|
|
@@ -237,8 +373,8 @@ var ListComponent = React4__namespace.memo(function ListComponent2({
|
|
|
237
373
|
contentOffset: initialContentOffset ? horizontal ? { x: initialContentOffset, y: 0 } : { x: 0, y: initialContentOffset } : void 0,
|
|
238
374
|
ref: refScrollView
|
|
239
375
|
},
|
|
240
|
-
/* @__PURE__ */
|
|
241
|
-
ListHeaderComponent && /* @__PURE__ */
|
|
376
|
+
/* @__PURE__ */ React5__namespace.createElement(reactNative.Animated.View, { style: additionalSize }),
|
|
377
|
+
ListHeaderComponent && /* @__PURE__ */ React5__namespace.createElement(
|
|
242
378
|
reactNative.Animated.View,
|
|
243
379
|
{
|
|
244
380
|
style: ListHeaderComponentStyle,
|
|
@@ -252,8 +388,8 @@ var ListComponent = React4__namespace.memo(function ListComponent2({
|
|
|
252
388
|
},
|
|
253
389
|
getComponent(ListHeaderComponent)
|
|
254
390
|
),
|
|
255
|
-
ListEmptyComponent &&
|
|
256
|
-
/* @__PURE__ */
|
|
391
|
+
ListEmptyComponent && getComponent(ListEmptyComponent),
|
|
392
|
+
/* @__PURE__ */ React5__namespace.createElement(
|
|
257
393
|
Containers,
|
|
258
394
|
{
|
|
259
395
|
horizontal,
|
|
@@ -264,7 +400,7 @@ var ListComponent = React4__namespace.memo(function ListComponent2({
|
|
|
264
400
|
updateItemSize
|
|
265
401
|
}
|
|
266
402
|
),
|
|
267
|
-
ListFooterComponent && /* @__PURE__ */
|
|
403
|
+
ListFooterComponent && /* @__PURE__ */ React5__namespace.createElement(reactNative.View, { style: ListFooterComponentStyle }, getComponent(ListFooterComponent))
|
|
268
404
|
);
|
|
269
405
|
});
|
|
270
406
|
|
|
@@ -304,14 +440,6 @@ var ScrollAdjustHandler = class {
|
|
|
304
440
|
return this.appliedAdjust;
|
|
305
441
|
}
|
|
306
442
|
};
|
|
307
|
-
var symbolFirst = Symbol();
|
|
308
|
-
function useInit(cb) {
|
|
309
|
-
const refValue = React4.useRef(symbolFirst);
|
|
310
|
-
if (refValue.current === symbolFirst) {
|
|
311
|
-
refValue.current = cb();
|
|
312
|
-
}
|
|
313
|
-
return refValue.current;
|
|
314
|
-
}
|
|
315
443
|
|
|
316
444
|
// src/viewability.ts
|
|
317
445
|
var mapViewabilityConfigCallbackPairs = /* @__PURE__ */ new Map();
|
|
@@ -462,13 +590,12 @@ function maybeUpdateViewabilityCallback(ctx, configId, viewToken) {
|
|
|
462
590
|
|
|
463
591
|
// src/LegendList.tsx
|
|
464
592
|
var DEFAULT_DRAW_DISTANCE = 250;
|
|
465
|
-
var POSITION_OUT_OF_VIEW = -1e7;
|
|
466
593
|
var DEFAULT_ITEM_SIZE = 100;
|
|
467
|
-
var LegendList =
|
|
468
|
-
return /* @__PURE__ */
|
|
594
|
+
var LegendList = React5.forwardRef(function LegendList2(props, forwardedRef) {
|
|
595
|
+
return /* @__PURE__ */ React5__namespace.createElement(StateProvider, null, /* @__PURE__ */ React5__namespace.createElement(LegendListInner, { ...props, ref: forwardedRef }));
|
|
469
596
|
});
|
|
470
|
-
var LegendListInner =
|
|
471
|
-
var _a, _b, _c, _d;
|
|
597
|
+
var LegendListInner = React5.forwardRef(function LegendListInner2(props, forwardedRef) {
|
|
598
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
472
599
|
const {
|
|
473
600
|
data,
|
|
474
601
|
initialScrollIndex,
|
|
@@ -488,20 +615,27 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
|
|
|
488
615
|
renderItem,
|
|
489
616
|
estimatedItemSize,
|
|
490
617
|
getEstimatedItemSize,
|
|
491
|
-
onEndReached,
|
|
492
|
-
onStartReached,
|
|
493
618
|
ListEmptyComponent,
|
|
494
619
|
onItemSizeChanged,
|
|
495
620
|
scrollEventThrottle,
|
|
496
621
|
refScrollView,
|
|
622
|
+
waitForInitialLayout = true,
|
|
623
|
+
extraData,
|
|
624
|
+
onLayout: onLayoutProp,
|
|
497
625
|
...rest
|
|
498
626
|
} = props;
|
|
499
627
|
const { style, contentContainerStyle } = props;
|
|
628
|
+
const callbacks = React5.useRef({
|
|
629
|
+
onStartReached: rest.onStartReached,
|
|
630
|
+
onEndReached: rest.onEndReached
|
|
631
|
+
});
|
|
632
|
+
callbacks.current.onStartReached = rest.onStartReached;
|
|
633
|
+
callbacks.current.onEndReached = rest.onEndReached;
|
|
500
634
|
const ctx = useStateContext();
|
|
501
|
-
const refScroller =
|
|
635
|
+
const refScroller = React5.useRef(null);
|
|
502
636
|
const scrollBuffer = drawDistance != null ? drawDistance : DEFAULT_DRAW_DISTANCE;
|
|
503
637
|
const keyExtractor = keyExtractorProp != null ? keyExtractorProp : (item, index) => index.toString();
|
|
504
|
-
const refState =
|
|
638
|
+
const refState = React5.useRef();
|
|
505
639
|
const getId = (index) => {
|
|
506
640
|
var _a2;
|
|
507
641
|
const data2 = (_a2 = refState.current) == null ? void 0 : _a2.data;
|
|
@@ -535,7 +669,7 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
|
|
|
535
669
|
}
|
|
536
670
|
return 0;
|
|
537
671
|
};
|
|
538
|
-
const initialContentOffset = initialScrollOffset != null ? initialScrollOffset :
|
|
672
|
+
const initialContentOffset = initialScrollOffset != null ? initialScrollOffset : React5.useMemo(calculateInitialOffset, []);
|
|
539
673
|
if (!refState.current) {
|
|
540
674
|
const initialScrollLength = reactNative.Dimensions.get("window")[horizontal ? "width" : "height"];
|
|
541
675
|
refState.current = {
|
|
@@ -543,7 +677,7 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
|
|
|
543
677
|
positions: /* @__PURE__ */ new Map(),
|
|
544
678
|
columns: /* @__PURE__ */ new Map(),
|
|
545
679
|
pendingAdjust: 0,
|
|
546
|
-
|
|
680
|
+
waitingForMicrotask: false,
|
|
547
681
|
isStartReached: initialContentOffset < initialScrollLength * onStartReachedThreshold,
|
|
548
682
|
isEndReached: false,
|
|
549
683
|
isAtBottom: false,
|
|
@@ -576,9 +710,9 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
|
|
|
576
710
|
belowAnchorElementPositions: void 0,
|
|
577
711
|
rowHeights: /* @__PURE__ */ new Map(),
|
|
578
712
|
startReachedBlockedByTimer: false,
|
|
579
|
-
layoutsPending: /* @__PURE__ */ new Set(),
|
|
580
713
|
scrollForNextCalculateItemsInView: void 0,
|
|
581
|
-
enableScrollForNextCalculateItemsInView: true
|
|
714
|
+
enableScrollForNextCalculateItemsInView: true,
|
|
715
|
+
minIndexSizeChanged: 0
|
|
582
716
|
};
|
|
583
717
|
refState.current.idsInFirstRender = new Set(data.map((_, i) => getId(i)));
|
|
584
718
|
if (maintainVisibleContentPosition) {
|
|
@@ -597,6 +731,8 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
|
|
|
597
731
|
}
|
|
598
732
|
}
|
|
599
733
|
set$(ctx, "scrollAdjust", 0);
|
|
734
|
+
set$(ctx, "maintainVisibleContentPosition", maintainVisibleContentPosition);
|
|
735
|
+
set$(ctx, "extraData", extraData);
|
|
600
736
|
}
|
|
601
737
|
const getAnchorElementIndex = () => {
|
|
602
738
|
const state = refState.current;
|
|
@@ -606,16 +742,16 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
|
|
|
606
742
|
}
|
|
607
743
|
return void 0;
|
|
608
744
|
};
|
|
609
|
-
const addTotalSize =
|
|
745
|
+
const addTotalSize = React5.useCallback((key, add, totalSizeBelowAnchor) => {
|
|
610
746
|
const state = refState.current;
|
|
611
|
-
const
|
|
747
|
+
const { scrollLength, indexByKey, anchorElement } = state;
|
|
748
|
+
const index = key === null ? 0 : indexByKey.get(key);
|
|
612
749
|
let isAboveAnchor = false;
|
|
613
750
|
if (maintainVisibleContentPosition) {
|
|
614
|
-
if (
|
|
751
|
+
if (anchorElement && index < getAnchorElementIndex()) {
|
|
615
752
|
isAboveAnchor = true;
|
|
616
753
|
}
|
|
617
754
|
}
|
|
618
|
-
state.totalSize;
|
|
619
755
|
if (key === null) {
|
|
620
756
|
state.totalSize = add;
|
|
621
757
|
state.totalSizeBelowAnchor = totalSizeBelowAnchor;
|
|
@@ -626,19 +762,19 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
|
|
|
626
762
|
}
|
|
627
763
|
}
|
|
628
764
|
let applyAdjustValue = void 0;
|
|
629
|
-
|
|
630
|
-
|
|
765
|
+
const totalSize = state.totalSize;
|
|
766
|
+
let resultSize = totalSize;
|
|
767
|
+
if (maintainVisibleContentPosition && totalSize > scrollLength) {
|
|
768
|
+
const newAdjust = anchorElement.coordinate - state.totalSizeBelowAnchor;
|
|
631
769
|
applyAdjustValue = -newAdjust;
|
|
632
770
|
state.belowAnchorElementPositions = buildElementPositionsBelowAnchor();
|
|
633
771
|
state.rowHeights.clear();
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
state.scroll -= diff;
|
|
641
|
-
});
|
|
772
|
+
if (applyAdjustValue !== void 0) {
|
|
773
|
+
resultSize -= applyAdjustValue;
|
|
774
|
+
refState.current.scrollAdjustHandler.requestAdjust(applyAdjustValue, (diff) => {
|
|
775
|
+
state.scroll -= diff;
|
|
776
|
+
});
|
|
777
|
+
}
|
|
642
778
|
}
|
|
643
779
|
set$(ctx, "totalSize", resultSize);
|
|
644
780
|
if (alignItemsAtEnd) {
|
|
@@ -696,7 +832,7 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
|
|
|
696
832
|
}
|
|
697
833
|
return res;
|
|
698
834
|
};
|
|
699
|
-
const calculateItemsInView =
|
|
835
|
+
const calculateItemsInView = React5.useCallback((speed) => {
|
|
700
836
|
const state = refState.current;
|
|
701
837
|
const {
|
|
702
838
|
data: data2,
|
|
@@ -705,12 +841,10 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
|
|
|
705
841
|
startBufferedId: startBufferedIdOrig,
|
|
706
842
|
positions,
|
|
707
843
|
columns,
|
|
708
|
-
scrollAdjustHandler
|
|
709
|
-
layoutsPending
|
|
844
|
+
scrollAdjustHandler
|
|
710
845
|
} = state;
|
|
711
|
-
if (state.
|
|
712
|
-
|
|
713
|
-
state.animFrameLayout = null;
|
|
846
|
+
if (state.waitingForMicrotask) {
|
|
847
|
+
state.waitingForMicrotask = false;
|
|
714
848
|
}
|
|
715
849
|
if (!data2) {
|
|
716
850
|
return;
|
|
@@ -718,7 +852,17 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
|
|
|
718
852
|
const topPad = (peek$(ctx, "stylePaddingTop") || 0) + (peek$(ctx, "headerSize") || 0);
|
|
719
853
|
const previousScrollAdjust = scrollAdjustHandler.getAppliedAdjust();
|
|
720
854
|
const scrollExtra = Math.max(-16, Math.min(16, speed)) * 16;
|
|
721
|
-
const scroll = scrollState - previousScrollAdjust - topPad
|
|
855
|
+
const scroll = scrollState - previousScrollAdjust - topPad;
|
|
856
|
+
let scrollBufferTop = scrollBuffer;
|
|
857
|
+
let scrollBufferBottom = scrollBuffer;
|
|
858
|
+
if (scrollExtra > 8) {
|
|
859
|
+
scrollBufferTop = 0;
|
|
860
|
+
scrollBufferBottom = scrollBuffer + scrollExtra;
|
|
861
|
+
}
|
|
862
|
+
if (scrollExtra < -8) {
|
|
863
|
+
scrollBufferTop = scrollBuffer - scrollExtra;
|
|
864
|
+
scrollBufferBottom = 0;
|
|
865
|
+
}
|
|
722
866
|
if (state.scrollForNextCalculateItemsInView) {
|
|
723
867
|
const { top: top2, bottom } = state.scrollForNextCalculateItemsInView;
|
|
724
868
|
if (scroll > top2 && scroll < bottom) {
|
|
@@ -731,8 +875,11 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
|
|
|
731
875
|
let startBufferedId = null;
|
|
732
876
|
let endNoBuffer = null;
|
|
733
877
|
let endBuffered = null;
|
|
734
|
-
|
|
735
|
-
|
|
878
|
+
let loopStart = startBufferedIdOrig ? state.indexByKey.get(startBufferedIdOrig) || 0 : 0;
|
|
879
|
+
if (state.minIndexSizeChanged !== void 0) {
|
|
880
|
+
loopStart = Math.min(state.minIndexSizeChanged, loopStart);
|
|
881
|
+
state.minIndexSizeChanged = void 0;
|
|
882
|
+
}
|
|
736
883
|
const anchorElementIndex = getAnchorElementIndex();
|
|
737
884
|
for (let i = loopStart; i >= 0; i--) {
|
|
738
885
|
const id = getId(i);
|
|
@@ -790,7 +937,7 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
|
|
|
790
937
|
if (startNoBuffer === null && top + size > scroll) {
|
|
791
938
|
startNoBuffer = i;
|
|
792
939
|
}
|
|
793
|
-
if (startBuffered === null && top + size > scroll -
|
|
940
|
+
if (startBuffered === null && top + size > scroll - scrollBufferTop) {
|
|
794
941
|
startBuffered = i;
|
|
795
942
|
startBufferedId = id;
|
|
796
943
|
}
|
|
@@ -798,7 +945,7 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
|
|
|
798
945
|
if (top <= scrollBottom) {
|
|
799
946
|
endNoBuffer = i;
|
|
800
947
|
}
|
|
801
|
-
if (top <= scrollBottom +
|
|
948
|
+
if (top <= scrollBottom + scrollBufferBottom) {
|
|
802
949
|
endBuffered = i;
|
|
803
950
|
} else {
|
|
804
951
|
break;
|
|
@@ -818,9 +965,9 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
|
|
|
818
965
|
endBuffered,
|
|
819
966
|
endNoBuffer
|
|
820
967
|
});
|
|
821
|
-
const nextTop = Math.ceil(startBuffered ? positions.get(startBufferedId) + scrollBuffer : 0);
|
|
968
|
+
const nextTop = Math.ceil(startBuffered !== null ? positions.get(startBufferedId) + scrollBuffer : 0);
|
|
822
969
|
const nextBottom = Math.floor(
|
|
823
|
-
endBuffered ? (positions.get(getId(endBuffered + 1)) || 0) - scrollLength - scrollBuffer : 0
|
|
970
|
+
endBuffered !== null ? (positions.get(getId(endBuffered + 1)) || 0) - scrollLength - scrollBuffer : 0
|
|
824
971
|
);
|
|
825
972
|
if (state.enableScrollForNextCalculateItemsInView) {
|
|
826
973
|
state.scrollForNextCalculateItemsInView = nextTop >= 0 && nextBottom >= 0 ? {
|
|
@@ -852,7 +999,7 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
|
|
|
852
999
|
break;
|
|
853
1000
|
}
|
|
854
1001
|
const index = state.indexByKey.get(key);
|
|
855
|
-
const pos = peek$(ctx, `containerPosition${u}`);
|
|
1002
|
+
const pos = peek$(ctx, `containerPosition${u}`).top;
|
|
856
1003
|
if (index < startBuffered || index > endBuffered) {
|
|
857
1004
|
const distance = Math.abs(pos - top2);
|
|
858
1005
|
if (index < 0 || distance > furthestDistance) {
|
|
@@ -871,7 +1018,7 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
|
|
|
871
1018
|
set$(ctx, `containerItemKey${containerId}`, id);
|
|
872
1019
|
const index = state.indexByKey.get(id);
|
|
873
1020
|
set$(ctx, `containerItemData${containerId}`, data2[index]);
|
|
874
|
-
set$(ctx, `containerPosition${containerId}`,
|
|
1021
|
+
set$(ctx, `containerPosition${containerId}`, ANCHORED_POSITION_OUT_OF_VIEW);
|
|
875
1022
|
set$(ctx, `containerColumn${containerId}`, -1);
|
|
876
1023
|
if (__DEV__ && numContainers > peek$(ctx, "numContainersPooled")) {
|
|
877
1024
|
console.warn(
|
|
@@ -895,19 +1042,31 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
|
|
|
895
1042
|
if (item) {
|
|
896
1043
|
const id = getId(itemIndex);
|
|
897
1044
|
if (itemKey !== id || itemIndex < startBuffered || itemIndex > endBuffered) {
|
|
898
|
-
const prevPos = peek$(ctx, `containerPosition${i}`);
|
|
1045
|
+
const prevPos = peek$(ctx, `containerPosition${i}`).top;
|
|
899
1046
|
const pos = positions.get(id) || 0;
|
|
900
1047
|
const size = getItemSize(id, itemIndex, data2[i]);
|
|
901
1048
|
if (pos + size >= scroll && pos <= scrollBottom || prevPos + size >= scroll && prevPos <= scrollBottom) {
|
|
902
|
-
set$(ctx, `containerPosition${i}`,
|
|
1049
|
+
set$(ctx, `containerPosition${i}`, ANCHORED_POSITION_OUT_OF_VIEW);
|
|
903
1050
|
}
|
|
904
1051
|
} else {
|
|
905
|
-
const pos =
|
|
1052
|
+
const pos = {
|
|
1053
|
+
type: "top",
|
|
1054
|
+
relativeCoordinate: positions.get(id) || 0,
|
|
1055
|
+
top: positions.get(id) || 0
|
|
1056
|
+
};
|
|
906
1057
|
const column2 = columns.get(id) || 1;
|
|
1058
|
+
if (maintainVisibleContentPosition && itemIndex < anchorElementIndex) {
|
|
1059
|
+
const currentRow = Math.floor(itemIndex / numColumnsProp);
|
|
1060
|
+
const rowHeight = getRowHeight(currentRow);
|
|
1061
|
+
const elementHeight = getItemSize(id, itemIndex, data2[i]);
|
|
1062
|
+
const diff = rowHeight - elementHeight;
|
|
1063
|
+
pos.relativeCoordinate = pos.top + getRowHeight(currentRow) - diff;
|
|
1064
|
+
pos.type = "bottom";
|
|
1065
|
+
}
|
|
907
1066
|
const prevPos = peek$(ctx, `containerPosition${i}`);
|
|
908
1067
|
const prevColumn = peek$(ctx, `containerColumn${i}`);
|
|
909
1068
|
const prevData = peek$(ctx, `containerItemData${i}`);
|
|
910
|
-
if (pos > POSITION_OUT_OF_VIEW && pos !== prevPos) {
|
|
1069
|
+
if (pos.relativeCoordinate > POSITION_OUT_OF_VIEW && pos.top !== prevPos.top) {
|
|
911
1070
|
set$(ctx, `containerPosition${i}`, pos);
|
|
912
1071
|
}
|
|
913
1072
|
if (column2 >= 0 && column2 !== prevColumn) {
|
|
@@ -920,12 +1079,7 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
|
|
|
920
1079
|
}
|
|
921
1080
|
}
|
|
922
1081
|
}
|
|
923
|
-
|
|
924
|
-
for (const containerId of layoutsPending) {
|
|
925
|
-
set$(ctx, `containerDidLayout${containerId}`, true);
|
|
926
|
-
}
|
|
927
|
-
layoutsPending.clear();
|
|
928
|
-
}
|
|
1082
|
+
set$(ctx, "containersDidLayout", true);
|
|
929
1083
|
if (state.viewabilityConfigCallbackPairs) {
|
|
930
1084
|
updateViewableItems(
|
|
931
1085
|
state,
|
|
@@ -969,6 +1123,7 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
|
|
|
969
1123
|
if (refState.current) {
|
|
970
1124
|
refState.current.isAtBottom = distanceFromEnd < scrollLength * maintainScrollAtEndThreshold;
|
|
971
1125
|
}
|
|
1126
|
+
const { onEndReached } = callbacks.current;
|
|
972
1127
|
if (onEndReached) {
|
|
973
1128
|
if (!refState.current.isEndReached) {
|
|
974
1129
|
if (distanceFromEnd < onEndReachedThreshold * scrollLength) {
|
|
@@ -990,6 +1145,7 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
|
|
|
990
1145
|
const { scrollLength, scroll } = refState.current;
|
|
991
1146
|
const distanceFromTop = scroll;
|
|
992
1147
|
refState.current.isAtTop = distanceFromTop < 0;
|
|
1148
|
+
const { onStartReached } = callbacks.current;
|
|
993
1149
|
if (onStartReached) {
|
|
994
1150
|
if (!refState.current.isStartReached && !refState.current.startReachedBlockedByTimer) {
|
|
995
1151
|
if (distanceFromTop < onStartReachedThreshold * scrollLength) {
|
|
@@ -1018,13 +1174,13 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
|
|
|
1018
1174
|
const itemKey = peek$(ctx, `containerItemKey${i}`);
|
|
1019
1175
|
if (!keyExtractorProp || itemKey && state.indexByKey.get(itemKey) === void 0) {
|
|
1020
1176
|
set$(ctx, `containerItemKey${i}`, void 0);
|
|
1021
|
-
set$(ctx, `
|
|
1177
|
+
set$(ctx, `containerItemData${i}`, void 0);
|
|
1178
|
+
set$(ctx, `containerPosition${i}`, ANCHORED_POSITION_OUT_OF_VIEW);
|
|
1022
1179
|
set$(ctx, `containerColumn${i}`, -1);
|
|
1023
1180
|
}
|
|
1024
1181
|
}
|
|
1025
1182
|
if (!keyExtractorProp) {
|
|
1026
|
-
state.
|
|
1027
|
-
state.positions;
|
|
1183
|
+
state.positions.clear();
|
|
1028
1184
|
}
|
|
1029
1185
|
calculateItemsInView(state.scrollVelocity);
|
|
1030
1186
|
}
|
|
@@ -1039,20 +1195,63 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
|
|
|
1039
1195
|
const isFirst = !refState.current.renderItem;
|
|
1040
1196
|
if (isFirst || data !== refState.current.data || numColumnsProp !== peek$(ctx, "numColumns")) {
|
|
1041
1197
|
if (!keyExtractorProp && !isFirst && data !== refState.current.data) {
|
|
1042
|
-
refState.current.sizes.clear();
|
|
1043
1198
|
refState.current.positions.clear();
|
|
1044
1199
|
}
|
|
1045
1200
|
refState.current.data = data;
|
|
1046
1201
|
let totalSize = 0;
|
|
1047
1202
|
let totalSizeBelowIndex = 0;
|
|
1048
1203
|
const indexByKey = /* @__PURE__ */ new Map();
|
|
1204
|
+
const newPositions = /* @__PURE__ */ new Map();
|
|
1049
1205
|
let column = 1;
|
|
1050
1206
|
let maxSizeInRow = 0;
|
|
1051
1207
|
for (let i = 0; i < data.length; i++) {
|
|
1052
1208
|
const key = getId(i);
|
|
1209
|
+
if (__DEV__) {
|
|
1210
|
+
if (indexByKey.has(key)) {
|
|
1211
|
+
console.error(
|
|
1212
|
+
`[legend-list] Error: Detected overlapping key (${key}) which causes missing items and gaps and other terrrible things. Check that keyExtractor returns unique values.`
|
|
1213
|
+
);
|
|
1214
|
+
}
|
|
1215
|
+
}
|
|
1053
1216
|
indexByKey.set(key, i);
|
|
1217
|
+
if (refState.current.positions.get(key) != null && refState.current.indexByKey.get(key) === i) {
|
|
1218
|
+
newPositions.set(key, refState.current.positions.get(key));
|
|
1219
|
+
}
|
|
1054
1220
|
}
|
|
1055
1221
|
refState.current.indexByKey = indexByKey;
|
|
1222
|
+
refState.current.positions = newPositions;
|
|
1223
|
+
if (!isFirst) {
|
|
1224
|
+
if (maintainVisibleContentPosition) {
|
|
1225
|
+
if (refState.current.anchorElement == null || indexByKey.get(refState.current.anchorElement.id) == null) {
|
|
1226
|
+
if (data.length) {
|
|
1227
|
+
const newAnchorElement = {
|
|
1228
|
+
coordinate: 0,
|
|
1229
|
+
id: getId(0)
|
|
1230
|
+
};
|
|
1231
|
+
refState.current.anchorElement = newAnchorElement;
|
|
1232
|
+
(_a = refState.current.belowAnchorElementPositions) == null ? void 0 : _a.clear();
|
|
1233
|
+
(_b = refScroller.current) == null ? void 0 : _b.scrollTo({ x: 0, y: 0, animated: false });
|
|
1234
|
+
setTimeout(() => {
|
|
1235
|
+
calculateItemsInView(0);
|
|
1236
|
+
}, 0);
|
|
1237
|
+
} else {
|
|
1238
|
+
refState.current.startBufferedId = void 0;
|
|
1239
|
+
}
|
|
1240
|
+
}
|
|
1241
|
+
} else {
|
|
1242
|
+
if (refState.current.startBufferedId != null && newPositions.get(refState.current.startBufferedId) == null) {
|
|
1243
|
+
if (data.length) {
|
|
1244
|
+
refState.current.startBufferedId = getId(0);
|
|
1245
|
+
} else {
|
|
1246
|
+
refState.current.startBufferedId = void 0;
|
|
1247
|
+
}
|
|
1248
|
+
(_c = refScroller.current) == null ? void 0 : _c.scrollTo({ x: 0, y: 0, animated: false });
|
|
1249
|
+
setTimeout(() => {
|
|
1250
|
+
calculateItemsInView(0);
|
|
1251
|
+
}, 0);
|
|
1252
|
+
}
|
|
1253
|
+
}
|
|
1254
|
+
}
|
|
1056
1255
|
const anchorElementIndex = getAnchorElementIndex();
|
|
1057
1256
|
for (let i = 0; i < data.length; i++) {
|
|
1058
1257
|
const key = getId(i);
|
|
@@ -1073,15 +1272,18 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
|
|
|
1073
1272
|
}
|
|
1074
1273
|
addTotalSize(null, totalSize, totalSizeBelowIndex);
|
|
1075
1274
|
}
|
|
1076
|
-
|
|
1275
|
+
React5.useEffect(() => {
|
|
1077
1276
|
checkResetContainers(
|
|
1078
1277
|
/*reset*/
|
|
1079
1278
|
!isFirst
|
|
1080
1279
|
);
|
|
1081
1280
|
}, [isFirst, data, numColumnsProp]);
|
|
1281
|
+
React5.useEffect(() => {
|
|
1282
|
+
set$(ctx, "extraData", extraData);
|
|
1283
|
+
}, [extraData]);
|
|
1082
1284
|
refState.current.renderItem = renderItem;
|
|
1083
|
-
const lastItemKey = getId(data
|
|
1084
|
-
const stylePaddingTop = (
|
|
1285
|
+
const lastItemKey = data.length > 0 ? getId(data.length - 1) : void 0;
|
|
1286
|
+
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;
|
|
1085
1287
|
const initalizeStateVars = () => {
|
|
1086
1288
|
set$(ctx, "lastItemKey", lastItemKey);
|
|
1087
1289
|
set$(ctx, "numColumns", numColumnsProp);
|
|
@@ -1090,8 +1292,8 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
|
|
|
1090
1292
|
if (isFirst) {
|
|
1091
1293
|
initalizeStateVars();
|
|
1092
1294
|
}
|
|
1093
|
-
|
|
1094
|
-
const getRenderedItem =
|
|
1295
|
+
React5.useEffect(initalizeStateVars, [lastItemKey, numColumnsProp, stylePaddingTop]);
|
|
1296
|
+
const getRenderedItem = React5.useCallback((key) => {
|
|
1095
1297
|
var _a2, _b2;
|
|
1096
1298
|
const state = refState.current;
|
|
1097
1299
|
if (!state) {
|
|
@@ -1102,89 +1304,27 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
|
|
|
1102
1304
|
if (index === void 0) {
|
|
1103
1305
|
return null;
|
|
1104
1306
|
}
|
|
1105
|
-
const
|
|
1106
|
-
|
|
1107
|
-
useInit(() => {
|
|
1108
|
-
const value = ctx.mapViewabilityValues.get(key2);
|
|
1109
|
-
if (value) {
|
|
1110
|
-
callback(value);
|
|
1111
|
-
}
|
|
1112
|
-
});
|
|
1113
|
-
ctx.mapViewabilityCallbacks.set(key2, callback);
|
|
1114
|
-
React4.useEffect(
|
|
1115
|
-
() => () => {
|
|
1116
|
-
ctx.mapViewabilityCallbacks.delete(key2);
|
|
1117
|
-
},
|
|
1118
|
-
[]
|
|
1119
|
-
);
|
|
1307
|
+
const useViewability2 = (configId, callback) => {
|
|
1308
|
+
useViewability(configId, callback);
|
|
1120
1309
|
};
|
|
1121
|
-
const
|
|
1122
|
-
|
|
1123
|
-
const value = ctx.mapViewabilityAmountValues.get(containerId);
|
|
1124
|
-
if (value) {
|
|
1125
|
-
callback(value);
|
|
1126
|
-
}
|
|
1127
|
-
});
|
|
1128
|
-
ctx.mapViewabilityAmountCallbacks.set(containerId, callback);
|
|
1129
|
-
React4.useEffect(
|
|
1130
|
-
() => () => {
|
|
1131
|
-
ctx.mapViewabilityAmountCallbacks.delete(containerId);
|
|
1132
|
-
},
|
|
1133
|
-
[]
|
|
1134
|
-
);
|
|
1310
|
+
const useViewabilityAmount2 = (callback) => {
|
|
1311
|
+
useViewabilityAmount(callback);
|
|
1135
1312
|
};
|
|
1136
|
-
const
|
|
1137
|
-
|
|
1138
|
-
const state2 = refState.current;
|
|
1139
|
-
let prevIndex = index;
|
|
1140
|
-
let prevItem = state2.data[index];
|
|
1141
|
-
const signal = `containerItemKey${containerId}`;
|
|
1142
|
-
const run = () => {
|
|
1143
|
-
const data3 = state2.data;
|
|
1144
|
-
if (data3) {
|
|
1145
|
-
const newKey = peek$(ctx, signal);
|
|
1146
|
-
const newIndex = state2.indexByKey.get(newKey);
|
|
1147
|
-
const newItem = data3[newIndex];
|
|
1148
|
-
if (newItem) {
|
|
1149
|
-
effect({
|
|
1150
|
-
index: newIndex,
|
|
1151
|
-
item: newItem,
|
|
1152
|
-
prevIndex,
|
|
1153
|
-
prevItem
|
|
1154
|
-
});
|
|
1155
|
-
}
|
|
1156
|
-
prevIndex = newIndex;
|
|
1157
|
-
prevItem = newItem;
|
|
1158
|
-
}
|
|
1159
|
-
};
|
|
1160
|
-
run();
|
|
1161
|
-
return listen$(ctx, signal, run);
|
|
1162
|
-
}, []);
|
|
1313
|
+
const useRecyclingEffect2 = (effect) => {
|
|
1314
|
+
useRecyclingEffect(effect);
|
|
1163
1315
|
};
|
|
1164
|
-
const
|
|
1165
|
-
|
|
1166
|
-
() => typeof valueOrFun === "function" ? valueOrFun({
|
|
1167
|
-
index,
|
|
1168
|
-
item: refState.current.data[index],
|
|
1169
|
-
prevIndex: void 0,
|
|
1170
|
-
prevItem: void 0
|
|
1171
|
-
}) : valueOrFun
|
|
1172
|
-
);
|
|
1173
|
-
useRecyclingEffect((state2) => {
|
|
1174
|
-
const newState = typeof valueOrFun === "function" ? valueOrFun(state2) : valueOrFun;
|
|
1175
|
-
stateInfo[1](newState);
|
|
1176
|
-
});
|
|
1177
|
-
return stateInfo;
|
|
1316
|
+
const useRecyclingState2 = (valueOrFun) => {
|
|
1317
|
+
return useRecyclingState(valueOrFun);
|
|
1178
1318
|
};
|
|
1179
1319
|
const renderedItem = (_b2 = (_a2 = refState.current).renderItem) == null ? void 0 : _b2.call(_a2, {
|
|
1180
1320
|
item: data2[index],
|
|
1181
1321
|
index,
|
|
1182
|
-
useViewability,
|
|
1183
|
-
useViewabilityAmount,
|
|
1184
|
-
useRecyclingEffect,
|
|
1185
|
-
useRecyclingState
|
|
1322
|
+
useViewability: useViewability2,
|
|
1323
|
+
useViewabilityAmount: useViewabilityAmount2,
|
|
1324
|
+
useRecyclingEffect: useRecyclingEffect2,
|
|
1325
|
+
useRecyclingState: useRecyclingState2
|
|
1186
1326
|
});
|
|
1187
|
-
return renderedItem;
|
|
1327
|
+
return { index, renderedItem };
|
|
1188
1328
|
}, []);
|
|
1189
1329
|
useInit(() => {
|
|
1190
1330
|
var _a2;
|
|
@@ -1196,33 +1336,26 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
|
|
|
1196
1336
|
const averageItemSize = (_a2 = estimatedItemSize != null ? estimatedItemSize : getEstimatedItemSize == null ? void 0 : getEstimatedItemSize(0, data[0])) != null ? _a2 : DEFAULT_ITEM_SIZE;
|
|
1197
1337
|
const numContainers = Math.ceil((scrollLength + scrollBuffer * 2) / averageItemSize) * numColumnsProp;
|
|
1198
1338
|
for (let i = 0; i < numContainers; i++) {
|
|
1199
|
-
set$(ctx, `containerPosition${i}`,
|
|
1339
|
+
set$(ctx, `containerPosition${i}`, ANCHORED_POSITION_OUT_OF_VIEW);
|
|
1200
1340
|
set$(ctx, `containerColumn${i}`, -1);
|
|
1201
1341
|
}
|
|
1202
1342
|
set$(ctx, "numContainers", numContainers);
|
|
1203
1343
|
set$(ctx, "numContainersPooled", numContainers * 2);
|
|
1204
1344
|
calculateItemsInView(state.scrollVelocity);
|
|
1205
1345
|
});
|
|
1206
|
-
const updateItemSize =
|
|
1207
|
-
|
|
1208
|
-
const
|
|
1346
|
+
const updateItemSize = React5.useCallback((containerId, itemKey, size) => {
|
|
1347
|
+
const state = refState.current;
|
|
1348
|
+
const { sizes, indexByKey, columns, sizesLaidOut, data: data2 } = state;
|
|
1209
1349
|
if (!data2) {
|
|
1210
1350
|
return;
|
|
1211
1351
|
}
|
|
1212
|
-
const state = refState.current;
|
|
1213
|
-
const { sizes, indexByKey, idsInFirstRender, columns, sizesLaidOut } = state;
|
|
1214
1352
|
const index = indexByKey.get(itemKey);
|
|
1215
1353
|
const numColumns = peek$(ctx, "numColumns");
|
|
1216
|
-
|
|
1217
|
-
const prevSize =
|
|
1218
|
-
const measured = peek$(ctx, `containerDidLayout${containerId}`);
|
|
1219
|
-
if (!measured) {
|
|
1220
|
-
state.layoutsPending.add(containerId);
|
|
1221
|
-
}
|
|
1354
|
+
state.minIndexSizeChanged = state.minIndexSizeChanged !== void 0 ? Math.min(state.minIndexSizeChanged, index) : index;
|
|
1355
|
+
const prevSize = getItemSize(itemKey, index, data2);
|
|
1222
1356
|
if (!prevSize || Math.abs(prevSize - size) > 0.5) {
|
|
1223
1357
|
let diff;
|
|
1224
1358
|
if (numColumns > 1) {
|
|
1225
|
-
const prevMaxSizeInRow = getRowHeight(row);
|
|
1226
1359
|
sizes.set(itemKey, size);
|
|
1227
1360
|
const column = columns.get(itemKey);
|
|
1228
1361
|
const loopStart = index - (column - 1);
|
|
@@ -1232,7 +1365,7 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
|
|
|
1232
1365
|
const size2 = getItemSize(id, i, data2[i]);
|
|
1233
1366
|
nextMaxSizeInRow = Math.max(nextMaxSizeInRow, size2);
|
|
1234
1367
|
}
|
|
1235
|
-
diff = nextMaxSizeInRow -
|
|
1368
|
+
diff = nextMaxSizeInRow - prevSize;
|
|
1236
1369
|
} else {
|
|
1237
1370
|
sizes.set(itemKey, size);
|
|
1238
1371
|
diff = size - prevSize;
|
|
@@ -1260,11 +1393,14 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
|
|
|
1260
1393
|
addTotalSize(itemKey, diff, 0);
|
|
1261
1394
|
doMaintainScrollAtEnd(true);
|
|
1262
1395
|
const scrollVelocity = state.scrollVelocity;
|
|
1263
|
-
if (!state.
|
|
1264
|
-
if (!peek$(ctx,
|
|
1265
|
-
state.
|
|
1266
|
-
|
|
1267
|
-
|
|
1396
|
+
if (!state.waitingForMicrotask && (Number.isNaN(scrollVelocity) || Math.abs(scrollVelocity) < 1)) {
|
|
1397
|
+
if (!peek$(ctx, "containersDidLayout")) {
|
|
1398
|
+
state.waitingForMicrotask = true;
|
|
1399
|
+
queueMicrotask(() => {
|
|
1400
|
+
if (state.waitingForMicrotask) {
|
|
1401
|
+
state.waitingForMicrotask = false;
|
|
1402
|
+
calculateItemsInView(state.scrollVelocity);
|
|
1403
|
+
}
|
|
1268
1404
|
});
|
|
1269
1405
|
} else {
|
|
1270
1406
|
calculateItemsInView(state.scrollVelocity);
|
|
@@ -1273,22 +1409,24 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
|
|
|
1273
1409
|
if (onItemSizeChanged) {
|
|
1274
1410
|
onItemSizeChanged({ size, previous: prevSize, index, itemKey, itemData: data2[index] });
|
|
1275
1411
|
}
|
|
1276
|
-
} else {
|
|
1277
|
-
set$(ctx, `containerDidLayout${containerId}`, true);
|
|
1278
1412
|
}
|
|
1279
1413
|
}, []);
|
|
1280
|
-
const handleScrollDebounced =
|
|
1414
|
+
const handleScrollDebounced = React5.useCallback((velocity) => {
|
|
1281
1415
|
calculateItemsInView(velocity);
|
|
1282
1416
|
checkAtBottom();
|
|
1283
1417
|
checkAtTop();
|
|
1284
1418
|
}, []);
|
|
1285
|
-
const onLayout =
|
|
1419
|
+
const onLayout = React5.useCallback((event) => {
|
|
1286
1420
|
const scrollLength = event.nativeEvent.layout[horizontal ? "width" : "height"];
|
|
1421
|
+
const didChange = scrollLength !== refState.current.scrollLength;
|
|
1287
1422
|
refState.current.scrollLength = scrollLength;
|
|
1288
1423
|
doMaintainScrollAtEnd(false);
|
|
1289
1424
|
doUpdatePaddingTop();
|
|
1290
1425
|
checkAtBottom();
|
|
1291
1426
|
checkAtTop();
|
|
1427
|
+
if (didChange) {
|
|
1428
|
+
calculateItemsInView(0);
|
|
1429
|
+
}
|
|
1292
1430
|
if (__DEV__) {
|
|
1293
1431
|
const isWidthZero = event.nativeEvent.layout.width === 0;
|
|
1294
1432
|
const isHeightZero = event.nativeEvent.layout.height === 0;
|
|
@@ -1298,8 +1436,11 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
|
|
|
1298
1436
|
);
|
|
1299
1437
|
}
|
|
1300
1438
|
}
|
|
1439
|
+
if (onLayoutProp) {
|
|
1440
|
+
onLayoutProp(event);
|
|
1441
|
+
}
|
|
1301
1442
|
}, []);
|
|
1302
|
-
const handleScroll =
|
|
1443
|
+
const handleScroll = React5.useCallback(
|
|
1303
1444
|
(event, fromSelf) => {
|
|
1304
1445
|
var _a2, _b2, _c2;
|
|
1305
1446
|
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) {
|
|
@@ -1341,7 +1482,7 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
|
|
|
1341
1482
|
},
|
|
1342
1483
|
[]
|
|
1343
1484
|
);
|
|
1344
|
-
|
|
1485
|
+
React5.useImperativeHandle(
|
|
1345
1486
|
forwardedRef,
|
|
1346
1487
|
() => {
|
|
1347
1488
|
const scrollToIndex = ({ index, animated }) => {
|
|
@@ -1351,9 +1492,9 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
|
|
|
1351
1492
|
};
|
|
1352
1493
|
return {
|
|
1353
1494
|
getNativeScrollRef: () => refScroller.current,
|
|
1354
|
-
getScrollableNode: refScroller.current.getScrollableNode,
|
|
1355
|
-
getScrollResponder: refScroller.current.getScrollResponder,
|
|
1356
|
-
flashScrollIndicators: refScroller.current.flashScrollIndicators,
|
|
1495
|
+
getScrollableNode: () => refScroller.current.getScrollableNode(),
|
|
1496
|
+
getScrollResponder: () => refScroller.current.getScrollResponder(),
|
|
1497
|
+
flashScrollIndicators: () => refScroller.current.flashScrollIndicators(),
|
|
1357
1498
|
scrollToIndex,
|
|
1358
1499
|
scrollToOffset: ({ offset, animated }) => {
|
|
1359
1500
|
const offsetObj = horizontal ? { x: offset, y: 0 } : { x: 0, y: offset };
|
|
@@ -1365,12 +1506,12 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
|
|
|
1365
1506
|
scrollToIndex({ index, animated });
|
|
1366
1507
|
}
|
|
1367
1508
|
},
|
|
1368
|
-
scrollToEnd: refScroller.current.scrollToEnd
|
|
1509
|
+
scrollToEnd: () => refScroller.current.scrollToEnd()
|
|
1369
1510
|
};
|
|
1370
1511
|
},
|
|
1371
1512
|
[]
|
|
1372
1513
|
);
|
|
1373
|
-
return /* @__PURE__ */
|
|
1514
|
+
return /* @__PURE__ */ React5__namespace.createElement(
|
|
1374
1515
|
ListComponent,
|
|
1375
1516
|
{
|
|
1376
1517
|
...rest,
|
|
@@ -1395,9 +1536,14 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
|
|
|
1395
1536
|
ListEmptyComponent: data.length === 0 ? ListEmptyComponent : void 0,
|
|
1396
1537
|
maintainVisibleContentPosition,
|
|
1397
1538
|
scrollEventThrottle: scrollEventThrottle != null ? scrollEventThrottle : reactNative.Platform.OS === "web" ? 16 : void 0,
|
|
1539
|
+
waitForInitialLayout,
|
|
1398
1540
|
style
|
|
1399
1541
|
}
|
|
1400
1542
|
);
|
|
1401
1543
|
});
|
|
1402
1544
|
|
|
1403
1545
|
exports.LegendList = LegendList;
|
|
1546
|
+
exports.useRecyclingEffect = useRecyclingEffect;
|
|
1547
|
+
exports.useRecyclingState = useRecyclingState;
|
|
1548
|
+
exports.useViewability = useViewability;
|
|
1549
|
+
exports.useViewabilityAmount = useViewabilityAmount;
|