@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.
Files changed (260) hide show
  1. package/.claude/settings.local.json +8 -0
  2. package/.cursor/rules/changelog.mdc +60 -0
  3. package/.github/FUNDING.yml +15 -0
  4. package/.gitignore +5 -0
  5. package/.prettierrc.json +5 -0
  6. package/.vscode/settings.json +14 -0
  7. package/CLAUDE.md +126 -0
  8. package/biome.json +46 -0
  9. package/bun.lock +1289 -0
  10. package/bunfig.toml +2 -0
  11. package/dist/CHANGELOG.md +119 -0
  12. package/dist/LICENSE +21 -0
  13. package/dist/README.md +139 -0
  14. package/{animated.d.mts → dist/animated.d.mts} +1 -1
  15. package/{animated.d.ts → dist/animated.d.ts} +1 -1
  16. package/{index.d.mts → dist/index.d.mts} +16 -10
  17. package/{index.d.ts → dist/index.d.ts} +16 -10
  18. package/{index.js → dist/index.js} +52 -32
  19. package/{index.mjs → dist/index.mjs} +52 -32
  20. package/{keyboard-controller.d.mts → dist/keyboard-controller.d.mts} +4 -4
  21. package/{keyboard-controller.d.ts → dist/keyboard-controller.d.ts} +4 -4
  22. package/dist/package.json +35 -0
  23. package/example/README.md +40 -0
  24. package/example/api/data/genres.json +23 -0
  25. package/example/api/data/playlist/10402-10749.json +1 -0
  26. package/example/api/data/playlist/10402-10770.json +1 -0
  27. package/example/api/data/playlist/10402-37.json +1 -0
  28. package/example/api/data/playlist/10749-10752.json +1 -0
  29. package/example/api/data/playlist/10749-10770.json +1 -0
  30. package/example/api/data/playlist/10749-37.json +1 -0
  31. package/example/api/data/playlist/10749-878.json +1 -0
  32. package/example/api/data/playlist/10751-10402.json +1 -0
  33. package/example/api/data/playlist/10751-10752.json +1 -0
  34. package/example/api/data/playlist/10751-37.json +1 -0
  35. package/example/api/data/playlist/10751-53.json +1 -0
  36. package/example/api/data/playlist/10751-878.json +1 -0
  37. package/example/api/data/playlist/10751-9648.json +1 -0
  38. package/example/api/data/playlist/10752-37.json +1 -0
  39. package/example/api/data/playlist/12-10402.json +1 -0
  40. package/example/api/data/playlist/12-10749.json +1 -0
  41. package/example/api/data/playlist/12-18.json +1 -0
  42. package/example/api/data/playlist/12-27.json +1 -0
  43. package/example/api/data/playlist/12-35.json +1 -0
  44. package/example/api/data/playlist/14-36.json +1 -0
  45. package/example/api/data/playlist/14-878.json +1 -0
  46. package/example/api/data/playlist/16-10751.json +1 -0
  47. package/example/api/data/playlist/16-10770.json +1 -0
  48. package/example/api/data/playlist/16-35.json +1 -0
  49. package/example/api/data/playlist/16-36.json +1 -0
  50. package/example/api/data/playlist/16-53.json +1 -0
  51. package/example/api/data/playlist/18-10751.json +1 -0
  52. package/example/api/data/playlist/18-10752.json +1 -0
  53. package/example/api/data/playlist/18-37.json +1 -0
  54. package/example/api/data/playlist/18-53.json +1 -0
  55. package/example/api/data/playlist/18-878.json +1 -0
  56. package/example/api/data/playlist/27-10749.json +1 -0
  57. package/example/api/data/playlist/27-10770.json +1 -0
  58. package/example/api/data/playlist/28-10749.json +1 -0
  59. package/example/api/data/playlist/28-10751.json +1 -0
  60. package/example/api/data/playlist/28-10770.json +1 -0
  61. package/example/api/data/playlist/28-16.json +1 -0
  62. package/example/api/data/playlist/28-18.json +1 -0
  63. package/example/api/data/playlist/28-36.json +1 -0
  64. package/example/api/data/playlist/28-37.json +1 -0
  65. package/example/api/data/playlist/28-53.json +1 -0
  66. package/example/api/data/playlist/28-80.json +1 -0
  67. package/example/api/data/playlist/28-99.json +1 -0
  68. package/example/api/data/playlist/35-10749.json +1 -0
  69. package/example/api/data/playlist/35-10751.json +1 -0
  70. package/example/api/data/playlist/35-10752.json +1 -0
  71. package/example/api/data/playlist/35-27.json +1 -0
  72. package/example/api/data/playlist/35-36.json +1 -0
  73. package/example/api/data/playlist/35-53.json +1 -0
  74. package/example/api/data/playlist/35-80.json +1 -0
  75. package/example/api/data/playlist/36-37.json +1 -0
  76. package/example/api/data/playlist/36-878.json +1 -0
  77. package/example/api/data/playlist/36-9648.json +1 -0
  78. package/example/api/data/playlist/53-10752.json +1 -0
  79. package/example/api/data/playlist/80-10770.json +1 -0
  80. package/example/api/data/playlist/80-14.json +1 -0
  81. package/example/api/data/playlist/80-18.json +1 -0
  82. package/example/api/data/playlist/80-37.json +1 -0
  83. package/example/api/data/playlist/878-37.json +1 -0
  84. package/example/api/data/playlist/9648-10770.json +1 -0
  85. package/example/api/data/playlist/9648-37.json +1 -0
  86. package/example/api/data/playlist/9648-53.json +1 -0
  87. package/example/api/data/playlist/9648-878.json +1 -0
  88. package/example/api/data/playlist/99-10749.json +1 -0
  89. package/example/api/data/playlist/99-14.json +1 -0
  90. package/example/api/data/playlist/99-18.json +1 -0
  91. package/example/api/data/playlist/99-27.json +1 -0
  92. package/example/api/data/playlist/99-53.json +1 -0
  93. package/example/api/data/playlist/99-9648.json +1 -0
  94. package/example/api/data/playlist/index.ts +73 -0
  95. package/example/api/data/rows.json +1 -0
  96. package/example/api/index.ts +36 -0
  97. package/example/app/(tabs)/_layout.tsx +60 -0
  98. package/example/app/(tabs)/cards.tsx +81 -0
  99. package/example/app/(tabs)/index.tsx +205 -0
  100. package/example/app/(tabs)/moviesL.tsx +7 -0
  101. package/example/app/(tabs)/moviesLR.tsx +7 -0
  102. package/example/app/+not-found.tsx +32 -0
  103. package/example/app/_layout.tsx +34 -0
  104. package/example/app/accurate-scrollto/index.tsx +125 -0
  105. package/example/app/accurate-scrollto-2/index.tsx +52 -0
  106. package/example/app/accurate-scrollto-huge/index.tsx +128 -0
  107. package/example/app/add-to-end/index.tsx +82 -0
  108. package/example/app/ai-chat/index.tsx +236 -0
  109. package/example/app/bidirectional-infinite-list/index.tsx +133 -0
  110. package/example/app/cards-columns/index.tsx +37 -0
  111. package/example/app/cards-flashlist/index.tsx +122 -0
  112. package/example/app/cards-flatlist/index.tsx +94 -0
  113. package/example/app/cards-no-recycle/index.tsx +110 -0
  114. package/example/app/cards-renderItem.tsx +354 -0
  115. package/example/app/chat-example/index.tsx +167 -0
  116. package/example/app/chat-infinite/index.tsx +239 -0
  117. package/example/app/chat-keyboard/index.tsx +248 -0
  118. package/example/app/chat-resize-outer/index.tsx +247 -0
  119. package/example/app/columns/index.tsx +78 -0
  120. package/example/app/countries/index.tsx +182 -0
  121. package/example/app/countries-flashlist/index.tsx +163 -0
  122. package/example/app/countries-reorder/index.tsx +187 -0
  123. package/example/app/extra-data/index.tsx +86 -0
  124. package/example/app/filter-elements/filter-data-provider.tsx +55 -0
  125. package/example/app/filter-elements/index.tsx +118 -0
  126. package/example/app/initial-scroll-index/index.tsx +106 -0
  127. package/example/app/initial-scroll-index/renderFixedItem.tsx +215 -0
  128. package/example/app/initial-scroll-index-free-height/index.tsx +70 -0
  129. package/example/app/initial-scroll-index-keyed/index.tsx +62 -0
  130. package/example/app/lazy-list/index.tsx +123 -0
  131. package/example/app/movies-flashlist/index.tsx +7 -0
  132. package/example/app/mutable-cells/index.tsx +104 -0
  133. package/example/app/video-feed/index.tsx +119 -0
  134. package/example/app.config.js +22 -0
  135. package/example/app.json +45 -0
  136. package/example/assets/fonts/SpaceMono-Regular.ttf +0 -0
  137. package/example/assets/images/adaptive-icon.png +0 -0
  138. package/example/assets/images/favicon.png +0 -0
  139. package/example/assets/images/icon.png +0 -0
  140. package/example/assets/images/partial-react-logo.png +0 -0
  141. package/example/assets/images/react-logo.png +0 -0
  142. package/example/assets/images/react-logo@2x.png +0 -0
  143. package/example/assets/images/react-logo@3x.png +0 -0
  144. package/example/assets/images/splash-icon.png +0 -0
  145. package/example/autoscroll.sh +101 -0
  146. package/example/bun.lock +2266 -0
  147. package/example/bunfig.toml +2 -0
  148. package/example/components/Breathe.tsx +54 -0
  149. package/example/components/Circle.tsx +69 -0
  150. package/example/components/Collapsible.tsx +44 -0
  151. package/example/components/ExternalLink.tsx +24 -0
  152. package/example/components/HapticTab.tsx +18 -0
  153. package/example/components/HelloWave.tsx +37 -0
  154. package/example/components/Movies.tsx +179 -0
  155. package/example/components/ParallaxScrollView.tsx +81 -0
  156. package/example/components/ThemedText.tsx +60 -0
  157. package/example/components/ThemedView.tsx +14 -0
  158. package/example/components/__tests__/ThemedText-test.tsx +10 -0
  159. package/example/components/__tests__/__snapshots__/ThemedText-test.tsx.snap +24 -0
  160. package/example/components/ui/IconSymbol.ios.tsx +32 -0
  161. package/example/components/ui/IconSymbol.tsx +43 -0
  162. package/example/components/ui/TabBarBackground.ios.tsx +22 -0
  163. package/example/components/ui/TabBarBackground.tsx +6 -0
  164. package/example/constants/Colors.ts +26 -0
  165. package/example/constants/constants.ts +5 -0
  166. package/example/constants/useScrollTest.ts +19 -0
  167. package/example/hooks/useColorScheme.ts +1 -0
  168. package/example/hooks/useColorScheme.web.ts +8 -0
  169. package/example/hooks/useThemeColor.ts +22 -0
  170. package/example/ios/.xcode.env +11 -0
  171. package/example/ios/Podfile +64 -0
  172. package/example/ios/Podfile.lock +2767 -0
  173. package/example/ios/Podfile.properties.json +5 -0
  174. package/example/ios/listtest/AppDelegate.swift +70 -0
  175. package/example/ios/listtest/Images.xcassets/AppIcon.appiconset/App-Icon-1024x1024@1x.png +0 -0
  176. package/example/ios/listtest/Images.xcassets/AppIcon.appiconset/Contents.json +14 -0
  177. package/example/ios/listtest/Images.xcassets/Contents.json +6 -0
  178. package/example/ios/listtest/Images.xcassets/SplashScreenBackground.colorset/Contents.json +20 -0
  179. package/example/ios/listtest/Images.xcassets/SplashScreenLogo.imageset/Contents.json +23 -0
  180. package/example/ios/listtest/Images.xcassets/SplashScreenLogo.imageset/image.png +0 -0
  181. package/example/ios/listtest/Images.xcassets/SplashScreenLogo.imageset/image@2x.png +0 -0
  182. package/example/ios/listtest/Images.xcassets/SplashScreenLogo.imageset/image@3x.png +0 -0
  183. package/example/ios/listtest/Info.plist +85 -0
  184. package/example/ios/listtest/PrivacyInfo.xcprivacy +48 -0
  185. package/example/ios/listtest/SplashScreen.storyboard +42 -0
  186. package/example/ios/listtest/Supporting/Expo.plist +12 -0
  187. package/example/ios/listtest/listtest-Bridging-Header.h +3 -0
  188. package/example/ios/listtest/listtest.entitlements +5 -0
  189. package/example/ios/listtest.xcodeproj/project.pbxproj +547 -0
  190. package/example/ios/listtest.xcodeproj/xcshareddata/xcschemes/listtest.xcscheme +88 -0
  191. package/example/ios/listtest.xcworkspace/contents.xcworkspacedata +10 -0
  192. package/example/metro.config.js +16 -0
  193. package/example/package.json +73 -0
  194. package/example/scripts/reset-project.js +84 -0
  195. package/example/tsconfig.json +26 -0
  196. package/package.json +88 -34
  197. package/posttsup.ts +24 -0
  198. package/src/Container.tsx +176 -0
  199. package/src/Containers.tsx +85 -0
  200. package/src/ContextContainer.ts +145 -0
  201. package/src/DebugView.tsx +83 -0
  202. package/src/LazyLegendList.tsx +41 -0
  203. package/src/LeanView.tsx +18 -0
  204. package/src/LegendList.tsx +558 -0
  205. package/src/ListComponent.tsx +191 -0
  206. package/src/ScrollAdjust.tsx +24 -0
  207. package/src/ScrollAdjustHandler.ts +26 -0
  208. package/src/Separator.tsx +14 -0
  209. package/src/animated.tsx +6 -0
  210. package/src/calculateItemsInView.ts +363 -0
  211. package/src/calculateOffsetForIndex.ts +23 -0
  212. package/src/calculateOffsetWithOffsetPosition.ts +26 -0
  213. package/src/checkAllSizesKnown.ts +17 -0
  214. package/src/checkAtBottom.ts +36 -0
  215. package/src/checkAtTop.ts +27 -0
  216. package/src/checkThreshold.ts +30 -0
  217. package/src/constants.ts +11 -0
  218. package/src/createColumnWrapperStyle.ts +16 -0
  219. package/src/doInitialAllocateContainers.ts +40 -0
  220. package/src/doMaintainScrollAtEnd.ts +34 -0
  221. package/src/findAvailableContainers.ts +98 -0
  222. package/src/finishScrollTo.ts +8 -0
  223. package/src/getId.ts +21 -0
  224. package/src/getItemSize.ts +52 -0
  225. package/src/getRenderedItem.ts +34 -0
  226. package/src/getScrollVelocity.ts +47 -0
  227. package/src/handleLayout.ts +70 -0
  228. package/src/helpers.ts +39 -0
  229. package/src/index.ts +11 -0
  230. package/src/keyboard-controller.tsx +63 -0
  231. package/src/onScroll.ts +66 -0
  232. package/src/prepareMVCP.ts +50 -0
  233. package/src/reanimated.tsx +63 -0
  234. package/src/requestAdjust.ts +41 -0
  235. package/src/scrollTo.ts +40 -0
  236. package/src/scrollToIndex.ts +34 -0
  237. package/src/setDidLayout.ts +25 -0
  238. package/src/setPaddingTop.ts +28 -0
  239. package/src/state.tsx +304 -0
  240. package/src/types.ts +610 -0
  241. package/src/updateAlignItemsPaddingTop.ts +18 -0
  242. package/src/updateAllPositions.ts +130 -0
  243. package/src/updateItemSize.ts +203 -0
  244. package/src/updateTotalSize.ts +44 -0
  245. package/src/useAnimatedValue.ts +6 -0
  246. package/src/useCombinedRef.ts +22 -0
  247. package/src/useInit.ts +17 -0
  248. package/src/useSyncLayout.tsx +68 -0
  249. package/src/useValue$.ts +53 -0
  250. package/src/viewability.ts +279 -0
  251. package/tsconfig.json +59 -0
  252. package/tsup.config.ts +21 -0
  253. /package/{animated.js → dist/animated.js} +0 -0
  254. /package/{animated.mjs → dist/animated.mjs} +0 -0
  255. /package/{keyboard-controller.js → dist/keyboard-controller.js} +0 -0
  256. /package/{keyboard-controller.mjs → dist/keyboard-controller.mjs} +0 -0
  257. /package/{reanimated.d.mts → dist/reanimated.d.mts} +0 -0
  258. /package/{reanimated.d.ts → dist/reanimated.d.ts} +0 -0
  259. /package/{reanimated.js → dist/reanimated.js} +0 -0
  260. /package/{reanimated.mjs → dist/reanimated.mjs} +0 -0
