@legendapp/list 0.4.3 → 0.4.4
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/README.md +0 -1
- package/index.d.mts +2 -1
- package/index.d.ts +2 -1
- package/index.js +62 -37
- package/index.mjs +62 -37
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -48,7 +48,6 @@ interface PropsOptional {
|
|
|
48
48
|
maintainScrollAtEndThreshold?: number;
|
|
49
49
|
onEndReached?: ((info: { distanceFromEnd: number }) => void) | null | undefined;
|
|
50
50
|
keyExtractor?: (item: T, index: number) => string;
|
|
51
|
-
onViewableRangeChanged?: (range: ViewableRange<T>) => void;
|
|
52
51
|
}
|
|
53
52
|
```
|
|
54
53
|
|
package/index.d.mts
CHANGED
|
@@ -19,11 +19,12 @@ type LegendListProps<T> = Omit<ComponentProps<typeof ScrollView>, 'contentOffset
|
|
|
19
19
|
}) => void) | null | undefined;
|
|
20
20
|
keyExtractor?: (item: T, index: number) => string;
|
|
21
21
|
renderItem?: (props: LegendListRenderItemProps<T>) => ReactNode;
|
|
22
|
-
onViewableRangeChanged?: (range: ViewableRange<T>) => void;
|
|
23
22
|
ListHeaderComponent?: React.ComponentType<any> | React.ReactElement | null | undefined;
|
|
24
23
|
ListHeaderComponentStyle?: StyleProp<ViewStyle> | undefined;
|
|
25
24
|
ListFooterComponent?: React.ComponentType<any> | React.ReactElement | null | undefined;
|
|
26
25
|
ListFooterComponentStyle?: StyleProp<ViewStyle> | undefined;
|
|
26
|
+
ListEmptyComponent?: React.ComponentType<any> | React.ReactElement | null | undefined;
|
|
27
|
+
ListEmptyComponentStyle?: StyleProp<ViewStyle> | undefined;
|
|
27
28
|
ItemSeparatorComponent?: React.ComponentType<any>;
|
|
28
29
|
viewabilityConfigCallbackPairs?: ViewabilityConfigCallbackPairs | undefined;
|
|
29
30
|
viewabilityConfig?: ViewabilityConfig;
|
package/index.d.ts
CHANGED
|
@@ -19,11 +19,12 @@ type LegendListProps<T> = Omit<ComponentProps<typeof ScrollView>, 'contentOffset
|
|
|
19
19
|
}) => void) | null | undefined;
|
|
20
20
|
keyExtractor?: (item: T, index: number) => string;
|
|
21
21
|
renderItem?: (props: LegendListRenderItemProps<T>) => ReactNode;
|
|
22
|
-
onViewableRangeChanged?: (range: ViewableRange<T>) => void;
|
|
23
22
|
ListHeaderComponent?: React.ComponentType<any> | React.ReactElement | null | undefined;
|
|
24
23
|
ListHeaderComponentStyle?: StyleProp<ViewStyle> | undefined;
|
|
25
24
|
ListFooterComponent?: React.ComponentType<any> | React.ReactElement | null | undefined;
|
|
26
25
|
ListFooterComponentStyle?: StyleProp<ViewStyle> | undefined;
|
|
26
|
+
ListEmptyComponent?: React.ComponentType<any> | React.ReactElement | null | undefined;
|
|
27
|
+
ListEmptyComponentStyle?: StyleProp<ViewStyle> | undefined;
|
|
27
28
|
ItemSeparatorComponent?: React.ComponentType<any>;
|
|
28
29
|
viewabilityConfigCallbackPairs?: ViewabilityConfigCallbackPairs | undefined;
|
|
29
30
|
viewabilityConfig?: ViewabilityConfig;
|
package/index.js
CHANGED
|
@@ -213,6 +213,8 @@ var ListComponent = React6__namespace.memo(function ListComponent2({
|
|
|
213
213
|
ListHeaderComponentStyle,
|
|
214
214
|
ListFooterComponent,
|
|
215
215
|
ListFooterComponentStyle,
|
|
216
|
+
ListEmptyComponent,
|
|
217
|
+
ListEmptyComponentStyle,
|
|
216
218
|
getRenderedItem,
|
|
217
219
|
updateItemSize,
|
|
218
220
|
addTotalSize,
|
|
@@ -254,6 +256,13 @@ var ListComponent = React6__namespace.memo(function ListComponent2({
|
|
|
254
256
|
},
|
|
255
257
|
getComponent(ListHeaderComponent)
|
|
256
258
|
),
|
|
259
|
+
ListEmptyComponent && /* @__PURE__ */ React6__namespace.createElement(
|
|
260
|
+
reactNative.View,
|
|
261
|
+
{
|
|
262
|
+
style: ListEmptyComponentStyle
|
|
263
|
+
},
|
|
264
|
+
getComponent(ListEmptyComponent)
|
|
265
|
+
),
|
|
257
266
|
/* @__PURE__ */ React6__namespace.createElement(
|
|
258
267
|
Containers,
|
|
259
268
|
{
|
|
@@ -271,7 +280,9 @@ var ListComponent = React6__namespace.memo(function ListComponent2({
|
|
|
271
280
|
// src/viewability.ts
|
|
272
281
|
var mapViewabilityConfigCallbackPairs = /* @__PURE__ */ new Map();
|
|
273
282
|
var mapViewabilityCallbacks = /* @__PURE__ */ new Map();
|
|
283
|
+
var mapViewabilityValues = /* @__PURE__ */ new Map();
|
|
274
284
|
var mapViewabilityAmountCallbacks = /* @__PURE__ */ new Map();
|
|
285
|
+
var mapViewabilityAmountValues = /* @__PURE__ */ new Map();
|
|
275
286
|
function setupViewability(props) {
|
|
276
287
|
let { viewabilityConfig, viewabilityConfigCallbackPairs, onViewableItemsChanged } = props;
|
|
277
288
|
viewabilityConfigCallbackPairs = viewabilityConfigCallbackPairs || [
|
|
@@ -369,20 +380,22 @@ function isViewable(state, ctx, viewabilityConfig, key, scrollSize, item, index)
|
|
|
369
380
|
const percent = isEntirelyVisible ? 100 : viewAreaMode ? percentOfScroller : percentVisible;
|
|
370
381
|
const isViewable2 = percent >= viewablePercentThreshold;
|
|
371
382
|
const containerId = findContainerId(state, ctx, index);
|
|
383
|
+
const value = {
|
|
384
|
+
index,
|
|
385
|
+
isViewable: isViewable2,
|
|
386
|
+
item,
|
|
387
|
+
key,
|
|
388
|
+
percentVisible,
|
|
389
|
+
percentOfScroller,
|
|
390
|
+
sizeVisible,
|
|
391
|
+
size,
|
|
392
|
+
position: top,
|
|
393
|
+
scrollSize
|
|
394
|
+
};
|
|
395
|
+
mapViewabilityAmountValues.set(containerId, value);
|
|
372
396
|
const cb = mapViewabilityAmountCallbacks.get(containerId);
|
|
373
397
|
if (cb) {
|
|
374
|
-
cb(
|
|
375
|
-
index,
|
|
376
|
-
isViewable: isViewable2,
|
|
377
|
-
item,
|
|
378
|
-
key,
|
|
379
|
-
percentVisible,
|
|
380
|
-
percentOfScroller,
|
|
381
|
-
sizeVisible,
|
|
382
|
-
size,
|
|
383
|
-
position: top,
|
|
384
|
-
scrollSize
|
|
385
|
-
});
|
|
398
|
+
cb(value);
|
|
386
399
|
}
|
|
387
400
|
return isViewable2;
|
|
388
401
|
}
|
|
@@ -398,6 +411,7 @@ function findContainerId(state, ctx, index) {
|
|
|
398
411
|
}
|
|
399
412
|
function maybeUpdateViewabilityCallback(configId, viewToken) {
|
|
400
413
|
const key = viewToken.key + configId;
|
|
414
|
+
mapViewabilityValues.set(key, viewToken);
|
|
401
415
|
const cb = mapViewabilityCallbacks.get(key);
|
|
402
416
|
cb == null ? void 0 : cb(viewToken);
|
|
403
417
|
}
|
|
@@ -443,7 +457,7 @@ var LegendListInner = React6.forwardRef(function LegendListInner2(props, forward
|
|
|
443
457
|
estimatedItemSize,
|
|
444
458
|
getEstimatedItemSize,
|
|
445
459
|
onEndReached,
|
|
446
|
-
|
|
460
|
+
ListEmptyComponent,
|
|
447
461
|
...rest
|
|
448
462
|
} = props;
|
|
449
463
|
const ctx = useStateContext();
|
|
@@ -542,9 +556,21 @@ var LegendListInner = React6.forwardRef(function LegendListInner2(props, forward
|
|
|
542
556
|
return null;
|
|
543
557
|
}
|
|
544
558
|
const useViewability = (configId, callback) => {
|
|
559
|
+
React6.useMemo(() => {
|
|
560
|
+
const value = mapViewabilityValues.get(containerIndex + configId);
|
|
561
|
+
if (value) {
|
|
562
|
+
callback(value);
|
|
563
|
+
}
|
|
564
|
+
}, []);
|
|
545
565
|
React6.useEffect(() => registerViewabilityCallback(containerIndex, configId, callback), []);
|
|
546
566
|
};
|
|
547
567
|
const useViewabilityAmount = (callback) => {
|
|
568
|
+
React6.useMemo(() => {
|
|
569
|
+
const value = mapViewabilityAmountValues.get(containerIndex);
|
|
570
|
+
if (value) {
|
|
571
|
+
callback(value);
|
|
572
|
+
}
|
|
573
|
+
}, []);
|
|
548
574
|
React6.useEffect(() => registerViewabilityAmountCallback(containerIndex, callback), []);
|
|
549
575
|
};
|
|
550
576
|
const useRecyclingEffect = (effect) => {
|
|
@@ -735,31 +761,20 @@ var LegendListInner = React6.forwardRef(function LegendListInner2(props, forward
|
|
|
735
761
|
}
|
|
736
762
|
}
|
|
737
763
|
}
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
if (refState.current.viewabilityConfigCallbackPairs) {
|
|
750
|
-
updateViewableItems(
|
|
751
|
-
refState.current,
|
|
752
|
-
ctx,
|
|
753
|
-
refState.current.viewabilityConfigCallbackPairs,
|
|
754
|
-
getId,
|
|
755
|
-
scrollLength,
|
|
756
|
-
startNoBuffer,
|
|
757
|
-
endNoBuffer
|
|
758
|
-
);
|
|
759
|
-
}
|
|
764
|
+
}
|
|
765
|
+
if (refState.current.viewabilityConfigCallbackPairs) {
|
|
766
|
+
updateViewableItems(
|
|
767
|
+
refState.current,
|
|
768
|
+
ctx,
|
|
769
|
+
refState.current.viewabilityConfigCallbackPairs,
|
|
770
|
+
getId,
|
|
771
|
+
scrollLength,
|
|
772
|
+
startNoBuffer,
|
|
773
|
+
endNoBuffer
|
|
774
|
+
);
|
|
760
775
|
}
|
|
761
776
|
});
|
|
762
|
-
}, [
|
|
777
|
+
}, []);
|
|
763
778
|
React6.useMemo(() => {
|
|
764
779
|
var _a2, _b2;
|
|
765
780
|
refState.current.viewabilityConfigCallbackPairs = setupViewability(props);
|
|
@@ -801,6 +816,15 @@ var LegendListInner = React6.forwardRef(function LegendListInner2(props, forward
|
|
|
801
816
|
if (refState.current) {
|
|
802
817
|
refState.current.isEndReached = false;
|
|
803
818
|
}
|
|
819
|
+
const numContainers = peek$(ctx, "numContainers");
|
|
820
|
+
if (data.length < numContainers) {
|
|
821
|
+
for (let i = 0; i < numContainers; i++) {
|
|
822
|
+
const itemIndex = peek$(ctx, `containerIndex${i}`);
|
|
823
|
+
if (itemIndex >= data.length) {
|
|
824
|
+
set$(ctx, `containerIndex${i}`, -1);
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
}
|
|
804
828
|
calculateItemsInView();
|
|
805
829
|
checkAtBottom();
|
|
806
830
|
}, [data]);
|
|
@@ -903,7 +927,8 @@ var LegendListInner = React6.forwardRef(function LegendListInner2(props, forward
|
|
|
903
927
|
onLayout,
|
|
904
928
|
recycleItems,
|
|
905
929
|
alignItemsAtEnd,
|
|
906
|
-
addTotalSize
|
|
930
|
+
addTotalSize,
|
|
931
|
+
ListEmptyComponent: data.length === 0 ? ListEmptyComponent : void 0
|
|
907
932
|
}
|
|
908
933
|
);
|
|
909
934
|
});
|
package/index.mjs
CHANGED
|
@@ -192,6 +192,8 @@ var ListComponent = React6.memo(function ListComponent2({
|
|
|
192
192
|
ListHeaderComponentStyle,
|
|
193
193
|
ListFooterComponent,
|
|
194
194
|
ListFooterComponentStyle,
|
|
195
|
+
ListEmptyComponent,
|
|
196
|
+
ListEmptyComponentStyle,
|
|
195
197
|
getRenderedItem,
|
|
196
198
|
updateItemSize,
|
|
197
199
|
addTotalSize,
|
|
@@ -233,6 +235,13 @@ var ListComponent = React6.memo(function ListComponent2({
|
|
|
233
235
|
},
|
|
234
236
|
getComponent(ListHeaderComponent)
|
|
235
237
|
),
|
|
238
|
+
ListEmptyComponent && /* @__PURE__ */ React6.createElement(
|
|
239
|
+
View,
|
|
240
|
+
{
|
|
241
|
+
style: ListEmptyComponentStyle
|
|
242
|
+
},
|
|
243
|
+
getComponent(ListEmptyComponent)
|
|
244
|
+
),
|
|
236
245
|
/* @__PURE__ */ React6.createElement(
|
|
237
246
|
Containers,
|
|
238
247
|
{
|
|
@@ -250,7 +259,9 @@ var ListComponent = React6.memo(function ListComponent2({
|
|
|
250
259
|
// src/viewability.ts
|
|
251
260
|
var mapViewabilityConfigCallbackPairs = /* @__PURE__ */ new Map();
|
|
252
261
|
var mapViewabilityCallbacks = /* @__PURE__ */ new Map();
|
|
262
|
+
var mapViewabilityValues = /* @__PURE__ */ new Map();
|
|
253
263
|
var mapViewabilityAmountCallbacks = /* @__PURE__ */ new Map();
|
|
264
|
+
var mapViewabilityAmountValues = /* @__PURE__ */ new Map();
|
|
254
265
|
function setupViewability(props) {
|
|
255
266
|
let { viewabilityConfig, viewabilityConfigCallbackPairs, onViewableItemsChanged } = props;
|
|
256
267
|
viewabilityConfigCallbackPairs = viewabilityConfigCallbackPairs || [
|
|
@@ -348,20 +359,22 @@ function isViewable(state, ctx, viewabilityConfig, key, scrollSize, item, index)
|
|
|
348
359
|
const percent = isEntirelyVisible ? 100 : viewAreaMode ? percentOfScroller : percentVisible;
|
|
349
360
|
const isViewable2 = percent >= viewablePercentThreshold;
|
|
350
361
|
const containerId = findContainerId(state, ctx, index);
|
|
362
|
+
const value = {
|
|
363
|
+
index,
|
|
364
|
+
isViewable: isViewable2,
|
|
365
|
+
item,
|
|
366
|
+
key,
|
|
367
|
+
percentVisible,
|
|
368
|
+
percentOfScroller,
|
|
369
|
+
sizeVisible,
|
|
370
|
+
size,
|
|
371
|
+
position: top,
|
|
372
|
+
scrollSize
|
|
373
|
+
};
|
|
374
|
+
mapViewabilityAmountValues.set(containerId, value);
|
|
351
375
|
const cb = mapViewabilityAmountCallbacks.get(containerId);
|
|
352
376
|
if (cb) {
|
|
353
|
-
cb(
|
|
354
|
-
index,
|
|
355
|
-
isViewable: isViewable2,
|
|
356
|
-
item,
|
|
357
|
-
key,
|
|
358
|
-
percentVisible,
|
|
359
|
-
percentOfScroller,
|
|
360
|
-
sizeVisible,
|
|
361
|
-
size,
|
|
362
|
-
position: top,
|
|
363
|
-
scrollSize
|
|
364
|
-
});
|
|
377
|
+
cb(value);
|
|
365
378
|
}
|
|
366
379
|
return isViewable2;
|
|
367
380
|
}
|
|
@@ -377,6 +390,7 @@ function findContainerId(state, ctx, index) {
|
|
|
377
390
|
}
|
|
378
391
|
function maybeUpdateViewabilityCallback(configId, viewToken) {
|
|
379
392
|
const key = viewToken.key + configId;
|
|
393
|
+
mapViewabilityValues.set(key, viewToken);
|
|
380
394
|
const cb = mapViewabilityCallbacks.get(key);
|
|
381
395
|
cb == null ? void 0 : cb(viewToken);
|
|
382
396
|
}
|
|
@@ -422,7 +436,7 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
|
|
|
422
436
|
estimatedItemSize,
|
|
423
437
|
getEstimatedItemSize,
|
|
424
438
|
onEndReached,
|
|
425
|
-
|
|
439
|
+
ListEmptyComponent,
|
|
426
440
|
...rest
|
|
427
441
|
} = props;
|
|
428
442
|
const ctx = useStateContext();
|
|
@@ -521,9 +535,21 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
|
|
|
521
535
|
return null;
|
|
522
536
|
}
|
|
523
537
|
const useViewability = (configId, callback) => {
|
|
538
|
+
useMemo(() => {
|
|
539
|
+
const value = mapViewabilityValues.get(containerIndex + configId);
|
|
540
|
+
if (value) {
|
|
541
|
+
callback(value);
|
|
542
|
+
}
|
|
543
|
+
}, []);
|
|
524
544
|
useEffect(() => registerViewabilityCallback(containerIndex, configId, callback), []);
|
|
525
545
|
};
|
|
526
546
|
const useViewabilityAmount = (callback) => {
|
|
547
|
+
useMemo(() => {
|
|
548
|
+
const value = mapViewabilityAmountValues.get(containerIndex);
|
|
549
|
+
if (value) {
|
|
550
|
+
callback(value);
|
|
551
|
+
}
|
|
552
|
+
}, []);
|
|
527
553
|
useEffect(() => registerViewabilityAmountCallback(containerIndex, callback), []);
|
|
528
554
|
};
|
|
529
555
|
const useRecyclingEffect = (effect) => {
|
|
@@ -714,31 +740,20 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
|
|
|
714
740
|
}
|
|
715
741
|
}
|
|
716
742
|
}
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
if (refState.current.viewabilityConfigCallbackPairs) {
|
|
729
|
-
updateViewableItems(
|
|
730
|
-
refState.current,
|
|
731
|
-
ctx,
|
|
732
|
-
refState.current.viewabilityConfigCallbackPairs,
|
|
733
|
-
getId,
|
|
734
|
-
scrollLength,
|
|
735
|
-
startNoBuffer,
|
|
736
|
-
endNoBuffer
|
|
737
|
-
);
|
|
738
|
-
}
|
|
743
|
+
}
|
|
744
|
+
if (refState.current.viewabilityConfigCallbackPairs) {
|
|
745
|
+
updateViewableItems(
|
|
746
|
+
refState.current,
|
|
747
|
+
ctx,
|
|
748
|
+
refState.current.viewabilityConfigCallbackPairs,
|
|
749
|
+
getId,
|
|
750
|
+
scrollLength,
|
|
751
|
+
startNoBuffer,
|
|
752
|
+
endNoBuffer
|
|
753
|
+
);
|
|
739
754
|
}
|
|
740
755
|
});
|
|
741
|
-
}, [
|
|
756
|
+
}, []);
|
|
742
757
|
useMemo(() => {
|
|
743
758
|
var _a2, _b2;
|
|
744
759
|
refState.current.viewabilityConfigCallbackPairs = setupViewability(props);
|
|
@@ -780,6 +795,15 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
|
|
|
780
795
|
if (refState.current) {
|
|
781
796
|
refState.current.isEndReached = false;
|
|
782
797
|
}
|
|
798
|
+
const numContainers = peek$(ctx, "numContainers");
|
|
799
|
+
if (data.length < numContainers) {
|
|
800
|
+
for (let i = 0; i < numContainers; i++) {
|
|
801
|
+
const itemIndex = peek$(ctx, `containerIndex${i}`);
|
|
802
|
+
if (itemIndex >= data.length) {
|
|
803
|
+
set$(ctx, `containerIndex${i}`, -1);
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
}
|
|
783
807
|
calculateItemsInView();
|
|
784
808
|
checkAtBottom();
|
|
785
809
|
}, [data]);
|
|
@@ -882,7 +906,8 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
|
|
|
882
906
|
onLayout,
|
|
883
907
|
recycleItems,
|
|
884
908
|
alignItemsAtEnd,
|
|
885
|
-
addTotalSize
|
|
909
|
+
addTotalSize,
|
|
910
|
+
ListEmptyComponent: data.length === 0 ? ListEmptyComponent : void 0
|
|
886
911
|
}
|
|
887
912
|
);
|
|
888
913
|
});
|