@legendapp/list 0.6.4 → 1.0.0-beta.0
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 +4 -1
- package/index.d.mts +6 -2
- package/index.d.ts +6 -2
- package/index.js +8 -4
- package/index.mjs +9 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -14,6 +14,10 @@ In addition to normal FlatList features:
|
|
|
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
|
+
## Documentation
|
|
18
|
+
|
|
19
|
+
See the [documentation site](https://www.legendapp.com/open-source/list) for the full documentation.
|
|
20
|
+
|
|
17
21
|
## Usage
|
|
18
22
|
|
|
19
23
|
## Install
|
|
@@ -41,7 +45,6 @@ interface PropsOptional {
|
|
|
41
45
|
initialScrollOffset?: number;
|
|
42
46
|
initialScrollIndex?: number;
|
|
43
47
|
drawDistance?: number;
|
|
44
|
-
initialContainers?: number;
|
|
45
48
|
recycleItems?: boolean;
|
|
46
49
|
onEndReachedThreshold?: number | null | undefined;
|
|
47
50
|
maintainScrollAtEnd?: boolean;
|
package/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ComponentProps, ReactNode, ForwardedRef, ReactElement } from 'react';
|
|
2
|
-
import { ScrollView, StyleProp, ViewStyle, ScrollViewComponent, ScrollResponderMixin } from 'react-native';
|
|
2
|
+
import { ScrollView, StyleProp, ViewStyle, ScrollViewProps, ScrollViewComponent, ScrollResponderMixin } from 'react-native';
|
|
3
3
|
import Animated from 'react-native-reanimated';
|
|
4
4
|
|
|
5
5
|
declare class ScrollAdjustHandler {
|
|
@@ -19,7 +19,6 @@ type LegendListPropsBase<ItemT, TScrollView extends ComponentProps<typeof Scroll
|
|
|
19
19
|
initialScrollOffset?: number;
|
|
20
20
|
initialScrollIndex?: number;
|
|
21
21
|
drawDistance?: number;
|
|
22
|
-
initialNumContainers?: number;
|
|
23
22
|
recycleItems?: boolean;
|
|
24
23
|
onEndReachedThreshold?: number | null | undefined;
|
|
25
24
|
onStartReachedThreshold?: number | null | undefined;
|
|
@@ -57,6 +56,11 @@ type LegendListPropsBase<ItemT, TScrollView extends ComponentProps<typeof Scroll
|
|
|
57
56
|
itemKey: string;
|
|
58
57
|
itemData: ItemT;
|
|
59
58
|
}) => void;
|
|
59
|
+
/**
|
|
60
|
+
* Render custom ScrollView component.
|
|
61
|
+
* @default (props) => <ScrollView {...props} />
|
|
62
|
+
*/
|
|
63
|
+
renderScrollComponent?: (props: ScrollViewProps) => React.ReactElement<ScrollViewProps>;
|
|
60
64
|
};
|
|
61
65
|
type LegendListProps<ItemT> = LegendListPropsBase<ItemT, ComponentProps<typeof ScrollView>>;
|
|
62
66
|
interface InternalState {
|
package/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ComponentProps, ReactNode, ForwardedRef, ReactElement } from 'react';
|
|
2
|
-
import { ScrollView, StyleProp, ViewStyle, ScrollViewComponent, ScrollResponderMixin } from 'react-native';
|
|
2
|
+
import { ScrollView, StyleProp, ViewStyle, ScrollViewProps, ScrollViewComponent, ScrollResponderMixin } from 'react-native';
|
|
3
3
|
import Animated from 'react-native-reanimated';
|
|
4
4
|
|
|
5
5
|
declare class ScrollAdjustHandler {
|
|
@@ -19,7 +19,6 @@ type LegendListPropsBase<ItemT, TScrollView extends ComponentProps<typeof Scroll
|
|
|
19
19
|
initialScrollOffset?: number;
|
|
20
20
|
initialScrollIndex?: number;
|
|
21
21
|
drawDistance?: number;
|
|
22
|
-
initialNumContainers?: number;
|
|
23
22
|
recycleItems?: boolean;
|
|
24
23
|
onEndReachedThreshold?: number | null | undefined;
|
|
25
24
|
onStartReachedThreshold?: number | null | undefined;
|
|
@@ -57,6 +56,11 @@ type LegendListPropsBase<ItemT, TScrollView extends ComponentProps<typeof Scroll
|
|
|
57
56
|
itemKey: string;
|
|
58
57
|
itemData: ItemT;
|
|
59
58
|
}) => void;
|
|
59
|
+
/**
|
|
60
|
+
* Render custom ScrollView component.
|
|
61
|
+
* @default (props) => <ScrollView {...props} />
|
|
62
|
+
*/
|
|
63
|
+
renderScrollComponent?: (props: ScrollViewProps) => React.ReactElement<ScrollViewProps>;
|
|
60
64
|
};
|
|
61
65
|
type LegendListProps<ItemT> = LegendListPropsBase<ItemT, ComponentProps<typeof ScrollView>>;
|
|
62
66
|
interface InternalState {
|
package/index.js
CHANGED
|
@@ -208,14 +208,19 @@ var ListComponent = React4__namespace.memo(function ListComponent2({
|
|
|
208
208
|
updateItemSize,
|
|
209
209
|
refScrollView,
|
|
210
210
|
maintainVisibleContentPosition,
|
|
211
|
+
renderScrollComponent,
|
|
211
212
|
...rest
|
|
212
213
|
}) {
|
|
213
214
|
const ctx = useStateContext();
|
|
214
215
|
const animPaddingTop = useValue$("paddingTop");
|
|
215
216
|
const animScrollAdjust = useValue$("scrollAdjust");
|
|
217
|
+
const ScrollComponent = renderScrollComponent ? React4.useMemo(
|
|
218
|
+
() => React4__namespace.forwardRef((props, ref) => renderScrollComponent({ ...props, ref })),
|
|
219
|
+
[renderScrollComponent]
|
|
220
|
+
) : reactNative.ScrollView;
|
|
216
221
|
const additionalSize = { marginTop: animScrollAdjust, paddingTop: animPaddingTop };
|
|
217
222
|
return /* @__PURE__ */ React4__namespace.createElement(
|
|
218
|
-
|
|
223
|
+
ScrollComponent,
|
|
219
224
|
{
|
|
220
225
|
...rest,
|
|
221
226
|
style,
|
|
@@ -469,7 +474,6 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
|
|
|
469
474
|
initialScrollIndex,
|
|
470
475
|
initialScrollOffset,
|
|
471
476
|
horizontal,
|
|
472
|
-
initialNumContainers,
|
|
473
477
|
drawDistance = 250,
|
|
474
478
|
recycleItems = false,
|
|
475
479
|
onEndReachedThreshold = 0.5,
|
|
@@ -869,7 +873,7 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
|
|
|
869
873
|
set$(ctx, `containerColumn${containerId}`, -1);
|
|
870
874
|
if (__DEV__ && numContainers > peek$(ctx, "numContainersPooled")) {
|
|
871
875
|
console.warn(
|
|
872
|
-
"[legend-list] No container to recycle,
|
|
876
|
+
"[legend-list] No container to recycle, so creating one on demand. This can be a performance issue and is likely caused by the estimatedItemSize being too small. Consider increasing estimatedItemSize. numContainers:",
|
|
873
877
|
numContainers
|
|
874
878
|
);
|
|
875
879
|
}
|
|
@@ -1182,7 +1186,7 @@ var LegendListInner = React4.forwardRef(function LegendListInner2(props, forward
|
|
|
1182
1186
|
refState.current.viewabilityConfigCallbackPairs = setupViewability(props);
|
|
1183
1187
|
const scrollLength = refState.current.scrollLength;
|
|
1184
1188
|
const averageItemSize = (_a2 = estimatedItemSize != null ? estimatedItemSize : getEstimatedItemSize == null ? void 0 : getEstimatedItemSize(0, data[0])) != null ? _a2 : DEFAULT_ITEM_SIZE;
|
|
1185
|
-
const numContainers =
|
|
1189
|
+
const numContainers = Math.ceil((scrollLength + scrollBuffer * 2) / averageItemSize) * numColumnsProp;
|
|
1186
1190
|
for (let i = 0; i < numContainers; i++) {
|
|
1187
1191
|
set$(ctx, `containerPosition${i}`, POSITION_OUT_OF_VIEW);
|
|
1188
1192
|
set$(ctx, `containerColumn${i}`, -1);
|
package/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React4 from 'react';
|
|
2
|
-
import React4__default, { forwardRef, useRef,
|
|
2
|
+
import React4__default, { useMemo, forwardRef, useRef, useCallback, useEffect, useImperativeHandle, useSyncExternalStore, useState } from 'react';
|
|
3
3
|
import { Animated, ScrollView, View, Dimensions, StyleSheet, Platform, useAnimatedValue as useAnimatedValue$1 } from 'react-native';
|
|
4
4
|
|
|
5
5
|
// src/LegendList.tsx
|
|
@@ -187,14 +187,19 @@ var ListComponent = React4.memo(function ListComponent2({
|
|
|
187
187
|
updateItemSize,
|
|
188
188
|
refScrollView,
|
|
189
189
|
maintainVisibleContentPosition,
|
|
190
|
+
renderScrollComponent,
|
|
190
191
|
...rest
|
|
191
192
|
}) {
|
|
192
193
|
const ctx = useStateContext();
|
|
193
194
|
const animPaddingTop = useValue$("paddingTop");
|
|
194
195
|
const animScrollAdjust = useValue$("scrollAdjust");
|
|
196
|
+
const ScrollComponent = renderScrollComponent ? useMemo(
|
|
197
|
+
() => React4.forwardRef((props, ref) => renderScrollComponent({ ...props, ref })),
|
|
198
|
+
[renderScrollComponent]
|
|
199
|
+
) : ScrollView;
|
|
195
200
|
const additionalSize = { marginTop: animScrollAdjust, paddingTop: animPaddingTop };
|
|
196
201
|
return /* @__PURE__ */ React4.createElement(
|
|
197
|
-
|
|
202
|
+
ScrollComponent,
|
|
198
203
|
{
|
|
199
204
|
...rest,
|
|
200
205
|
style,
|
|
@@ -448,7 +453,6 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
|
|
|
448
453
|
initialScrollIndex,
|
|
449
454
|
initialScrollOffset,
|
|
450
455
|
horizontal,
|
|
451
|
-
initialNumContainers,
|
|
452
456
|
drawDistance = 250,
|
|
453
457
|
recycleItems = false,
|
|
454
458
|
onEndReachedThreshold = 0.5,
|
|
@@ -848,7 +852,7 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
|
|
|
848
852
|
set$(ctx, `containerColumn${containerId}`, -1);
|
|
849
853
|
if (__DEV__ && numContainers > peek$(ctx, "numContainersPooled")) {
|
|
850
854
|
console.warn(
|
|
851
|
-
"[legend-list] No container to recycle,
|
|
855
|
+
"[legend-list] No container to recycle, so creating one on demand. This can be a performance issue and is likely caused by the estimatedItemSize being too small. Consider increasing estimatedItemSize. numContainers:",
|
|
852
856
|
numContainers
|
|
853
857
|
);
|
|
854
858
|
}
|
|
@@ -1161,7 +1165,7 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
|
|
|
1161
1165
|
refState.current.viewabilityConfigCallbackPairs = setupViewability(props);
|
|
1162
1166
|
const scrollLength = refState.current.scrollLength;
|
|
1163
1167
|
const averageItemSize = (_a2 = estimatedItemSize != null ? estimatedItemSize : getEstimatedItemSize == null ? void 0 : getEstimatedItemSize(0, data[0])) != null ? _a2 : DEFAULT_ITEM_SIZE;
|
|
1164
|
-
const numContainers =
|
|
1168
|
+
const numContainers = Math.ceil((scrollLength + scrollBuffer * 2) / averageItemSize) * numColumnsProp;
|
|
1165
1169
|
for (let i = 0; i < numContainers; i++) {
|
|
1166
1170
|
set$(ctx, `containerPosition${i}`, POSITION_OUT_OF_VIEW);
|
|
1167
1171
|
set$(ctx, `containerColumn${i}`, -1);
|