@legendapp/list 0.2.1 → 0.2.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 +3 -3
- package/index.d.mts +3 -3
- package/index.d.ts +3 -3
- package/index.js +7 -7
- package/index.mjs +7 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@ This is an early release to test and gather feedback. It's not used in productio
|
|
|
11
11
|
In addition to normal FlatList features:
|
|
12
12
|
|
|
13
13
|
- Dynamic layouts supported. Just use the `estimatedItemLength` prop to give a close estimate so that layouts aren't too far off, and positions will adjust while rendering.
|
|
14
|
-
- `
|
|
14
|
+
- `maintainScrollAtEnd`: If true and scroll is within `maintainScrollAtEndThreshold * screen height` then changing items or heights will scroll to the bottom. This can be useful for chat interfaces.
|
|
15
15
|
- `recycleItems` prop enables toggling recycling of list items. If enabled it will reuse item components for improved performance, but it will reuse any local state in items. So if you have local state in items you likely want this disabled.
|
|
16
16
|
|
|
17
17
|
## Usage
|
|
@@ -40,8 +40,8 @@ interface PropsOptional {
|
|
|
40
40
|
initialContainers?: number;
|
|
41
41
|
recycleItems?: boolean;
|
|
42
42
|
onEndReachedThreshold?: number | null | undefined;
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
maintainScrollAtEnd?: boolean;
|
|
44
|
+
maintainScrollAtEndThreshold?: number;
|
|
45
45
|
onEndReached?: ((info: { distanceFromEnd: number }) => void) | null | undefined;
|
|
46
46
|
keyExtractor?: (item: T, index: number) => string;
|
|
47
47
|
onViewableRangeChanged?: (range: ViewableRange<T>) => void;
|
package/index.d.mts
CHANGED
|
@@ -9,9 +9,9 @@ type LegendListProps<T> = Omit<ComponentProps<typeof ScrollView>, 'contentOffset
|
|
|
9
9
|
initialContainers?: number;
|
|
10
10
|
recycleItems?: boolean;
|
|
11
11
|
onEndReachedThreshold?: number | null | undefined;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
maintainScrollAtEnd?: boolean;
|
|
13
|
+
maintainScrollAtEndThreshold?: number;
|
|
14
|
+
alignItemsAtEnd?: boolean;
|
|
15
15
|
estimatedItemLength: (index: number) => number;
|
|
16
16
|
onEndReached?: ((info: {
|
|
17
17
|
distanceFromEnd: number;
|
package/index.d.ts
CHANGED
|
@@ -9,9 +9,9 @@ type LegendListProps<T> = Omit<ComponentProps<typeof ScrollView>, 'contentOffset
|
|
|
9
9
|
initialContainers?: number;
|
|
10
10
|
recycleItems?: boolean;
|
|
11
11
|
onEndReachedThreshold?: number | null | undefined;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
maintainScrollAtEnd?: boolean;
|
|
13
|
+
maintainScrollAtEndThreshold?: number;
|
|
14
|
+
alignItemsAtEnd?: boolean;
|
|
15
15
|
estimatedItemLength: (index: number) => number;
|
|
16
16
|
onEndReached?: ((info: {
|
|
17
17
|
distanceFromEnd: number;
|
package/index.js
CHANGED
|
@@ -86,9 +86,9 @@ var LegendList = React2.forwardRef(function LegendList2(props, forwardedRef) {
|
|
|
86
86
|
drawDistance,
|
|
87
87
|
recycleItems = true,
|
|
88
88
|
onEndReachedThreshold,
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
89
|
+
maintainScrollAtEnd = false,
|
|
90
|
+
maintainScrollAtEndThreshold = 0.1,
|
|
91
|
+
alignItemsAtEnd = false,
|
|
92
92
|
keyExtractor,
|
|
93
93
|
renderItem,
|
|
94
94
|
estimatedItemLength,
|
|
@@ -144,7 +144,7 @@ var LegendList = React2.forwardRef(function LegendList2(props, forwardedRef) {
|
|
|
144
144
|
const setTotalLength = (length) => {
|
|
145
145
|
visibleRange$.totalLength.set(length);
|
|
146
146
|
const screenLength = refPositions.current.scrollLength;
|
|
147
|
-
if (
|
|
147
|
+
if (alignItemsAtEnd) {
|
|
148
148
|
const listPaddingTop = ((style == null ? void 0 : style.paddingTop) || 0) + ((contentContainerStyle == null ? void 0 : contentContainerStyle.paddingTop) || 0);
|
|
149
149
|
paddingTop$.set(Math.max(0, screenLength - length - listPaddingTop));
|
|
150
150
|
}
|
|
@@ -305,7 +305,7 @@ var LegendList = React2.forwardRef(function LegendList2(props, forwardedRef) {
|
|
|
305
305
|
const newScroll = visibleRange$.scroll.peek();
|
|
306
306
|
const distanceFromEnd = visibleRange$.totalLength.peek() - newScroll - scrollLength;
|
|
307
307
|
if (refPositions.current) {
|
|
308
|
-
refPositions.current.isAtBottom = distanceFromEnd < scrollLength *
|
|
308
|
+
refPositions.current.isAtBottom = distanceFromEnd < scrollLength * maintainScrollAtEndThreshold;
|
|
309
309
|
}
|
|
310
310
|
if (onEndReached && !((_a = refPositions.current) == null ? void 0 : _a.isEndReached)) {
|
|
311
311
|
if (distanceFromEnd < (onEndReachedThreshold || 0.5) * scrollLength) {
|
|
@@ -341,7 +341,7 @@ var LegendList = React2.forwardRef(function LegendList2(props, forwardedRef) {
|
|
|
341
341
|
state.beginBatch();
|
|
342
342
|
lengths.set(id, length);
|
|
343
343
|
setTotalLength(visibleRange$.totalLength.peek() + (length - prevLength));
|
|
344
|
-
if (((_d = refPositions.current) == null ? void 0 : _d.isAtBottom) &&
|
|
344
|
+
if (((_d = refPositions.current) == null ? void 0 : _d.isAtBottom) && maintainScrollAtEnd) {
|
|
345
345
|
requestAnimationFrame(() => {
|
|
346
346
|
var _a2;
|
|
347
347
|
(_a2 = refScroller.current) == null ? void 0 : _a2.scrollToEnd({
|
|
@@ -400,7 +400,7 @@ var LegendList = React2.forwardRef(function LegendList2(props, forwardedRef) {
|
|
|
400
400
|
...rest,
|
|
401
401
|
ref: refScroller
|
|
402
402
|
},
|
|
403
|
-
|
|
403
|
+
alignItemsAtEnd && /* @__PURE__ */ React2__namespace.createElement(react.Reactive.View, { $style: () => ({ height: paddingTop$.get() }) }),
|
|
404
404
|
ListHeaderComponent && /* @__PURE__ */ React2__namespace.createElement(react.Reactive.View, { $style: ListHeaderComponentStyle }, ListHeaderComponent),
|
|
405
405
|
/* @__PURE__ */ React2__namespace.createElement(
|
|
406
406
|
react.Reactive.View,
|
package/index.mjs
CHANGED
|
@@ -65,9 +65,9 @@ var LegendList = forwardRef(function LegendList2(props, forwardedRef) {
|
|
|
65
65
|
drawDistance,
|
|
66
66
|
recycleItems = true,
|
|
67
67
|
onEndReachedThreshold,
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
68
|
+
maintainScrollAtEnd = false,
|
|
69
|
+
maintainScrollAtEndThreshold = 0.1,
|
|
70
|
+
alignItemsAtEnd = false,
|
|
71
71
|
keyExtractor,
|
|
72
72
|
renderItem,
|
|
73
73
|
estimatedItemLength,
|
|
@@ -123,7 +123,7 @@ var LegendList = forwardRef(function LegendList2(props, forwardedRef) {
|
|
|
123
123
|
const setTotalLength = (length) => {
|
|
124
124
|
visibleRange$.totalLength.set(length);
|
|
125
125
|
const screenLength = refPositions.current.scrollLength;
|
|
126
|
-
if (
|
|
126
|
+
if (alignItemsAtEnd) {
|
|
127
127
|
const listPaddingTop = ((style == null ? void 0 : style.paddingTop) || 0) + ((contentContainerStyle == null ? void 0 : contentContainerStyle.paddingTop) || 0);
|
|
128
128
|
paddingTop$.set(Math.max(0, screenLength - length - listPaddingTop));
|
|
129
129
|
}
|
|
@@ -284,7 +284,7 @@ var LegendList = forwardRef(function LegendList2(props, forwardedRef) {
|
|
|
284
284
|
const newScroll = visibleRange$.scroll.peek();
|
|
285
285
|
const distanceFromEnd = visibleRange$.totalLength.peek() - newScroll - scrollLength;
|
|
286
286
|
if (refPositions.current) {
|
|
287
|
-
refPositions.current.isAtBottom = distanceFromEnd < scrollLength *
|
|
287
|
+
refPositions.current.isAtBottom = distanceFromEnd < scrollLength * maintainScrollAtEndThreshold;
|
|
288
288
|
}
|
|
289
289
|
if (onEndReached && !((_a = refPositions.current) == null ? void 0 : _a.isEndReached)) {
|
|
290
290
|
if (distanceFromEnd < (onEndReachedThreshold || 0.5) * scrollLength) {
|
|
@@ -320,7 +320,7 @@ var LegendList = forwardRef(function LegendList2(props, forwardedRef) {
|
|
|
320
320
|
beginBatch();
|
|
321
321
|
lengths.set(id, length);
|
|
322
322
|
setTotalLength(visibleRange$.totalLength.peek() + (length - prevLength));
|
|
323
|
-
if (((_d = refPositions.current) == null ? void 0 : _d.isAtBottom) &&
|
|
323
|
+
if (((_d = refPositions.current) == null ? void 0 : _d.isAtBottom) && maintainScrollAtEnd) {
|
|
324
324
|
requestAnimationFrame(() => {
|
|
325
325
|
var _a2;
|
|
326
326
|
(_a2 = refScroller.current) == null ? void 0 : _a2.scrollToEnd({
|
|
@@ -379,7 +379,7 @@ var LegendList = forwardRef(function LegendList2(props, forwardedRef) {
|
|
|
379
379
|
...rest,
|
|
380
380
|
ref: refScroller
|
|
381
381
|
},
|
|
382
|
-
|
|
382
|
+
alignItemsAtEnd && /* @__PURE__ */ React2.createElement(Reactive.View, { $style: () => ({ height: paddingTop$.get() }) }),
|
|
383
383
|
ListHeaderComponent && /* @__PURE__ */ React2.createElement(Reactive.View, { $style: ListHeaderComponentStyle }, ListHeaderComponent),
|
|
384
384
|
/* @__PURE__ */ React2.createElement(
|
|
385
385
|
Reactive.View,
|