@legendapp/list 2.0.0-next.2 → 2.0.0-next.3

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/{dist/animated.d.mts → animated.d.mts} +1 -0
  2. package/{dist/animated.d.ts → animated.d.ts} +1 -0
  3. package/{dist/index.d.mts → index.d.mts} +8 -1
  4. package/{dist/index.d.ts → index.d.ts} +8 -1
  5. package/{dist/index.js → index.js} +50 -4
  6. package/{dist/index.mjs → index.mjs} +50 -4
  7. package/{dist/keyboard-controller.d.mts → keyboard-controller.d.mts} +4 -0
  8. package/{dist/keyboard-controller.d.ts → keyboard-controller.d.ts} +4 -0
  9. package/package.json +34 -88
  10. package/.claude/settings.local.json +0 -8
  11. package/.cursor/rules/changelog.mdc +0 -60
  12. package/.github/FUNDING.yml +0 -15
  13. package/.gitignore +0 -5
  14. package/.prettierrc.json +0 -5
  15. package/.vscode/settings.json +0 -14
  16. package/CLAUDE.md +0 -126
  17. package/biome.json +0 -46
  18. package/bun.lock +0 -1289
  19. package/bunfig.toml +0 -2
  20. package/dist/CHANGELOG.md +0 -119
  21. package/dist/LICENSE +0 -21
  22. package/dist/README.md +0 -139
  23. package/dist/package.json +0 -35
  24. package/example/README.md +0 -40
  25. package/example/api/data/genres.json +0 -23
  26. package/example/api/data/playlist/10402-10749.json +0 -1
  27. package/example/api/data/playlist/10402-10770.json +0 -1
  28. package/example/api/data/playlist/10402-37.json +0 -1
  29. package/example/api/data/playlist/10749-10752.json +0 -1
  30. package/example/api/data/playlist/10749-10770.json +0 -1
  31. package/example/api/data/playlist/10749-37.json +0 -1
  32. package/example/api/data/playlist/10749-878.json +0 -1
  33. package/example/api/data/playlist/10751-10402.json +0 -1
  34. package/example/api/data/playlist/10751-10752.json +0 -1
  35. package/example/api/data/playlist/10751-37.json +0 -1
  36. package/example/api/data/playlist/10751-53.json +0 -1
  37. package/example/api/data/playlist/10751-878.json +0 -1
  38. package/example/api/data/playlist/10751-9648.json +0 -1
  39. package/example/api/data/playlist/10752-37.json +0 -1
  40. package/example/api/data/playlist/12-10402.json +0 -1
  41. package/example/api/data/playlist/12-10749.json +0 -1
  42. package/example/api/data/playlist/12-18.json +0 -1
  43. package/example/api/data/playlist/12-27.json +0 -1
  44. package/example/api/data/playlist/12-35.json +0 -1
  45. package/example/api/data/playlist/14-36.json +0 -1
  46. package/example/api/data/playlist/14-878.json +0 -1
  47. package/example/api/data/playlist/16-10751.json +0 -1
  48. package/example/api/data/playlist/16-10770.json +0 -1
  49. package/example/api/data/playlist/16-35.json +0 -1
  50. package/example/api/data/playlist/16-36.json +0 -1
  51. package/example/api/data/playlist/16-53.json +0 -1
  52. package/example/api/data/playlist/18-10751.json +0 -1
  53. package/example/api/data/playlist/18-10752.json +0 -1
  54. package/example/api/data/playlist/18-37.json +0 -1
  55. package/example/api/data/playlist/18-53.json +0 -1
  56. package/example/api/data/playlist/18-878.json +0 -1
  57. package/example/api/data/playlist/27-10749.json +0 -1
  58. package/example/api/data/playlist/27-10770.json +0 -1
  59. package/example/api/data/playlist/28-10749.json +0 -1
  60. package/example/api/data/playlist/28-10751.json +0 -1
  61. package/example/api/data/playlist/28-10770.json +0 -1
  62. package/example/api/data/playlist/28-16.json +0 -1
  63. package/example/api/data/playlist/28-18.json +0 -1
  64. package/example/api/data/playlist/28-36.json +0 -1
  65. package/example/api/data/playlist/28-37.json +0 -1
  66. package/example/api/data/playlist/28-53.json +0 -1
  67. package/example/api/data/playlist/28-80.json +0 -1
  68. package/example/api/data/playlist/28-99.json +0 -1
  69. package/example/api/data/playlist/35-10749.json +0 -1
  70. package/example/api/data/playlist/35-10751.json +0 -1
  71. package/example/api/data/playlist/35-10752.json +0 -1
  72. package/example/api/data/playlist/35-27.json +0 -1
  73. package/example/api/data/playlist/35-36.json +0 -1
  74. package/example/api/data/playlist/35-53.json +0 -1
  75. package/example/api/data/playlist/35-80.json +0 -1
  76. package/example/api/data/playlist/36-37.json +0 -1
  77. package/example/api/data/playlist/36-878.json +0 -1
  78. package/example/api/data/playlist/36-9648.json +0 -1
  79. package/example/api/data/playlist/53-10752.json +0 -1
  80. package/example/api/data/playlist/80-10770.json +0 -1
  81. package/example/api/data/playlist/80-14.json +0 -1
  82. package/example/api/data/playlist/80-18.json +0 -1
  83. package/example/api/data/playlist/80-37.json +0 -1
  84. package/example/api/data/playlist/878-37.json +0 -1
  85. package/example/api/data/playlist/9648-10770.json +0 -1
  86. package/example/api/data/playlist/9648-37.json +0 -1
  87. package/example/api/data/playlist/9648-53.json +0 -1
  88. package/example/api/data/playlist/9648-878.json +0 -1
  89. package/example/api/data/playlist/99-10749.json +0 -1
  90. package/example/api/data/playlist/99-14.json +0 -1
  91. package/example/api/data/playlist/99-18.json +0 -1
  92. package/example/api/data/playlist/99-27.json +0 -1
  93. package/example/api/data/playlist/99-53.json +0 -1
  94. package/example/api/data/playlist/99-9648.json +0 -1
  95. package/example/api/data/playlist/index.ts +0 -73
  96. package/example/api/data/rows.json +0 -1
  97. package/example/api/index.ts +0 -36
  98. package/example/app/(tabs)/_layout.tsx +0 -60
  99. package/example/app/(tabs)/cards.tsx +0 -81
  100. package/example/app/(tabs)/index.tsx +0 -205
  101. package/example/app/(tabs)/moviesL.tsx +0 -7
  102. package/example/app/(tabs)/moviesLR.tsx +0 -7
  103. package/example/app/+not-found.tsx +0 -32
  104. package/example/app/_layout.tsx +0 -34
  105. package/example/app/accurate-scrollto/index.tsx +0 -125
  106. package/example/app/accurate-scrollto-2/index.tsx +0 -52
  107. package/example/app/accurate-scrollto-huge/index.tsx +0 -128
  108. package/example/app/add-to-end/index.tsx +0 -82
  109. package/example/app/ai-chat/index.tsx +0 -236
  110. package/example/app/bidirectional-infinite-list/index.tsx +0 -133
  111. package/example/app/cards-columns/index.tsx +0 -37
  112. package/example/app/cards-flashlist/index.tsx +0 -122
  113. package/example/app/cards-flatlist/index.tsx +0 -94
  114. package/example/app/cards-no-recycle/index.tsx +0 -110
  115. package/example/app/cards-renderItem.tsx +0 -354
  116. package/example/app/chat-example/index.tsx +0 -167
  117. package/example/app/chat-infinite/index.tsx +0 -239
  118. package/example/app/chat-keyboard/index.tsx +0 -248
  119. package/example/app/chat-resize-outer/index.tsx +0 -247
  120. package/example/app/columns/index.tsx +0 -78
  121. package/example/app/countries/index.tsx +0 -182
  122. package/example/app/countries-flashlist/index.tsx +0 -163
  123. package/example/app/countries-reorder/index.tsx +0 -187
  124. package/example/app/extra-data/index.tsx +0 -86
  125. package/example/app/filter-elements/filter-data-provider.tsx +0 -55
  126. package/example/app/filter-elements/index.tsx +0 -118
  127. package/example/app/initial-scroll-index/index.tsx +0 -106
  128. package/example/app/initial-scroll-index/renderFixedItem.tsx +0 -215
  129. package/example/app/initial-scroll-index-free-height/index.tsx +0 -70
  130. package/example/app/initial-scroll-index-keyed/index.tsx +0 -62
  131. package/example/app/lazy-list/index.tsx +0 -123
  132. package/example/app/movies-flashlist/index.tsx +0 -7
  133. package/example/app/mutable-cells/index.tsx +0 -104
  134. package/example/app/video-feed/index.tsx +0 -119
  135. package/example/app.config.js +0 -22
  136. package/example/app.json +0 -45
  137. package/example/assets/fonts/SpaceMono-Regular.ttf +0 -0
  138. package/example/assets/images/adaptive-icon.png +0 -0
  139. package/example/assets/images/favicon.png +0 -0
  140. package/example/assets/images/icon.png +0 -0
  141. package/example/assets/images/partial-react-logo.png +0 -0
  142. package/example/assets/images/react-logo.png +0 -0
  143. package/example/assets/images/react-logo@2x.png +0 -0
  144. package/example/assets/images/react-logo@3x.png +0 -0
  145. package/example/assets/images/splash-icon.png +0 -0
  146. package/example/autoscroll.sh +0 -101
  147. package/example/bun.lock +0 -2266
  148. package/example/bunfig.toml +0 -2
  149. package/example/components/Breathe.tsx +0 -54
  150. package/example/components/Circle.tsx +0 -69
  151. package/example/components/Collapsible.tsx +0 -44
  152. package/example/components/ExternalLink.tsx +0 -24
  153. package/example/components/HapticTab.tsx +0 -18
  154. package/example/components/HelloWave.tsx +0 -37
  155. package/example/components/Movies.tsx +0 -179
  156. package/example/components/ParallaxScrollView.tsx +0 -81
  157. package/example/components/ThemedText.tsx +0 -60
  158. package/example/components/ThemedView.tsx +0 -14
  159. package/example/components/__tests__/ThemedText-test.tsx +0 -10
  160. package/example/components/__tests__/__snapshots__/ThemedText-test.tsx.snap +0 -24
  161. package/example/components/ui/IconSymbol.ios.tsx +0 -32
  162. package/example/components/ui/IconSymbol.tsx +0 -43
  163. package/example/components/ui/TabBarBackground.ios.tsx +0 -22
  164. package/example/components/ui/TabBarBackground.tsx +0 -6
  165. package/example/constants/Colors.ts +0 -26
  166. package/example/constants/constants.ts +0 -5
  167. package/example/constants/useScrollTest.ts +0 -19
  168. package/example/hooks/useColorScheme.ts +0 -1
  169. package/example/hooks/useColorScheme.web.ts +0 -8
  170. package/example/hooks/useThemeColor.ts +0 -22
  171. package/example/ios/.xcode.env +0 -11
  172. package/example/ios/Podfile +0 -64
  173. package/example/ios/Podfile.lock +0 -2767
  174. package/example/ios/Podfile.properties.json +0 -5
  175. package/example/ios/listtest/AppDelegate.swift +0 -70
  176. package/example/ios/listtest/Images.xcassets/AppIcon.appiconset/App-Icon-1024x1024@1x.png +0 -0
  177. package/example/ios/listtest/Images.xcassets/AppIcon.appiconset/Contents.json +0 -14
  178. package/example/ios/listtest/Images.xcassets/Contents.json +0 -6
  179. package/example/ios/listtest/Images.xcassets/SplashScreenBackground.colorset/Contents.json +0 -20
  180. package/example/ios/listtest/Images.xcassets/SplashScreenLogo.imageset/Contents.json +0 -23
  181. package/example/ios/listtest/Images.xcassets/SplashScreenLogo.imageset/image.png +0 -0
  182. package/example/ios/listtest/Images.xcassets/SplashScreenLogo.imageset/image@2x.png +0 -0
  183. package/example/ios/listtest/Images.xcassets/SplashScreenLogo.imageset/image@3x.png +0 -0
  184. package/example/ios/listtest/Info.plist +0 -85
  185. package/example/ios/listtest/PrivacyInfo.xcprivacy +0 -48
  186. package/example/ios/listtest/SplashScreen.storyboard +0 -42
  187. package/example/ios/listtest/Supporting/Expo.plist +0 -12
  188. package/example/ios/listtest/listtest-Bridging-Header.h +0 -3
  189. package/example/ios/listtest/listtest.entitlements +0 -5
  190. package/example/ios/listtest.xcodeproj/project.pbxproj +0 -547
  191. package/example/ios/listtest.xcodeproj/xcshareddata/xcschemes/listtest.xcscheme +0 -88
  192. package/example/ios/listtest.xcworkspace/contents.xcworkspacedata +0 -10
  193. package/example/metro.config.js +0 -16
  194. package/example/package.json +0 -73
  195. package/example/scripts/reset-project.js +0 -84
  196. package/example/tsconfig.json +0 -26
  197. package/posttsup.ts +0 -24
  198. package/src/Container.tsx +0 -176
  199. package/src/Containers.tsx +0 -85
  200. package/src/ContextContainer.ts +0 -145
  201. package/src/DebugView.tsx +0 -83
  202. package/src/LazyLegendList.tsx +0 -41
  203. package/src/LeanView.tsx +0 -18
  204. package/src/LegendList.tsx +0 -558
  205. package/src/ListComponent.tsx +0 -191
  206. package/src/ScrollAdjust.tsx +0 -24
  207. package/src/ScrollAdjustHandler.ts +0 -26
  208. package/src/Separator.tsx +0 -14
  209. package/src/animated.tsx +0 -6
  210. package/src/calculateItemsInView.ts +0 -363
  211. package/src/calculateOffsetForIndex.ts +0 -23
  212. package/src/calculateOffsetWithOffsetPosition.ts +0 -26
  213. package/src/checkAllSizesKnown.ts +0 -17
  214. package/src/checkAtBottom.ts +0 -36
  215. package/src/checkAtTop.ts +0 -27
  216. package/src/checkThreshold.ts +0 -30
  217. package/src/constants.ts +0 -11
  218. package/src/createColumnWrapperStyle.ts +0 -16
  219. package/src/doInitialAllocateContainers.ts +0 -40
  220. package/src/doMaintainScrollAtEnd.ts +0 -34
  221. package/src/findAvailableContainers.ts +0 -98
  222. package/src/finishScrollTo.ts +0 -8
  223. package/src/getId.ts +0 -21
  224. package/src/getItemSize.ts +0 -52
  225. package/src/getRenderedItem.ts +0 -34
  226. package/src/getScrollVelocity.ts +0 -47
  227. package/src/handleLayout.ts +0 -70
  228. package/src/helpers.ts +0 -39
  229. package/src/index.ts +0 -11
  230. package/src/keyboard-controller.tsx +0 -63
  231. package/src/onScroll.ts +0 -66
  232. package/src/prepareMVCP.ts +0 -50
  233. package/src/reanimated.tsx +0 -63
  234. package/src/requestAdjust.ts +0 -41
  235. package/src/scrollTo.ts +0 -40
  236. package/src/scrollToIndex.ts +0 -34
  237. package/src/setDidLayout.ts +0 -25
  238. package/src/setPaddingTop.ts +0 -28
  239. package/src/state.tsx +0 -304
  240. package/src/types.ts +0 -610
  241. package/src/updateAlignItemsPaddingTop.ts +0 -18
  242. package/src/updateAllPositions.ts +0 -130
  243. package/src/updateItemSize.ts +0 -203
  244. package/src/updateTotalSize.ts +0 -44
  245. package/src/useAnimatedValue.ts +0 -6
  246. package/src/useCombinedRef.ts +0 -22
  247. package/src/useInit.ts +0 -17
  248. package/src/useSyncLayout.tsx +0 -68
  249. package/src/useValue$.ts +0 -53
  250. package/src/viewability.ts +0 -279
  251. package/tsconfig.json +0 -59
  252. package/tsup.config.ts +0 -21
  253. /package/{dist/animated.js → animated.js} +0 -0
  254. /package/{dist/animated.mjs → animated.mjs} +0 -0
  255. /package/{dist/keyboard-controller.js → keyboard-controller.js} +0 -0
  256. /package/{dist/keyboard-controller.mjs → keyboard-controller.mjs} +0 -0
  257. /package/{dist/reanimated.d.mts → reanimated.d.mts} +0 -0
  258. /package/{dist/reanimated.d.ts → reanimated.d.ts} +0 -0
  259. /package/{dist/reanimated.js → reanimated.js} +0 -0
  260. /package/{dist/reanimated.mjs → reanimated.mjs} +0 -0
