@legendapp/list 3.0.0-beta.10 → 3.0.0-beta.11
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 -1
- package/index.d.ts +1 -1
- package/index.js +86 -42
- package/index.mjs +86 -42
- package/index.native.d.mts +1 -1
- package/index.native.d.ts +1 -1
- package/index.native.js +82 -39
- package/index.native.mjs +82 -39
- package/keyboard.js +1 -2
- package/keyboard.mjs +1 -2
- package/package.json +1 -1
- package/section-list.js +13 -5
- package/section-list.mjs +13 -5
- package/section-list.native.js +13 -2
- package/section-list.native.mjs +13 -2
package/index.d.mts
CHANGED
|
@@ -12,7 +12,7 @@ declare const LegendList: (<T>(props: LegendListProps<T> & React.RefAttributes<L
|
|
|
12
12
|
declare function useViewability<ItemT = any>(callback: ViewabilityCallback<ItemT>, configId?: string): void;
|
|
13
13
|
declare function useViewabilityAmount<ItemT = any>(callback: ViewabilityAmountCallback<ItemT>): void;
|
|
14
14
|
declare function useRecyclingEffect(effect: (info: LegendListRecyclingState<unknown>) => void | (() => void)): void;
|
|
15
|
-
declare function useRecyclingState<ItemT>(valueOrFun: ((info: LegendListRecyclingState<ItemT>) => ItemT) | ItemT): readonly [ItemT
|
|
15
|
+
declare function useRecyclingState<ItemT>(valueOrFun: ((info: LegendListRecyclingState<ItemT>) => ItemT) | ItemT): readonly [ItemT, Dispatch<SetStateAction<ItemT>>];
|
|
16
16
|
declare function useIsLastItem(): boolean;
|
|
17
17
|
declare function useListScrollSize(): {
|
|
18
18
|
width: number;
|
package/index.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ declare const LegendList: (<T>(props: LegendListProps<T> & React.RefAttributes<L
|
|
|
12
12
|
declare function useViewability<ItemT = any>(callback: ViewabilityCallback<ItemT>, configId?: string): void;
|
|
13
13
|
declare function useViewabilityAmount<ItemT = any>(callback: ViewabilityAmountCallback<ItemT>): void;
|
|
14
14
|
declare function useRecyclingEffect(effect: (info: LegendListRecyclingState<unknown>) => void | (() => void)): void;
|
|
15
|
-
declare function useRecyclingState<ItemT>(valueOrFun: ((info: LegendListRecyclingState<ItemT>) => ItemT) | ItemT): readonly [ItemT
|
|
15
|
+
declare function useRecyclingState<ItemT>(valueOrFun: ((info: LegendListRecyclingState<ItemT>) => ItemT) | ItemT): readonly [ItemT, Dispatch<SetStateAction<ItemT>>];
|
|
16
16
|
declare function useIsLastItem(): boolean;
|
|
17
17
|
declare function useListScrollSize(): {
|
|
18
18
|
width: number;
|
package/index.js
CHANGED
|
@@ -367,48 +367,70 @@ function useInit(cb) {
|
|
|
367
367
|
|
|
368
368
|
// src/state/ContextContainer.ts
|
|
369
369
|
var ContextContainer = React3.createContext(null);
|
|
370
|
+
function useContextContainer() {
|
|
371
|
+
return React3.useContext(ContextContainer);
|
|
372
|
+
}
|
|
370
373
|
function useViewability(callback, configId) {
|
|
371
374
|
const ctx = useStateContext();
|
|
372
|
-
const
|
|
373
|
-
const key = containerId + (configId != null ? configId : "");
|
|
375
|
+
const containerContext = useContextContainer();
|
|
374
376
|
useInit(() => {
|
|
377
|
+
if (!containerContext) {
|
|
378
|
+
return;
|
|
379
|
+
}
|
|
380
|
+
const { containerId } = containerContext;
|
|
381
|
+
const key = containerId + (configId != null ? configId : "");
|
|
375
382
|
const value = ctx.mapViewabilityValues.get(key);
|
|
376
383
|
if (value) {
|
|
377
384
|
callback(value);
|
|
378
385
|
}
|
|
379
386
|
});
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
387
|
+
React3.useEffect(() => {
|
|
388
|
+
if (!containerContext) {
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
391
|
+
const { containerId } = containerContext;
|
|
392
|
+
const key = containerId + (configId != null ? configId : "");
|
|
393
|
+
ctx.mapViewabilityCallbacks.set(key, callback);
|
|
394
|
+
return () => {
|
|
383
395
|
ctx.mapViewabilityCallbacks.delete(key);
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
);
|
|
396
|
+
};
|
|
397
|
+
}, [ctx, callback, configId, containerContext]);
|
|
387
398
|
}
|
|
388
399
|
function useViewabilityAmount(callback) {
|
|
389
400
|
const ctx = useStateContext();
|
|
390
|
-
const
|
|
401
|
+
const containerContext = useContextContainer();
|
|
391
402
|
useInit(() => {
|
|
403
|
+
if (!containerContext) {
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
406
|
+
const { containerId } = containerContext;
|
|
392
407
|
const value = ctx.mapViewabilityAmountValues.get(containerId);
|
|
393
408
|
if (value) {
|
|
394
409
|
callback(value);
|
|
395
410
|
}
|
|
396
411
|
});
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
412
|
+
React3.useEffect(() => {
|
|
413
|
+
if (!containerContext) {
|
|
414
|
+
return;
|
|
415
|
+
}
|
|
416
|
+
const { containerId } = containerContext;
|
|
417
|
+
ctx.mapViewabilityAmountCallbacks.set(containerId, callback);
|
|
418
|
+
return () => {
|
|
400
419
|
ctx.mapViewabilityAmountCallbacks.delete(containerId);
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
);
|
|
420
|
+
};
|
|
421
|
+
}, [ctx, callback, containerContext]);
|
|
404
422
|
}
|
|
405
423
|
function useRecyclingEffect(effect) {
|
|
406
|
-
const
|
|
424
|
+
const containerContext = useContextContainer();
|
|
407
425
|
const prevValues = React3.useRef({
|
|
408
426
|
prevIndex: void 0,
|
|
409
427
|
prevItem: void 0
|
|
410
428
|
});
|
|
411
429
|
React3.useEffect(() => {
|
|
430
|
+
if (!containerContext) {
|
|
431
|
+
return;
|
|
432
|
+
}
|
|
433
|
+
const { index, value } = containerContext;
|
|
412
434
|
let ret;
|
|
413
435
|
if (prevValues.current.prevIndex !== void 0 && prevValues.current.prevItem !== void 0) {
|
|
414
436
|
ret = effect({
|
|
@@ -423,48 +445,73 @@ function useRecyclingEffect(effect) {
|
|
|
423
445
|
prevItem: value
|
|
424
446
|
};
|
|
425
447
|
return ret;
|
|
426
|
-
}, [
|
|
448
|
+
}, [effect, containerContext]);
|
|
427
449
|
}
|
|
428
450
|
function useRecyclingState(valueOrFun) {
|
|
429
|
-
|
|
430
|
-
const
|
|
431
|
-
|
|
432
|
-
|
|
451
|
+
var _a3, _b;
|
|
452
|
+
const containerContext = useContextContainer();
|
|
453
|
+
const computeValue = (ctx) => {
|
|
454
|
+
if (isFunction(valueOrFun)) {
|
|
455
|
+
const initializer = valueOrFun;
|
|
456
|
+
return ctx ? initializer({
|
|
457
|
+
index: ctx.index,
|
|
458
|
+
item: ctx.value,
|
|
459
|
+
prevIndex: void 0,
|
|
460
|
+
prevItem: void 0
|
|
461
|
+
}) : initializer();
|
|
462
|
+
}
|
|
463
|
+
return valueOrFun;
|
|
464
|
+
};
|
|
465
|
+
const [stateValue, setStateValue] = React3.useState(() => {
|
|
466
|
+
return computeValue(containerContext);
|
|
433
467
|
});
|
|
434
|
-
const
|
|
435
|
-
const
|
|
436
|
-
if (
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
index,
|
|
440
|
-
item: value,
|
|
441
|
-
prevIndex: void 0,
|
|
442
|
-
prevItem: void 0
|
|
443
|
-
}) : valueOrFun;
|
|
468
|
+
const prevItemKeyRef = React3.useRef((_a3 = containerContext == null ? void 0 : containerContext.itemKey) != null ? _a3 : null);
|
|
469
|
+
const currentItemKey = (_b = containerContext == null ? void 0 : containerContext.itemKey) != null ? _b : null;
|
|
470
|
+
if (currentItemKey !== null && prevItemKeyRef.current !== currentItemKey) {
|
|
471
|
+
prevItemKeyRef.current = currentItemKey;
|
|
472
|
+
setStateValue(computeValue(containerContext));
|
|
444
473
|
}
|
|
474
|
+
const triggerLayout = containerContext == null ? void 0 : containerContext.triggerLayout;
|
|
445
475
|
const setState = React3.useCallback(
|
|
446
476
|
(newState) => {
|
|
447
|
-
|
|
448
|
-
|
|
477
|
+
if (!triggerLayout) {
|
|
478
|
+
return;
|
|
479
|
+
}
|
|
480
|
+
setStateValue((prevValue) => {
|
|
481
|
+
return isFunction(newState) ? newState(prevValue) : newState;
|
|
482
|
+
});
|
|
449
483
|
triggerLayout();
|
|
450
484
|
},
|
|
451
|
-
[triggerLayout
|
|
485
|
+
[triggerLayout]
|
|
452
486
|
);
|
|
453
|
-
return [
|
|
487
|
+
return [stateValue, setState];
|
|
454
488
|
}
|
|
455
489
|
function useIsLastItem() {
|
|
456
|
-
const
|
|
457
|
-
const isLast = useSelector$("lastItemKeys", (lastItemKeys) =>
|
|
490
|
+
const containerContext = useContextContainer();
|
|
491
|
+
const isLast = useSelector$("lastItemKeys", (lastItemKeys) => {
|
|
492
|
+
if (containerContext) {
|
|
493
|
+
const { itemKey } = containerContext;
|
|
494
|
+
if (!isNullOrUndefined(itemKey)) {
|
|
495
|
+
return (lastItemKeys == null ? void 0 : lastItemKeys.includes(itemKey)) || false;
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
return false;
|
|
499
|
+
});
|
|
458
500
|
return isLast;
|
|
459
501
|
}
|
|
460
502
|
function useListScrollSize() {
|
|
461
503
|
const [scrollSize] = useArr$(["scrollSize"]);
|
|
462
504
|
return scrollSize;
|
|
463
505
|
}
|
|
506
|
+
var noop = () => {
|
|
507
|
+
};
|
|
464
508
|
function useSyncLayout() {
|
|
465
|
-
|
|
466
|
-
|
|
509
|
+
const containerContext = useContextContainer();
|
|
510
|
+
if (containerContext) {
|
|
511
|
+
const { triggerLayout: syncLayout } = containerContext;
|
|
467
512
|
return syncLayout;
|
|
513
|
+
} else {
|
|
514
|
+
return noop;
|
|
468
515
|
}
|
|
469
516
|
}
|
|
470
517
|
|
|
@@ -1109,9 +1156,6 @@ function ScrollAdjust() {
|
|
|
1109
1156
|
} else {
|
|
1110
1157
|
scrollView.scrollBy(0, scrollDelta);
|
|
1111
1158
|
}
|
|
1112
|
-
if (IS_DEV) {
|
|
1113
|
-
console.log("ScrollAdjust (web scrollBy)", scrollDelta, "total offset:", scrollOffset);
|
|
1114
|
-
}
|
|
1115
1159
|
}
|
|
1116
1160
|
lastScrollOffsetRef.current = scrollOffset;
|
|
1117
1161
|
}
|
package/index.mjs
CHANGED
|
@@ -346,48 +346,70 @@ function useInit(cb) {
|
|
|
346
346
|
|
|
347
347
|
// src/state/ContextContainer.ts
|
|
348
348
|
var ContextContainer = createContext(null);
|
|
349
|
+
function useContextContainer() {
|
|
350
|
+
return useContext(ContextContainer);
|
|
351
|
+
}
|
|
349
352
|
function useViewability(callback, configId) {
|
|
350
353
|
const ctx = useStateContext();
|
|
351
|
-
const
|
|
352
|
-
const key = containerId + (configId != null ? configId : "");
|
|
354
|
+
const containerContext = useContextContainer();
|
|
353
355
|
useInit(() => {
|
|
356
|
+
if (!containerContext) {
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
const { containerId } = containerContext;
|
|
360
|
+
const key = containerId + (configId != null ? configId : "");
|
|
354
361
|
const value = ctx.mapViewabilityValues.get(key);
|
|
355
362
|
if (value) {
|
|
356
363
|
callback(value);
|
|
357
364
|
}
|
|
358
365
|
});
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
366
|
+
useEffect(() => {
|
|
367
|
+
if (!containerContext) {
|
|
368
|
+
return;
|
|
369
|
+
}
|
|
370
|
+
const { containerId } = containerContext;
|
|
371
|
+
const key = containerId + (configId != null ? configId : "");
|
|
372
|
+
ctx.mapViewabilityCallbacks.set(key, callback);
|
|
373
|
+
return () => {
|
|
362
374
|
ctx.mapViewabilityCallbacks.delete(key);
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
);
|
|
375
|
+
};
|
|
376
|
+
}, [ctx, callback, configId, containerContext]);
|
|
366
377
|
}
|
|
367
378
|
function useViewabilityAmount(callback) {
|
|
368
379
|
const ctx = useStateContext();
|
|
369
|
-
const
|
|
380
|
+
const containerContext = useContextContainer();
|
|
370
381
|
useInit(() => {
|
|
382
|
+
if (!containerContext) {
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
385
|
+
const { containerId } = containerContext;
|
|
371
386
|
const value = ctx.mapViewabilityAmountValues.get(containerId);
|
|
372
387
|
if (value) {
|
|
373
388
|
callback(value);
|
|
374
389
|
}
|
|
375
390
|
});
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
391
|
+
useEffect(() => {
|
|
392
|
+
if (!containerContext) {
|
|
393
|
+
return;
|
|
394
|
+
}
|
|
395
|
+
const { containerId } = containerContext;
|
|
396
|
+
ctx.mapViewabilityAmountCallbacks.set(containerId, callback);
|
|
397
|
+
return () => {
|
|
379
398
|
ctx.mapViewabilityAmountCallbacks.delete(containerId);
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
);
|
|
399
|
+
};
|
|
400
|
+
}, [ctx, callback, containerContext]);
|
|
383
401
|
}
|
|
384
402
|
function useRecyclingEffect(effect) {
|
|
385
|
-
const
|
|
403
|
+
const containerContext = useContextContainer();
|
|
386
404
|
const prevValues = useRef({
|
|
387
405
|
prevIndex: void 0,
|
|
388
406
|
prevItem: void 0
|
|
389
407
|
});
|
|
390
408
|
useEffect(() => {
|
|
409
|
+
if (!containerContext) {
|
|
410
|
+
return;
|
|
411
|
+
}
|
|
412
|
+
const { index, value } = containerContext;
|
|
391
413
|
let ret;
|
|
392
414
|
if (prevValues.current.prevIndex !== void 0 && prevValues.current.prevItem !== void 0) {
|
|
393
415
|
ret = effect({
|
|
@@ -402,48 +424,73 @@ function useRecyclingEffect(effect) {
|
|
|
402
424
|
prevItem: value
|
|
403
425
|
};
|
|
404
426
|
return ret;
|
|
405
|
-
}, [
|
|
427
|
+
}, [effect, containerContext]);
|
|
406
428
|
}
|
|
407
429
|
function useRecyclingState(valueOrFun) {
|
|
408
|
-
|
|
409
|
-
const
|
|
410
|
-
|
|
411
|
-
|
|
430
|
+
var _a3, _b;
|
|
431
|
+
const containerContext = useContextContainer();
|
|
432
|
+
const computeValue = (ctx) => {
|
|
433
|
+
if (isFunction(valueOrFun)) {
|
|
434
|
+
const initializer = valueOrFun;
|
|
435
|
+
return ctx ? initializer({
|
|
436
|
+
index: ctx.index,
|
|
437
|
+
item: ctx.value,
|
|
438
|
+
prevIndex: void 0,
|
|
439
|
+
prevItem: void 0
|
|
440
|
+
}) : initializer();
|
|
441
|
+
}
|
|
442
|
+
return valueOrFun;
|
|
443
|
+
};
|
|
444
|
+
const [stateValue, setStateValue] = useState(() => {
|
|
445
|
+
return computeValue(containerContext);
|
|
412
446
|
});
|
|
413
|
-
const
|
|
414
|
-
const
|
|
415
|
-
if (
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
index,
|
|
419
|
-
item: value,
|
|
420
|
-
prevIndex: void 0,
|
|
421
|
-
prevItem: void 0
|
|
422
|
-
}) : valueOrFun;
|
|
447
|
+
const prevItemKeyRef = useRef((_a3 = containerContext == null ? void 0 : containerContext.itemKey) != null ? _a3 : null);
|
|
448
|
+
const currentItemKey = (_b = containerContext == null ? void 0 : containerContext.itemKey) != null ? _b : null;
|
|
449
|
+
if (currentItemKey !== null && prevItemKeyRef.current !== currentItemKey) {
|
|
450
|
+
prevItemKeyRef.current = currentItemKey;
|
|
451
|
+
setStateValue(computeValue(containerContext));
|
|
423
452
|
}
|
|
453
|
+
const triggerLayout = containerContext == null ? void 0 : containerContext.triggerLayout;
|
|
424
454
|
const setState = useCallback(
|
|
425
455
|
(newState) => {
|
|
426
|
-
|
|
427
|
-
|
|
456
|
+
if (!triggerLayout) {
|
|
457
|
+
return;
|
|
458
|
+
}
|
|
459
|
+
setStateValue((prevValue) => {
|
|
460
|
+
return isFunction(newState) ? newState(prevValue) : newState;
|
|
461
|
+
});
|
|
428
462
|
triggerLayout();
|
|
429
463
|
},
|
|
430
|
-
[triggerLayout
|
|
464
|
+
[triggerLayout]
|
|
431
465
|
);
|
|
432
|
-
return [
|
|
466
|
+
return [stateValue, setState];
|
|
433
467
|
}
|
|
434
468
|
function useIsLastItem() {
|
|
435
|
-
const
|
|
436
|
-
const isLast = useSelector$("lastItemKeys", (lastItemKeys) =>
|
|
469
|
+
const containerContext = useContextContainer();
|
|
470
|
+
const isLast = useSelector$("lastItemKeys", (lastItemKeys) => {
|
|
471
|
+
if (containerContext) {
|
|
472
|
+
const { itemKey } = containerContext;
|
|
473
|
+
if (!isNullOrUndefined(itemKey)) {
|
|
474
|
+
return (lastItemKeys == null ? void 0 : lastItemKeys.includes(itemKey)) || false;
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
return false;
|
|
478
|
+
});
|
|
437
479
|
return isLast;
|
|
438
480
|
}
|
|
439
481
|
function useListScrollSize() {
|
|
440
482
|
const [scrollSize] = useArr$(["scrollSize"]);
|
|
441
483
|
return scrollSize;
|
|
442
484
|
}
|
|
485
|
+
var noop = () => {
|
|
486
|
+
};
|
|
443
487
|
function useSyncLayout() {
|
|
444
|
-
|
|
445
|
-
|
|
488
|
+
const containerContext = useContextContainer();
|
|
489
|
+
if (containerContext) {
|
|
490
|
+
const { triggerLayout: syncLayout } = containerContext;
|
|
446
491
|
return syncLayout;
|
|
492
|
+
} else {
|
|
493
|
+
return noop;
|
|
447
494
|
}
|
|
448
495
|
}
|
|
449
496
|
|
|
@@ -1088,9 +1135,6 @@ function ScrollAdjust() {
|
|
|
1088
1135
|
} else {
|
|
1089
1136
|
scrollView.scrollBy(0, scrollDelta);
|
|
1090
1137
|
}
|
|
1091
|
-
if (IS_DEV) {
|
|
1092
|
-
console.log("ScrollAdjust (web scrollBy)", scrollDelta, "total offset:", scrollOffset);
|
|
1093
|
-
}
|
|
1094
1138
|
}
|
|
1095
1139
|
lastScrollOffsetRef.current = scrollOffset;
|
|
1096
1140
|
}
|
package/index.native.d.mts
CHANGED
|
@@ -12,7 +12,7 @@ declare const LegendList: (<T>(props: LegendListProps<T> & React.RefAttributes<L
|
|
|
12
12
|
declare function useViewability<ItemT = any>(callback: ViewabilityCallback<ItemT>, configId?: string): void;
|
|
13
13
|
declare function useViewabilityAmount<ItemT = any>(callback: ViewabilityAmountCallback<ItemT>): void;
|
|
14
14
|
declare function useRecyclingEffect(effect: (info: LegendListRecyclingState<unknown>) => void | (() => void)): void;
|
|
15
|
-
declare function useRecyclingState<ItemT>(valueOrFun: ((info: LegendListRecyclingState<ItemT>) => ItemT) | ItemT): readonly [ItemT
|
|
15
|
+
declare function useRecyclingState<ItemT>(valueOrFun: ((info: LegendListRecyclingState<ItemT>) => ItemT) | ItemT): readonly [ItemT, Dispatch<SetStateAction<ItemT>>];
|
|
16
16
|
declare function useIsLastItem(): boolean;
|
|
17
17
|
declare function useListScrollSize(): {
|
|
18
18
|
width: number;
|
package/index.native.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ declare const LegendList: (<T>(props: LegendListProps<T> & React.RefAttributes<L
|
|
|
12
12
|
declare function useViewability<ItemT = any>(callback: ViewabilityCallback<ItemT>, configId?: string): void;
|
|
13
13
|
declare function useViewabilityAmount<ItemT = any>(callback: ViewabilityAmountCallback<ItemT>): void;
|
|
14
14
|
declare function useRecyclingEffect(effect: (info: LegendListRecyclingState<unknown>) => void | (() => void)): void;
|
|
15
|
-
declare function useRecyclingState<ItemT>(valueOrFun: ((info: LegendListRecyclingState<ItemT>) => ItemT) | ItemT): readonly [ItemT
|
|
15
|
+
declare function useRecyclingState<ItemT>(valueOrFun: ((info: LegendListRecyclingState<ItemT>) => ItemT) | ItemT): readonly [ItemT, Dispatch<SetStateAction<ItemT>>];
|
|
16
16
|
declare function useIsLastItem(): boolean;
|
|
17
17
|
declare function useListScrollSize(): {
|
|
18
18
|
width: number;
|
package/index.native.js
CHANGED
|
@@ -411,48 +411,70 @@ function useInit(cb) {
|
|
|
411
411
|
|
|
412
412
|
// src/state/ContextContainer.ts
|
|
413
413
|
var ContextContainer = React2.createContext(null);
|
|
414
|
+
function useContextContainer() {
|
|
415
|
+
return React2.useContext(ContextContainer);
|
|
416
|
+
}
|
|
414
417
|
function useViewability(callback, configId) {
|
|
415
418
|
const ctx = useStateContext();
|
|
416
|
-
const
|
|
417
|
-
const key = containerId + (configId != null ? configId : "");
|
|
419
|
+
const containerContext = useContextContainer();
|
|
418
420
|
useInit(() => {
|
|
421
|
+
if (!containerContext) {
|
|
422
|
+
return;
|
|
423
|
+
}
|
|
424
|
+
const { containerId } = containerContext;
|
|
425
|
+
const key = containerId + (configId != null ? configId : "");
|
|
419
426
|
const value = ctx.mapViewabilityValues.get(key);
|
|
420
427
|
if (value) {
|
|
421
428
|
callback(value);
|
|
422
429
|
}
|
|
423
430
|
});
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
431
|
+
React2.useEffect(() => {
|
|
432
|
+
if (!containerContext) {
|
|
433
|
+
return;
|
|
434
|
+
}
|
|
435
|
+
const { containerId } = containerContext;
|
|
436
|
+
const key = containerId + (configId != null ? configId : "");
|
|
437
|
+
ctx.mapViewabilityCallbacks.set(key, callback);
|
|
438
|
+
return () => {
|
|
427
439
|
ctx.mapViewabilityCallbacks.delete(key);
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
);
|
|
440
|
+
};
|
|
441
|
+
}, [ctx, callback, configId, containerContext]);
|
|
431
442
|
}
|
|
432
443
|
function useViewabilityAmount(callback) {
|
|
433
444
|
const ctx = useStateContext();
|
|
434
|
-
const
|
|
445
|
+
const containerContext = useContextContainer();
|
|
435
446
|
useInit(() => {
|
|
447
|
+
if (!containerContext) {
|
|
448
|
+
return;
|
|
449
|
+
}
|
|
450
|
+
const { containerId } = containerContext;
|
|
436
451
|
const value = ctx.mapViewabilityAmountValues.get(containerId);
|
|
437
452
|
if (value) {
|
|
438
453
|
callback(value);
|
|
439
454
|
}
|
|
440
455
|
});
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
456
|
+
React2.useEffect(() => {
|
|
457
|
+
if (!containerContext) {
|
|
458
|
+
return;
|
|
459
|
+
}
|
|
460
|
+
const { containerId } = containerContext;
|
|
461
|
+
ctx.mapViewabilityAmountCallbacks.set(containerId, callback);
|
|
462
|
+
return () => {
|
|
444
463
|
ctx.mapViewabilityAmountCallbacks.delete(containerId);
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
);
|
|
464
|
+
};
|
|
465
|
+
}, [ctx, callback, containerContext]);
|
|
448
466
|
}
|
|
449
467
|
function useRecyclingEffect(effect) {
|
|
450
|
-
const
|
|
468
|
+
const containerContext = useContextContainer();
|
|
451
469
|
const prevValues = React2.useRef({
|
|
452
470
|
prevIndex: void 0,
|
|
453
471
|
prevItem: void 0
|
|
454
472
|
});
|
|
455
473
|
React2.useEffect(() => {
|
|
474
|
+
if (!containerContext) {
|
|
475
|
+
return;
|
|
476
|
+
}
|
|
477
|
+
const { index, value } = containerContext;
|
|
456
478
|
let ret;
|
|
457
479
|
if (prevValues.current.prevIndex !== void 0 && prevValues.current.prevItem !== void 0) {
|
|
458
480
|
ret = effect({
|
|
@@ -467,38 +489,58 @@ function useRecyclingEffect(effect) {
|
|
|
467
489
|
prevItem: value
|
|
468
490
|
};
|
|
469
491
|
return ret;
|
|
470
|
-
}, [
|
|
492
|
+
}, [effect, containerContext]);
|
|
471
493
|
}
|
|
472
494
|
function useRecyclingState(valueOrFun) {
|
|
473
|
-
|
|
474
|
-
const
|
|
475
|
-
|
|
476
|
-
|
|
495
|
+
var _a3, _b;
|
|
496
|
+
const containerContext = useContextContainer();
|
|
497
|
+
const computeValue = (ctx) => {
|
|
498
|
+
if (isFunction(valueOrFun)) {
|
|
499
|
+
const initializer = valueOrFun;
|
|
500
|
+
return ctx ? initializer({
|
|
501
|
+
index: ctx.index,
|
|
502
|
+
item: ctx.value,
|
|
503
|
+
prevIndex: void 0,
|
|
504
|
+
prevItem: void 0
|
|
505
|
+
}) : initializer();
|
|
506
|
+
}
|
|
507
|
+
return valueOrFun;
|
|
508
|
+
};
|
|
509
|
+
const [stateValue, setStateValue] = React2.useState(() => {
|
|
510
|
+
return computeValue(containerContext);
|
|
477
511
|
});
|
|
478
|
-
const
|
|
479
|
-
const
|
|
480
|
-
if (
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
index,
|
|
484
|
-
item: value,
|
|
485
|
-
prevIndex: void 0,
|
|
486
|
-
prevItem: void 0
|
|
487
|
-
}) : valueOrFun;
|
|
512
|
+
const prevItemKeyRef = React2.useRef((_a3 = containerContext == null ? void 0 : containerContext.itemKey) != null ? _a3 : null);
|
|
513
|
+
const currentItemKey = (_b = containerContext == null ? void 0 : containerContext.itemKey) != null ? _b : null;
|
|
514
|
+
if (currentItemKey !== null && prevItemKeyRef.current !== currentItemKey) {
|
|
515
|
+
prevItemKeyRef.current = currentItemKey;
|
|
516
|
+
setStateValue(computeValue(containerContext));
|
|
488
517
|
}
|
|
518
|
+
const triggerLayout = containerContext == null ? void 0 : containerContext.triggerLayout;
|
|
489
519
|
const setState = React2.useCallback(
|
|
490
520
|
(newState) => {
|
|
491
|
-
|
|
492
|
-
|
|
521
|
+
if (!triggerLayout) {
|
|
522
|
+
return;
|
|
523
|
+
}
|
|
524
|
+
setStateValue((prevValue) => {
|
|
525
|
+
return isFunction(newState) ? newState(prevValue) : newState;
|
|
526
|
+
});
|
|
493
527
|
triggerLayout();
|
|
494
528
|
},
|
|
495
|
-
[triggerLayout
|
|
529
|
+
[triggerLayout]
|
|
496
530
|
);
|
|
497
|
-
return [
|
|
531
|
+
return [stateValue, setState];
|
|
498
532
|
}
|
|
499
533
|
function useIsLastItem() {
|
|
500
|
-
const
|
|
501
|
-
const isLast = useSelector$("lastItemKeys", (lastItemKeys) =>
|
|
534
|
+
const containerContext = useContextContainer();
|
|
535
|
+
const isLast = useSelector$("lastItemKeys", (lastItemKeys) => {
|
|
536
|
+
if (containerContext) {
|
|
537
|
+
const { itemKey } = containerContext;
|
|
538
|
+
if (!isNullOrUndefined(itemKey)) {
|
|
539
|
+
return (lastItemKeys == null ? void 0 : lastItemKeys.includes(itemKey)) || false;
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
return false;
|
|
543
|
+
});
|
|
502
544
|
return isLast;
|
|
503
545
|
}
|
|
504
546
|
function useListScrollSize() {
|
|
@@ -508,8 +550,9 @@ function useListScrollSize() {
|
|
|
508
550
|
var noop = () => {
|
|
509
551
|
};
|
|
510
552
|
function useSyncLayout() {
|
|
511
|
-
|
|
512
|
-
|
|
553
|
+
const containerContext = useContextContainer();
|
|
554
|
+
if (IsNewArchitecture && containerContext) {
|
|
555
|
+
const { triggerLayout: syncLayout } = containerContext;
|
|
513
556
|
return syncLayout;
|
|
514
557
|
} else {
|
|
515
558
|
return noop;
|
package/index.native.mjs
CHANGED
|
@@ -390,48 +390,70 @@ function useInit(cb) {
|
|
|
390
390
|
|
|
391
391
|
// src/state/ContextContainer.ts
|
|
392
392
|
var ContextContainer = createContext(null);
|
|
393
|
+
function useContextContainer() {
|
|
394
|
+
return useContext(ContextContainer);
|
|
395
|
+
}
|
|
393
396
|
function useViewability(callback, configId) {
|
|
394
397
|
const ctx = useStateContext();
|
|
395
|
-
const
|
|
396
|
-
const key = containerId + (configId != null ? configId : "");
|
|
398
|
+
const containerContext = useContextContainer();
|
|
397
399
|
useInit(() => {
|
|
400
|
+
if (!containerContext) {
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
const { containerId } = containerContext;
|
|
404
|
+
const key = containerId + (configId != null ? configId : "");
|
|
398
405
|
const value = ctx.mapViewabilityValues.get(key);
|
|
399
406
|
if (value) {
|
|
400
407
|
callback(value);
|
|
401
408
|
}
|
|
402
409
|
});
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
410
|
+
useEffect(() => {
|
|
411
|
+
if (!containerContext) {
|
|
412
|
+
return;
|
|
413
|
+
}
|
|
414
|
+
const { containerId } = containerContext;
|
|
415
|
+
const key = containerId + (configId != null ? configId : "");
|
|
416
|
+
ctx.mapViewabilityCallbacks.set(key, callback);
|
|
417
|
+
return () => {
|
|
406
418
|
ctx.mapViewabilityCallbacks.delete(key);
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
);
|
|
419
|
+
};
|
|
420
|
+
}, [ctx, callback, configId, containerContext]);
|
|
410
421
|
}
|
|
411
422
|
function useViewabilityAmount(callback) {
|
|
412
423
|
const ctx = useStateContext();
|
|
413
|
-
const
|
|
424
|
+
const containerContext = useContextContainer();
|
|
414
425
|
useInit(() => {
|
|
426
|
+
if (!containerContext) {
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
const { containerId } = containerContext;
|
|
415
430
|
const value = ctx.mapViewabilityAmountValues.get(containerId);
|
|
416
431
|
if (value) {
|
|
417
432
|
callback(value);
|
|
418
433
|
}
|
|
419
434
|
});
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
435
|
+
useEffect(() => {
|
|
436
|
+
if (!containerContext) {
|
|
437
|
+
return;
|
|
438
|
+
}
|
|
439
|
+
const { containerId } = containerContext;
|
|
440
|
+
ctx.mapViewabilityAmountCallbacks.set(containerId, callback);
|
|
441
|
+
return () => {
|
|
423
442
|
ctx.mapViewabilityAmountCallbacks.delete(containerId);
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
);
|
|
443
|
+
};
|
|
444
|
+
}, [ctx, callback, containerContext]);
|
|
427
445
|
}
|
|
428
446
|
function useRecyclingEffect(effect) {
|
|
429
|
-
const
|
|
447
|
+
const containerContext = useContextContainer();
|
|
430
448
|
const prevValues = useRef({
|
|
431
449
|
prevIndex: void 0,
|
|
432
450
|
prevItem: void 0
|
|
433
451
|
});
|
|
434
452
|
useEffect(() => {
|
|
453
|
+
if (!containerContext) {
|
|
454
|
+
return;
|
|
455
|
+
}
|
|
456
|
+
const { index, value } = containerContext;
|
|
435
457
|
let ret;
|
|
436
458
|
if (prevValues.current.prevIndex !== void 0 && prevValues.current.prevItem !== void 0) {
|
|
437
459
|
ret = effect({
|
|
@@ -446,38 +468,58 @@ function useRecyclingEffect(effect) {
|
|
|
446
468
|
prevItem: value
|
|
447
469
|
};
|
|
448
470
|
return ret;
|
|
449
|
-
}, [
|
|
471
|
+
}, [effect, containerContext]);
|
|
450
472
|
}
|
|
451
473
|
function useRecyclingState(valueOrFun) {
|
|
452
|
-
|
|
453
|
-
const
|
|
454
|
-
|
|
455
|
-
|
|
474
|
+
var _a3, _b;
|
|
475
|
+
const containerContext = useContextContainer();
|
|
476
|
+
const computeValue = (ctx) => {
|
|
477
|
+
if (isFunction(valueOrFun)) {
|
|
478
|
+
const initializer = valueOrFun;
|
|
479
|
+
return ctx ? initializer({
|
|
480
|
+
index: ctx.index,
|
|
481
|
+
item: ctx.value,
|
|
482
|
+
prevIndex: void 0,
|
|
483
|
+
prevItem: void 0
|
|
484
|
+
}) : initializer();
|
|
485
|
+
}
|
|
486
|
+
return valueOrFun;
|
|
487
|
+
};
|
|
488
|
+
const [stateValue, setStateValue] = useState(() => {
|
|
489
|
+
return computeValue(containerContext);
|
|
456
490
|
});
|
|
457
|
-
const
|
|
458
|
-
const
|
|
459
|
-
if (
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
index,
|
|
463
|
-
item: value,
|
|
464
|
-
prevIndex: void 0,
|
|
465
|
-
prevItem: void 0
|
|
466
|
-
}) : valueOrFun;
|
|
491
|
+
const prevItemKeyRef = useRef((_a3 = containerContext == null ? void 0 : containerContext.itemKey) != null ? _a3 : null);
|
|
492
|
+
const currentItemKey = (_b = containerContext == null ? void 0 : containerContext.itemKey) != null ? _b : null;
|
|
493
|
+
if (currentItemKey !== null && prevItemKeyRef.current !== currentItemKey) {
|
|
494
|
+
prevItemKeyRef.current = currentItemKey;
|
|
495
|
+
setStateValue(computeValue(containerContext));
|
|
467
496
|
}
|
|
497
|
+
const triggerLayout = containerContext == null ? void 0 : containerContext.triggerLayout;
|
|
468
498
|
const setState = useCallback(
|
|
469
499
|
(newState) => {
|
|
470
|
-
|
|
471
|
-
|
|
500
|
+
if (!triggerLayout) {
|
|
501
|
+
return;
|
|
502
|
+
}
|
|
503
|
+
setStateValue((prevValue) => {
|
|
504
|
+
return isFunction(newState) ? newState(prevValue) : newState;
|
|
505
|
+
});
|
|
472
506
|
triggerLayout();
|
|
473
507
|
},
|
|
474
|
-
[triggerLayout
|
|
508
|
+
[triggerLayout]
|
|
475
509
|
);
|
|
476
|
-
return [
|
|
510
|
+
return [stateValue, setState];
|
|
477
511
|
}
|
|
478
512
|
function useIsLastItem() {
|
|
479
|
-
const
|
|
480
|
-
const isLast = useSelector$("lastItemKeys", (lastItemKeys) =>
|
|
513
|
+
const containerContext = useContextContainer();
|
|
514
|
+
const isLast = useSelector$("lastItemKeys", (lastItemKeys) => {
|
|
515
|
+
if (containerContext) {
|
|
516
|
+
const { itemKey } = containerContext;
|
|
517
|
+
if (!isNullOrUndefined(itemKey)) {
|
|
518
|
+
return (lastItemKeys == null ? void 0 : lastItemKeys.includes(itemKey)) || false;
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
return false;
|
|
522
|
+
});
|
|
481
523
|
return isLast;
|
|
482
524
|
}
|
|
483
525
|
function useListScrollSize() {
|
|
@@ -487,8 +529,9 @@ function useListScrollSize() {
|
|
|
487
529
|
var noop = () => {
|
|
488
530
|
};
|
|
489
531
|
function useSyncLayout() {
|
|
490
|
-
|
|
491
|
-
|
|
532
|
+
const containerContext = useContextContainer();
|
|
533
|
+
if (IsNewArchitecture && containerContext) {
|
|
534
|
+
const { triggerLayout: syncLayout } = containerContext;
|
|
492
535
|
return syncLayout;
|
|
493
536
|
} else {
|
|
494
537
|
return noop;
|
package/keyboard.js
CHANGED
|
@@ -87,8 +87,7 @@ var KeyboardAvoidingLegendList = React.forwardRef(function KeyboardAvoidingLegen
|
|
|
87
87
|
const setScrollProcessingEnabled = React.useCallback(
|
|
88
88
|
(enabled) => {
|
|
89
89
|
var _a;
|
|
90
|
-
|
|
91
|
-
(_a = refLegendList.current) == null ? void 0 : _a.setScrollProcessingEnabled(enabled);
|
|
90
|
+
return (_a = refLegendList.current) == null ? void 0 : _a.setScrollProcessingEnabled(enabled);
|
|
92
91
|
},
|
|
93
92
|
[refLegendList]
|
|
94
93
|
);
|
package/keyboard.mjs
CHANGED
|
@@ -66,8 +66,7 @@ var KeyboardAvoidingLegendList = forwardRef(function KeyboardAvoidingLegendList2
|
|
|
66
66
|
const setScrollProcessingEnabled = useCallback(
|
|
67
67
|
(enabled) => {
|
|
68
68
|
var _a;
|
|
69
|
-
|
|
70
|
-
(_a = refLegendList.current) == null ? void 0 : _a.setScrollProcessingEnabled(enabled);
|
|
69
|
+
return (_a = refLegendList.current) == null ? void 0 : _a.setScrollProcessingEnabled(enabled);
|
|
71
70
|
},
|
|
72
71
|
[refLegendList]
|
|
73
72
|
);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@legendapp/list",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.11",
|
|
4
4
|
"description": "Legend List is a drop-in replacement for FlatList with much better performance and supporting dynamically sized items.",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"private": false,
|
package/section-list.js
CHANGED
|
@@ -365,9 +365,20 @@ var IsNewArchitecture = true;
|
|
|
365
365
|
|
|
366
366
|
// src/state/ContextContainer.ts
|
|
367
367
|
var ContextContainer = React3.createContext(null);
|
|
368
|
+
function useContextContainer() {
|
|
369
|
+
return React3.useContext(ContextContainer);
|
|
370
|
+
}
|
|
368
371
|
function useIsLastItem() {
|
|
369
|
-
const
|
|
370
|
-
const isLast = useSelector$("lastItemKeys", (lastItemKeys) =>
|
|
372
|
+
const containerContext = useContextContainer();
|
|
373
|
+
const isLast = useSelector$("lastItemKeys", (lastItemKeys) => {
|
|
374
|
+
if (containerContext) {
|
|
375
|
+
const { itemKey } = containerContext;
|
|
376
|
+
if (!isNullOrUndefined(itemKey)) {
|
|
377
|
+
return (lastItemKeys == null ? void 0 : lastItemKeys.includes(itemKey)) || false;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
return false;
|
|
381
|
+
});
|
|
371
382
|
return isLast;
|
|
372
383
|
}
|
|
373
384
|
|
|
@@ -1012,9 +1023,6 @@ function ScrollAdjust() {
|
|
|
1012
1023
|
} else {
|
|
1013
1024
|
scrollView.scrollBy(0, scrollDelta);
|
|
1014
1025
|
}
|
|
1015
|
-
if (IS_DEV) {
|
|
1016
|
-
console.log("ScrollAdjust (web scrollBy)", scrollDelta, "total offset:", scrollOffset);
|
|
1017
|
-
}
|
|
1018
1026
|
}
|
|
1019
1027
|
lastScrollOffsetRef.current = scrollOffset;
|
|
1020
1028
|
}
|
package/section-list.mjs
CHANGED
|
@@ -344,9 +344,20 @@ var IsNewArchitecture = true;
|
|
|
344
344
|
|
|
345
345
|
// src/state/ContextContainer.ts
|
|
346
346
|
var ContextContainer = createContext(null);
|
|
347
|
+
function useContextContainer() {
|
|
348
|
+
return useContext(ContextContainer);
|
|
349
|
+
}
|
|
347
350
|
function useIsLastItem() {
|
|
348
|
-
const
|
|
349
|
-
const isLast = useSelector$("lastItemKeys", (lastItemKeys) =>
|
|
351
|
+
const containerContext = useContextContainer();
|
|
352
|
+
const isLast = useSelector$("lastItemKeys", (lastItemKeys) => {
|
|
353
|
+
if (containerContext) {
|
|
354
|
+
const { itemKey } = containerContext;
|
|
355
|
+
if (!isNullOrUndefined(itemKey)) {
|
|
356
|
+
return (lastItemKeys == null ? void 0 : lastItemKeys.includes(itemKey)) || false;
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
return false;
|
|
360
|
+
});
|
|
350
361
|
return isLast;
|
|
351
362
|
}
|
|
352
363
|
|
|
@@ -991,9 +1002,6 @@ function ScrollAdjust() {
|
|
|
991
1002
|
} else {
|
|
992
1003
|
scrollView.scrollBy(0, scrollDelta);
|
|
993
1004
|
}
|
|
994
|
-
if (IS_DEV) {
|
|
995
|
-
console.log("ScrollAdjust (web scrollBy)", scrollDelta, "total offset:", scrollOffset);
|
|
996
|
-
}
|
|
997
1005
|
}
|
|
998
1006
|
lastScrollOffsetRef.current = scrollOffset;
|
|
999
1007
|
}
|
package/section-list.native.js
CHANGED
|
@@ -411,9 +411,20 @@ function useInit(cb) {
|
|
|
411
411
|
|
|
412
412
|
// src/state/ContextContainer.ts
|
|
413
413
|
var ContextContainer = React2.createContext(null);
|
|
414
|
+
function useContextContainer() {
|
|
415
|
+
return React2.useContext(ContextContainer);
|
|
416
|
+
}
|
|
414
417
|
function useIsLastItem() {
|
|
415
|
-
const
|
|
416
|
-
const isLast = useSelector$("lastItemKeys", (lastItemKeys) =>
|
|
418
|
+
const containerContext = useContextContainer();
|
|
419
|
+
const isLast = useSelector$("lastItemKeys", (lastItemKeys) => {
|
|
420
|
+
if (containerContext) {
|
|
421
|
+
const { itemKey } = containerContext;
|
|
422
|
+
if (!isNullOrUndefined(itemKey)) {
|
|
423
|
+
return (lastItemKeys == null ? void 0 : lastItemKeys.includes(itemKey)) || false;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
return false;
|
|
427
|
+
});
|
|
417
428
|
return isLast;
|
|
418
429
|
}
|
|
419
430
|
|
package/section-list.native.mjs
CHANGED
|
@@ -390,9 +390,20 @@ function useInit(cb) {
|
|
|
390
390
|
|
|
391
391
|
// src/state/ContextContainer.ts
|
|
392
392
|
var ContextContainer = createContext(null);
|
|
393
|
+
function useContextContainer() {
|
|
394
|
+
return useContext(ContextContainer);
|
|
395
|
+
}
|
|
393
396
|
function useIsLastItem() {
|
|
394
|
-
const
|
|
395
|
-
const isLast = useSelector$("lastItemKeys", (lastItemKeys) =>
|
|
397
|
+
const containerContext = useContextContainer();
|
|
398
|
+
const isLast = useSelector$("lastItemKeys", (lastItemKeys) => {
|
|
399
|
+
if (containerContext) {
|
|
400
|
+
const { itemKey } = containerContext;
|
|
401
|
+
if (!isNullOrUndefined(itemKey)) {
|
|
402
|
+
return (lastItemKeys == null ? void 0 : lastItemKeys.includes(itemKey)) || false;
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
return false;
|
|
406
|
+
});
|
|
396
407
|
return isLast;
|
|
397
408
|
}
|
|
398
409
|
|