@legendapp/list 0.1.0 → 0.1.2
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 +8 -0
- package/index.d.mts +28 -2
- package/index.d.ts +28 -2
- package/index.js +11 -4
- package/index.mjs +12 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -70,3 +70,11 @@ There's not a lot of code here so hopefully it's easy to contribute. If you want
|
|
|
70
70
|
- Other important missing features from FlatList or other lists libraries
|
|
71
71
|
- Optimizations:
|
|
72
72
|
- Loop over only potentially changed items when adjusting heights rather than data array
|
|
73
|
+
|
|
74
|
+
## Community
|
|
75
|
+
|
|
76
|
+
Join us on [Discord](https://discord.gg/tuW2pAffjA) to get involved with the Legend community.
|
|
77
|
+
|
|
78
|
+
## 👩⚖️ License
|
|
79
|
+
|
|
80
|
+
[MIT](LICENSE)
|
package/index.d.mts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { ComponentProps, ReactNode } from 'react';
|
|
3
|
-
import
|
|
3
|
+
import * as react_native from 'react-native';
|
|
4
|
+
import { ScrollView, StyleProp, ViewStyle } from 'react-native';
|
|
4
5
|
|
|
5
6
|
type LegendListProps<T> = Omit<ComponentProps<typeof ScrollView>, 'contentOffset'> & {
|
|
6
7
|
data: ArrayLike<any> & T[];
|
|
@@ -19,6 +20,10 @@ type LegendListProps<T> = Omit<ComponentProps<typeof ScrollView>, 'contentOffset
|
|
|
19
20
|
keyExtractor?: (item: T, index: number) => string;
|
|
20
21
|
renderItem?: (props: LegendListRenderItemInfo<T>) => ReactNode;
|
|
21
22
|
onViewableRangeChanged?: (range: ViewableRange<T>) => void;
|
|
23
|
+
ListHeaderComponent?: ReactNode;
|
|
24
|
+
ListHeaderComponentStyle?: StyleProp<ViewStyle> | undefined;
|
|
25
|
+
ListFooterComponent?: ReactNode;
|
|
26
|
+
ListFooterComponentStyle?: StyleProp<ViewStyle> | undefined;
|
|
22
27
|
};
|
|
23
28
|
interface ViewableRange<T> {
|
|
24
29
|
startBuffered: number;
|
|
@@ -32,6 +37,27 @@ interface LegendListRenderItemInfo<ItemT> {
|
|
|
32
37
|
index: number;
|
|
33
38
|
}
|
|
34
39
|
|
|
35
|
-
declare
|
|
40
|
+
declare const LegendList: React.ForwardRefExoticComponent<Omit<react_native.ScrollViewProps, "contentOffset"> & {
|
|
41
|
+
data: ArrayLike<any> & unknown[];
|
|
42
|
+
initialScrollOffset?: number;
|
|
43
|
+
initialScrollIndex?: number;
|
|
44
|
+
drawDistance?: number;
|
|
45
|
+
initialContainers?: number;
|
|
46
|
+
recycleItems?: boolean;
|
|
47
|
+
onEndReachedThreshold?: number | null | undefined;
|
|
48
|
+
autoScrollToBottom?: boolean;
|
|
49
|
+
autoScrollToBottomThreshold?: number;
|
|
50
|
+
estimatedItemLength: (index: number) => number;
|
|
51
|
+
onEndReached?: ((info: {
|
|
52
|
+
distanceFromEnd: number;
|
|
53
|
+
}) => void) | null | undefined;
|
|
54
|
+
keyExtractor?: ((item: unknown, index: number) => string) | undefined;
|
|
55
|
+
renderItem?: ((props: LegendListRenderItemInfo<unknown>) => React.ReactNode) | undefined;
|
|
56
|
+
onViewableRangeChanged?: ((range: ViewableRange<unknown>) => void) | undefined;
|
|
57
|
+
ListHeaderComponent?: React.ReactNode;
|
|
58
|
+
ListHeaderComponentStyle?: react_native.StyleProp<react_native.ViewStyle> | undefined;
|
|
59
|
+
ListFooterComponent?: React.ReactNode;
|
|
60
|
+
ListFooterComponentStyle?: react_native.StyleProp<react_native.ViewStyle> | undefined;
|
|
61
|
+
} & React.RefAttributes<ScrollView>>;
|
|
36
62
|
|
|
37
63
|
export { LegendList, type LegendListProps, type LegendListRenderItemInfo, type ViewableRange };
|
package/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { ComponentProps, ReactNode } from 'react';
|
|
3
|
-
import
|
|
3
|
+
import * as react_native from 'react-native';
|
|
4
|
+
import { ScrollView, StyleProp, ViewStyle } from 'react-native';
|
|
4
5
|
|
|
5
6
|
type LegendListProps<T> = Omit<ComponentProps<typeof ScrollView>, 'contentOffset'> & {
|
|
6
7
|
data: ArrayLike<any> & T[];
|
|
@@ -19,6 +20,10 @@ type LegendListProps<T> = Omit<ComponentProps<typeof ScrollView>, 'contentOffset
|
|
|
19
20
|
keyExtractor?: (item: T, index: number) => string;
|
|
20
21
|
renderItem?: (props: LegendListRenderItemInfo<T>) => ReactNode;
|
|
21
22
|
onViewableRangeChanged?: (range: ViewableRange<T>) => void;
|
|
23
|
+
ListHeaderComponent?: ReactNode;
|
|
24
|
+
ListHeaderComponentStyle?: StyleProp<ViewStyle> | undefined;
|
|
25
|
+
ListFooterComponent?: ReactNode;
|
|
26
|
+
ListFooterComponentStyle?: StyleProp<ViewStyle> | undefined;
|
|
22
27
|
};
|
|
23
28
|
interface ViewableRange<T> {
|
|
24
29
|
startBuffered: number;
|
|
@@ -32,6 +37,27 @@ interface LegendListRenderItemInfo<ItemT> {
|
|
|
32
37
|
index: number;
|
|
33
38
|
}
|
|
34
39
|
|
|
35
|
-
declare
|
|
40
|
+
declare const LegendList: React.ForwardRefExoticComponent<Omit<react_native.ScrollViewProps, "contentOffset"> & {
|
|
41
|
+
data: ArrayLike<any> & unknown[];
|
|
42
|
+
initialScrollOffset?: number;
|
|
43
|
+
initialScrollIndex?: number;
|
|
44
|
+
drawDistance?: number;
|
|
45
|
+
initialContainers?: number;
|
|
46
|
+
recycleItems?: boolean;
|
|
47
|
+
onEndReachedThreshold?: number | null | undefined;
|
|
48
|
+
autoScrollToBottom?: boolean;
|
|
49
|
+
autoScrollToBottomThreshold?: number;
|
|
50
|
+
estimatedItemLength: (index: number) => number;
|
|
51
|
+
onEndReached?: ((info: {
|
|
52
|
+
distanceFromEnd: number;
|
|
53
|
+
}) => void) | null | undefined;
|
|
54
|
+
keyExtractor?: ((item: unknown, index: number) => string) | undefined;
|
|
55
|
+
renderItem?: ((props: LegendListRenderItemInfo<unknown>) => React.ReactNode) | undefined;
|
|
56
|
+
onViewableRangeChanged?: ((range: ViewableRange<unknown>) => void) | undefined;
|
|
57
|
+
ListHeaderComponent?: React.ReactNode;
|
|
58
|
+
ListHeaderComponentStyle?: react_native.StyleProp<react_native.ViewStyle> | undefined;
|
|
59
|
+
ListFooterComponent?: React.ReactNode;
|
|
60
|
+
ListFooterComponentStyle?: react_native.StyleProp<react_native.ViewStyle> | undefined;
|
|
61
|
+
} & React.RefAttributes<ScrollView>>;
|
|
36
62
|
|
|
37
63
|
export { LegendList, type LegendListProps, type LegendListRenderItemInfo, type ViewableRange };
|
package/index.js
CHANGED
|
@@ -71,7 +71,7 @@ var Container = ({
|
|
|
71
71
|
enableReactNativeComponents.enableReactNativeComponents();
|
|
72
72
|
var DEFAULT_SCROLL_BUFFER = 0;
|
|
73
73
|
var POSITION_OUT_OF_VIEW = -1e4;
|
|
74
|
-
|
|
74
|
+
var LegendList = React2.forwardRef((props, forwardedRef) => {
|
|
75
75
|
const {
|
|
76
76
|
data,
|
|
77
77
|
initialScrollIndex,
|
|
@@ -90,9 +90,14 @@ function LegendList(props) {
|
|
|
90
90
|
estimatedItemLength,
|
|
91
91
|
onEndReached,
|
|
92
92
|
onViewableRangeChanged,
|
|
93
|
+
ListHeaderComponent,
|
|
94
|
+
ListHeaderComponentStyle,
|
|
95
|
+
ListFooterComponent,
|
|
96
|
+
ListFooterComponentStyle,
|
|
93
97
|
...rest
|
|
94
98
|
} = props;
|
|
95
|
-
const
|
|
99
|
+
const internalRef = React2.useRef(null);
|
|
100
|
+
const refScroller = forwardedRef || internalRef;
|
|
96
101
|
const containers$ = react.useObservable(() => []);
|
|
97
102
|
const visibleRange$ = react.useObservable(() => ({
|
|
98
103
|
start: 0,
|
|
@@ -366,6 +371,7 @@ function LegendList(props) {
|
|
|
366
371
|
...rest,
|
|
367
372
|
ref: refScroller
|
|
368
373
|
},
|
|
374
|
+
ListHeaderComponent && /* @__PURE__ */ React2__namespace.createElement(react.Reactive.View, { $style: ListHeaderComponentStyle }, ListHeaderComponent),
|
|
369
375
|
/* @__PURE__ */ React2__namespace.createElement(
|
|
370
376
|
react.Reactive.View,
|
|
371
377
|
{
|
|
@@ -386,8 +392,9 @@ function LegendList(props) {
|
|
|
386
392
|
onLayout: updateItemLength
|
|
387
393
|
}
|
|
388
394
|
))
|
|
389
|
-
)
|
|
395
|
+
),
|
|
396
|
+
ListFooterComponent && /* @__PURE__ */ React2__namespace.createElement(react.Reactive.View, { $style: ListFooterComponentStyle }, ListFooterComponent)
|
|
390
397
|
);
|
|
391
|
-
}
|
|
398
|
+
});
|
|
392
399
|
|
|
393
400
|
exports.LegendList = LegendList;
|
package/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React2 from 'react';
|
|
2
|
-
import { useRef, useCallback, useMemo, useEffect } from 'react';
|
|
2
|
+
import { forwardRef, useRef, useCallback, useMemo, useEffect } from 'react';
|
|
3
3
|
import { beginBatch, endBatch } from '@legendapp/state';
|
|
4
4
|
import { enableReactNativeComponents } from '@legendapp/state/config/enableReactNativeComponents';
|
|
5
5
|
import { useObservable, use$, Reactive } from '@legendapp/state/react';
|
|
@@ -50,7 +50,7 @@ var Container = ({
|
|
|
50
50
|
enableReactNativeComponents();
|
|
51
51
|
var DEFAULT_SCROLL_BUFFER = 0;
|
|
52
52
|
var POSITION_OUT_OF_VIEW = -1e4;
|
|
53
|
-
|
|
53
|
+
var LegendList = forwardRef((props, forwardedRef) => {
|
|
54
54
|
const {
|
|
55
55
|
data,
|
|
56
56
|
initialScrollIndex,
|
|
@@ -69,9 +69,14 @@ function LegendList(props) {
|
|
|
69
69
|
estimatedItemLength,
|
|
70
70
|
onEndReached,
|
|
71
71
|
onViewableRangeChanged,
|
|
72
|
+
ListHeaderComponent,
|
|
73
|
+
ListHeaderComponentStyle,
|
|
74
|
+
ListFooterComponent,
|
|
75
|
+
ListFooterComponentStyle,
|
|
72
76
|
...rest
|
|
73
77
|
} = props;
|
|
74
|
-
const
|
|
78
|
+
const internalRef = useRef(null);
|
|
79
|
+
const refScroller = forwardedRef || internalRef;
|
|
75
80
|
const containers$ = useObservable(() => []);
|
|
76
81
|
const visibleRange$ = useObservable(() => ({
|
|
77
82
|
start: 0,
|
|
@@ -345,6 +350,7 @@ function LegendList(props) {
|
|
|
345
350
|
...rest,
|
|
346
351
|
ref: refScroller
|
|
347
352
|
},
|
|
353
|
+
ListHeaderComponent && /* @__PURE__ */ React2.createElement(Reactive.View, { $style: ListHeaderComponentStyle }, ListHeaderComponent),
|
|
348
354
|
/* @__PURE__ */ React2.createElement(
|
|
349
355
|
Reactive.View,
|
|
350
356
|
{
|
|
@@ -365,8 +371,9 @@ function LegendList(props) {
|
|
|
365
371
|
onLayout: updateItemLength
|
|
366
372
|
}
|
|
367
373
|
))
|
|
368
|
-
)
|
|
374
|
+
),
|
|
375
|
+
ListFooterComponent && /* @__PURE__ */ React2.createElement(Reactive.View, { $style: ListFooterComponentStyle }, ListFooterComponent)
|
|
369
376
|
);
|
|
370
|
-
}
|
|
377
|
+
});
|
|
371
378
|
|
|
372
379
|
export { LegendList };
|