@@ -1,247 +0,0 @@
1
- import { LegendList } from "@legendapp/list";
2
- import { useHeaderHeight } from "@react-navigation/elements";
3
- import { Fragment, useState } from "react";
4
- import { KeyboardAvoidingView, Platform, Pressable, StyleSheet, Text, View } from "react-native";
5
- import { SafeAreaView } from "react-native-safe-area-context";
6
-
7
- type Message = {
8
- id: string;
9
- text: string;
10
- sender: "user" | "bot";
11
- timeStamp: number;
12
- };
13
-
14
- let idCounter = 0;
15
- const MS_PER_SECOND = 1000;
16
-
17
- const defaultChatMessages: Message[] = [
18
- {
19
- id: String(idCounter++),
20
- text: "Hi, I have a question about your product",
21
- sender: "user",
22
- timeStamp: Date.now() - MS_PER_SECOND * 5,
23
- },
24
- {
25
- id: String(idCounter++),
26
- text: "Hello there! How can I assist you today?",
27
- sender: "bot",
28
- timeStamp: Date.now() - MS_PER_SECOND * 4,
29
- },
30
- {
31
- id: String(idCounter++),
32
- text: "I'm looking for information about pricing plans",
33
- sender: "user",
34
- timeStamp: Date.now() - MS_PER_SECOND * 4,
35
- },
36
- {
37
- id: String(idCounter++),
38
- text: "We offer several pricing tiers based on your needs",
39
- sender: "bot",
40
- timeStamp: Date.now() - MS_PER_SECOND * 4,
41
- },
42
- {
43
- id: String(idCounter++),
44
- text: "Our basic plan starts at $9.99 per month",
45
- sender: "bot",
46
- timeStamp: Date.now() - MS_PER_SECOND * 4,
47
- },
48
- {
49
- id: String(idCounter++),
50
- text: "Do you offer any discounts for annual billing?",
51
- sender: "user",
52
- timeStamp: Date.now() - MS_PER_SECOND * 4,
53
- },
54
- {
55
- id: String(idCounter++),
56
- text: "Yes! You can save 20% with our annual billing option",
57
- sender: "bot",
58
- timeStamp: Date.now() - MS_PER_SECOND * 4,
59
- },
60
- {
61
- id: String(idCounter++),
62
- text: "That sounds great. What features are included?",
63
- sender: "user",
64
- timeStamp: Date.now() - MS_PER_SECOND * 4,
65
- },
66
- {
67
- id: String(idCounter++),
68
- text: "The basic plan includes all core features plus 10GB storage",
69
- sender: "bot",
70
- timeStamp: Date.now() - MS_PER_SECOND * 4,
71
- },
72
- {
73
- id: String(idCounter++),
74
- text: "Premium plans include priority support and additional tools",
75
- sender: "bot",
76
- timeStamp: Date.now() - MS_PER_SECOND * 4,
77
- },
78
- {
79
- id: String(idCounter++),
80
- text: "I think the basic plan would work for my needs",
81
- sender: "user",
82
- timeStamp: Date.now() - MS_PER_SECOND * 4,
83
- },
84
- {
85
- id: String(idCounter++),
86
- text: "Perfect! I can help you get set up with that",
87
- sender: "bot",
88
- timeStamp: Date.now() - MS_PER_SECOND * 4,
89
- },
90
- {
91
- id: String(idCounter++),
92
- text: "Thanks for your help so far",
93
- sender: "user",
94
- timeStamp: Date.now() - MS_PER_SECOND * 4,
95
- },
96
- {
97
- id: String(idCounter++),
98
- text: "You're welcome! Is there anything else I can assist with today?",
99
- sender: "bot",
100
- timeStamp: Date.now() - MS_PER_SECOND * 3,
101
- },
102
- ];
103
-
104
- const ChatResizeOuter = () => {
105
- const [messages, setMessages] = useState<Message[]>(defaultChatMessages);
106
- const [inputText, setInputText] = useState("");
107
- const headerHeight = Platform.OS === "ios" ? useHeaderHeight() : 80;
108
- const [buttonHeight, setButtonHeight] = useState(40);
109
-
110
- const sendMessage = () => {
111
- const text = inputText || "Empty message";
112
- if (text.trim()) {
113
- setMessages((messages) => [
114
- ...messages,
115
- { id: String(idCounter++), text: text, sender: "user", timeStamp: Date.now() },
116
- ]);
117
- setInputText("");
118
- setTimeout(() => {
119
- setMessages((messages) => [
120
- ...messages,
121
- {
122
- id: String(idCounter++),
123
- text: `Answer: ${text.toUpperCase()}`,
124
- sender: "bot",
125
- timeStamp: Date.now(),
126
- },
127
- ]);
128
- }, 300);
129
- }
130
- };
131
-
132
- return (
133
- <SafeAreaView style={styles.container} edges={["bottom"]}>
134
- <KeyboardAvoidingView
135
- style={styles.container}
136
- behavior="padding"
137
- keyboardVerticalOffset={headerHeight}
138
- contentContainerStyle={{ flex: 1 }}
139
- >
140
- <LegendList
141
- data={messages}
142
- contentContainerStyle={styles.contentContainer}
143
- keyExtractor={(item) => item.id}
144
- estimatedItemSize={10} // A size that's way too small to check the behavior is correct
145
- initialScrollIndex={messages.length - 1}
146
- maintainVisibleContentPosition
147
- maintainScrollAtEnd
148
- maintainScrollAtEndThreshold={0.1}
149
- alignItemsAtEnd
150
- renderItem={renderItem}
151
- />
152
- </KeyboardAvoidingView>
153
- <Pressable
154
- style={{
155
- height: buttonHeight,
156
- backgroundColor: "rgba(0, 0, 0, 0.1)",
157
- alignItems: "center",
158
- justifyContent: "center",
159
- }}
160
- onPress={() => {
161
- setButtonHeight(buttonHeight === 40 ? 300 : 40);
162
- }}
163
- >
164
- <Text style={{ fontSize: 16, fontWeight: "medium" }}>Resize</Text>
165
- </Pressable>
166
- </SafeAreaView>
167
- );
168
- };
169
-
170
- const styles = StyleSheet.create({
171
- container: {
172
- flex: 1,
173
- backgroundColor: "#fff",
174
- },
175
- contentContainer: {
176
- paddingHorizontal: 16,
177
- },
178
- messageContainer: {
179
- padding: 16,
180
- borderRadius: 16,
181
- marginVertical: 4,
182
- },
183
- messageText: {
184
- fontSize: 16,
185
- },
186
- userMessageText: {
187
- color: "white",
188
- },
189
- inputContainer: {
190
- flexDirection: "row",
191
- alignItems: "center",
192
- padding: 10,
193
- borderTopWidth: 1,
194
- borderColor: "#ccc",
195
- },
196
- botMessageContainer: {
197
- backgroundColor: "#f1f1f1",
198
- },
199
- userMessageContainer: {
200
- backgroundColor: "#007AFF",
201
- },
202
- botStyle: {
203
- maxWidth: "75%",
204
- alignSelf: "flex-start",
205
- },
206
- userStyle: {
207
- maxWidth: "75%",
208
- alignSelf: "flex-end",
209
- alignItems: "flex-end",
210
- },
211
- input: {
212
- flex: 1,
213
- borderWidth: 1,
214
- borderColor: "#ccc",
215
- borderRadius: 5,
216
- padding: 10,
217
- marginRight: 10,
218
- },
219
- timeStamp: {
220
- marginVertical: 5,
221
- },
222
- timeStampText: {
223
- fontSize: 12,
224
- color: "#888",
225
- },
226
- });
227
-
228
- export default ChatResizeOuter;
229
-
230
- const renderItem = ({ item }: { item: Message }) => {
231
- return (
232
- <Fragment>
233
- <View
234
- style={[
235
- styles.messageContainer,
236
- item.sender === "bot" ? styles.botMessageContainer : styles.userMessageContainer,
237
- item.sender === "bot" ? styles.botStyle : styles.userStyle,
238
- ]}
239
- >
240
- <Text style={[styles.messageText, item.sender === "user" && styles.userMessageText]}>{item.text}</Text>
241
- </View>
242
- <View style={[styles.timeStamp, item.sender === "bot" ? styles.botStyle : styles.userStyle]}>
243
- <Text style={styles.timeStampText}>{new Date(item.timeStamp).toLocaleTimeString()}</Text>
244
- </View>
245
- </Fragment>
246
- );
247
- };
@@ -1,78 +0,0 @@
1
- import { LegendList } from "@legendapp/list";
2
- import { useState } from "react";
3
- import { useEffect } from "react";
4
- import { LogBox, StyleSheet, Text, View } from "react-native";
5
-
6
- LogBox.ignoreLogs(["Open debugger"]);
7
-
8
- const initialData = Array.from({ length: 8 }, (_, index) => ({ id: index.toString() }));
9
-
10
- export default function Columns() {
11
- const [data, setData] = useState(initialData);
12
-
13
- useEffect(() => {
14
- setTimeout(() => {
15
- setData(Array.from({ length: 20 }, (_, index) => ({ id: index.toString() })));
16
- }, 1000);
17
- });
18
-
19
- return (
20
- <View style={styles.container}>
21
- <LegendList
22
- data={data}
23
- renderItem={Item}
24
- keyExtractor={(item) => item.id}
25
- numColumns={3}
26
- columnWrapperStyle={{
27
- columnGap: 16,
28
- rowGap: 16,
29
- }}
30
- />
31
- </View>
32
- );
33
- }
34
-
35
- function Item({ item }: { item: { id: string } }) {
36
- return (
37
- <View style={styles.redRectangle}>
38
- <View style={styles.redRectangleInner} />
39
- <Text>Item {item.id}</Text>
40
- </View>
41
- );
42
- }
43
-
44
- const styles = StyleSheet.create({
45
- container: {
46
- flex: 1,
47
- backgroundColor: "#fff",
48
- },
49
- redRectangle: {
50
- aspectRatio: 1,
51
- },
52
- redRectangleInner: {
53
- height: "100%",
54
- width: "100%",
55
- backgroundColor: "red",
56
- borderRadius: 8,
57
- },
58
- columnWrapper: {
59
- justifyContent: "space-between",
60
- },
61
- listHeader: {
62
- alignSelf: "center",
63
- height: 100,
64
- width: 100,
65
- backgroundColor: "#456AAA",
66
- borderRadius: 12,
67
- marginHorizontal: 8,
68
- marginVertical: 8,
69
- },
70
- listEmpty: {
71
- flex: 1,
72
- justifyContent: "center",
73
- alignItems: "center",
74
- backgroundColor: "#6789AB",
75
- paddingVertical: 16,
76
- height: 100,
77
- },
78
- });
@@ -1,182 +0,0 @@
1
- import { LegendList } from "@legendapp/list";
2
- import { type TCountryCode, countries, getEmojiFlag } from "countries-list";
3
- import { useMemo, useState } from "react";
4
- import { Pressable, StatusBar, StyleSheet, Text, TextInput, View } from "react-native";
5
- import { SafeAreaProvider, SafeAreaView } from "react-native-safe-area-context";
6
-
7
- export const unstable_settings = {
8
- initialRouteName: "index",
9
- };
10
-
11
- export const createTitle = () => "Countries";
12
-
13
- type Country = {
14
- id: string;
15
- name: string;
16
- flag: string;
17
- };
18
-
19
- // Convert countries object to array and add an id
20
- const DATA: Country[] = Object.entries(countries)
21
- .map(([code, country]) => ({
22
- id: code,
23
- name: country.name,
24
- flag: getEmojiFlag(code as TCountryCode),
25
- }))
26
- .sort((a, b) => a.name.localeCompare(b.name));
27
-
28
- type ItemProps = {
29
- item: Country;
30
- onPress: () => void;
31
- isSelected: boolean;
32
- };
33
-
34
- const Item = ({ item, onPress, isSelected }: ItemProps) => (
35
- <Pressable
36
- onPress={onPress}
37
- style={({ pressed }) => [styles.item, isSelected && styles.selectedItem, pressed && styles.pressedItem]}
38
- >
39
- <View style={styles.flagContainer}>
40
- <Text style={styles.flag}>{item.flag}</Text>
41
- </View>
42
- <View style={styles.contentContainer}>
43
- <Text style={[styles.title, isSelected && styles.selectedText]}>
44
- {item.name}
45
- <Text style={styles.countryCode}> ({item.id})</Text>
46
- </Text>
47
- </View>
48
- </Pressable>
49
- );
50
-
51
- const App = () => {
52
- const [selectedId, setSelectedId] = useState<string>();
53
- const [searchQuery, setSearchQuery] = useState("");
54
-
55
- const filteredData = useMemo(() => {
56
- const query = searchQuery.toLowerCase();
57
- return DATA.filter(
58
- (country) => country.name.toLowerCase().includes(query) || country.id.toLowerCase().includes(query),
59
- );
60
- }, [searchQuery]);
61
-
62
- const renderItem = ({ item }: { item: Country }) => {
63
- const isSelected = item.id === selectedId;
64
- return <Item item={item} onPress={() => setSelectedId(item.id)} isSelected={isSelected} />;
65
- };
66
-
67
- return (
68
- <SafeAreaProvider>
69
- <SafeAreaView style={styles.container}>
70
- <View style={styles.searchContainer}>
71
- <TextInput
72
- style={styles.searchInput}
73
- placeholder="Search country or code..."
74
- value={searchQuery}
75
- onChangeText={setSearchQuery}
76
- clearButtonMode="while-editing"
77
- autoCapitalize="none"
78
- autoCorrect={false}
79
- />
80
- </View>
81
- <LegendList
82
- data={filteredData}
83
- renderItem={renderItem}
84
- keyExtractor={(item) => item.id}
85
- extraData={selectedId}
86
- estimatedItemSize={70}
87
- recycleItems
88
- onStartReachedThreshold={0.1}
89
- onStartReached={({ distanceFromStart }) => {
90
- console.log("onStartReached", distanceFromStart);
91
- }}
92
- onEndReachedThreshold={0.1}
93
- onEndReached={({ distanceFromEnd }) => {
94
- console.log("onEndReached", distanceFromEnd);
95
- }}
96
- // ListHeaderComponent={<View style={{ height: 200, backgroundColor: "red" }} />}
97
- // ListFooterComponent={<View style={{ height: 200, backgroundColor: "blue" }} />}
98
- // ItemSeparatorComponent={Separator}
99
- />
100
- </SafeAreaView>
101
- </SafeAreaProvider>
102
- );
103
- };
104
-
105
- const Separator = () => <View style={{ height: 40, backgroundColor: "green" }} />;
106
-
107
- export default App;
108
-
109
- const styles = StyleSheet.create({
110
- container: {
111
- flex: 1,
112
- marginTop: StatusBar.currentHeight || 0,
113
- backgroundColor: "#f5f5f5",
114
- },
115
- searchContainer: {
116
- padding: 8,
117
- backgroundColor: "#fff",
118
- borderBottomWidth: 1,
119
- borderBottomColor: "#e0e0e0",
120
- },
121
- searchInput: {
122
- height: 40,
123
- backgroundColor: "#f5f5f5",
124
- borderRadius: 8,
125
- paddingHorizontal: 12,
126
- fontSize: 16,
127
- },
128
- item: {
129
- paddingHorizontal: 16,
130
- paddingVertical: 6,
131
- flexDirection: "row",
132
- alignItems: "center",
133
- backgroundColor: "#fff",
134
- borderRadius: 12,
135
- // shadowColor: "#000",
136
- // shadowOffset: {
137
- // width: 0,
138
- // height: 2,
139
- // },
140
- // shadowOpacity: 0.1,
141
- // shadowRadius: 3,
142
- // elevation: 3,
143
- },
144
- selectedItem: {
145
- // backgroundColor: "#e3f2fd",
146
- // borderColor: "#1976d2",
147
- // borderWidth: 1,
148
- },
149
- pressedItem: {
150
- // backgroundColor: "#f0f0f0",
151
- },
152
- flagContainer: {
153
- marginRight: 16,
154
- width: 40,
155
- height: 40,
156
- borderRadius: 20,
157
- backgroundColor: "#f8f9fa",
158
- alignItems: "center",
159
- justifyContent: "center",
160
- },
161
- flag: {
162
- fontSize: 28,
163
- },
164
- contentContainer: {
165
- flex: 1,
166
- justifyContent: "center",
167
- },
168
- title: {
169
- fontSize: 16,
170
- color: "#333",
171
- fontWeight: "500",
172
- },
173
- selectedText: {
174
- color: "#1976d2",
175
- fontWeight: "600",
176
- },
177
- countryCode: {
178
- fontSize: 14,
179
- color: "#666",
180
- fontWeight: "400",
181
- },
182
- });
@@ -1,163 +0,0 @@
1
- import { FlashList } from "@shopify/flash-list";
2
- import { type TCountryCode, countries, getEmojiFlag } from "countries-list";
3
- import { useMemo, useState } from "react";
4
- import { Pressable, StatusBar, StyleSheet, Text, TextInput, View } from "react-native";
5
- import { SafeAreaProvider, SafeAreaView } from "react-native-safe-area-context";
6
-
7
- export const unstable_settings = {
8
- initialRouteName: "index",
9
- };
10
-
11
- export const createTitle = () => "Countries";
12
-
13
- type Country = {
14
- id: string;
15
- name: string;
16
- flag: string;
17
- };
18
-
19
- // Convert countries object to array and add an id
20
- const DATA: Country[] = Object.entries(countries)
21
- .map(([code, country]) => ({
22
- id: code,
23
- name: country.name,
24
- flag: getEmojiFlag(code as TCountryCode),
25
- }))
26
- .sort((a, b) => a.name.localeCompare(b.name));
27
-
28
- type ItemProps = {
29
- item: Country;
30
- onPress: () => void;
31
- isSelected: boolean;
32
- };
33
-
34
- const Item = ({ item, onPress, isSelected }: ItemProps) => (
35
- <Pressable
36
- onPress={onPress}
37
- style={({ pressed }) => [styles.item, isSelected && styles.selectedItem, pressed && styles.pressedItem]}
38
- >
39
- <View style={styles.flagContainer}>
40
- <Text style={styles.flag}>{item.flag}</Text>
41
- </View>
42
- <View style={styles.contentContainer}>
43
- <Text style={[styles.title, isSelected && styles.selectedText]}>
44
- {item.name}
45
- <Text style={styles.countryCode}> ({item.id})</Text>
46
- </Text>
47
- </View>
48
- </Pressable>
49
- );
50
-
51
- const App = () => {
52
- const [selectedId, setSelectedId] = useState<string>();
53
- const [searchQuery, setSearchQuery] = useState("");
54
-
55
- const filteredData = useMemo(() => {
56
- const query = searchQuery.toLowerCase();
57
- return DATA.filter(
58
- (country) => country.name.toLowerCase().includes(query) || country.id.toLowerCase().includes(query),
59
- );
60
- }, [searchQuery]);
61
-
62
- const renderItem = ({ item }: { item: Country }) => {
63
- const isSelected = item.id === selectedId;
64
- return <Item item={item} onPress={() => setSelectedId(item.id)} isSelected={isSelected} />;
65
- };
66
-
67
- return (
68
- <SafeAreaProvider>
69
- <SafeAreaView style={styles.container}>
70
- <View style={styles.searchContainer}>
71
- <TextInput
72
- style={styles.searchInput}
73
- placeholder="Search country or code..."
74
- value={searchQuery}
75
- onChangeText={setSearchQuery}
76
- clearButtonMode="while-editing"
77
- autoCapitalize="none"
78
- autoCorrect={false}
79
- />
80
- </View>
81
- <FlashList
82
- data={filteredData}
83
- renderItem={renderItem}
84
- keyExtractor={(item) => item.id}
85
- extraData={selectedId}
86
- estimatedItemSize={70}
87
- //scrollEventThrottle={200}
88
- disableAutoLayout
89
- />
90
- </SafeAreaView>
91
- </SafeAreaProvider>
92
- );
93
- };
94
-
95
- export default App;
96
-
97
- const styles = StyleSheet.create({
98
- container: {
99
- flex: 1,
100
- marginTop: StatusBar.currentHeight || 0,
101
- backgroundColor: "#f5f5f5",
102
- },
103
- searchContainer: {
104
- padding: 8,
105
- backgroundColor: "#fff",
106
- borderBottomWidth: 1,
107
- borderBottomColor: "#e0e0e0",
108
- },
109
- searchInput: {
110
- height: 40,
111
- backgroundColor: "#f5f5f5",
112
- borderRadius: 8,
113
- paddingHorizontal: 12,
114
- fontSize: 16,
115
- },
116
- item: {
117
- paddingHorizontal: 16,
118
- paddingVertical: 6,
119
- flexDirection: "row",
120
- alignItems: "center",
121
- backgroundColor: "#fff",
122
- borderRadius: 12,
123
- // elevation: 3,
124
- },
125
- selectedItem: {
126
- // backgroundColor: "#e3f2fd",
127
- // borderColor: "#1976d2",
128
- // borderWidth: 1,
129
- },
130
- pressedItem: {
131
- // backgroundColor: "#f0f0f0",
132
- },
133
- flagContainer: {
134
- marginRight: 16,
135
- width: 40,
136
- height: 40,
137
- borderRadius: 20,
138
- backgroundColor: "#f8f9fa",
139
- alignItems: "center",
140
- justifyContent: "center",
141
- },
142
- flag: {
143
- fontSize: 28,
144
- },
145
- contentContainer: {
146
- flex: 1,
147
- justifyContent: "center",
148
- },
149
- title: {
150
- fontSize: 16,
151
- color: "#333",
152
- fontWeight: "500",
153
- },
154
- selectedText: {
155
- color: "#1976d2",
156
- fontWeight: "600",
157
- },
158
- countryCode: {
159
- fontSize: 14,
160
- color: "#666",
161
- fontWeight: "400",
162
- },
163
- });