@legendapp/list 1.0.0-beta.5 → 1.0.0-beta.7
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 +1 -0
- package/index.d.ts +1 -0
- package/index.js +38 -10
- package/index.mjs +38 -10
- package/package.json +1 -1
package/index.d.mts
CHANGED
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -229,7 +229,7 @@ var Container = ({
|
|
|
229
229
|
if (isNewArchitecture) {
|
|
230
230
|
React5.useLayoutEffect(() => {
|
|
231
231
|
var _a, _b;
|
|
232
|
-
if (itemKey) {
|
|
232
|
+
if (itemKey !== void 0) {
|
|
233
233
|
const measured = (_b = (_a = ref.current) == null ? void 0 : _a.unstable_getBoundingClientRect) == null ? void 0 : _b.call(_a);
|
|
234
234
|
if (measured) {
|
|
235
235
|
const size = Math.floor(measured[horizontal ? "width" : "height"] * 8) / 8;
|
|
@@ -254,12 +254,24 @@ var Container = ({
|
|
|
254
254
|
var useAnimatedValue = reactNative.useAnimatedValue || ((initialValue) => {
|
|
255
255
|
return React5.useRef(new reactNative.Animated.Value(initialValue)).current;
|
|
256
256
|
});
|
|
257
|
-
function useValue$(key, getValue,
|
|
257
|
+
function useValue$(key, getValue, useMicrotask) {
|
|
258
258
|
var _a;
|
|
259
259
|
const ctx = useStateContext();
|
|
260
260
|
const animValue = useAnimatedValue((_a = getValue ? getValue(peek$(ctx, key)) : peek$(ctx, key)) != null ? _a : 0);
|
|
261
261
|
React5.useMemo(() => {
|
|
262
|
-
|
|
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
|
+
});
|
|
263
275
|
}, []);
|
|
264
276
|
return animValue;
|
|
265
277
|
}
|
|
@@ -274,7 +286,12 @@ var Containers = React5__namespace.memo(function Containers2({
|
|
|
274
286
|
getRenderedItem
|
|
275
287
|
}) {
|
|
276
288
|
const numContainers = use$("numContainersPooled");
|
|
277
|
-
const animSize = useValue$(
|
|
289
|
+
const animSize = useValue$(
|
|
290
|
+
"totalSize",
|
|
291
|
+
void 0,
|
|
292
|
+
/*useMicrotask*/
|
|
293
|
+
true
|
|
294
|
+
);
|
|
278
295
|
const animOpacity = waitForInitialLayout ? useValue$("containersDidLayout", (value) => value ? 1 : 0) : void 0;
|
|
279
296
|
const containers = [];
|
|
280
297
|
for (let i = 0; i < numContainers; i++) {
|
|
@@ -343,7 +360,7 @@ var ListComponent = React5__namespace.memo(function ListComponent2({
|
|
|
343
360
|
{
|
|
344
361
|
...rest,
|
|
345
362
|
style,
|
|
346
|
-
maintainVisibleContentPosition: maintainVisibleContentPosition ? { minIndexForVisible: 0 } : void 0,
|
|
363
|
+
maintainVisibleContentPosition: maintainVisibleContentPosition && !ListEmptyComponent ? { minIndexForVisible: 0 } : void 0,
|
|
347
364
|
contentContainerStyle: [
|
|
348
365
|
contentContainerStyle,
|
|
349
366
|
horizontal ? {
|
|
@@ -694,7 +711,8 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
|
|
|
694
711
|
rowHeights: /* @__PURE__ */ new Map(),
|
|
695
712
|
startReachedBlockedByTimer: false,
|
|
696
713
|
scrollForNextCalculateItemsInView: void 0,
|
|
697
|
-
enableScrollForNextCalculateItemsInView: true
|
|
714
|
+
enableScrollForNextCalculateItemsInView: true,
|
|
715
|
+
minIndexSizeChanged: 0
|
|
698
716
|
};
|
|
699
717
|
refState.current.idsInFirstRender = new Set(data.map((_, i) => getId(i)));
|
|
700
718
|
if (maintainVisibleContentPosition) {
|
|
@@ -856,8 +874,11 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
|
|
|
856
874
|
let startBufferedId = null;
|
|
857
875
|
let endNoBuffer = null;
|
|
858
876
|
let endBuffered = null;
|
|
859
|
-
|
|
860
|
-
|
|
877
|
+
let loopStart = startBufferedIdOrig ? state.indexByKey.get(startBufferedIdOrig) || 0 : 0;
|
|
878
|
+
if (state.minIndexSizeChanged !== void 0) {
|
|
879
|
+
loopStart = Math.min(state.minIndexSizeChanged, loopStart);
|
|
880
|
+
state.minIndexSizeChanged = void 0;
|
|
881
|
+
}
|
|
861
882
|
const anchorElementIndex = getAnchorElementIndex();
|
|
862
883
|
for (let i = loopStart; i >= 0; i--) {
|
|
863
884
|
const id = getId(i);
|
|
@@ -1152,12 +1173,12 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
|
|
|
1152
1173
|
const itemKey = peek$(ctx, `containerItemKey${i}`);
|
|
1153
1174
|
if (!keyExtractorProp || itemKey && state.indexByKey.get(itemKey) === void 0) {
|
|
1154
1175
|
set$(ctx, `containerItemKey${i}`, void 0);
|
|
1176
|
+
set$(ctx, `containerItemData${i}`, void 0);
|
|
1155
1177
|
set$(ctx, `containerPosition${i}`, ANCHORED_POSITION_OUT_OF_VIEW);
|
|
1156
1178
|
set$(ctx, `containerColumn${i}`, -1);
|
|
1157
1179
|
}
|
|
1158
1180
|
}
|
|
1159
1181
|
if (!keyExtractorProp) {
|
|
1160
|
-
state.sizes.clear();
|
|
1161
1182
|
state.positions.clear();
|
|
1162
1183
|
}
|
|
1163
1184
|
calculateItemsInView(state.scrollVelocity);
|
|
@@ -1173,7 +1194,6 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
|
|
|
1173
1194
|
const isFirst = !refState.current.renderItem;
|
|
1174
1195
|
if (isFirst || data !== refState.current.data || numColumnsProp !== peek$(ctx, "numColumns")) {
|
|
1175
1196
|
if (!keyExtractorProp && !isFirst && data !== refState.current.data) {
|
|
1176
|
-
refState.current.sizes.clear();
|
|
1177
1197
|
refState.current.positions.clear();
|
|
1178
1198
|
}
|
|
1179
1199
|
refState.current.data = data;
|
|
@@ -1185,6 +1205,13 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
|
|
|
1185
1205
|
let maxSizeInRow = 0;
|
|
1186
1206
|
for (let i = 0; i < data.length; i++) {
|
|
1187
1207
|
const key = getId(i);
|
|
1208
|
+
if (__DEV__) {
|
|
1209
|
+
if (indexByKey.has(key)) {
|
|
1210
|
+
console.error(
|
|
1211
|
+
`[legend-list] Error: Detected overlapping key (${key}) which causes missing items and gaps and other terrrible things. Check that keyExtractor returns unique values.`
|
|
1212
|
+
);
|
|
1213
|
+
}
|
|
1214
|
+
}
|
|
1188
1215
|
indexByKey.set(key, i);
|
|
1189
1216
|
if (refState.current.positions.get(key) != null && refState.current.indexByKey.get(key) === i) {
|
|
1190
1217
|
newPositions.set(key, refState.current.positions.get(key));
|
|
@@ -1323,6 +1350,7 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
|
|
|
1323
1350
|
const { sizes, indexByKey, columns, sizesLaidOut } = state;
|
|
1324
1351
|
const index = indexByKey.get(itemKey);
|
|
1325
1352
|
const numColumns = peek$(ctx, "numColumns");
|
|
1353
|
+
state.minIndexSizeChanged = state.minIndexSizeChanged !== void 0 ? Math.min(state.minIndexSizeChanged, index) : index;
|
|
1326
1354
|
const row = Math.floor(index / numColumns);
|
|
1327
1355
|
const prevSize = getRowHeight(row);
|
|
1328
1356
|
if (!prevSize || Math.abs(prevSize - size) > 0.5) {
|
package/index.mjs
CHANGED
|
@@ -208,7 +208,7 @@ var Container = ({
|
|
|
208
208
|
if (isNewArchitecture) {
|
|
209
209
|
useLayoutEffect(() => {
|
|
210
210
|
var _a, _b;
|
|
211
|
-
if (itemKey) {
|
|
211
|
+
if (itemKey !== void 0) {
|
|
212
212
|
const measured = (_b = (_a = ref.current) == null ? void 0 : _a.unstable_getBoundingClientRect) == null ? void 0 : _b.call(_a);
|
|
213
213
|
if (measured) {
|
|
214
214
|
const size = Math.floor(measured[horizontal ? "width" : "height"] * 8) / 8;
|
|
@@ -233,12 +233,24 @@ var Container = ({
|
|
|
233
233
|
var useAnimatedValue = useAnimatedValue$1 || ((initialValue) => {
|
|
234
234
|
return useRef(new Animated.Value(initialValue)).current;
|
|
235
235
|
});
|
|
236
|
-
function useValue$(key, getValue,
|
|
236
|
+
function useValue$(key, getValue, useMicrotask) {
|
|
237
237
|
var _a;
|
|
238
238
|
const ctx = useStateContext();
|
|
239
239
|
const animValue = useAnimatedValue((_a = getValue ? getValue(peek$(ctx, key)) : peek$(ctx, key)) != null ? _a : 0);
|
|
240
240
|
useMemo(() => {
|
|
241
|
-
|
|
241
|
+
let newValue = void 0;
|
|
242
|
+
listen$(ctx, key, (v) => {
|
|
243
|
+
if (useMicrotask && newValue === void 0) {
|
|
244
|
+
queueMicrotask(() => {
|
|
245
|
+
animValue.setValue(newValue);
|
|
246
|
+
newValue = void 0;
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
newValue = getValue ? getValue(v) : v;
|
|
250
|
+
if (!useMicrotask) {
|
|
251
|
+
animValue.setValue(newValue);
|
|
252
|
+
}
|
|
253
|
+
});
|
|
242
254
|
}, []);
|
|
243
255
|
return animValue;
|
|
244
256
|
}
|
|
@@ -253,7 +265,12 @@ var Containers = React5.memo(function Containers2({
|
|
|
253
265
|
getRenderedItem
|
|
254
266
|
}) {
|
|
255
267
|
const numContainers = use$("numContainersPooled");
|
|
256
|
-
const animSize = useValue$(
|
|
268
|
+
const animSize = useValue$(
|
|
269
|
+
"totalSize",
|
|
270
|
+
void 0,
|
|
271
|
+
/*useMicrotask*/
|
|
272
|
+
true
|
|
273
|
+
);
|
|
257
274
|
const animOpacity = waitForInitialLayout ? useValue$("containersDidLayout", (value) => value ? 1 : 0) : void 0;
|
|
258
275
|
const containers = [];
|
|
259
276
|
for (let i = 0; i < numContainers; i++) {
|
|
@@ -322,7 +339,7 @@ var ListComponent = React5.memo(function ListComponent2({
|
|
|
322
339
|
{
|
|
323
340
|
...rest,
|
|
324
341
|
style,
|
|
325
|
-
maintainVisibleContentPosition: maintainVisibleContentPosition ? { minIndexForVisible: 0 } : void 0,
|
|
342
|
+
maintainVisibleContentPosition: maintainVisibleContentPosition && !ListEmptyComponent ? { minIndexForVisible: 0 } : void 0,
|
|
326
343
|
contentContainerStyle: [
|
|
327
344
|
contentContainerStyle,
|
|
328
345
|
horizontal ? {
|
|
@@ -673,7 +690,8 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
|
|
|
673
690
|
rowHeights: /* @__PURE__ */ new Map(),
|
|
674
691
|
startReachedBlockedByTimer: false,
|
|
675
692
|
scrollForNextCalculateItemsInView: void 0,
|
|
676
|
-
enableScrollForNextCalculateItemsInView: true
|
|
693
|
+
enableScrollForNextCalculateItemsInView: true,
|
|
694
|
+
minIndexSizeChanged: 0
|
|
677
695
|
};
|
|
678
696
|
refState.current.idsInFirstRender = new Set(data.map((_, i) => getId(i)));
|
|
679
697
|
if (maintainVisibleContentPosition) {
|
|
@@ -835,8 +853,11 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
|
|
|
835
853
|
let startBufferedId = null;
|
|
836
854
|
let endNoBuffer = null;
|
|
837
855
|
let endBuffered = null;
|
|
838
|
-
|
|
839
|
-
|
|
856
|
+
let loopStart = startBufferedIdOrig ? state.indexByKey.get(startBufferedIdOrig) || 0 : 0;
|
|
857
|
+
if (state.minIndexSizeChanged !== void 0) {
|
|
858
|
+
loopStart = Math.min(state.minIndexSizeChanged, loopStart);
|
|
859
|
+
state.minIndexSizeChanged = void 0;
|
|
860
|
+
}
|
|
840
861
|
const anchorElementIndex = getAnchorElementIndex();
|
|
841
862
|
for (let i = loopStart; i >= 0; i--) {
|
|
842
863
|
const id = getId(i);
|
|
@@ -1131,12 +1152,12 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
|
|
|
1131
1152
|
const itemKey = peek$(ctx, `containerItemKey${i}`);
|
|
1132
1153
|
if (!keyExtractorProp || itemKey && state.indexByKey.get(itemKey) === void 0) {
|
|
1133
1154
|
set$(ctx, `containerItemKey${i}`, void 0);
|
|
1155
|
+
set$(ctx, `containerItemData${i}`, void 0);
|
|
1134
1156
|
set$(ctx, `containerPosition${i}`, ANCHORED_POSITION_OUT_OF_VIEW);
|
|
1135
1157
|
set$(ctx, `containerColumn${i}`, -1);
|
|
1136
1158
|
}
|
|
1137
1159
|
}
|
|
1138
1160
|
if (!keyExtractorProp) {
|
|
1139
|
-
state.sizes.clear();
|
|
1140
1161
|
state.positions.clear();
|
|
1141
1162
|
}
|
|
1142
1163
|
calculateItemsInView(state.scrollVelocity);
|
|
@@ -1152,7 +1173,6 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
|
|
|
1152
1173
|
const isFirst = !refState.current.renderItem;
|
|
1153
1174
|
if (isFirst || data !== refState.current.data || numColumnsProp !== peek$(ctx, "numColumns")) {
|
|
1154
1175
|
if (!keyExtractorProp && !isFirst && data !== refState.current.data) {
|
|
1155
|
-
refState.current.sizes.clear();
|
|
1156
1176
|
refState.current.positions.clear();
|
|
1157
1177
|
}
|
|
1158
1178
|
refState.current.data = data;
|
|
@@ -1164,6 +1184,13 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
|
|
|
1164
1184
|
let maxSizeInRow = 0;
|
|
1165
1185
|
for (let i = 0; i < data.length; i++) {
|
|
1166
1186
|
const key = getId(i);
|
|
1187
|
+
if (__DEV__) {
|
|
1188
|
+
if (indexByKey.has(key)) {
|
|
1189
|
+
console.error(
|
|
1190
|
+
`[legend-list] Error: Detected overlapping key (${key}) which causes missing items and gaps and other terrrible things. Check that keyExtractor returns unique values.`
|
|
1191
|
+
);
|
|
1192
|
+
}
|
|
1193
|
+
}
|
|
1167
1194
|
indexByKey.set(key, i);
|
|
1168
1195
|
if (refState.current.positions.get(key) != null && refState.current.indexByKey.get(key) === i) {
|
|
1169
1196
|
newPositions.set(key, refState.current.positions.get(key));
|
|
@@ -1302,6 +1329,7 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
|
|
|
1302
1329
|
const { sizes, indexByKey, columns, sizesLaidOut } = state;
|
|
1303
1330
|
const index = indexByKey.get(itemKey);
|
|
1304
1331
|
const numColumns = peek$(ctx, "numColumns");
|
|
1332
|
+
state.minIndexSizeChanged = state.minIndexSizeChanged !== void 0 ? Math.min(state.minIndexSizeChanged, index) : index;
|
|
1305
1333
|
const row = Math.floor(index / numColumns);
|
|
1306
1334
|
const prevSize = getRowHeight(row);
|
|
1307
1335
|
if (!prevSize || Math.abs(prevSize - size) > 0.5) {
|