@@ -0,0 +1,215 @@
1
+ import { MaterialIcons } from "@expo/vector-icons";
2
+ import Swipeable from "react-native-gesture-handler/ReanimatedSwipeable";
3
+
4
+ import { Image, Platform, Pressable, StyleSheet, Text, UIManager, View } from "react-native";
5
+
6
+ import { loremSentences, randomNames } from "@/app/cards-renderItem";
7
+ import { RectButton } from "react-native-gesture-handler";
8
+
9
+ export interface Item {
10
+ id: string;
11
+ }
12
+
13
+ // Generate random metadata
14
+ const randomAvatars = Array.from({ length: 20 }, (_, i) => `https://i.pravatar.cc/150?img=${i + 1}`);
15
+
16
+ interface ItemCardProps {
17
+ item: Item;
18
+ index: number;
19
+ height: number;
20
+ }
21
+
22
+ if (Platform.OS === "android") {
23
+ if (UIManager.setLayoutAnimationEnabledExperimental) {
24
+ UIManager.setLayoutAnimationEnabledExperimental(true);
25
+ }
26
+ }
27
+
28
+ const renderRightActions = () => {
29
+ return (
30
+ <RectButton
31
+ style={{
32
+ width: 80,
33
+ height: "100%",
34
+ backgroundColor: "#4CAF50",
35
+ justifyContent: "center",
36
+ alignItems: "center",
37
+ borderTopRightRadius: 12,
38
+ borderBottomRightRadius: 12,
39
+ shadowColor: "#000",
40
+ shadowOffset: { width: 2, height: 0 },
41
+ shadowOpacity: 0.1,
42
+ shadowRadius: 4,
43
+ }}
44
+ onPress={() => {
45
+ console.log("Marked as complete");
46
+ }}
47
+ >
48
+ <MaterialIcons name="check-circle" size={24} color="white" />
49
+ <Text
50
+ style={{
51
+ color: "white",
52
+ fontSize: 12,
53
+ marginTop: 4,
54
+ fontWeight: "600",
55
+ }}
56
+ >
57
+ Complete
58
+ </Text>
59
+ </RectButton>
60
+ );
61
+ };
62
+
63
+ export const ItemCard = ({ item, height }: ItemCardProps) => {
64
+ const indexForData = item.id.includes("new") ? 100 + +item.id.replace("new", "") : +item.id;
65
+
66
+ // Generate 1-5 random sentences
67
+ const numSentences = 5;
68
+ // const indexForData =
69
+ // item.id === "0" ? 0 : item.id === "1" ? 1 : item.id === "new0" ? 2 : 3;
70
+ // const numSentences =
71
+ // item.id === "0" ? 1 : item.id === "1" ? 2 : item.id === "new0" ? 4 : 8;
72
+ const randomText = Array.from({ length: numSentences }, (_, i) => loremSentences[i]).join(" ");
73
+
74
+ // Use randomIndex to deterministically select random data
75
+ const avatarUrl = randomAvatars[indexForData % randomAvatars.length];
76
+ const authorName = randomNames[indexForData % randomNames.length];
77
+ const timestamp = `${Math.max(1, indexForData % 24)}h ago`;
78
+
79
+ return (
80
+ <View style={[styles.itemOuterContainer, { height }]}>
81
+ <Swipeable
82
+ renderRightActions={renderRightActions}
83
+ overshootRight={true}
84
+ containerStyle={{ backgroundColor: "#4CAF50", borderRadius: 12 }}
85
+ >
86
+ <Pressable
87
+ onPress={() => {
88
+ // LinearTransition.easing(Easing.ease);
89
+ }}
90
+ >
91
+ <View
92
+ style={[
93
+ styles.itemContainer,
94
+ {
95
+ // padding: 16,
96
+ backgroundColor: "#ffffff",
97
+ borderRadius: 12,
98
+ shadowColor: "#000",
99
+ shadowOffset: { width: 0, height: 2 },
100
+ shadowOpacity: 0.1,
101
+ shadowRadius: 4,
102
+ // marginVertical: 8,
103
+ overflow: "hidden",
104
+ },
105
+ ]}
106
+ >
107
+ <View style={styles.headerContainer}>
108
+ <Image source={{ uri: avatarUrl }} style={styles.avatar} />
109
+ <View style={styles.headerText}>
110
+ <Text style={styles.authorName}>
111
+ {authorName} {item.id}
112
+ </Text>
113
+ <Text style={styles.timestamp}>{timestamp}</Text>
114
+ </View>
115
+ </View>
116
+
117
+ <Text style={styles.itemTitle}>Item #{item.id}</Text>
118
+ <Text
119
+ style={styles.itemBody}
120
+ // numberOfLines={isExpanded ? undefined : 10}
121
+ >
122
+ {randomText}
123
+ </Text>
124
+ <View style={styles.itemFooter}>
125
+ <Text style={styles.footerText}>❤️ 42</Text>
126
+ <Text style={styles.footerText}>💬 12</Text>
127
+ <Text style={styles.footerText}>🔄 8</Text>
128
+ </View>
129
+ </View>
130
+ </Pressable>
131
+ </Swipeable>
132
+ </View>
133
+ );
134
+ };
135
+
136
+ export const renderItem = ({ item, index, height }: ItemCardProps) => (
137
+ <ItemCard item={item} index={index} height={height} />
138
+ );
139
+
140
+ const styles = StyleSheet.create({
141
+ itemOuterContainer: {
142
+ paddingVertical: 8,
143
+ paddingHorizontal: 8,
144
+ // marginTop: 16,
145
+ // maxWidth: 360,
146
+ },
147
+ itemContainer: {
148
+ padding: 16,
149
+ // borderBottomWidth: 1,
150
+ // borderBottomColor: "#ccc",
151
+ },
152
+ titleContainer: {
153
+ flexDirection: "row",
154
+ alignItems: "center",
155
+ gap: 8,
156
+ },
157
+ stepContainer: {
158
+ gap: 8,
159
+ marginBottom: 8,
160
+ },
161
+ listContainer: {
162
+ paddingHorizontal: 16,
163
+ },
164
+ itemTitle: {
165
+ fontSize: 18,
166
+ fontWeight: "bold",
167
+ marginBottom: 8,
168
+ color: "#1a1a1a",
169
+ },
170
+ itemBody: {
171
+ fontSize: 14,
172
+ color: "#666666",
173
+ lineHeight: 20,
174
+ // flex: 1,
175
+ },
176
+ itemFooter: {
177
+ flexDirection: "row",
178
+ justifyContent: "flex-start",
179
+ gap: 16,
180
+ marginTop: 12,
181
+ paddingTop: 12,
182
+ borderTopWidth: 1,
183
+ borderTopColor: "#f0f0f0",
184
+ },
185
+ footerText: {
186
+ fontSize: 14,
187
+ color: "#888888",
188
+ },
189
+ headerContainer: {
190
+ flexDirection: "row",
191
+ alignItems: "center",
192
+ marginBottom: 12,
193
+ },
194
+ avatar: {
195
+ width: 40,
196
+ height: 40,
197
+ borderRadius: 20,
198
+ marginRight: 12,
199
+ },
200
+ headerText: {
201
+ flex: 1,
202
+ },
203
+ authorName: {
204
+ fontSize: 16,
205
+ fontWeight: "600",
206
+ color: "#1a1a1a",
207
+ },
208
+ timestamp: {
209
+ fontSize: 12,
210
+ color: "#888888",
211
+ marginTop: 2,
212
+ },
213
+ });
214
+
215
+ export default renderItem;
@@ -0,0 +1,70 @@
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 { StyleSheet, View } from "react-native";
6
+ import { useSafeAreaInsets } from "react-native-safe-area-context";
7
+
8
+ //** Purpose of this component is to show that LegendList with initialScrollIndex can correctly scroll to the begginning
9
+ // and the end of the list even if element height is unknown and calculated dynamically */
10
+ export default function IntialScrollIndexFreeHeight() {
11
+ const listRef = useRef<LegendListRef>(null);
12
+
13
+ const [data, setData] = useState<Item[]>(
14
+ () =>
15
+ Array.from({ length: 100 }, (_, i) => ({
16
+ id: i.toString(),
17
+ })) as any[],
18
+ );
19
+
20
+ const { top, bottom } = useSafeAreaInsets();
21
+
22
+ return (
23
+ <View style={[StyleSheet.absoluteFill, styles.outerContainer]} key="legendlist">
24
+ <LegendList
25
+ ref={listRef}
26
+ initialScrollIndex={50}
27
+ style={[StyleSheet.absoluteFill, styles.scrollContainer]}
28
+ contentContainerStyle={styles.listContainer}
29
+ data={data}
30
+ renderItem={renderItem}
31
+ keyExtractor={(item) => `id${item.id}`}
32
+ estimatedItemSize={ESTIMATED_ITEM_LENGTH}
33
+ drawDistance={DRAW_DISTANCE}
34
+ maintainVisibleContentPosition
35
+ recycleItems={true}
36
+ //ListHeaderComponent={<View style={{ height: top }} />}
37
+ ListFooterComponent={<View style={{ height: bottom }} />}
38
+ numColumns={1}
39
+ />
40
+ </View>
41
+ );
42
+ }
43
+
44
+ const styles = StyleSheet.create({
45
+ listHeader: {
46
+ alignSelf: "center",
47
+ height: 100,
48
+ width: 100,
49
+ backgroundColor: "#456AAA",
50
+ borderRadius: 12,
51
+ marginHorizontal: 8,
52
+ marginVertical: 8,
53
+ },
54
+ listEmpty: {
55
+ flex: 1,
56
+ justifyContent: "center",
57
+ alignItems: "center",
58
+ backgroundColor: "#6789AB",
59
+ paddingVertical: 16,
60
+ },
61
+ outerContainer: {
62
+ backgroundColor: "#456",
63
+ },
64
+ scrollContainer: {},
65
+ listContainer: {
66
+ width: "100%",
67
+ maxWidth: "100%",
68
+ marginHorizontal: "auto",
69
+ },
70
+ });
@@ -0,0 +1,62 @@
1
+ import { LegendList } from "@legendapp/list";
2
+ import { useCallback, useState } from "react";
3
+ import { Button, StyleSheet, Text, View } from "react-native";
4
+
5
+ // Dummy data: 50 items
6
+ const DATA = Array.from({ length: 70 }, (_, i) => ({ label: `Item ${i}`, height: ((i * 7919) % 100) + 10 }));
7
+
8
+ export default function App() {
9
+ const [scrollToIdx, setScrollToIdx] = useState(0);
10
+
11
+ console.log("keyed");
12
+
13
+ const renderItem = useCallback(
14
+ ({ item }) => (
15
+ <View style={[styles.item, { height: item.height }]}>
16
+ <Text>{item.label}</Text>
17
+ </View>
18
+ ),
19
+ [],
20
+ );
21
+
22
+ return (
23
+ <View style={styles.container}>
24
+ <View style={styles.buttons}>
25
+ <Button title="Scroll to 10" onPress={() => setScrollToIdx(10)} />
26
+ <Button title="Scroll to 20" onPress={() => setScrollToIdx(20)} />
27
+ <Button title="Scroll to 30" onPress={() => setScrollToIdx(30)} />
28
+ <Button title="Scroll to 40" onPress={() => setScrollToIdx(40)} />
29
+ </View>
30
+
31
+ <View key={scrollToIdx} style={styles.list}>
32
+ <LegendList
33
+ data={DATA}
34
+ renderItem={renderItem}
35
+ keyExtractor={(item) => item.label}
36
+ estimatedItemSize={60}
37
+ style={styles.list}
38
+ initialScrollIndex={scrollToIdx}
39
+ maintainVisibleContentPosition
40
+ />
41
+ </View>
42
+ </View>
43
+ );
44
+ }
45
+
46
+ const styles = StyleSheet.create({
47
+ container: { flex: 1 },
48
+ buttons: {
49
+ flexDirection: "row",
50
+ justifyContent: "space-around",
51
+ marginBottom: 10,
52
+ },
53
+ list: { flex: 1 },
54
+ item: {
55
+ justifyContent: "center",
56
+ alignItems: "center",
57
+ backgroundColor: "#fafafa",
58
+ marginVertical: 4,
59
+ marginHorizontal: 16,
60
+ borderRadius: 8,
61
+ },
62
+ });
@@ -0,0 +1,123 @@
1
+ import { LazyLegendList, type LegendListRef } from "@legendapp/list";
2
+ import { type TCountryCode, countries, getEmojiFlag } from "countries-list";
3
+ import { useRef, useState } from "react";
4
+ import { Pressable, StatusBar, StyleSheet, Text, View } from "react-native";
5
+
6
+ type Country = {
7
+ id: string;
8
+ name: string;
9
+ flag: string;
10
+ };
11
+
12
+ const DATA: Country[] = Object.entries(countries)
13
+ .map(([code, country]) => ({
14
+ id: code,
15
+ name: country.name,
16
+ flag: getEmojiFlag(code as TCountryCode),
17
+ }))
18
+ .sort((a, b) => a.name.localeCompare(b.name));
19
+
20
+ export default function LazyList() {
21
+ const listRef = useRef<LegendListRef>(null);
22
+ const [selectedId, setSelectedId] = useState<string>();
23
+
24
+ return (
25
+ <View style={styles.container}>
26
+ <LazyLegendList ref={listRef} maintainVisibleContentPosition recycleItems>
27
+ <View style={styles.heading}>
28
+ <Text style={styles.headingText}>Countries lazy scrollview</Text>
29
+ </View>
30
+ {DATA.map((country) => (
31
+ <Pressable
32
+ key={country.id}
33
+ onPress={() => setSelectedId(country.id)}
34
+ style={({ pressed }) => [
35
+ styles.item,
36
+ selectedId === country.id && styles.selectedItem,
37
+ pressed && styles.pressedItem,
38
+ ]}
39
+ >
40
+ <View style={styles.flagContainer}>
41
+ <Text style={styles.flag}>{country.flag}</Text>
42
+ </View>
43
+ <View style={styles.contentContainer}>
44
+ <Text style={[styles.title, selectedId === country.id && styles.selectedText]}>
45
+ {country.name}
46
+ <Text style={styles.countryCode}> ({country.id})</Text>
47
+ </Text>
48
+ </View>
49
+ </Pressable>
50
+ ))}
51
+ </LazyLegendList>
52
+ </View>
53
+ );
54
+ }
55
+
56
+ const styles = StyleSheet.create({
57
+ container: {
58
+ flex: 1,
59
+ marginTop: StatusBar.currentHeight || 0,
60
+ backgroundColor: "#f5f5f5",
61
+ },
62
+ heading: {
63
+ paddingVertical: 8,
64
+ paddingHorizontal: 16,
65
+ },
66
+ headingText: {
67
+ fontWeight: "bold",
68
+ },
69
+ item: {
70
+ paddingHorizontal: 16,
71
+ paddingVertical: 6,
72
+ flexDirection: "row",
73
+ alignItems: "center",
74
+ backgroundColor: "#fff",
75
+ borderRadius: 12,
76
+ // shadowColor: "#000",
77
+ // shadowOffset: {
78
+ // width: 0,
79
+ // height: 2,
80
+ // },
81
+ // shadowOpacity: 0.1,
82
+ // shadowRadius: 3,
83
+ // elevation: 3,
84
+ },
85
+ selectedItem: {
86
+ // backgroundColor: "#e3f2fd",
87
+ // borderColor: "#1976d2",
88
+ // borderWidth: 1,
89
+ },
90
+ pressedItem: {
91
+ // backgroundColor: "#f0f0f0",
92
+ },
93
+ flagContainer: {
94
+ marginRight: 16,
95
+ width: 40,
96
+ height: 40,
97
+ borderRadius: 20,
98
+ backgroundColor: "#f8f9fa",
99
+ alignItems: "center",
100
+ justifyContent: "center",
101
+ },
102
+ flag: {
103
+ fontSize: 28,
104
+ },
105
+ contentContainer: {
106
+ flex: 1,
107
+ justifyContent: "center",
108
+ },
109
+ title: {
110
+ fontSize: 16,
111
+ color: "#333",
112
+ fontWeight: "500",
113
+ },
114
+ selectedText: {
115
+ color: "#1976d2",
116
+ fontWeight: "600",
117
+ },
118
+ countryCode: {
119
+ fontSize: 14,
120
+ color: "#666",
121
+ fontWeight: "400",
122
+ },
123
+ });
@@ -0,0 +1,7 @@
1
+ import Movies from "@/components/Movies";
2
+
3
+ const App = () => {
4
+ return <Movies isLegend={false} />;
5
+ };
6
+
7
+ export default App;
@@ -0,0 +1,104 @@
1
+ import { LegendList, type LegendListRenderItemProps } from "@legendapp/list";
2
+ import type React from "react";
3
+ import { createContext, useCallback, useContext, useState } from "react";
4
+ import { Button, StyleSheet, Text, View } from "react-native";
5
+
6
+ const fakeData = Array.from({ length: 100 }, (_, index) => ({
7
+ id: index,
8
+ title: `Item ${index + 1}`,
9
+ score: 0,
10
+ }));
11
+
12
+ type Item = (typeof fakeData)[number];
13
+
14
+ const DataContext = createContext({
15
+ data: fakeData,
16
+ increment: (id: number) => {},
17
+ });
18
+
19
+ export const DataProvider = ({ initialData, children }: { initialData: Item[]; children: React.ReactNode }) => {
20
+ const [data, setData] = useState(initialData);
21
+
22
+ const increment = useCallback((id: number) => {
23
+ setData((prevData) => {
24
+ return prevData.map((item) => {
25
+ if (item.id === id) {
26
+ return { ...item, score: item.score + 1 };
27
+ }
28
+ return item;
29
+ });
30
+ });
31
+ }, []);
32
+
33
+ return <DataContext.Provider value={{ data, increment }}>{children}</DataContext.Provider>;
34
+ };
35
+
36
+ export const useData = () => useContext(DataContext);
37
+
38
+ const Item = ({ item }: { item: Item }) => {
39
+ const { increment } = useData();
40
+ return (
41
+ <View
42
+ style={{
43
+ height: 100,
44
+ backgroundColor: "#fefefe",
45
+ justifyContent: "center",
46
+ paddingHorizontal: 24,
47
+ borderRadius: 16,
48
+ }}
49
+ >
50
+ <Text style={{ fontSize: 24, fontWeight: "bold" }}>{`${item.title} - Score:${item.score}`}</Text>
51
+ <Button
52
+ title="Increment"
53
+ onPress={() => {
54
+ increment(item.id);
55
+ }}
56
+ />
57
+ </View>
58
+ );
59
+ };
60
+
61
+ const ItemSeparatorComponent = () => <View style={{ height: 16 }} />;
62
+
63
+ export const List = () => {
64
+ const { data } = useData();
65
+ const renderItem = ({ item }: LegendListRenderItemProps<Item>) => <Item item={item} />;
66
+ return (
67
+ <View style={{ flex: 1, paddingHorizontal: 16, marginTop: 70 }}>
68
+ <LegendList
69
+ data={data}
70
+ estimatedItemSize={116}
71
+ ItemSeparatorComponent={ItemSeparatorComponent}
72
+ renderItem={renderItem}
73
+ keyExtractor={(item) => String(item.id)}
74
+ />
75
+ </View>
76
+ );
77
+ };
78
+
79
+ export default function HomeScreen() {
80
+ return (
81
+ <DataProvider initialData={fakeData}>
82
+ <List />
83
+ </DataProvider>
84
+ );
85
+ }
86
+
87
+ const styles = StyleSheet.create({
88
+ titleContainer: {
89
+ flexDirection: "row",
90
+ alignItems: "center",
91
+ gap: 8,
92
+ },
93
+ stepContainer: {
94
+ gap: 8,
95
+ marginBottom: 8,
96
+ },
97
+ reactLogo: {
98
+ height: 178,
99
+ width: 290,
100
+ bottom: 0,
101
+ left: 0,
102
+ position: "absolute",
103
+ },
104
+ });
@@ -0,0 +1,119 @@
1
+ import { LegendList } from "@legendapp/list";
2
+ import { useState } from "react";
3
+ import { useEffect } from "react";
4
+ import { Dimensions, LogBox, StyleSheet, Text, View } from "react-native";
5
+
6
+ LogBox.ignoreLogs(["Open debugger"]);
7
+
8
+ const WINDOW_HEIGHT = Dimensions.get("window").height;
9
+ const colors = ["#FF6B6B", "#4ECDC4", "#45B7D1", "#96CEB4", "#FFEEAD", "#D4A5A5", "#9B59B6", "#3498DB"];
10
+
11
+ const initialData = Array.from({ length: 8 }, (_, index) => ({
12
+ id: index.toString(),
13
+ color: colors[index % colors.length],
14
+ }));
15
+
16
+ export default function VideoFeed() {
17
+ const [data, setData] = useState(initialData);
18
+ const [height, setHeight] = useState(0);
19
+
20
+ useEffect(() => {
21
+ setTimeout(() => {
22
+ setData(
23
+ Array.from({ length: 10 }, (_, index) => ({
24
+ id: index.toString(),
25
+ color: colors[index % colors.length],
26
+ })),
27
+ );
28
+ }, 1000);
29
+ }, []);
30
+
31
+ return (
32
+ <View style={styles.container} onLayout={(e) => setHeight(e.nativeEvent.layout.height)}>
33
+ {!!height && (
34
+ <LegendList
35
+ data={data}
36
+ renderItem={Item}
37
+ keyExtractor={(item) => item.id}
38
+ decelerationRate="fast"
39
+ showsVerticalScrollIndicator={false}
40
+ estimatedItemSize={height}
41
+ pagingEnabled
42
+ drawDistance={1}
43
+ extraData={height}
44
+ onEndReached={() => {
45
+ setData([
46
+ ...data,
47
+ ...Array.from({ length: 10 }, (_, index) => ({
48
+ id: (data.length + index).toString(),
49
+ color: colors[index % colors.length],
50
+ })),
51
+ ]);
52
+ }}
53
+ />
54
+ )}
55
+ </View>
56
+ );
57
+ }
58
+
59
+ function Item({ item, extraData }: { item: { id: string; color: string }; extraData: number }) {
60
+ return (
61
+ <View style={[styles.rectangle, { height: extraData }]}>
62
+ <View style={[styles.rectangleInner, { backgroundColor: item.color }]} />
63
+ <Text style={styles.itemText}>Item {item.id}</Text>
64
+ </View>
65
+ );
66
+ }
67
+
68
+ const styles = StyleSheet.create({
69
+ container: {
70
+ flex: 1,
71
+ backgroundColor: "#fff",
72
+ },
73
+ rectangle: {
74
+ height: WINDOW_HEIGHT,
75
+ width: "100%",
76
+ position: "relative",
77
+ },
78
+ rectangleInner: {
79
+ height: "100%",
80
+ width: "100%",
81
+ },
82
+ itemText: {
83
+ position: "absolute",
84
+ bottom: 20,
85
+ left: 20,
86
+ color: "#fff",
87
+ fontSize: 18,
88
+ fontWeight: "bold",
89
+ },
90
+ redRectangle: {
91
+ aspectRatio: 1,
92
+ },
93
+ redRectangleInner: {
94
+ height: "100%",
95
+ width: "100%",
96
+ backgroundColor: "red",
97
+ borderRadius: 8,
98
+ },
99
+ columnWrapper: {
100
+ justifyContent: "space-between",
101
+ },
102
+ listHeader: {
103
+ alignSelf: "center",
104
+ height: 100,
105
+ width: 100,
106
+ backgroundColor: "#456AAA",
107
+ borderRadius: 12,
108
+ marginHorizontal: 8,
109
+ marginVertical: 8,
110
+ },
111
+ listEmpty: {
112
+ flex: 1,
113
+ justifyContent: "center",
114
+ alignItems: "center",
115
+ backgroundColor: "#6789AB",
116
+ paddingVertical: 16,
117
+ height: 100,
118
+ },
119
+ });