@legendapp/list 2.0.0-next.1 → 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} +16 -10
- package/{index.d.ts → dist/index.d.ts} +16 -10
- package/{index.js → dist/index.js} +52 -32
- package/{index.mjs → dist/index.mjs} +52 -32
- 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/{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
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { ThemedText } from "@/components/ThemedText";
|
|
2
|
+
import { ThemedView } from "@/components/ThemedView";
|
|
3
|
+
import { LegendList } from "@legendapp/list";
|
|
4
|
+
import { useBottomTabBarHeight } from "@react-navigation/bottom-tabs";
|
|
5
|
+
import { Link, type LinkProps } from "expo-router";
|
|
6
|
+
import { useCallback } from "react";
|
|
7
|
+
import { type LayoutChangeEvent, Platform, Pressable, StyleSheet, View, useColorScheme } from "react-native";
|
|
8
|
+
import { SafeAreaView } from "react-native-safe-area-context";
|
|
9
|
+
|
|
10
|
+
// @ts-expect-error nativeFabricUIManager is not defined in the global object types
|
|
11
|
+
export const IsNewArchitecture = global.nativeFabricUIManager != null;
|
|
12
|
+
|
|
13
|
+
type ListElement = {
|
|
14
|
+
id: number;
|
|
15
|
+
title: string;
|
|
16
|
+
url: LinkProps["href"];
|
|
17
|
+
index: number;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const data: ListElement[] = [
|
|
21
|
+
{
|
|
22
|
+
title: "Bidirectional Infinite List",
|
|
23
|
+
url: "/bidirectional-infinite-list",
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
title: "Chat example",
|
|
27
|
+
url: "/chat-example",
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
title: "AI Chat",
|
|
31
|
+
url: "/ai-chat",
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
title: "Infinite chat",
|
|
35
|
+
url: "/chat-infinite",
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
title: "Countries List",
|
|
39
|
+
url: "/countries",
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
title: "Lazy List",
|
|
43
|
+
url: "/lazy-list",
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
title: "Accurate scrollToIndex",
|
|
47
|
+
url: "/accurate-scrollto",
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
title: "Accurate scrollToIndex 2",
|
|
51
|
+
url: "/accurate-scrollto-2",
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
title: "Columns",
|
|
55
|
+
url: "/columns",
|
|
56
|
+
},
|
|
57
|
+
|
|
58
|
+
{
|
|
59
|
+
title: "Cards Columns",
|
|
60
|
+
url: "/cards-columns",
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
title: "Chat keyboard",
|
|
64
|
+
url: "/chat-keyboard",
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
title: "Movies FlashList",
|
|
68
|
+
url: "/movies-flashlist",
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
title: "Initial scroll index precise navigation",
|
|
72
|
+
url: "/initial-scroll-index",
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
title: "Initial scroll index(free element height)",
|
|
76
|
+
url: "/initial-scroll-index-free-height",
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
title: "Initial Scroll Index keyed",
|
|
80
|
+
url: "/initial-scroll-index-keyed",
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
title: "Mutable elements",
|
|
84
|
+
url: "/mutable-cells",
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
title: "Extra data",
|
|
88
|
+
url: "/extra-data",
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
title: "Countries List(FlashList)",
|
|
92
|
+
url: "/countries-flashlist",
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
title: "Filter elements",
|
|
96
|
+
url: "/filter-elements",
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
title: "Video feed",
|
|
100
|
+
url: "/video-feed",
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
title: "Countries Reorder",
|
|
104
|
+
url: "/countries-reorder",
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
title: "Cards FlashList",
|
|
108
|
+
url: "/cards-flashlist",
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
title: "Cards no recycle",
|
|
112
|
+
url: "/cards-no-recycle",
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
title: "Cards FlatList",
|
|
116
|
+
url: "/cards-flatlist",
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
title: "Add to the end",
|
|
120
|
+
url: "/add-to-end",
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
title: "Chat resize outer",
|
|
124
|
+
url: "/chat-resize-outer",
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
title: "Accurate scrollToHuge",
|
|
128
|
+
url: "/accurate-scrollto-huge",
|
|
129
|
+
},
|
|
130
|
+
].map(
|
|
131
|
+
(v, i) =>
|
|
132
|
+
({
|
|
133
|
+
...v,
|
|
134
|
+
id: i + 1,
|
|
135
|
+
}) as ListElement,
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
const RightIcon = () => <ThemedText type="subtitle">›</ThemedText>;
|
|
139
|
+
|
|
140
|
+
const ListItem = ({ title, url, index }: ListElement) => {
|
|
141
|
+
const theme = useColorScheme() ?? "light";
|
|
142
|
+
|
|
143
|
+
return (
|
|
144
|
+
<Link href={url} asChild>
|
|
145
|
+
<Pressable>
|
|
146
|
+
<ThemedView
|
|
147
|
+
style={[
|
|
148
|
+
styles.item,
|
|
149
|
+
{ borderColor: theme === "light" ? "#ccc" : "#666" },
|
|
150
|
+
index === 0 && { borderTopWidth: 1 },
|
|
151
|
+
]}
|
|
152
|
+
>
|
|
153
|
+
<ThemedText>{title}</ThemedText>
|
|
154
|
+
<RightIcon />
|
|
155
|
+
</ThemedView>
|
|
156
|
+
</Pressable>
|
|
157
|
+
</Link>
|
|
158
|
+
);
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
const ListElements = () => {
|
|
162
|
+
const height = useBottomTabBarHeight();
|
|
163
|
+
const onLayout = useCallback((event: LayoutChangeEvent) => {
|
|
164
|
+
console.log("onlayout", event.nativeEvent.layout);
|
|
165
|
+
}, []);
|
|
166
|
+
return (
|
|
167
|
+
<SafeAreaView style={styles.container}>
|
|
168
|
+
<LegendList
|
|
169
|
+
estimatedItemSize={60}
|
|
170
|
+
data={data}
|
|
171
|
+
renderItem={({ item, index }) => <ListItem {...item} index={index} />}
|
|
172
|
+
keyExtractor={(item) => item.id.toString()}
|
|
173
|
+
onItemSizeChanged={(info) => {
|
|
174
|
+
console.log("item size changed", info);
|
|
175
|
+
}}
|
|
176
|
+
ListHeaderComponent={
|
|
177
|
+
<View style={{ paddingHorizontal: 16, paddingVertical: 8 }}>
|
|
178
|
+
<ThemedText style={{ fontWeight: "bold" }}>
|
|
179
|
+
{IsNewArchitecture ? "New" : "Old"} Architecture, {__DEV__ ? "DEV" : "PROD"}
|
|
180
|
+
</ThemedText>
|
|
181
|
+
</View>
|
|
182
|
+
}
|
|
183
|
+
ListFooterComponent={<View />}
|
|
184
|
+
ListFooterComponentStyle={{ height: Platform.OS === "ios" ? height : 0 }}
|
|
185
|
+
onLayout={onLayout}
|
|
186
|
+
/>
|
|
187
|
+
</SafeAreaView>
|
|
188
|
+
);
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
const styles = StyleSheet.create({
|
|
192
|
+
container: {
|
|
193
|
+
flex: 1,
|
|
194
|
+
},
|
|
195
|
+
item: {
|
|
196
|
+
padding: 16,
|
|
197
|
+
height: 60,
|
|
198
|
+
borderBottomWidth: 1,
|
|
199
|
+
width: "100%",
|
|
200
|
+
flexDirection: "row",
|
|
201
|
+
justifyContent: "space-between",
|
|
202
|
+
},
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
export default ListElements;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Link, Stack } from "expo-router";
|
|
2
|
+
import { StyleSheet } from "react-native";
|
|
3
|
+
|
|
4
|
+
import { ThemedText } from "@/components/ThemedText";
|
|
5
|
+
import { ThemedView } from "@/components/ThemedView";
|
|
6
|
+
|
|
7
|
+
export default function NotFoundScreen() {
|
|
8
|
+
return (
|
|
9
|
+
<>
|
|
10
|
+
<Stack.Screen options={{ title: "Oops!" }} />
|
|
11
|
+
<ThemedView style={styles.container}>
|
|
12
|
+
<ThemedText type="title">This screen doesn't exist.</ThemedText>
|
|
13
|
+
<Link href="/" style={styles.link}>
|
|
14
|
+
<ThemedText type="link">Go to home screen!</ThemedText>
|
|
15
|
+
</Link>
|
|
16
|
+
</ThemedView>
|
|
17
|
+
</>
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const styles = StyleSheet.create({
|
|
22
|
+
container: {
|
|
23
|
+
flex: 1,
|
|
24
|
+
alignItems: "center",
|
|
25
|
+
justifyContent: "center",
|
|
26
|
+
padding: 20,
|
|
27
|
+
},
|
|
28
|
+
link: {
|
|
29
|
+
marginTop: 15,
|
|
30
|
+
paddingVertical: 15,
|
|
31
|
+
},
|
|
32
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { DarkTheme, DefaultTheme, ThemeProvider } from "@react-navigation/native";
|
|
2
|
+
import { Stack } from "expo-router";
|
|
3
|
+
import { StatusBar } from "expo-status-bar";
|
|
4
|
+
import "react-native-reanimated";
|
|
5
|
+
import { useColorScheme } from "@/hooks/useColorScheme";
|
|
6
|
+
import { GestureHandlerRootView } from "react-native-gesture-handler";
|
|
7
|
+
import { ReanimatedLogLevel } from "react-native-reanimated";
|
|
8
|
+
import { configureReanimatedLogger } from "react-native-reanimated";
|
|
9
|
+
import { enableFreeze } from "react-native-screens";
|
|
10
|
+
|
|
11
|
+
// Prevent the splash screen from auto-hiding before asset loading is complete.
|
|
12
|
+
enableFreeze(); // freeze inactive tabs in the tabbar, to improve benchmarking accuracy
|
|
13
|
+
|
|
14
|
+
configureReanimatedLogger({
|
|
15
|
+
level: ReanimatedLogLevel.warn,
|
|
16
|
+
strict: false, // Reanimated runs in strict mode by default
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
export default function RootLayout() {
|
|
20
|
+
const colorScheme = useColorScheme();
|
|
21
|
+
console.log("starting in", __DEV__ ? "dev" : "prod");
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<GestureHandlerRootView style={{ flex: 1 }}>
|
|
25
|
+
<ThemeProvider value={colorScheme === "dark" ? DarkTheme : DefaultTheme}>
|
|
26
|
+
<Stack>
|
|
27
|
+
<Stack.Screen name="(tabs)" options={{ headerShown: false, title: "Examples" }} />
|
|
28
|
+
<Stack.Screen name="+not-found" />
|
|
29
|
+
</Stack>
|
|
30
|
+
<StatusBar style="auto" />
|
|
31
|
+
</ThemeProvider>
|
|
32
|
+
</GestureHandlerRootView>
|
|
33
|
+
);
|
|
34
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { type Item, renderItem } from "@/app/cards-renderItem";
|
|
2
|
+
import { DRAW_DISTANCE, ESTIMATED_ITEM_LENGTH } from "@/constants/constants";
|
|
3
|
+
import { LegendList, type LegendListRef } from "@legendapp/list";
|
|
4
|
+
import { useRef, useState } from "react";
|
|
5
|
+
import { Button, Platform, StatusBar, StyleSheet, Text, View } from "react-native";
|
|
6
|
+
import { TextInput } from "react-native-gesture-handler";
|
|
7
|
+
|
|
8
|
+
interface CardsProps {
|
|
9
|
+
numColumns?: number;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export default function AccurateScrollTo({ numColumns = 1 }: CardsProps) {
|
|
13
|
+
const listRef = useRef<LegendListRef>(null);
|
|
14
|
+
|
|
15
|
+
const [data, setData] = useState<Item[]>(
|
|
16
|
+
() =>
|
|
17
|
+
Array.from({ length: 1000 }, (_, i) => ({
|
|
18
|
+
id: i.toString(),
|
|
19
|
+
})) as any[],
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
const buttonText = useRef<string>("");
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
<View style={styles.container}>
|
|
26
|
+
<View style={styles.searchContainer}>
|
|
27
|
+
<TextInput
|
|
28
|
+
style={styles.searchInput}
|
|
29
|
+
placeholder="Select item to scroll to"
|
|
30
|
+
clearButtonMode="while-editing"
|
|
31
|
+
autoCapitalize="none"
|
|
32
|
+
autoCorrect={false}
|
|
33
|
+
onChangeText={(text) => {
|
|
34
|
+
buttonText.current = text;
|
|
35
|
+
}}
|
|
36
|
+
/>
|
|
37
|
+
<Button
|
|
38
|
+
title="Scroll to item"
|
|
39
|
+
onPress={() => {
|
|
40
|
+
const index = Number(buttonText.current) || 0;
|
|
41
|
+
console.log("scrolling to index", index);
|
|
42
|
+
if (index !== -1) {
|
|
43
|
+
listRef.current?.scrollToIndex({ index, animated: true });
|
|
44
|
+
}
|
|
45
|
+
}}
|
|
46
|
+
/>
|
|
47
|
+
<Button
|
|
48
|
+
title="Scroll to end"
|
|
49
|
+
onPress={() => {
|
|
50
|
+
console.log("scrolling to end");
|
|
51
|
+
listRef.current?.scrollToEnd({ animated: true });
|
|
52
|
+
}}
|
|
53
|
+
/>
|
|
54
|
+
</View>
|
|
55
|
+
<LegendList
|
|
56
|
+
ref={listRef}
|
|
57
|
+
contentContainerStyle={styles.listContainer}
|
|
58
|
+
data={data}
|
|
59
|
+
renderItem={renderItem}
|
|
60
|
+
keyExtractor={(item) => `id${item.id}`}
|
|
61
|
+
estimatedItemSize={ESTIMATED_ITEM_LENGTH + 120}
|
|
62
|
+
drawDistance={DRAW_DISTANCE}
|
|
63
|
+
maintainVisibleContentPosition
|
|
64
|
+
recycleItems={true}
|
|
65
|
+
numColumns={numColumns}
|
|
66
|
+
ListEmptyComponent={
|
|
67
|
+
<View style={styles.listEmpty}>
|
|
68
|
+
<Text style={{ color: "white" }}>Empty</Text>
|
|
69
|
+
</View>
|
|
70
|
+
}
|
|
71
|
+
/>
|
|
72
|
+
</View>
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const styles = StyleSheet.create({
|
|
77
|
+
listHeader: {
|
|
78
|
+
alignSelf: "center",
|
|
79
|
+
height: 100,
|
|
80
|
+
width: 100,
|
|
81
|
+
backgroundColor: "#456AAA",
|
|
82
|
+
borderRadius: 12,
|
|
83
|
+
marginHorizontal: 8,
|
|
84
|
+
marginVertical: 8,
|
|
85
|
+
},
|
|
86
|
+
listEmpty: {
|
|
87
|
+
flex: 1,
|
|
88
|
+
justifyContent: "center",
|
|
89
|
+
alignItems: "center",
|
|
90
|
+
backgroundColor: "#6789AB",
|
|
91
|
+
paddingVertical: 16,
|
|
92
|
+
},
|
|
93
|
+
outerContainer: {
|
|
94
|
+
backgroundColor: "#456",
|
|
95
|
+
bottom: Platform.OS === "ios" ? 82 : 0,
|
|
96
|
+
},
|
|
97
|
+
scrollContainer: {},
|
|
98
|
+
listContainer: {
|
|
99
|
+
width: 400,
|
|
100
|
+
maxWidth: "100%",
|
|
101
|
+
marginHorizontal: "auto",
|
|
102
|
+
paddingBottom: 200,
|
|
103
|
+
},
|
|
104
|
+
searchContainer: {
|
|
105
|
+
padding: 8,
|
|
106
|
+
backgroundColor: "#fff",
|
|
107
|
+
borderBottomWidth: 1,
|
|
108
|
+
borderBottomColor: "#e0e0e0",
|
|
109
|
+
flexDirection: "row",
|
|
110
|
+
justifyContent: "space-between",
|
|
111
|
+
},
|
|
112
|
+
searchInput: {
|
|
113
|
+
height: 40,
|
|
114
|
+
backgroundColor: "#f5f5f5",
|
|
115
|
+
borderRadius: 8,
|
|
116
|
+
paddingHorizontal: 12,
|
|
117
|
+
fontSize: 16,
|
|
118
|
+
flexGrow: 1,
|
|
119
|
+
},
|
|
120
|
+
container: {
|
|
121
|
+
flex: 1,
|
|
122
|
+
marginTop: StatusBar.currentHeight || 0,
|
|
123
|
+
backgroundColor: "#f5f5f5",
|
|
124
|
+
},
|
|
125
|
+
});
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { LegendList, type LegendListRef, type LegendListRenderItemProps } from "@legendapp/list";
|
|
2
|
+
import { useEffect, useRef } from "react";
|
|
3
|
+
import { Text, View } from "react-native";
|
|
4
|
+
const App = () => {
|
|
5
|
+
const dummyData = Array.from({ length: 100 }, (_, index) => ({
|
|
6
|
+
id: index,
|
|
7
|
+
name: `Item ${index}`,
|
|
8
|
+
value: Math.floor(Math.random() * 1000),
|
|
9
|
+
isActive: Math.random() > 0.5,
|
|
10
|
+
height: Math.floor(Math.random() * 200) + 50, // Random height between 50 and 250
|
|
11
|
+
createdAt: new Date(Date.now() - Math.floor(Math.random() * 10000000000)).toISOString(),
|
|
12
|
+
}));
|
|
13
|
+
const renderItem = (props: LegendListRenderItemProps<any>) => {
|
|
14
|
+
return (
|
|
15
|
+
<View
|
|
16
|
+
style={{
|
|
17
|
+
padding: 10,
|
|
18
|
+
backgroundColor: "#fff",
|
|
19
|
+
borderColor: "#ddd",
|
|
20
|
+
height: props.item.height,
|
|
21
|
+
borderWidth: 1,
|
|
22
|
+
borderRadius: 12,
|
|
23
|
+
}}
|
|
24
|
+
>
|
|
25
|
+
<Text style={{ fontWeight: "bold" }}>{props.item.name}</Text>
|
|
26
|
+
</View>
|
|
27
|
+
);
|
|
28
|
+
};
|
|
29
|
+
const listRef = useRef<LegendListRef>(null);
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
setTimeout(() => {
|
|
32
|
+
listRef.current?.scrollToIndex({
|
|
33
|
+
index: 80,
|
|
34
|
+
animated: true,
|
|
35
|
+
});
|
|
36
|
+
}, 1000);
|
|
37
|
+
}, []);
|
|
38
|
+
return (
|
|
39
|
+
<View style={{ flex: 1, padding: 20, backgroundColor: "gray" }}>
|
|
40
|
+
<LegendList
|
|
41
|
+
ref={listRef}
|
|
42
|
+
data={dummyData}
|
|
43
|
+
maintainVisibleContentPosition
|
|
44
|
+
keyExtractor={(item) => `id${item.id}`}
|
|
45
|
+
renderItem={renderItem}
|
|
46
|
+
estimatedItemSize={25}
|
|
47
|
+
recycleItems
|
|
48
|
+
/>
|
|
49
|
+
</View>
|
|
50
|
+
);
|
|
51
|
+
};
|
|
52
|
+
export default App;
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { type Item, renderItem } from "@/app/cards-renderItem";
|
|
2
|
+
import { DRAW_DISTANCE, ESTIMATED_ITEM_LENGTH } from "@/constants/constants";
|
|
3
|
+
import { LegendList, type LegendListRef } from "@legendapp/list";
|
|
4
|
+
import { useRef, useState } from "react";
|
|
5
|
+
import { Button, Platform, StatusBar, StyleSheet, Text, View } from "react-native";
|
|
6
|
+
import { TextInput } from "react-native-gesture-handler";
|
|
7
|
+
|
|
8
|
+
interface CardsProps {
|
|
9
|
+
numColumns?: number;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export default function AccurateScrollToHuge({ numColumns = 1 }: CardsProps) {
|
|
13
|
+
const listRef = useRef<LegendListRef>(null);
|
|
14
|
+
|
|
15
|
+
const [data, setData] = useState<Item[]>(
|
|
16
|
+
() =>
|
|
17
|
+
Array.from({ length: 1000 }, (_, i) => ({
|
|
18
|
+
id: i.toString(),
|
|
19
|
+
})) as any[],
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
const buttonText = useRef<string>("");
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
<View style={styles.container}>
|
|
26
|
+
<View style={styles.searchContainer}>
|
|
27
|
+
<TextInput
|
|
28
|
+
style={styles.searchInput}
|
|
29
|
+
placeholder="Select item to scroll to"
|
|
30
|
+
clearButtonMode="while-editing"
|
|
31
|
+
autoCapitalize="none"
|
|
32
|
+
autoCorrect={false}
|
|
33
|
+
onChangeText={(text) => {
|
|
34
|
+
buttonText.current = text;
|
|
35
|
+
}}
|
|
36
|
+
/>
|
|
37
|
+
<Button
|
|
38
|
+
title="Scroll to item"
|
|
39
|
+
onPress={() => {
|
|
40
|
+
const index = Number(buttonText.current) || 0;
|
|
41
|
+
console.log("scrolling to index", index);
|
|
42
|
+
if (index !== -1) {
|
|
43
|
+
listRef.current?.scrollToIndex({ index, animated: true });
|
|
44
|
+
}
|
|
45
|
+
}}
|
|
46
|
+
/>
|
|
47
|
+
<Button
|
|
48
|
+
title="Scroll to end"
|
|
49
|
+
onPress={() => {
|
|
50
|
+
console.log("scrolling to end");
|
|
51
|
+
listRef.current?.scrollToEnd({ animated: true });
|
|
52
|
+
}}
|
|
53
|
+
/>
|
|
54
|
+
</View>
|
|
55
|
+
<LegendList
|
|
56
|
+
ref={listRef}
|
|
57
|
+
contentContainerStyle={styles.listContainer}
|
|
58
|
+
data={data}
|
|
59
|
+
// @ts-ignore
|
|
60
|
+
renderItem={({ item, index }) =>
|
|
61
|
+
// @ts-ignore
|
|
62
|
+
renderItem({ item, index, numSentences: (indexForData) => ((indexForData * 7919) % 40) + 40 })
|
|
63
|
+
}
|
|
64
|
+
keyExtractor={(item) => `id${item.id}`}
|
|
65
|
+
estimatedItemSize={ESTIMATED_ITEM_LENGTH + 120}
|
|
66
|
+
drawDistance={DRAW_DISTANCE}
|
|
67
|
+
maintainVisibleContentPosition
|
|
68
|
+
recycleItems={true}
|
|
69
|
+
numColumns={numColumns}
|
|
70
|
+
ListEmptyComponent={
|
|
71
|
+
<View style={styles.listEmpty}>
|
|
72
|
+
<Text style={{ color: "white" }}>Empty</Text>
|
|
73
|
+
</View>
|
|
74
|
+
}
|
|
75
|
+
/>
|
|
76
|
+
</View>
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const styles = StyleSheet.create({
|
|
81
|
+
listHeader: {
|
|
82
|
+
alignSelf: "center",
|
|
83
|
+
height: 100,
|
|
84
|
+
width: 100,
|
|
85
|
+
backgroundColor: "#456AAA",
|
|
86
|
+
borderRadius: 12,
|
|
87
|
+
marginHorizontal: 8,
|
|
88
|
+
marginVertical: 8,
|
|
89
|
+
},
|
|
90
|
+
listEmpty: {
|
|
91
|
+
flex: 1,
|
|
92
|
+
justifyContent: "center",
|
|
93
|
+
alignItems: "center",
|
|
94
|
+
backgroundColor: "#6789AB",
|
|
95
|
+
paddingVertical: 16,
|
|
96
|
+
},
|
|
97
|
+
outerContainer: {
|
|
98
|
+
backgroundColor: "#456",
|
|
99
|
+
bottom: Platform.OS === "ios" ? 82 : 0,
|
|
100
|
+
},
|
|
101
|
+
scrollContainer: {},
|
|
102
|
+
listContainer: {
|
|
103
|
+
width: 400,
|
|
104
|
+
maxWidth: "100%",
|
|
105
|
+
marginHorizontal: "auto",
|
|
106
|
+
},
|
|
107
|
+
searchContainer: {
|
|
108
|
+
padding: 8,
|
|
109
|
+
backgroundColor: "#fff",
|
|
110
|
+
borderBottomWidth: 1,
|
|
111
|
+
borderBottomColor: "#e0e0e0",
|
|
112
|
+
flexDirection: "row",
|
|
113
|
+
justifyContent: "space-between",
|
|
114
|
+
},
|
|
115
|
+
searchInput: {
|
|
116
|
+
height: 40,
|
|
117
|
+
backgroundColor: "#f5f5f5",
|
|
118
|
+
borderRadius: 8,
|
|
119
|
+
paddingHorizontal: 12,
|
|
120
|
+
fontSize: 16,
|
|
121
|
+
flexGrow: 1,
|
|
122
|
+
},
|
|
123
|
+
container: {
|
|
124
|
+
flex: 1,
|
|
125
|
+
marginTop: StatusBar.currentHeight || 0,
|
|
126
|
+
backgroundColor: "#f5f5f5",
|
|
127
|
+
},
|
|
128
|
+
});
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { LegendList } from "@legendapp/list";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import { Button, SafeAreaView, StyleSheet, Text, View } from "react-native";
|
|
4
|
+
|
|
5
|
+
const ListComponent = () => {
|
|
6
|
+
const [items, setItems] = useState<{ id: string; title: string }[]>([]);
|
|
7
|
+
const [counter, setCounter] = useState(0);
|
|
8
|
+
|
|
9
|
+
const addSixtyItems = () => {
|
|
10
|
+
const newItems = [];
|
|
11
|
+
const startIndex = counter;
|
|
12
|
+
|
|
13
|
+
for (let i = 0; i < 60; i++) {
|
|
14
|
+
newItems.push({
|
|
15
|
+
id: `item-${startIndex + i}`,
|
|
16
|
+
|
|
17
|
+
title: `Item ${startIndex + i}`,
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
setItems([...items, ...newItems]);
|
|
22
|
+
setCounter((prev) => prev + 60);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const renderItem = ({ item }: { item: { id: string; title: string } }) => (
|
|
26
|
+
<View style={styles.itemContainer}>
|
|
27
|
+
<Text style={styles.itemText}>{item.title}</Text>
|
|
28
|
+
</View>
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<SafeAreaView style={styles.safeArea}>
|
|
33
|
+
<View style={styles.container}>
|
|
34
|
+
<Button title="Add 60 Items" onPress={addSixtyItems} color="#4285F4" />
|
|
35
|
+
|
|
36
|
+
<LegendList
|
|
37
|
+
data={items}
|
|
38
|
+
renderItem={renderItem}
|
|
39
|
+
keyExtractor={(item) => item.id}
|
|
40
|
+
style={styles.list}
|
|
41
|
+
contentContainerStyle={styles.listContent}
|
|
42
|
+
maintainScrollAtEnd
|
|
43
|
+
/>
|
|
44
|
+
</View>
|
|
45
|
+
</SafeAreaView>
|
|
46
|
+
);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const styles = StyleSheet.create({
|
|
50
|
+
safeArea: {
|
|
51
|
+
flex: 1,
|
|
52
|
+
backgroundColor: "#f5f5f5",
|
|
53
|
+
},
|
|
54
|
+
container: {
|
|
55
|
+
flex: 1,
|
|
56
|
+
padding: 16,
|
|
57
|
+
backgroundColor: "#f5f5f5",
|
|
58
|
+
},
|
|
59
|
+
list: {
|
|
60
|
+
flex: 1,
|
|
61
|
+
marginTop: 16,
|
|
62
|
+
},
|
|
63
|
+
listContent: {
|
|
64
|
+
paddingBottom: 16,
|
|
65
|
+
},
|
|
66
|
+
itemContainer: {
|
|
67
|
+
backgroundColor: "white",
|
|
68
|
+
padding: 16,
|
|
69
|
+
marginVertical: 8,
|
|
70
|
+
borderRadius: 8,
|
|
71
|
+
shadowColor: "#000",
|
|
72
|
+
shadowOffset: { width: 0, height: 1 },
|
|
73
|
+
shadowOpacity: 0.2,
|
|
74
|
+
shadowRadius: 1,
|
|
75
|
+
elevation: 2,
|
|
76
|
+
},
|
|
77
|
+
itemText: {
|
|
78
|
+
fontSize: 16,
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
export default ListComponent;
|