@legendapp/list 2.0.0-next.0 → 2.0.0-next.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/settings.local.json +8 -0
- package/.cursor/rules/changelog.mdc +60 -0
- package/.github/FUNDING.yml +15 -0
- package/.gitignore +5 -0
- package/.prettierrc.json +5 -0
- package/.vscode/settings.json +14 -0
- package/CLAUDE.md +126 -0
- package/biome.json +46 -0
- package/bun.lock +1289 -0
- package/bunfig.toml +2 -0
- package/dist/CHANGELOG.md +119 -0
- package/dist/LICENSE +21 -0
- package/dist/README.md +139 -0
- package/{animated.d.mts → dist/animated.d.mts} +1 -1
- package/{animated.d.ts → dist/animated.d.ts} +1 -1
- package/{index.d.mts → dist/index.d.mts} +63 -15
- package/{index.d.ts → dist/index.d.ts} +63 -15
- package/dist/index.js +2525 -0
- package/dist/index.mjs +2497 -0
- package/{keyboard-controller.d.mts → dist/keyboard-controller.d.mts} +4 -4
- package/{keyboard-controller.d.ts → dist/keyboard-controller.d.ts} +4 -4
- package/dist/package.json +35 -0
- package/example/README.md +40 -0
- package/example/api/data/genres.json +23 -0
- package/example/api/data/playlist/10402-10749.json +1 -0
- package/example/api/data/playlist/10402-10770.json +1 -0
- package/example/api/data/playlist/10402-37.json +1 -0
- package/example/api/data/playlist/10749-10752.json +1 -0
- package/example/api/data/playlist/10749-10770.json +1 -0
- package/example/api/data/playlist/10749-37.json +1 -0
- package/example/api/data/playlist/10749-878.json +1 -0
- package/example/api/data/playlist/10751-10402.json +1 -0
- package/example/api/data/playlist/10751-10752.json +1 -0
- package/example/api/data/playlist/10751-37.json +1 -0
- package/example/api/data/playlist/10751-53.json +1 -0
- package/example/api/data/playlist/10751-878.json +1 -0
- package/example/api/data/playlist/10751-9648.json +1 -0
- package/example/api/data/playlist/10752-37.json +1 -0
- package/example/api/data/playlist/12-10402.json +1 -0
- package/example/api/data/playlist/12-10749.json +1 -0
- package/example/api/data/playlist/12-18.json +1 -0
- package/example/api/data/playlist/12-27.json +1 -0
- package/example/api/data/playlist/12-35.json +1 -0
- package/example/api/data/playlist/14-36.json +1 -0
- package/example/api/data/playlist/14-878.json +1 -0
- package/example/api/data/playlist/16-10751.json +1 -0
- package/example/api/data/playlist/16-10770.json +1 -0
- package/example/api/data/playlist/16-35.json +1 -0
- package/example/api/data/playlist/16-36.json +1 -0
- package/example/api/data/playlist/16-53.json +1 -0
- package/example/api/data/playlist/18-10751.json +1 -0
- package/example/api/data/playlist/18-10752.json +1 -0
- package/example/api/data/playlist/18-37.json +1 -0
- package/example/api/data/playlist/18-53.json +1 -0
- package/example/api/data/playlist/18-878.json +1 -0
- package/example/api/data/playlist/27-10749.json +1 -0
- package/example/api/data/playlist/27-10770.json +1 -0
- package/example/api/data/playlist/28-10749.json +1 -0
- package/example/api/data/playlist/28-10751.json +1 -0
- package/example/api/data/playlist/28-10770.json +1 -0
- package/example/api/data/playlist/28-16.json +1 -0
- package/example/api/data/playlist/28-18.json +1 -0
- package/example/api/data/playlist/28-36.json +1 -0
- package/example/api/data/playlist/28-37.json +1 -0
- package/example/api/data/playlist/28-53.json +1 -0
- package/example/api/data/playlist/28-80.json +1 -0
- package/example/api/data/playlist/28-99.json +1 -0
- package/example/api/data/playlist/35-10749.json +1 -0
- package/example/api/data/playlist/35-10751.json +1 -0
- package/example/api/data/playlist/35-10752.json +1 -0
- package/example/api/data/playlist/35-27.json +1 -0
- package/example/api/data/playlist/35-36.json +1 -0
- package/example/api/data/playlist/35-53.json +1 -0
- package/example/api/data/playlist/35-80.json +1 -0
- package/example/api/data/playlist/36-37.json +1 -0
- package/example/api/data/playlist/36-878.json +1 -0
- package/example/api/data/playlist/36-9648.json +1 -0
- package/example/api/data/playlist/53-10752.json +1 -0
- package/example/api/data/playlist/80-10770.json +1 -0
- package/example/api/data/playlist/80-14.json +1 -0
- package/example/api/data/playlist/80-18.json +1 -0
- package/example/api/data/playlist/80-37.json +1 -0
- package/example/api/data/playlist/878-37.json +1 -0
- package/example/api/data/playlist/9648-10770.json +1 -0
- package/example/api/data/playlist/9648-37.json +1 -0
- package/example/api/data/playlist/9648-53.json +1 -0
- package/example/api/data/playlist/9648-878.json +1 -0
- package/example/api/data/playlist/99-10749.json +1 -0
- package/example/api/data/playlist/99-14.json +1 -0
- package/example/api/data/playlist/99-18.json +1 -0
- package/example/api/data/playlist/99-27.json +1 -0
- package/example/api/data/playlist/99-53.json +1 -0
- package/example/api/data/playlist/99-9648.json +1 -0
- package/example/api/data/playlist/index.ts +73 -0
- package/example/api/data/rows.json +1 -0
- package/example/api/index.ts +36 -0
- package/example/app/(tabs)/_layout.tsx +60 -0
- package/example/app/(tabs)/cards.tsx +81 -0
- package/example/app/(tabs)/index.tsx +205 -0
- package/example/app/(tabs)/moviesL.tsx +7 -0
- package/example/app/(tabs)/moviesLR.tsx +7 -0
- package/example/app/+not-found.tsx +32 -0
- package/example/app/_layout.tsx +34 -0
- package/example/app/accurate-scrollto/index.tsx +125 -0
- package/example/app/accurate-scrollto-2/index.tsx +52 -0
- package/example/app/accurate-scrollto-huge/index.tsx +128 -0
- package/example/app/add-to-end/index.tsx +82 -0
- package/example/app/ai-chat/index.tsx +236 -0
- package/example/app/bidirectional-infinite-list/index.tsx +133 -0
- package/example/app/cards-columns/index.tsx +37 -0
- package/example/app/cards-flashlist/index.tsx +122 -0
- package/example/app/cards-flatlist/index.tsx +94 -0
- package/example/app/cards-no-recycle/index.tsx +110 -0
- package/example/app/cards-renderItem.tsx +354 -0
- package/example/app/chat-example/index.tsx +167 -0
- package/example/app/chat-infinite/index.tsx +239 -0
- package/example/app/chat-keyboard/index.tsx +248 -0
- package/example/app/chat-resize-outer/index.tsx +247 -0
- package/example/app/columns/index.tsx +78 -0
- package/example/app/countries/index.tsx +182 -0
- package/example/app/countries-flashlist/index.tsx +163 -0
- package/example/app/countries-reorder/index.tsx +187 -0
- package/example/app/extra-data/index.tsx +86 -0
- package/example/app/filter-elements/filter-data-provider.tsx +55 -0
- package/example/app/filter-elements/index.tsx +118 -0
- package/example/app/initial-scroll-index/index.tsx +106 -0
- package/example/app/initial-scroll-index/renderFixedItem.tsx +215 -0
- package/example/app/initial-scroll-index-free-height/index.tsx +70 -0
- package/example/app/initial-scroll-index-keyed/index.tsx +62 -0
- package/example/app/lazy-list/index.tsx +123 -0
- package/example/app/movies-flashlist/index.tsx +7 -0
- package/example/app/mutable-cells/index.tsx +104 -0
- package/example/app/video-feed/index.tsx +119 -0
- package/example/app.config.js +22 -0
- package/example/app.json +45 -0
- package/example/assets/fonts/SpaceMono-Regular.ttf +0 -0
- package/example/assets/images/adaptive-icon.png +0 -0
- package/example/assets/images/favicon.png +0 -0
- package/example/assets/images/icon.png +0 -0
- package/example/assets/images/partial-react-logo.png +0 -0
- package/example/assets/images/react-logo.png +0 -0
- package/example/assets/images/react-logo@2x.png +0 -0
- package/example/assets/images/react-logo@3x.png +0 -0
- package/example/assets/images/splash-icon.png +0 -0
- package/example/autoscroll.sh +101 -0
- package/example/bun.lock +2266 -0
- package/example/bunfig.toml +2 -0
- package/example/components/Breathe.tsx +54 -0
- package/example/components/Circle.tsx +69 -0
- package/example/components/Collapsible.tsx +44 -0
- package/example/components/ExternalLink.tsx +24 -0
- package/example/components/HapticTab.tsx +18 -0
- package/example/components/HelloWave.tsx +37 -0
- package/example/components/Movies.tsx +179 -0
- package/example/components/ParallaxScrollView.tsx +81 -0
- package/example/components/ThemedText.tsx +60 -0
- package/example/components/ThemedView.tsx +14 -0
- package/example/components/__tests__/ThemedText-test.tsx +10 -0
- package/example/components/__tests__/__snapshots__/ThemedText-test.tsx.snap +24 -0
- package/example/components/ui/IconSymbol.ios.tsx +32 -0
- package/example/components/ui/IconSymbol.tsx +43 -0
- package/example/components/ui/TabBarBackground.ios.tsx +22 -0
- package/example/components/ui/TabBarBackground.tsx +6 -0
- package/example/constants/Colors.ts +26 -0
- package/example/constants/constants.ts +5 -0
- package/example/constants/useScrollTest.ts +19 -0
- package/example/hooks/useColorScheme.ts +1 -0
- package/example/hooks/useColorScheme.web.ts +8 -0
- package/example/hooks/useThemeColor.ts +22 -0
- package/example/ios/.xcode.env +11 -0
- package/example/ios/Podfile +64 -0
- package/example/ios/Podfile.lock +2767 -0
- package/example/ios/Podfile.properties.json +5 -0
- package/example/ios/listtest/AppDelegate.swift +70 -0
- package/example/ios/listtest/Images.xcassets/AppIcon.appiconset/App-Icon-1024x1024@1x.png +0 -0
- package/example/ios/listtest/Images.xcassets/AppIcon.appiconset/Contents.json +14 -0
- package/example/ios/listtest/Images.xcassets/Contents.json +6 -0
- package/example/ios/listtest/Images.xcassets/SplashScreenBackground.colorset/Contents.json +20 -0
- package/example/ios/listtest/Images.xcassets/SplashScreenLogo.imageset/Contents.json +23 -0
- package/example/ios/listtest/Images.xcassets/SplashScreenLogo.imageset/image.png +0 -0
- package/example/ios/listtest/Images.xcassets/SplashScreenLogo.imageset/image@2x.png +0 -0
- package/example/ios/listtest/Images.xcassets/SplashScreenLogo.imageset/image@3x.png +0 -0
- package/example/ios/listtest/Info.plist +85 -0
- package/example/ios/listtest/PrivacyInfo.xcprivacy +48 -0
- package/example/ios/listtest/SplashScreen.storyboard +42 -0
- package/example/ios/listtest/Supporting/Expo.plist +12 -0
- package/example/ios/listtest/listtest-Bridging-Header.h +3 -0
- package/example/ios/listtest/listtest.entitlements +5 -0
- package/example/ios/listtest.xcodeproj/project.pbxproj +547 -0
- package/example/ios/listtest.xcodeproj/xcshareddata/xcschemes/listtest.xcscheme +88 -0
- package/example/ios/listtest.xcworkspace/contents.xcworkspacedata +10 -0
- package/example/metro.config.js +16 -0
- package/example/package.json +73 -0
- package/example/scripts/reset-project.js +84 -0
- package/example/tsconfig.json +26 -0
- package/package.json +88 -34
- package/posttsup.ts +24 -0
- package/src/Container.tsx +176 -0
- package/src/Containers.tsx +85 -0
- package/src/ContextContainer.ts +145 -0
- package/src/DebugView.tsx +83 -0
- package/src/LazyLegendList.tsx +41 -0
- package/src/LeanView.tsx +18 -0
- package/src/LegendList.tsx +558 -0
- package/src/ListComponent.tsx +191 -0
- package/src/ScrollAdjust.tsx +24 -0
- package/src/ScrollAdjustHandler.ts +26 -0
- package/src/Separator.tsx +14 -0
- package/src/animated.tsx +6 -0
- package/src/calculateItemsInView.ts +363 -0
- package/src/calculateOffsetForIndex.ts +23 -0
- package/src/calculateOffsetWithOffsetPosition.ts +26 -0
- package/src/checkAllSizesKnown.ts +17 -0
- package/src/checkAtBottom.ts +36 -0
- package/src/checkAtTop.ts +27 -0
- package/src/checkThreshold.ts +30 -0
- package/src/constants.ts +11 -0
- package/src/createColumnWrapperStyle.ts +16 -0
- package/src/doInitialAllocateContainers.ts +40 -0
- package/src/doMaintainScrollAtEnd.ts +34 -0
- package/src/findAvailableContainers.ts +98 -0
- package/src/finishScrollTo.ts +8 -0
- package/src/getId.ts +21 -0
- package/src/getItemSize.ts +52 -0
- package/src/getRenderedItem.ts +34 -0
- package/src/getScrollVelocity.ts +47 -0
- package/src/handleLayout.ts +70 -0
- package/src/helpers.ts +39 -0
- package/src/index.ts +11 -0
- package/src/keyboard-controller.tsx +63 -0
- package/src/onScroll.ts +66 -0
- package/src/prepareMVCP.ts +50 -0
- package/src/reanimated.tsx +63 -0
- package/src/requestAdjust.ts +41 -0
- package/src/scrollTo.ts +40 -0
- package/src/scrollToIndex.ts +34 -0
- package/src/setDidLayout.ts +25 -0
- package/src/setPaddingTop.ts +28 -0
- package/src/state.tsx +304 -0
- package/src/types.ts +610 -0
- package/src/updateAlignItemsPaddingTop.ts +18 -0
- package/src/updateAllPositions.ts +130 -0
- package/src/updateItemSize.ts +203 -0
- package/src/updateTotalSize.ts +44 -0
- package/src/useAnimatedValue.ts +6 -0
- package/src/useCombinedRef.ts +22 -0
- package/src/useInit.ts +17 -0
- package/src/useSyncLayout.tsx +68 -0
- package/src/useValue$.ts +53 -0
- package/src/viewability.ts +279 -0
- package/tsconfig.json +59 -0
- package/tsup.config.ts +21 -0
- package/index.js +0 -2348
- package/index.mjs +0 -2320
- /package/{animated.js → dist/animated.js} +0 -0
- /package/{animated.mjs → dist/animated.mjs} +0 -0
- /package/{keyboard-controller.js → dist/keyboard-controller.js} +0 -0
- /package/{keyboard-controller.mjs → dist/keyboard-controller.mjs} +0 -0
- /package/{reanimated.d.mts → dist/reanimated.d.mts} +0 -0
- /package/{reanimated.d.ts → dist/reanimated.d.ts} +0 -0
- /package/{reanimated.js → dist/reanimated.js} +0 -0
- /package/{reanimated.mjs → dist/reanimated.mjs} +0 -0
|
@@ -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,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
|
+
});
|