@legendapp/list 2.0.0-next.0 → 2.0.0-next.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/.claude/settings.local.json +8 -0
- package/.cursor/rules/changelog.mdc +60 -0
- package/.github/FUNDING.yml +15 -0
- package/.gitignore +5 -0
- package/.prettierrc.json +5 -0
- package/.vscode/settings.json +14 -0
- package/CLAUDE.md +126 -0
- package/biome.json +46 -0
- package/bun.lock +1289 -0
- package/bunfig.toml +2 -0
- package/dist/CHANGELOG.md +119 -0
- package/dist/LICENSE +21 -0
- package/dist/README.md +139 -0
- package/{animated.d.mts → dist/animated.d.mts} +1 -1
- package/{animated.d.ts → dist/animated.d.ts} +1 -1
- package/{index.d.mts → dist/index.d.mts} +63 -15
- package/{index.d.ts → dist/index.d.ts} +63 -15
- package/dist/index.js +2525 -0
- package/dist/index.mjs +2497 -0
- package/{keyboard-controller.d.mts → dist/keyboard-controller.d.mts} +4 -4
- package/{keyboard-controller.d.ts → dist/keyboard-controller.d.ts} +4 -4
- package/dist/package.json +35 -0
- package/example/README.md +40 -0
- package/example/api/data/genres.json +23 -0
- package/example/api/data/playlist/10402-10749.json +1 -0
- package/example/api/data/playlist/10402-10770.json +1 -0
- package/example/api/data/playlist/10402-37.json +1 -0
- package/example/api/data/playlist/10749-10752.json +1 -0
- package/example/api/data/playlist/10749-10770.json +1 -0
- package/example/api/data/playlist/10749-37.json +1 -0
- package/example/api/data/playlist/10749-878.json +1 -0
- package/example/api/data/playlist/10751-10402.json +1 -0
- package/example/api/data/playlist/10751-10752.json +1 -0
- package/example/api/data/playlist/10751-37.json +1 -0
- package/example/api/data/playlist/10751-53.json +1 -0
- package/example/api/data/playlist/10751-878.json +1 -0
- package/example/api/data/playlist/10751-9648.json +1 -0
- package/example/api/data/playlist/10752-37.json +1 -0
- package/example/api/data/playlist/12-10402.json +1 -0
- package/example/api/data/playlist/12-10749.json +1 -0
- package/example/api/data/playlist/12-18.json +1 -0
- package/example/api/data/playlist/12-27.json +1 -0
- package/example/api/data/playlist/12-35.json +1 -0
- package/example/api/data/playlist/14-36.json +1 -0
- package/example/api/data/playlist/14-878.json +1 -0
- package/example/api/data/playlist/16-10751.json +1 -0
- package/example/api/data/playlist/16-10770.json +1 -0
- package/example/api/data/playlist/16-35.json +1 -0
- package/example/api/data/playlist/16-36.json +1 -0
- package/example/api/data/playlist/16-53.json +1 -0
- package/example/api/data/playlist/18-10751.json +1 -0
- package/example/api/data/playlist/18-10752.json +1 -0
- package/example/api/data/playlist/18-37.json +1 -0
- package/example/api/data/playlist/18-53.json +1 -0
- package/example/api/data/playlist/18-878.json +1 -0
- package/example/api/data/playlist/27-10749.json +1 -0
- package/example/api/data/playlist/27-10770.json +1 -0
- package/example/api/data/playlist/28-10749.json +1 -0
- package/example/api/data/playlist/28-10751.json +1 -0
- package/example/api/data/playlist/28-10770.json +1 -0
- package/example/api/data/playlist/28-16.json +1 -0
- package/example/api/data/playlist/28-18.json +1 -0
- package/example/api/data/playlist/28-36.json +1 -0
- package/example/api/data/playlist/28-37.json +1 -0
- package/example/api/data/playlist/28-53.json +1 -0
- package/example/api/data/playlist/28-80.json +1 -0
- package/example/api/data/playlist/28-99.json +1 -0
- package/example/api/data/playlist/35-10749.json +1 -0
- package/example/api/data/playlist/35-10751.json +1 -0
- package/example/api/data/playlist/35-10752.json +1 -0
- package/example/api/data/playlist/35-27.json +1 -0
- package/example/api/data/playlist/35-36.json +1 -0
- package/example/api/data/playlist/35-53.json +1 -0
- package/example/api/data/playlist/35-80.json +1 -0
- package/example/api/data/playlist/36-37.json +1 -0
- package/example/api/data/playlist/36-878.json +1 -0
- package/example/api/data/playlist/36-9648.json +1 -0
- package/example/api/data/playlist/53-10752.json +1 -0
- package/example/api/data/playlist/80-10770.json +1 -0
- package/example/api/data/playlist/80-14.json +1 -0
- package/example/api/data/playlist/80-18.json +1 -0
- package/example/api/data/playlist/80-37.json +1 -0
- package/example/api/data/playlist/878-37.json +1 -0
- package/example/api/data/playlist/9648-10770.json +1 -0
- package/example/api/data/playlist/9648-37.json +1 -0
- package/example/api/data/playlist/9648-53.json +1 -0
- package/example/api/data/playlist/9648-878.json +1 -0
- package/example/api/data/playlist/99-10749.json +1 -0
- package/example/api/data/playlist/99-14.json +1 -0
- package/example/api/data/playlist/99-18.json +1 -0
- package/example/api/data/playlist/99-27.json +1 -0
- package/example/api/data/playlist/99-53.json +1 -0
- package/example/api/data/playlist/99-9648.json +1 -0
- package/example/api/data/playlist/index.ts +73 -0
- package/example/api/data/rows.json +1 -0
- package/example/api/index.ts +36 -0
- package/example/app/(tabs)/_layout.tsx +60 -0
- package/example/app/(tabs)/cards.tsx +81 -0
- package/example/app/(tabs)/index.tsx +205 -0
- package/example/app/(tabs)/moviesL.tsx +7 -0
- package/example/app/(tabs)/moviesLR.tsx +7 -0
- package/example/app/+not-found.tsx +32 -0
- package/example/app/_layout.tsx +34 -0
- package/example/app/accurate-scrollto/index.tsx +125 -0
- package/example/app/accurate-scrollto-2/index.tsx +52 -0
- package/example/app/accurate-scrollto-huge/index.tsx +128 -0
- package/example/app/add-to-end/index.tsx +82 -0
- package/example/app/ai-chat/index.tsx +236 -0
- package/example/app/bidirectional-infinite-list/index.tsx +133 -0
- package/example/app/cards-columns/index.tsx +37 -0
- package/example/app/cards-flashlist/index.tsx +122 -0
- package/example/app/cards-flatlist/index.tsx +94 -0
- package/example/app/cards-no-recycle/index.tsx +110 -0
- package/example/app/cards-renderItem.tsx +354 -0
- package/example/app/chat-example/index.tsx +167 -0
- package/example/app/chat-infinite/index.tsx +239 -0
- package/example/app/chat-keyboard/index.tsx +248 -0
- package/example/app/chat-resize-outer/index.tsx +247 -0
- package/example/app/columns/index.tsx +78 -0
- package/example/app/countries/index.tsx +182 -0
- package/example/app/countries-flashlist/index.tsx +163 -0
- package/example/app/countries-reorder/index.tsx +187 -0
- package/example/app/extra-data/index.tsx +86 -0
- package/example/app/filter-elements/filter-data-provider.tsx +55 -0
- package/example/app/filter-elements/index.tsx +118 -0
- package/example/app/initial-scroll-index/index.tsx +106 -0
- package/example/app/initial-scroll-index/renderFixedItem.tsx +215 -0
- package/example/app/initial-scroll-index-free-height/index.tsx +70 -0
- package/example/app/initial-scroll-index-keyed/index.tsx +62 -0
- package/example/app/lazy-list/index.tsx +123 -0
- package/example/app/movies-flashlist/index.tsx +7 -0
- package/example/app/mutable-cells/index.tsx +104 -0
- package/example/app/video-feed/index.tsx +119 -0
- package/example/app.config.js +22 -0
- package/example/app.json +45 -0
- package/example/assets/fonts/SpaceMono-Regular.ttf +0 -0
- package/example/assets/images/adaptive-icon.png +0 -0
- package/example/assets/images/favicon.png +0 -0
- package/example/assets/images/icon.png +0 -0
- package/example/assets/images/partial-react-logo.png +0 -0
- package/example/assets/images/react-logo.png +0 -0
- package/example/assets/images/react-logo@2x.png +0 -0
- package/example/assets/images/react-logo@3x.png +0 -0
- package/example/assets/images/splash-icon.png +0 -0
- package/example/autoscroll.sh +101 -0
- package/example/bun.lock +2266 -0
- package/example/bunfig.toml +2 -0
- package/example/components/Breathe.tsx +54 -0
- package/example/components/Circle.tsx +69 -0
- package/example/components/Collapsible.tsx +44 -0
- package/example/components/ExternalLink.tsx +24 -0
- package/example/components/HapticTab.tsx +18 -0
- package/example/components/HelloWave.tsx +37 -0
- package/example/components/Movies.tsx +179 -0
- package/example/components/ParallaxScrollView.tsx +81 -0
- package/example/components/ThemedText.tsx +60 -0
- package/example/components/ThemedView.tsx +14 -0
- package/example/components/__tests__/ThemedText-test.tsx +10 -0
- package/example/components/__tests__/__snapshots__/ThemedText-test.tsx.snap +24 -0
- package/example/components/ui/IconSymbol.ios.tsx +32 -0
- package/example/components/ui/IconSymbol.tsx +43 -0
- package/example/components/ui/TabBarBackground.ios.tsx +22 -0
- package/example/components/ui/TabBarBackground.tsx +6 -0
- package/example/constants/Colors.ts +26 -0
- package/example/constants/constants.ts +5 -0
- package/example/constants/useScrollTest.ts +19 -0
- package/example/hooks/useColorScheme.ts +1 -0
- package/example/hooks/useColorScheme.web.ts +8 -0
- package/example/hooks/useThemeColor.ts +22 -0
- package/example/ios/.xcode.env +11 -0
- package/example/ios/Podfile +64 -0
- package/example/ios/Podfile.lock +2767 -0
- package/example/ios/Podfile.properties.json +5 -0
- package/example/ios/listtest/AppDelegate.swift +70 -0
- package/example/ios/listtest/Images.xcassets/AppIcon.appiconset/App-Icon-1024x1024@1x.png +0 -0
- package/example/ios/listtest/Images.xcassets/AppIcon.appiconset/Contents.json +14 -0
- package/example/ios/listtest/Images.xcassets/Contents.json +6 -0
- package/example/ios/listtest/Images.xcassets/SplashScreenBackground.colorset/Contents.json +20 -0
- package/example/ios/listtest/Images.xcassets/SplashScreenLogo.imageset/Contents.json +23 -0
- package/example/ios/listtest/Images.xcassets/SplashScreenLogo.imageset/image.png +0 -0
- package/example/ios/listtest/Images.xcassets/SplashScreenLogo.imageset/image@2x.png +0 -0
- package/example/ios/listtest/Images.xcassets/SplashScreenLogo.imageset/image@3x.png +0 -0
- package/example/ios/listtest/Info.plist +85 -0
- package/example/ios/listtest/PrivacyInfo.xcprivacy +48 -0
- package/example/ios/listtest/SplashScreen.storyboard +42 -0
- package/example/ios/listtest/Supporting/Expo.plist +12 -0
- package/example/ios/listtest/listtest-Bridging-Header.h +3 -0
- package/example/ios/listtest/listtest.entitlements +5 -0
- package/example/ios/listtest.xcodeproj/project.pbxproj +547 -0
- package/example/ios/listtest.xcodeproj/xcshareddata/xcschemes/listtest.xcscheme +88 -0
- package/example/ios/listtest.xcworkspace/contents.xcworkspacedata +10 -0
- package/example/metro.config.js +16 -0
- package/example/package.json +73 -0
- package/example/scripts/reset-project.js +84 -0
- package/example/tsconfig.json +26 -0
- package/package.json +88 -34
- package/posttsup.ts +24 -0
- package/src/Container.tsx +176 -0
- package/src/Containers.tsx +85 -0
- package/src/ContextContainer.ts +145 -0
- package/src/DebugView.tsx +83 -0
- package/src/LazyLegendList.tsx +41 -0
- package/src/LeanView.tsx +18 -0
- package/src/LegendList.tsx +558 -0
- package/src/ListComponent.tsx +191 -0
- package/src/ScrollAdjust.tsx +24 -0
- package/src/ScrollAdjustHandler.ts +26 -0
- package/src/Separator.tsx +14 -0
- package/src/animated.tsx +6 -0
- package/src/calculateItemsInView.ts +363 -0
- package/src/calculateOffsetForIndex.ts +23 -0
- package/src/calculateOffsetWithOffsetPosition.ts +26 -0
- package/src/checkAllSizesKnown.ts +17 -0
- package/src/checkAtBottom.ts +36 -0
- package/src/checkAtTop.ts +27 -0
- package/src/checkThreshold.ts +30 -0
- package/src/constants.ts +11 -0
- package/src/createColumnWrapperStyle.ts +16 -0
- package/src/doInitialAllocateContainers.ts +40 -0
- package/src/doMaintainScrollAtEnd.ts +34 -0
- package/src/findAvailableContainers.ts +98 -0
- package/src/finishScrollTo.ts +8 -0
- package/src/getId.ts +21 -0
- package/src/getItemSize.ts +52 -0
- package/src/getRenderedItem.ts +34 -0
- package/src/getScrollVelocity.ts +47 -0
- package/src/handleLayout.ts +70 -0
- package/src/helpers.ts +39 -0
- package/src/index.ts +11 -0
- package/src/keyboard-controller.tsx +63 -0
- package/src/onScroll.ts +66 -0
- package/src/prepareMVCP.ts +50 -0
- package/src/reanimated.tsx +63 -0
- package/src/requestAdjust.ts +41 -0
- package/src/scrollTo.ts +40 -0
- package/src/scrollToIndex.ts +34 -0
- package/src/setDidLayout.ts +25 -0
- package/src/setPaddingTop.ts +28 -0
- package/src/state.tsx +304 -0
- package/src/types.ts +610 -0
- package/src/updateAlignItemsPaddingTop.ts +18 -0
- package/src/updateAllPositions.ts +130 -0
- package/src/updateItemSize.ts +203 -0
- package/src/updateTotalSize.ts +44 -0
- package/src/useAnimatedValue.ts +6 -0
- package/src/useCombinedRef.ts +22 -0
- package/src/useInit.ts +17 -0
- package/src/useSyncLayout.tsx +68 -0
- package/src/useValue$.ts +53 -0
- package/src/viewability.ts +279 -0
- package/tsconfig.json +59 -0
- package/tsup.config.ts +21 -0
- package/index.js +0 -2348
- package/index.mjs +0 -2320
- /package/{animated.js → dist/animated.js} +0 -0
- /package/{animated.mjs → dist/animated.mjs} +0 -0
- /package/{keyboard-controller.js → dist/keyboard-controller.js} +0 -0
- /package/{keyboard-controller.mjs → dist/keyboard-controller.mjs} +0 -0
- /package/{reanimated.d.mts → dist/reanimated.d.mts} +0 -0
- /package/{reanimated.d.ts → dist/reanimated.d.ts} +0 -0
- /package/{reanimated.js → dist/reanimated.js} +0 -0
- /package/{reanimated.mjs → dist/reanimated.mjs} +0 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,610 @@
|
|
|
1
|
+
import { type ComponentProps, type ReactNode, forwardRef, memo } from "react";
|
|
2
|
+
import type {
|
|
3
|
+
Animated,
|
|
4
|
+
LayoutRectangle,
|
|
5
|
+
NativeScrollEvent,
|
|
6
|
+
NativeSyntheticEvent,
|
|
7
|
+
ScrollResponderMixin,
|
|
8
|
+
ScrollView,
|
|
9
|
+
ScrollViewComponent,
|
|
10
|
+
ScrollViewProps,
|
|
11
|
+
StyleProp,
|
|
12
|
+
ViewStyle,
|
|
13
|
+
} from "react-native";
|
|
14
|
+
import type Reanimated from "react-native-reanimated";
|
|
15
|
+
|
|
16
|
+
import type { ScrollAdjustHandler } from "./ScrollAdjustHandler";
|
|
17
|
+
|
|
18
|
+
export type LegendListPropsBase<
|
|
19
|
+
ItemT,
|
|
20
|
+
TScrollView extends
|
|
21
|
+
| ComponentProps<typeof ScrollView>
|
|
22
|
+
| ComponentProps<typeof Animated.ScrollView>
|
|
23
|
+
| ComponentProps<typeof Reanimated.ScrollView>,
|
|
24
|
+
> = Omit<
|
|
25
|
+
TScrollView,
|
|
26
|
+
| "contentOffset"
|
|
27
|
+
| "contentInset"
|
|
28
|
+
| "maintainVisibleContentPosition"
|
|
29
|
+
| "stickyHeaderIndices"
|
|
30
|
+
| "removeClippedSubviews"
|
|
31
|
+
| "children"
|
|
32
|
+
> & {
|
|
33
|
+
/**
|
|
34
|
+
* If true, aligns items at the end of the list.
|
|
35
|
+
* @default false
|
|
36
|
+
*/
|
|
37
|
+
alignItemsAtEnd?: boolean;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Style applied to each column's wrapper view.
|
|
41
|
+
*/
|
|
42
|
+
columnWrapperStyle?: ColumnWrapperStyle;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Array of items to render in the list.
|
|
46
|
+
* @required
|
|
47
|
+
*/
|
|
48
|
+
data: ReadonlyArray<ItemT>;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Distance in pixels to pre-render items ahead of the visible area.
|
|
52
|
+
* @default 250
|
|
53
|
+
*/
|
|
54
|
+
drawDistance?: number;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Estimated size of each item in pixels, a hint for the first render. After some
|
|
58
|
+
* items are rendered, the average size of rendered items will be used instead.
|
|
59
|
+
* @default undefined
|
|
60
|
+
*/
|
|
61
|
+
estimatedItemSize?: number;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Estimated size of the ScrollView in pixels, a hint for the first render to improve performance
|
|
65
|
+
* @default undefined
|
|
66
|
+
*/
|
|
67
|
+
estimatedListSize?: { height: number; width: number };
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Extra data to trigger re-rendering when changed.
|
|
71
|
+
*/
|
|
72
|
+
extraData?: any;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* In case you have distinct item sizes, you can provide a function to get the size of an item.
|
|
76
|
+
* Use instead of FlatList's getItemLayout or FlashList overrideItemLayout if you want to have accurate initialScrollOffset, you should provide this function
|
|
77
|
+
*/
|
|
78
|
+
getEstimatedItemSize?: (index: number, item: ItemT) => number;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Ratio of initial container pool size to data length (e.g., 0.5 for half).
|
|
82
|
+
* @default 2
|
|
83
|
+
*/
|
|
84
|
+
initialContainerPoolRatio?: number | undefined;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Initial scroll position in pixels.
|
|
88
|
+
* @default 0
|
|
89
|
+
*/
|
|
90
|
+
initialScrollOffset?: number;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Index to scroll to initially.
|
|
94
|
+
* @default 0
|
|
95
|
+
*/
|
|
96
|
+
initialScrollIndex?:
|
|
97
|
+
| number
|
|
98
|
+
| {
|
|
99
|
+
index: number;
|
|
100
|
+
viewOffset?: number | undefined;
|
|
101
|
+
viewPosition?: number | undefined;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Component to render between items, receiving the leading item as prop.
|
|
106
|
+
*/
|
|
107
|
+
ItemSeparatorComponent?: React.ComponentType<{ leadingItem: ItemT }>;
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Function to extract a unique key for each item.
|
|
111
|
+
*/
|
|
112
|
+
keyExtractor?: (item: ItemT, index: number) => string;
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Component or element to render when the list is empty.
|
|
116
|
+
*/
|
|
117
|
+
ListEmptyComponent?: React.ComponentType<any> | React.ReactElement | null | undefined;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Component or element to render below the list.
|
|
121
|
+
*/
|
|
122
|
+
ListFooterComponent?: React.ComponentType<any> | React.ReactElement | null | undefined;
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Style for the footer component.
|
|
126
|
+
*/
|
|
127
|
+
ListFooterComponentStyle?: StyleProp<ViewStyle> | undefined;
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Component or element to render above the list.
|
|
131
|
+
*/
|
|
132
|
+
ListHeaderComponent?: React.ComponentType<any> | React.ReactElement | null | undefined;
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Style for the header component.
|
|
136
|
+
*/
|
|
137
|
+
ListHeaderComponentStyle?: StyleProp<ViewStyle> | undefined;
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* If true, auto-scrolls to end when new items are added.
|
|
141
|
+
* @default false
|
|
142
|
+
*/
|
|
143
|
+
maintainScrollAtEnd?: boolean | MaintainScrollAtEndOptions;
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Distance threshold in percentage of screen size to trigger maintainScrollAtEnd.
|
|
147
|
+
* @default 0.1
|
|
148
|
+
*/
|
|
149
|
+
maintainScrollAtEndThreshold?: number;
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* If true, maintains visibility of content during scroll (e.g., after insertions).
|
|
153
|
+
* @default false
|
|
154
|
+
*/
|
|
155
|
+
maintainVisibleContentPosition?: boolean;
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Number of columns to render items in.
|
|
159
|
+
* @default 1
|
|
160
|
+
*/
|
|
161
|
+
numColumns?: number;
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Called when scrolling reaches the end within onEndReachedThreshold.
|
|
165
|
+
*/
|
|
166
|
+
onEndReached?: ((info: { distanceFromEnd: number }) => void) | null | undefined;
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* How close to the end (in fractional units of visible length) to trigger onEndReached.
|
|
170
|
+
* @default 0.5
|
|
171
|
+
*/
|
|
172
|
+
onEndReachedThreshold?: number | null | undefined;
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Called when an item's size changes.
|
|
176
|
+
*/
|
|
177
|
+
onItemSizeChanged?: (info: {
|
|
178
|
+
size: number;
|
|
179
|
+
previous: number;
|
|
180
|
+
index: number;
|
|
181
|
+
itemKey: string;
|
|
182
|
+
itemData: ItemT;
|
|
183
|
+
}) => void;
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Function to call when the user pulls to refresh.
|
|
187
|
+
*/
|
|
188
|
+
onRefresh?: () => void;
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Called when scrolling reaches the start within onStartReachedThreshold.
|
|
192
|
+
*/
|
|
193
|
+
onStartReached?: ((info: { distanceFromStart: number }) => void) | null | undefined;
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* How close to the start (in fractional units of visible length) to trigger onStartReached.
|
|
197
|
+
* @default 0.5
|
|
198
|
+
*/
|
|
199
|
+
onStartReachedThreshold?: number | null | undefined;
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Called when the viewability of items changes.
|
|
203
|
+
*/
|
|
204
|
+
onViewableItemsChanged?: OnViewableItemsChanged | undefined;
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Offset in pixels for the refresh indicator.
|
|
208
|
+
* @default 0
|
|
209
|
+
*/
|
|
210
|
+
progressViewOffset?: number;
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* If true, recycles item views for better performance.
|
|
214
|
+
* @default false
|
|
215
|
+
*/
|
|
216
|
+
recycleItems?: boolean;
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Ref to the underlying ScrollView component.
|
|
220
|
+
*/
|
|
221
|
+
refScrollView?: React.Ref<ScrollView>;
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* If true, shows a refresh indicator.
|
|
225
|
+
* @default false
|
|
226
|
+
*/
|
|
227
|
+
refreshing?: boolean;
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Function or React component to render each item in the list.
|
|
231
|
+
* Can be either:
|
|
232
|
+
* - A function: (props: LegendListRenderItemProps<ItemT>) => ReactNode
|
|
233
|
+
* - A React component: React.ComponentType<LegendListRenderItemProps<ItemT>>
|
|
234
|
+
* @required
|
|
235
|
+
*/
|
|
236
|
+
renderItem?:
|
|
237
|
+
| ((props: LegendListRenderItemProps<ItemT>) => ReactNode)
|
|
238
|
+
| React.ComponentType<LegendListRenderItemProps<ItemT>>;
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Render custom ScrollView component.
|
|
242
|
+
* @default (props) => <ScrollView {...props} />
|
|
243
|
+
*/
|
|
244
|
+
renderScrollComponent?: (props: ScrollViewProps) => React.ReactElement<ScrollViewProps>;
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* This will log a suggested estimatedItemSize.
|
|
248
|
+
* @required
|
|
249
|
+
* @default false
|
|
250
|
+
*/
|
|
251
|
+
suggestEstimatedItemSize?: boolean;
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Configuration for determining item viewability.
|
|
255
|
+
*/
|
|
256
|
+
viewabilityConfig?: ViewabilityConfig;
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Pairs of viewability configs and their callbacks for tracking visibility.
|
|
260
|
+
*/
|
|
261
|
+
viewabilityConfigCallbackPairs?: ViewabilityConfigCallbackPairs | undefined;
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* If true, delays rendering until initial layout is complete.
|
|
265
|
+
* @default false
|
|
266
|
+
*/
|
|
267
|
+
waitForInitialLayout?: boolean;
|
|
268
|
+
|
|
269
|
+
onLoad?: (info: { elapsedTimeInMs: number }) => void;
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
export interface MaintainScrollAtEndOptions {
|
|
273
|
+
onLayout?: boolean;
|
|
274
|
+
onItemLayout?: boolean;
|
|
275
|
+
onDataChange?: boolean;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
export interface ColumnWrapperStyle {
|
|
279
|
+
rowGap?: number;
|
|
280
|
+
gap?: number;
|
|
281
|
+
columnGap?: number;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
export type LegendListProps<ItemT> = LegendListPropsBase<
|
|
285
|
+
ItemT,
|
|
286
|
+
Omit<ComponentProps<typeof ScrollView>, "scrollEventThrottle">
|
|
287
|
+
>;
|
|
288
|
+
|
|
289
|
+
export interface InternalState {
|
|
290
|
+
positions: Map<string, number>;
|
|
291
|
+
columns: Map<string, number>;
|
|
292
|
+
sizes: Map<string, number>;
|
|
293
|
+
sizesKnown: Map<string, number>;
|
|
294
|
+
containerItemKeys: Set<string>;
|
|
295
|
+
pendingAdjust: number;
|
|
296
|
+
isStartReached: boolean;
|
|
297
|
+
isEndReached: boolean;
|
|
298
|
+
isAtEnd: boolean;
|
|
299
|
+
isAtStart: boolean;
|
|
300
|
+
hasScrolled?: boolean;
|
|
301
|
+
scrollLength: number;
|
|
302
|
+
startBuffered: number;
|
|
303
|
+
startBufferedId?: string;
|
|
304
|
+
startNoBuffer: number;
|
|
305
|
+
endBuffered: number;
|
|
306
|
+
endNoBuffer: number;
|
|
307
|
+
firstFullyOnScreenIndex: number;
|
|
308
|
+
idsInView: string[];
|
|
309
|
+
scrollPending: number;
|
|
310
|
+
scroll: number;
|
|
311
|
+
scrollTime: number;
|
|
312
|
+
scrollPrev: number;
|
|
313
|
+
scrollPrevTime: number;
|
|
314
|
+
scrollAdjustHandler: ScrollAdjustHandler;
|
|
315
|
+
maintainingScrollAtEnd?: boolean;
|
|
316
|
+
totalSize: number;
|
|
317
|
+
otherAxisSize?: number;
|
|
318
|
+
timeouts: Set<number>;
|
|
319
|
+
timeoutSizeMessage: any;
|
|
320
|
+
nativeMarginTop: number;
|
|
321
|
+
indexByKey: Map<string, number>;
|
|
322
|
+
idCache: Map<number, string>;
|
|
323
|
+
viewabilityConfigCallbackPairs: ViewabilityConfigCallbackPairs | undefined;
|
|
324
|
+
scrollHistory: Array<{ scroll: number; time: number }>;
|
|
325
|
+
startReachedBlockedByTimer: boolean;
|
|
326
|
+
endReachedBlockedByTimer: boolean;
|
|
327
|
+
scrollForNextCalculateItemsInView: { top: number; bottom: number } | undefined;
|
|
328
|
+
enableScrollForNextCalculateItemsInView: boolean;
|
|
329
|
+
minIndexSizeChanged: number | undefined;
|
|
330
|
+
queuedInitialLayout?: boolean | undefined;
|
|
331
|
+
queuedCalculateItemsInView: number | undefined;
|
|
332
|
+
lastBatchingAction: number;
|
|
333
|
+
ignoreScrollFromMVCP?: { lt?: number; gt?: number };
|
|
334
|
+
ignoreScrollFromMVCPTimeout?: any;
|
|
335
|
+
scrollingTo?:
|
|
336
|
+
| { offset: number; index?: number; viewOffset?: number; viewPosition?: number; animated?: boolean }
|
|
337
|
+
| undefined;
|
|
338
|
+
needsOtherAxisSize?: boolean;
|
|
339
|
+
averageSizes: Record<
|
|
340
|
+
string,
|
|
341
|
+
{
|
|
342
|
+
num: number;
|
|
343
|
+
avg: number;
|
|
344
|
+
}
|
|
345
|
+
>;
|
|
346
|
+
refScroller: React.RefObject<ScrollView>;
|
|
347
|
+
loadStartTime: number;
|
|
348
|
+
initialScroll: ScrollIndexWithOffsetPosition | undefined;
|
|
349
|
+
lastLayout: LayoutRectangle | undefined;
|
|
350
|
+
props: {
|
|
351
|
+
alignItemsAtEnd: boolean;
|
|
352
|
+
data: readonly any[];
|
|
353
|
+
estimatedItemSize: number | undefined;
|
|
354
|
+
getEstimatedItemSize: ((index: number, item: any) => number) | undefined;
|
|
355
|
+
horizontal: boolean;
|
|
356
|
+
keyExtractor: ((item: any, index: number) => string) | undefined;
|
|
357
|
+
maintainScrollAtEnd: boolean | MaintainScrollAtEndOptions;
|
|
358
|
+
maintainScrollAtEndThreshold: number | undefined;
|
|
359
|
+
maintainVisibleContentPosition: boolean;
|
|
360
|
+
onEndReached: (((info: { distanceFromEnd: number }) => void) | null | undefined) | undefined;
|
|
361
|
+
onEndReachedThreshold: number | null | undefined;
|
|
362
|
+
onItemSizeChanged:
|
|
363
|
+
| ((info: {
|
|
364
|
+
size: number;
|
|
365
|
+
previous: number;
|
|
366
|
+
index: number;
|
|
367
|
+
itemKey: string;
|
|
368
|
+
itemData: any;
|
|
369
|
+
}) => void)
|
|
370
|
+
| undefined;
|
|
371
|
+
onLoad: ((info: { elapsedTimeInMs: number }) => void) | undefined;
|
|
372
|
+
onScroll: ((event: NativeSyntheticEvent<NativeScrollEvent>) => void) | undefined;
|
|
373
|
+
onStartReached: (((info: { distanceFromStart: number }) => void) | null | undefined) | undefined;
|
|
374
|
+
onStartReachedThreshold: number | null | undefined;
|
|
375
|
+
suggestEstimatedItemSize: boolean;
|
|
376
|
+
stylePaddingBottom: number | undefined;
|
|
377
|
+
renderItem:
|
|
378
|
+
| ((props: LegendListRenderItemProps<any>) => ReactNode)
|
|
379
|
+
| React.ComponentType<LegendListRenderItemProps<any>>;
|
|
380
|
+
initialScroll: { index: number; viewOffset?: number; viewPosition?: number } | undefined;
|
|
381
|
+
scrollBuffer: number;
|
|
382
|
+
viewabilityConfigCallbackPairs: ViewabilityConfigCallbackPairs | undefined;
|
|
383
|
+
numColumns: number;
|
|
384
|
+
initialContainerPoolRatio: number;
|
|
385
|
+
stylePaddingTop: number | undefined;
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
export interface ViewableRange<T> {
|
|
390
|
+
startBuffered: number;
|
|
391
|
+
start: number;
|
|
392
|
+
endBuffered: number;
|
|
393
|
+
end: number;
|
|
394
|
+
items: T[];
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
export interface LegendListRenderItemProps<ItemT> {
|
|
398
|
+
item: ItemT;
|
|
399
|
+
index: number;
|
|
400
|
+
extraData: any;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
export type ScrollState = {
|
|
404
|
+
contentLength: number;
|
|
405
|
+
end: number;
|
|
406
|
+
endBuffered: number;
|
|
407
|
+
isAtEnd: boolean;
|
|
408
|
+
isAtStart: boolean;
|
|
409
|
+
scroll: number;
|
|
410
|
+
scrollLength: number;
|
|
411
|
+
start: number;
|
|
412
|
+
startBuffered: number;
|
|
413
|
+
sizes: Map<string, number>;
|
|
414
|
+
sizeAtIndex: (index: number) => number;
|
|
415
|
+
};
|
|
416
|
+
|
|
417
|
+
export type LegendListRef = {
|
|
418
|
+
/**
|
|
419
|
+
* Displays the scroll indicators momentarily.
|
|
420
|
+
*/
|
|
421
|
+
flashScrollIndicators(): void;
|
|
422
|
+
|
|
423
|
+
/**
|
|
424
|
+
* Returns the native ScrollView component reference.
|
|
425
|
+
*/
|
|
426
|
+
getNativeScrollRef(): React.ElementRef<typeof ScrollViewComponent>;
|
|
427
|
+
|
|
428
|
+
/**
|
|
429
|
+
* Returns the scroll responder instance for handling scroll events.
|
|
430
|
+
*/
|
|
431
|
+
getScrollableNode(): any;
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* Returns the ScrollResponderMixin for advanced scroll handling.
|
|
435
|
+
*/
|
|
436
|
+
getScrollResponder(): ScrollResponderMixin;
|
|
437
|
+
|
|
438
|
+
/**
|
|
439
|
+
* Returns the internal state of the scroll virtualization.
|
|
440
|
+
*/
|
|
441
|
+
getState(): ScrollState;
|
|
442
|
+
|
|
443
|
+
/**
|
|
444
|
+
* Scrolls a specific index into view.
|
|
445
|
+
* @param params - Parameters for scrolling.
|
|
446
|
+
* @param params.animated - If true, animates the scroll. Default: true.
|
|
447
|
+
* @param params.index - The index to scroll to.
|
|
448
|
+
*/
|
|
449
|
+
scrollIndexIntoView(params: {
|
|
450
|
+
animated?: boolean | undefined;
|
|
451
|
+
index: number;
|
|
452
|
+
}): void;
|
|
453
|
+
|
|
454
|
+
/**
|
|
455
|
+
* Scrolls a specific index into view.
|
|
456
|
+
* @param params - Parameters for scrolling.
|
|
457
|
+
* @param params.animated - If true, animates the scroll. Default: true.
|
|
458
|
+
* @param params.item - The item to scroll to.
|
|
459
|
+
*/
|
|
460
|
+
scrollItemIntoView(params: {
|
|
461
|
+
animated?: boolean | undefined;
|
|
462
|
+
item: any;
|
|
463
|
+
}): void;
|
|
464
|
+
|
|
465
|
+
/**
|
|
466
|
+
* Scrolls to the end of the list.
|
|
467
|
+
* @param options - Options for scrolling.
|
|
468
|
+
* @param options.animated - If true, animates the scroll. Default: true.
|
|
469
|
+
*/
|
|
470
|
+
scrollToEnd(options?: { animated?: boolean | undefined }): void;
|
|
471
|
+
|
|
472
|
+
/**
|
|
473
|
+
* Scrolls to a specific index in the list.
|
|
474
|
+
* @param params - Parameters for scrolling.
|
|
475
|
+
* @param params.animated - If true, animates the scroll. Default: true.
|
|
476
|
+
* @param params.index - The index to scroll to.
|
|
477
|
+
* @param params.viewOffset - Offset from the target position.
|
|
478
|
+
* @param params.viewPosition - Position of the item in the viewport (0 to 1).
|
|
479
|
+
*/
|
|
480
|
+
scrollToIndex(params: {
|
|
481
|
+
animated?: boolean | undefined;
|
|
482
|
+
index: number;
|
|
483
|
+
viewOffset?: number | undefined;
|
|
484
|
+
viewPosition?: number | undefined;
|
|
485
|
+
}): void;
|
|
486
|
+
|
|
487
|
+
/**
|
|
488
|
+
* Scrolls to a specific item in the list.
|
|
489
|
+
* @param params - Parameters for scrolling.
|
|
490
|
+
* @param params.animated - If true, animates the scroll. Default: true.
|
|
491
|
+
* @param params.item - The item to scroll to.
|
|
492
|
+
* @param params.viewOffset - Offset from the target position.
|
|
493
|
+
* @param params.viewPosition - Position of the item in the viewport (0 to 1).
|
|
494
|
+
*/
|
|
495
|
+
scrollToItem(params: {
|
|
496
|
+
animated?: boolean | undefined;
|
|
497
|
+
item: any;
|
|
498
|
+
viewOffset?: number | undefined;
|
|
499
|
+
viewPosition?: number | undefined;
|
|
500
|
+
}): void;
|
|
501
|
+
|
|
502
|
+
/**
|
|
503
|
+
* Scrolls to a specific offset in pixels.
|
|
504
|
+
* @param params - Parameters for scrolling.
|
|
505
|
+
* @param params.offset - The pixel offset to scroll to.
|
|
506
|
+
* @param params.animated - If true, animates the scroll. Default: true.
|
|
507
|
+
*/
|
|
508
|
+
scrollToOffset(params: { offset: number; animated?: boolean | undefined }): void;
|
|
509
|
+
|
|
510
|
+
/**
|
|
511
|
+
* Sets or adds to the offset of the visible content anchor.
|
|
512
|
+
* @param value - The offset to set or add.
|
|
513
|
+
* @param animated - If true, uses Animated to animate the change.
|
|
514
|
+
*/
|
|
515
|
+
setVisibleContentAnchorOffset(value: number | ((value: number) => number)): void;
|
|
516
|
+
};
|
|
517
|
+
|
|
518
|
+
export interface ViewToken<ItemT = any> {
|
|
519
|
+
item: ItemT;
|
|
520
|
+
key: string;
|
|
521
|
+
index: number;
|
|
522
|
+
isViewable: boolean;
|
|
523
|
+
containerId: number;
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
export interface ViewAmountToken<ItemT = any> extends ViewToken<ItemT> {
|
|
527
|
+
sizeVisible: number;
|
|
528
|
+
size: number;
|
|
529
|
+
percentVisible: number;
|
|
530
|
+
percentOfScroller: number;
|
|
531
|
+
scrollSize: number;
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
export interface ViewabilityConfigCallbackPair {
|
|
535
|
+
viewabilityConfig: ViewabilityConfig;
|
|
536
|
+
onViewableItemsChanged?: OnViewableItemsChanged;
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
export type ViewabilityConfigCallbackPairs = ViewabilityConfigCallbackPair[];
|
|
540
|
+
|
|
541
|
+
export type OnViewableItemsChanged =
|
|
542
|
+
| ((info: { viewableItems: Array<ViewToken>; changed: Array<ViewToken> }) => void)
|
|
543
|
+
| null;
|
|
544
|
+
|
|
545
|
+
export interface ViewabilityConfig {
|
|
546
|
+
/**
|
|
547
|
+
* A unique ID to identify this viewability config
|
|
548
|
+
*/
|
|
549
|
+
id?: string;
|
|
550
|
+
|
|
551
|
+
/**
|
|
552
|
+
* Minimum amount of time (in milliseconds) that an item must be physically viewable before the
|
|
553
|
+
* viewability callback will be fired. A high number means that scrolling through content without
|
|
554
|
+
* stopping will not mark the content as viewable.
|
|
555
|
+
*/
|
|
556
|
+
minimumViewTime?: number | undefined;
|
|
557
|
+
|
|
558
|
+
/**
|
|
559
|
+
* Percent of viewport that must be covered for a partially occluded item to count as
|
|
560
|
+
* "viewable", 0-100. Fully visible items are always considered viewable. A value of 0 means
|
|
561
|
+
* that a single pixel in the viewport makes the item viewable, and a value of 100 means that
|
|
562
|
+
* an item must be either entirely visible or cover the entire viewport to count as viewable.
|
|
563
|
+
*/
|
|
564
|
+
viewAreaCoveragePercentThreshold?: number | undefined;
|
|
565
|
+
|
|
566
|
+
/**
|
|
567
|
+
* Similar to `viewAreaCoveragePercentThreshold`, but considers the percent of the item that is visible,
|
|
568
|
+
* rather than the fraction of the viewable area it covers.
|
|
569
|
+
*/
|
|
570
|
+
itemVisiblePercentThreshold?: number | undefined;
|
|
571
|
+
|
|
572
|
+
/**
|
|
573
|
+
* Nothing is considered viewable until the user scrolls or `recordInteraction` is called after
|
|
574
|
+
* render.
|
|
575
|
+
*/
|
|
576
|
+
waitForInteraction?: boolean | undefined;
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
export type ViewabilityCallback = (viewToken: ViewToken) => void;
|
|
580
|
+
export type ViewabilityAmountCallback = (viewToken: ViewAmountToken) => void;
|
|
581
|
+
|
|
582
|
+
export interface LegendListRecyclingState<T> {
|
|
583
|
+
item: T;
|
|
584
|
+
prevItem: T | undefined;
|
|
585
|
+
index: number;
|
|
586
|
+
prevIndex: number | undefined;
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
// biome-ignore lint/complexity/noBannedTypes: This is correct
|
|
590
|
+
export type TypedForwardRef = <T, P = {}>(
|
|
591
|
+
render: (props: P, ref: React.Ref<T>) => React.ReactNode,
|
|
592
|
+
) => (props: P & React.RefAttributes<T>) => React.ReactNode;
|
|
593
|
+
|
|
594
|
+
export const typedForwardRef = forwardRef as TypedForwardRef;
|
|
595
|
+
|
|
596
|
+
export type TypedMemo = <T extends React.ComponentType<any>>(
|
|
597
|
+
Component: T,
|
|
598
|
+
propsAreEqual?: (prevProps: Readonly<ComponentProps<T>>, nextProps: Readonly<ComponentProps<T>>) => boolean,
|
|
599
|
+
) => T & { displayName?: string };
|
|
600
|
+
|
|
601
|
+
export const typedMemo = memo as TypedMemo;
|
|
602
|
+
|
|
603
|
+
export type ScrollIndexWithOffsetPosition = {
|
|
604
|
+
index: number;
|
|
605
|
+
viewOffset?: number;
|
|
606
|
+
viewPosition?: number;
|
|
607
|
+
};
|
|
608
|
+
|
|
609
|
+
export type GetRenderedItemResult<ItemT> = { index: number; item: ItemT; renderedItem: React.ReactNode };
|
|
610
|
+
export type GetRenderedItem = (key: string) => GetRenderedItemResult<any> | null;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { setPaddingTop } from "./setPaddingTop";
|
|
2
|
+
import { type StateContext, getContentSize } from "./state";
|
|
3
|
+
import type { InternalState } from "./types";
|
|
4
|
+
|
|
5
|
+
export function updateAlignItemsPaddingTop(ctx: StateContext, state: InternalState) {
|
|
6
|
+
const {
|
|
7
|
+
scrollLength,
|
|
8
|
+
props: { alignItemsAtEnd, data },
|
|
9
|
+
} = state;
|
|
10
|
+
if (alignItemsAtEnd) {
|
|
11
|
+
let alignItemsPaddingTop = 0;
|
|
12
|
+
if (data?.length > 0) {
|
|
13
|
+
const contentSize = getContentSize(ctx);
|
|
14
|
+
alignItemsPaddingTop = Math.max(0, Math.floor(scrollLength - contentSize));
|
|
15
|
+
}
|
|
16
|
+
setPaddingTop(ctx, { alignItemsPaddingTop });
|
|
17
|
+
}
|
|
18
|
+
}
|