@legendapp/list 2.0.0-next.1 → 2.0.0-next.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/settings.local.json +8 -0
- package/.cursor/rules/changelog.mdc +60 -0
- package/.github/FUNDING.yml +15 -0
- package/.gitignore +5 -0
- package/.prettierrc.json +5 -0
- package/.vscode/settings.json +14 -0
- package/CLAUDE.md +126 -0
- package/biome.json +46 -0
- package/bun.lock +1289 -0
- package/bunfig.toml +2 -0
- package/dist/CHANGELOG.md +119 -0
- package/dist/LICENSE +21 -0
- package/dist/README.md +139 -0
- package/{animated.d.mts → dist/animated.d.mts} +1 -1
- package/{animated.d.ts → dist/animated.d.ts} +1 -1
- package/{index.d.mts → dist/index.d.mts} +16 -10
- package/{index.d.ts → dist/index.d.ts} +16 -10
- package/{index.js → dist/index.js} +52 -32
- package/{index.mjs → dist/index.mjs} +52 -32
- package/{keyboard-controller.d.mts → dist/keyboard-controller.d.mts} +4 -4
- package/{keyboard-controller.d.ts → dist/keyboard-controller.d.ts} +4 -4
- package/dist/package.json +35 -0
- package/example/README.md +40 -0
- package/example/api/data/genres.json +23 -0
- package/example/api/data/playlist/10402-10749.json +1 -0
- package/example/api/data/playlist/10402-10770.json +1 -0
- package/example/api/data/playlist/10402-37.json +1 -0
- package/example/api/data/playlist/10749-10752.json +1 -0
- package/example/api/data/playlist/10749-10770.json +1 -0
- package/example/api/data/playlist/10749-37.json +1 -0
- package/example/api/data/playlist/10749-878.json +1 -0
- package/example/api/data/playlist/10751-10402.json +1 -0
- package/example/api/data/playlist/10751-10752.json +1 -0
- package/example/api/data/playlist/10751-37.json +1 -0
- package/example/api/data/playlist/10751-53.json +1 -0
- package/example/api/data/playlist/10751-878.json +1 -0
- package/example/api/data/playlist/10751-9648.json +1 -0
- package/example/api/data/playlist/10752-37.json +1 -0
- package/example/api/data/playlist/12-10402.json +1 -0
- package/example/api/data/playlist/12-10749.json +1 -0
- package/example/api/data/playlist/12-18.json +1 -0
- package/example/api/data/playlist/12-27.json +1 -0
- package/example/api/data/playlist/12-35.json +1 -0
- package/example/api/data/playlist/14-36.json +1 -0
- package/example/api/data/playlist/14-878.json +1 -0
- package/example/api/data/playlist/16-10751.json +1 -0
- package/example/api/data/playlist/16-10770.json +1 -0
- package/example/api/data/playlist/16-35.json +1 -0
- package/example/api/data/playlist/16-36.json +1 -0
- package/example/api/data/playlist/16-53.json +1 -0
- package/example/api/data/playlist/18-10751.json +1 -0
- package/example/api/data/playlist/18-10752.json +1 -0
- package/example/api/data/playlist/18-37.json +1 -0
- package/example/api/data/playlist/18-53.json +1 -0
- package/example/api/data/playlist/18-878.json +1 -0
- package/example/api/data/playlist/27-10749.json +1 -0
- package/example/api/data/playlist/27-10770.json +1 -0
- package/example/api/data/playlist/28-10749.json +1 -0
- package/example/api/data/playlist/28-10751.json +1 -0
- package/example/api/data/playlist/28-10770.json +1 -0
- package/example/api/data/playlist/28-16.json +1 -0
- package/example/api/data/playlist/28-18.json +1 -0
- package/example/api/data/playlist/28-36.json +1 -0
- package/example/api/data/playlist/28-37.json +1 -0
- package/example/api/data/playlist/28-53.json +1 -0
- package/example/api/data/playlist/28-80.json +1 -0
- package/example/api/data/playlist/28-99.json +1 -0
- package/example/api/data/playlist/35-10749.json +1 -0
- package/example/api/data/playlist/35-10751.json +1 -0
- package/example/api/data/playlist/35-10752.json +1 -0
- package/example/api/data/playlist/35-27.json +1 -0
- package/example/api/data/playlist/35-36.json +1 -0
- package/example/api/data/playlist/35-53.json +1 -0
- package/example/api/data/playlist/35-80.json +1 -0
- package/example/api/data/playlist/36-37.json +1 -0
- package/example/api/data/playlist/36-878.json +1 -0
- package/example/api/data/playlist/36-9648.json +1 -0
- package/example/api/data/playlist/53-10752.json +1 -0
- package/example/api/data/playlist/80-10770.json +1 -0
- package/example/api/data/playlist/80-14.json +1 -0
- package/example/api/data/playlist/80-18.json +1 -0
- package/example/api/data/playlist/80-37.json +1 -0
- package/example/api/data/playlist/878-37.json +1 -0
- package/example/api/data/playlist/9648-10770.json +1 -0
- package/example/api/data/playlist/9648-37.json +1 -0
- package/example/api/data/playlist/9648-53.json +1 -0
- package/example/api/data/playlist/9648-878.json +1 -0
- package/example/api/data/playlist/99-10749.json +1 -0
- package/example/api/data/playlist/99-14.json +1 -0
- package/example/api/data/playlist/99-18.json +1 -0
- package/example/api/data/playlist/99-27.json +1 -0
- package/example/api/data/playlist/99-53.json +1 -0
- package/example/api/data/playlist/99-9648.json +1 -0
- package/example/api/data/playlist/index.ts +73 -0
- package/example/api/data/rows.json +1 -0
- package/example/api/index.ts +36 -0
- package/example/app/(tabs)/_layout.tsx +60 -0
- package/example/app/(tabs)/cards.tsx +81 -0
- package/example/app/(tabs)/index.tsx +205 -0
- package/example/app/(tabs)/moviesL.tsx +7 -0
- package/example/app/(tabs)/moviesLR.tsx +7 -0
- package/example/app/+not-found.tsx +32 -0
- package/example/app/_layout.tsx +34 -0
- package/example/app/accurate-scrollto/index.tsx +125 -0
- package/example/app/accurate-scrollto-2/index.tsx +52 -0
- package/example/app/accurate-scrollto-huge/index.tsx +128 -0
- package/example/app/add-to-end/index.tsx +82 -0
- package/example/app/ai-chat/index.tsx +236 -0
- package/example/app/bidirectional-infinite-list/index.tsx +133 -0
- package/example/app/cards-columns/index.tsx +37 -0
- package/example/app/cards-flashlist/index.tsx +122 -0
- package/example/app/cards-flatlist/index.tsx +94 -0
- package/example/app/cards-no-recycle/index.tsx +110 -0
- package/example/app/cards-renderItem.tsx +354 -0
- package/example/app/chat-example/index.tsx +167 -0
- package/example/app/chat-infinite/index.tsx +239 -0
- package/example/app/chat-keyboard/index.tsx +248 -0
- package/example/app/chat-resize-outer/index.tsx +247 -0
- package/example/app/columns/index.tsx +78 -0
- package/example/app/countries/index.tsx +182 -0
- package/example/app/countries-flashlist/index.tsx +163 -0
- package/example/app/countries-reorder/index.tsx +187 -0
- package/example/app/extra-data/index.tsx +86 -0
- package/example/app/filter-elements/filter-data-provider.tsx +55 -0
- package/example/app/filter-elements/index.tsx +118 -0
- package/example/app/initial-scroll-index/index.tsx +106 -0
- package/example/app/initial-scroll-index/renderFixedItem.tsx +215 -0
- package/example/app/initial-scroll-index-free-height/index.tsx +70 -0
- package/example/app/initial-scroll-index-keyed/index.tsx +62 -0
- package/example/app/lazy-list/index.tsx +123 -0
- package/example/app/movies-flashlist/index.tsx +7 -0
- package/example/app/mutable-cells/index.tsx +104 -0
- package/example/app/video-feed/index.tsx +119 -0
- package/example/app.config.js +22 -0
- package/example/app.json +45 -0
- package/example/assets/fonts/SpaceMono-Regular.ttf +0 -0
- package/example/assets/images/adaptive-icon.png +0 -0
- package/example/assets/images/favicon.png +0 -0
- package/example/assets/images/icon.png +0 -0
- package/example/assets/images/partial-react-logo.png +0 -0
- package/example/assets/images/react-logo.png +0 -0
- package/example/assets/images/react-logo@2x.png +0 -0
- package/example/assets/images/react-logo@3x.png +0 -0
- package/example/assets/images/splash-icon.png +0 -0
- package/example/autoscroll.sh +101 -0
- package/example/bun.lock +2266 -0
- package/example/bunfig.toml +2 -0
- package/example/components/Breathe.tsx +54 -0
- package/example/components/Circle.tsx +69 -0
- package/example/components/Collapsible.tsx +44 -0
- package/example/components/ExternalLink.tsx +24 -0
- package/example/components/HapticTab.tsx +18 -0
- package/example/components/HelloWave.tsx +37 -0
- package/example/components/Movies.tsx +179 -0
- package/example/components/ParallaxScrollView.tsx +81 -0
- package/example/components/ThemedText.tsx +60 -0
- package/example/components/ThemedView.tsx +14 -0
- package/example/components/__tests__/ThemedText-test.tsx +10 -0
- package/example/components/__tests__/__snapshots__/ThemedText-test.tsx.snap +24 -0
- package/example/components/ui/IconSymbol.ios.tsx +32 -0
- package/example/components/ui/IconSymbol.tsx +43 -0
- package/example/components/ui/TabBarBackground.ios.tsx +22 -0
- package/example/components/ui/TabBarBackground.tsx +6 -0
- package/example/constants/Colors.ts +26 -0
- package/example/constants/constants.ts +5 -0
- package/example/constants/useScrollTest.ts +19 -0
- package/example/hooks/useColorScheme.ts +1 -0
- package/example/hooks/useColorScheme.web.ts +8 -0
- package/example/hooks/useThemeColor.ts +22 -0
- package/example/ios/.xcode.env +11 -0
- package/example/ios/Podfile +64 -0
- package/example/ios/Podfile.lock +2767 -0
- package/example/ios/Podfile.properties.json +5 -0
- package/example/ios/listtest/AppDelegate.swift +70 -0
- package/example/ios/listtest/Images.xcassets/AppIcon.appiconset/App-Icon-1024x1024@1x.png +0 -0
- package/example/ios/listtest/Images.xcassets/AppIcon.appiconset/Contents.json +14 -0
- package/example/ios/listtest/Images.xcassets/Contents.json +6 -0
- package/example/ios/listtest/Images.xcassets/SplashScreenBackground.colorset/Contents.json +20 -0
- package/example/ios/listtest/Images.xcassets/SplashScreenLogo.imageset/Contents.json +23 -0
- package/example/ios/listtest/Images.xcassets/SplashScreenLogo.imageset/image.png +0 -0
- package/example/ios/listtest/Images.xcassets/SplashScreenLogo.imageset/image@2x.png +0 -0
- package/example/ios/listtest/Images.xcassets/SplashScreenLogo.imageset/image@3x.png +0 -0
- package/example/ios/listtest/Info.plist +85 -0
- package/example/ios/listtest/PrivacyInfo.xcprivacy +48 -0
- package/example/ios/listtest/SplashScreen.storyboard +42 -0
- package/example/ios/listtest/Supporting/Expo.plist +12 -0
- package/example/ios/listtest/listtest-Bridging-Header.h +3 -0
- package/example/ios/listtest/listtest.entitlements +5 -0
- package/example/ios/listtest.xcodeproj/project.pbxproj +547 -0
- package/example/ios/listtest.xcodeproj/xcshareddata/xcschemes/listtest.xcscheme +88 -0
- package/example/ios/listtest.xcworkspace/contents.xcworkspacedata +10 -0
- package/example/metro.config.js +16 -0
- package/example/package.json +73 -0
- package/example/scripts/reset-project.js +84 -0
- package/example/tsconfig.json +26 -0
- package/package.json +88 -34
- package/posttsup.ts +24 -0
- package/src/Container.tsx +176 -0
- package/src/Containers.tsx +85 -0
- package/src/ContextContainer.ts +145 -0
- package/src/DebugView.tsx +83 -0
- package/src/LazyLegendList.tsx +41 -0
- package/src/LeanView.tsx +18 -0
- package/src/LegendList.tsx +558 -0
- package/src/ListComponent.tsx +191 -0
- package/src/ScrollAdjust.tsx +24 -0
- package/src/ScrollAdjustHandler.ts +26 -0
- package/src/Separator.tsx +14 -0
- package/src/animated.tsx +6 -0
- package/src/calculateItemsInView.ts +363 -0
- package/src/calculateOffsetForIndex.ts +23 -0
- package/src/calculateOffsetWithOffsetPosition.ts +26 -0
- package/src/checkAllSizesKnown.ts +17 -0
- package/src/checkAtBottom.ts +36 -0
- package/src/checkAtTop.ts +27 -0
- package/src/checkThreshold.ts +30 -0
- package/src/constants.ts +11 -0
- package/src/createColumnWrapperStyle.ts +16 -0
- package/src/doInitialAllocateContainers.ts +40 -0
- package/src/doMaintainScrollAtEnd.ts +34 -0
- package/src/findAvailableContainers.ts +98 -0
- package/src/finishScrollTo.ts +8 -0
- package/src/getId.ts +21 -0
- package/src/getItemSize.ts +52 -0
- package/src/getRenderedItem.ts +34 -0
- package/src/getScrollVelocity.ts +47 -0
- package/src/handleLayout.ts +70 -0
- package/src/helpers.ts +39 -0
- package/src/index.ts +11 -0
- package/src/keyboard-controller.tsx +63 -0
- package/src/onScroll.ts +66 -0
- package/src/prepareMVCP.ts +50 -0
- package/src/reanimated.tsx +63 -0
- package/src/requestAdjust.ts +41 -0
- package/src/scrollTo.ts +40 -0
- package/src/scrollToIndex.ts +34 -0
- package/src/setDidLayout.ts +25 -0
- package/src/setPaddingTop.ts +28 -0
- package/src/state.tsx +304 -0
- package/src/types.ts +610 -0
- package/src/updateAlignItemsPaddingTop.ts +18 -0
- package/src/updateAllPositions.ts +130 -0
- package/src/updateItemSize.ts +203 -0
- package/src/updateTotalSize.ts +44 -0
- package/src/useAnimatedValue.ts +6 -0
- package/src/useCombinedRef.ts +22 -0
- package/src/useInit.ts +17 -0
- package/src/useSyncLayout.tsx +68 -0
- package/src/useValue$.ts +53 -0
- package/src/viewability.ts +279 -0
- package/tsconfig.json +59 -0
- package/tsup.config.ts +21 -0
- /package/{animated.js → dist/animated.js} +0 -0
- /package/{animated.mjs → dist/animated.mjs} +0 -0
- /package/{keyboard-controller.js → dist/keyboard-controller.js} +0 -0
- /package/{keyboard-controller.mjs → dist/keyboard-controller.mjs} +0 -0
- /package/{reanimated.d.mts → dist/reanimated.d.mts} +0 -0
- /package/{reanimated.d.ts → dist/reanimated.d.ts} +0 -0
- /package/{reanimated.js → dist/reanimated.js} +0 -0
- /package/{reanimated.mjs → dist/reanimated.mjs} +0 -0
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { type Item, renderItem } from "@/app/cards-renderItem";
|
|
2
|
+
import { DO_SCROLL_TEST, DRAW_DISTANCE, ESTIMATED_ITEM_LENGTH } from "@/constants/constants";
|
|
3
|
+
import { useScrollTest } from "@/constants/useScrollTest";
|
|
4
|
+
import { LegendList, type LegendListRef } from "@legendapp/list";
|
|
5
|
+
import { useRef, useState } from "react";
|
|
6
|
+
import { LogBox, Platform, StyleSheet, Text, View } from "react-native";
|
|
7
|
+
|
|
8
|
+
LogBox.ignoreLogs(["Open debugger"]);
|
|
9
|
+
|
|
10
|
+
interface CardsProps {
|
|
11
|
+
numColumns?: number;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export default function Cards({ numColumns = 1 }: CardsProps) {
|
|
15
|
+
const listRef = useRef<LegendListRef>(null);
|
|
16
|
+
|
|
17
|
+
const [data, setData] = useState<Item[]>(
|
|
18
|
+
() =>
|
|
19
|
+
Array.from({ length: 1000 }, (_, i) => ({
|
|
20
|
+
id: i.toString(),
|
|
21
|
+
})) as any[],
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
if (DO_SCROLL_TEST) {
|
|
25
|
+
useScrollTest((offset) => {
|
|
26
|
+
listRef.current?.scrollToOffset({
|
|
27
|
+
offset: offset,
|
|
28
|
+
animated: true,
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<View style={[StyleSheet.absoluteFill, styles.outerContainer]} key="legendlist">
|
|
35
|
+
<LegendList
|
|
36
|
+
ref={listRef}
|
|
37
|
+
style={[StyleSheet.absoluteFill, styles.scrollContainer]}
|
|
38
|
+
contentContainerStyle={styles.listContainer}
|
|
39
|
+
data={data}
|
|
40
|
+
renderItem={renderItem}
|
|
41
|
+
keyExtractor={(item) => `id${item.id}`}
|
|
42
|
+
estimatedItemSize={ESTIMATED_ITEM_LENGTH}
|
|
43
|
+
drawDistance={DRAW_DISTANCE}
|
|
44
|
+
recycleItems={false}
|
|
45
|
+
numColumns={numColumns}
|
|
46
|
+
// initialScrollIndex={50}
|
|
47
|
+
// alignItemsAtEnd
|
|
48
|
+
// maintainScrollAtEnd
|
|
49
|
+
// onEndReached={({ distanceFromEnd }) => {
|
|
50
|
+
// console.log("onEndReached", distanceFromEnd);
|
|
51
|
+
// }}
|
|
52
|
+
ListHeaderComponent={<View />}
|
|
53
|
+
ListHeaderComponentStyle={styles.listHeader}
|
|
54
|
+
ListFooterComponent={<View />}
|
|
55
|
+
ListFooterComponentStyle={styles.listHeader}
|
|
56
|
+
ListEmptyComponent={
|
|
57
|
+
<View style={styles.listEmpty}>
|
|
58
|
+
<Text style={{ color: "white" }}>Empty</Text>
|
|
59
|
+
</View>
|
|
60
|
+
}
|
|
61
|
+
// viewabilityConfigCallbackPairs={[
|
|
62
|
+
// {
|
|
63
|
+
// viewabilityConfig: { id: "viewability", viewAreaCoveragePercentThreshold: 50 },
|
|
64
|
+
// // onViewableItemsChanged: ({ viewableItems, changed }) => {
|
|
65
|
+
// // console.log(
|
|
66
|
+
// // 'onViewableItems',
|
|
67
|
+
// // viewableItems.map((v) => v.key),
|
|
68
|
+
// // );
|
|
69
|
+
// // // console.log('onViewableChanged', changed);
|
|
70
|
+
// // },
|
|
71
|
+
// },
|
|
72
|
+
// ]}
|
|
73
|
+
|
|
74
|
+
// initialScrollOffset={20000}
|
|
75
|
+
// initialScrollIndex={500}
|
|
76
|
+
// inverted
|
|
77
|
+
// horizontal
|
|
78
|
+
/>
|
|
79
|
+
</View>
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const styles = StyleSheet.create({
|
|
84
|
+
listHeader: {
|
|
85
|
+
alignSelf: "center",
|
|
86
|
+
height: 100,
|
|
87
|
+
width: 100,
|
|
88
|
+
backgroundColor: "#456AAA",
|
|
89
|
+
borderRadius: 12,
|
|
90
|
+
marginHorizontal: 8,
|
|
91
|
+
marginVertical: 8,
|
|
92
|
+
},
|
|
93
|
+
listEmpty: {
|
|
94
|
+
flex: 1,
|
|
95
|
+
justifyContent: "center",
|
|
96
|
+
alignItems: "center",
|
|
97
|
+
backgroundColor: "#6789AB",
|
|
98
|
+
paddingVertical: 16,
|
|
99
|
+
},
|
|
100
|
+
outerContainer: {
|
|
101
|
+
backgroundColor: "#456",
|
|
102
|
+
bottom: Platform.OS === "ios" ? 82 : 0,
|
|
103
|
+
},
|
|
104
|
+
scrollContainer: {},
|
|
105
|
+
listContainer: {
|
|
106
|
+
width: 400,
|
|
107
|
+
maxWidth: "100%",
|
|
108
|
+
marginHorizontal: "auto",
|
|
109
|
+
},
|
|
110
|
+
});
|
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
import { MaterialIcons } from "@expo/vector-icons";
|
|
2
|
+
import { LegendList, type LegendListRenderItemProps, useRecyclingState } from "@legendapp/list";
|
|
3
|
+
import { memo, useRef, useState } from "react";
|
|
4
|
+
import { Animated, Image, Platform, Pressable, StyleSheet, Text, UIManager, View } from "react-native";
|
|
5
|
+
import { RectButton } from "react-native-gesture-handler";
|
|
6
|
+
import Swipeable, { type SwipeableMethods } from "react-native-gesture-handler/ReanimatedSwipeable";
|
|
7
|
+
|
|
8
|
+
export interface Item {
|
|
9
|
+
id: string;
|
|
10
|
+
}
|
|
11
|
+
const demoNestedList = false;
|
|
12
|
+
|
|
13
|
+
// Generate random metadata
|
|
14
|
+
const randomAvatars = Array.from({ length: 20 }, (_, i) => `https://i.pravatar.cc/150?img=${i + 1}`);
|
|
15
|
+
|
|
16
|
+
export const randomNames = [
|
|
17
|
+
"Alex Thompson",
|
|
18
|
+
"Jordan Lee",
|
|
19
|
+
"Sam Parker",
|
|
20
|
+
"Taylor Kim",
|
|
21
|
+
"Morgan Chen",
|
|
22
|
+
"Riley Zhang",
|
|
23
|
+
"Casey Williams",
|
|
24
|
+
"Quinn Anderson",
|
|
25
|
+
"Blake Martinez",
|
|
26
|
+
"Avery Rodriguez",
|
|
27
|
+
"Drew Campbell",
|
|
28
|
+
"Jamie Foster",
|
|
29
|
+
"Skylar Patel",
|
|
30
|
+
"Charlie Wright",
|
|
31
|
+
"Sage Mitchell",
|
|
32
|
+
"River Johnson",
|
|
33
|
+
"Phoenix Garcia",
|
|
34
|
+
"Jordan Taylor",
|
|
35
|
+
"Reese Cooper",
|
|
36
|
+
"Morgan Bailey",
|
|
37
|
+
];
|
|
38
|
+
|
|
39
|
+
// Array of lorem ipsum sentences to randomly choose from
|
|
40
|
+
export const loremSentences = [
|
|
41
|
+
"Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
|
|
42
|
+
"Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
|
|
43
|
+
"Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris.",
|
|
44
|
+
"Duis aute irure dolor in reprehenderit in voluptate velit esse.",
|
|
45
|
+
"Excepteur sint occaecat cupidatat non proident, sunt in culpa.",
|
|
46
|
+
"Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit.",
|
|
47
|
+
"Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet.",
|
|
48
|
+
"Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
|
|
49
|
+
"Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
|
|
50
|
+
"Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris.",
|
|
51
|
+
"Duis aute irure dolor in reprehenderit in voluptate velit esse.",
|
|
52
|
+
"Excepteur sint occaecat cupidatat non proident, sunt in culpa.",
|
|
53
|
+
"Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit.",
|
|
54
|
+
"Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet.",
|
|
55
|
+
];
|
|
56
|
+
|
|
57
|
+
if (Platform.OS === "android") {
|
|
58
|
+
if (UIManager.setLayoutAnimationEnabledExperimental) {
|
|
59
|
+
UIManager.setLayoutAnimationEnabledExperimental(true);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const renderRightActions = () => {
|
|
64
|
+
return (
|
|
65
|
+
<RectButton
|
|
66
|
+
style={{
|
|
67
|
+
width: 80,
|
|
68
|
+
height: "100%",
|
|
69
|
+
backgroundColor: "#4CAF50",
|
|
70
|
+
justifyContent: "center",
|
|
71
|
+
alignItems: "center",
|
|
72
|
+
borderTopRightRadius: 12,
|
|
73
|
+
borderBottomRightRadius: 12,
|
|
74
|
+
shadowColor: "#000",
|
|
75
|
+
shadowOffset: { width: 2, height: 0 },
|
|
76
|
+
shadowOpacity: 0.1,
|
|
77
|
+
shadowRadius: 4,
|
|
78
|
+
}}
|
|
79
|
+
onPress={() => {
|
|
80
|
+
console.log("Marked as complete");
|
|
81
|
+
}}
|
|
82
|
+
>
|
|
83
|
+
<MaterialIcons name="check-circle" size={24} color="white" />
|
|
84
|
+
<Text
|
|
85
|
+
style={{
|
|
86
|
+
color: "white",
|
|
87
|
+
fontSize: 12,
|
|
88
|
+
marginTop: 4,
|
|
89
|
+
fontWeight: "600",
|
|
90
|
+
}}
|
|
91
|
+
>
|
|
92
|
+
Complete
|
|
93
|
+
</Text>
|
|
94
|
+
</RectButton>
|
|
95
|
+
);
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
// Inline Separator makes containers rerender each data change
|
|
99
|
+
const Separator = () => <View style={{ height: 10 }} />;
|
|
100
|
+
|
|
101
|
+
export const ItemCard = memo(
|
|
102
|
+
({
|
|
103
|
+
item,
|
|
104
|
+
index,
|
|
105
|
+
extraData,
|
|
106
|
+
numSentences: numSentencesProp,
|
|
107
|
+
}: LegendListRenderItemProps<Item> & { numSentences: number | ((index: number) => number) }) => {
|
|
108
|
+
const refSwipeable = useRef<SwipeableMethods>();
|
|
109
|
+
|
|
110
|
+
// A useState that resets when the item is recycled
|
|
111
|
+
const [isExpanded, setIsExpanded] = extraData?.recycleState ? useRecyclingState(() => false) : useState(false);
|
|
112
|
+
|
|
113
|
+
const swipeableState = useRef(false);
|
|
114
|
+
|
|
115
|
+
// console.log(Math.round(performance.now()), "renderItem", index);
|
|
116
|
+
|
|
117
|
+
// A callback when the item is recycled
|
|
118
|
+
// useRecyclingEffect?.(({ item, prevItem, index, prevIndex }) => {
|
|
119
|
+
// if (swipeableState.current) {
|
|
120
|
+
// // this is expensive operation, run .close() only if the swipeable is open
|
|
121
|
+
// refSwipeable?.current?.close();
|
|
122
|
+
// }
|
|
123
|
+
// });
|
|
124
|
+
|
|
125
|
+
// A callback when the item viewability (from viewabilityConfig) changes
|
|
126
|
+
// useViewability?.("viewability", ({ item, isViewable, index }) => {
|
|
127
|
+
// // console.log('viewable', viewToken.index, viewToken.isViewable);
|
|
128
|
+
// });
|
|
129
|
+
|
|
130
|
+
// @ts-ignore
|
|
131
|
+
// const opacity = useViewabilityAmount ? useAnimatedValue(1) : 1;
|
|
132
|
+
// useViewabilityAmount?.(({ sizeVisible, size, percentOfScroller }) => {
|
|
133
|
+
// // @ts-ignore
|
|
134
|
+
// // opacity.setValue(Math.max(0, Math.min(1, sizeVisible / Math.min(400, size || 400)) ** 1.5));
|
|
135
|
+
// // console.log('viewable', sizeVisible, size, percentOfScroller);
|
|
136
|
+
// });
|
|
137
|
+
|
|
138
|
+
// Math.abs needed for negative indices
|
|
139
|
+
const indexForData = Math.abs(item.id.includes("new") ? 100 + +item.id.replace("new", "") : +item.id);
|
|
140
|
+
|
|
141
|
+
// Generate 1-5 random sentences
|
|
142
|
+
const numSentences = numSentencesProp
|
|
143
|
+
? typeof numSentencesProp === "function"
|
|
144
|
+
? numSentencesProp(indexForData)
|
|
145
|
+
: numSentencesProp
|
|
146
|
+
: ((indexForData * 7919) % 4) + 1; // Using prime number 7919 for better distribution
|
|
147
|
+
// const indexForData =
|
|
148
|
+
// item.id === "0" ? 0 : item.id === "1" ? 1 : item.id === "new0" ? 2 : 3;
|
|
149
|
+
// const numSentences =
|
|
150
|
+
// item.id === "0" ? 1 : item.id === "1" ? 2 : item.id === "new0" ? 4 : 8;
|
|
151
|
+
const randomText = Array.from(
|
|
152
|
+
{ length: numSentences },
|
|
153
|
+
(_, i) => loremSentences[i % loremSentences.length],
|
|
154
|
+
).join(" ");
|
|
155
|
+
|
|
156
|
+
// Use randomIndex to deterministically select random data
|
|
157
|
+
const avatarUrl = randomAvatars[indexForData % randomAvatars.length];
|
|
158
|
+
const authorName = randomNames[indexForData % randomNames.length];
|
|
159
|
+
const timestamp = `${Math.max(1, indexForData % 24)}h ago`;
|
|
160
|
+
|
|
161
|
+
if (index === 1 && demoNestedList) {
|
|
162
|
+
return (
|
|
163
|
+
<Animated.View style={[styles.nestedListContainer]}>
|
|
164
|
+
<LegendList
|
|
165
|
+
showsHorizontalScrollIndicator={false}
|
|
166
|
+
horizontal
|
|
167
|
+
estimatedItemSize={400}
|
|
168
|
+
keyExtractor={(item) => item.text}
|
|
169
|
+
data={[
|
|
170
|
+
{
|
|
171
|
+
id: "1",
|
|
172
|
+
text: "List Item 1",
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
id: "2",
|
|
176
|
+
text: "List Item 2",
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
id: "3",
|
|
180
|
+
text: "List Item 3",
|
|
181
|
+
},
|
|
182
|
+
]}
|
|
183
|
+
ItemSeparatorComponent={Separator}
|
|
184
|
+
renderItem={({ item }) => (
|
|
185
|
+
<View style={styles.nestedListItem}>
|
|
186
|
+
<Text>{item.text}</Text>
|
|
187
|
+
</View>
|
|
188
|
+
)}
|
|
189
|
+
/>
|
|
190
|
+
</Animated.View>
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
return (
|
|
195
|
+
<View style={{ ...styles.itemOuterContainer }}>
|
|
196
|
+
<Swipeable
|
|
197
|
+
renderRightActions={renderRightActions}
|
|
198
|
+
overshootRight={true}
|
|
199
|
+
containerStyle={styles.swipeableContainer}
|
|
200
|
+
ref={refSwipeable as any}
|
|
201
|
+
onSwipeableWillOpen={() => {
|
|
202
|
+
swipeableState.current = true;
|
|
203
|
+
}}
|
|
204
|
+
onSwipeableWillClose={() => {
|
|
205
|
+
swipeableState.current = false;
|
|
206
|
+
}}
|
|
207
|
+
>
|
|
208
|
+
<Pressable
|
|
209
|
+
onPress={(e) => {
|
|
210
|
+
// LinearTransition.easing(Easing.ease);
|
|
211
|
+
|
|
212
|
+
e.stopPropagation();
|
|
213
|
+
setIsExpanded(!isExpanded);
|
|
214
|
+
}}
|
|
215
|
+
>
|
|
216
|
+
<View
|
|
217
|
+
style={[
|
|
218
|
+
styles.itemContainer,
|
|
219
|
+
{
|
|
220
|
+
// padding: 16,
|
|
221
|
+
backgroundColor: "#ffffff",
|
|
222
|
+
borderRadius: 12,
|
|
223
|
+
shadowColor: "#000",
|
|
224
|
+
shadowOffset: { width: 0, height: 2 },
|
|
225
|
+
shadowOpacity: 0.1,
|
|
226
|
+
shadowRadius: 4,
|
|
227
|
+
// marginVertical: 8,
|
|
228
|
+
overflow: "hidden",
|
|
229
|
+
},
|
|
230
|
+
]}
|
|
231
|
+
>
|
|
232
|
+
<View style={styles.headerContainer}>
|
|
233
|
+
<Image source={{ uri: avatarUrl }} style={styles.avatar} />
|
|
234
|
+
<View style={styles.headerText}>
|
|
235
|
+
<Text style={styles.authorName}>
|
|
236
|
+
{authorName} {item.id}
|
|
237
|
+
</Text>
|
|
238
|
+
<Text style={styles.timestamp}>{timestamp}</Text>
|
|
239
|
+
</View>
|
|
240
|
+
</View>
|
|
241
|
+
|
|
242
|
+
<Text style={styles.itemTitle}>Item #{item.id}</Text>
|
|
243
|
+
<Text
|
|
244
|
+
style={styles.itemBody}
|
|
245
|
+
// numberOfLines={isExpanded ? undefined : 10}
|
|
246
|
+
>
|
|
247
|
+
{randomText}
|
|
248
|
+
{isExpanded ? randomText : null}
|
|
249
|
+
</Text>
|
|
250
|
+
<View style={styles.itemFooter}>
|
|
251
|
+
<Text style={styles.footerText}>❤️ 42</Text>
|
|
252
|
+
<Text style={styles.footerText}>💬 12</Text>
|
|
253
|
+
<Text style={styles.footerText}>🔄 8</Text>
|
|
254
|
+
</View>
|
|
255
|
+
</View>
|
|
256
|
+
{/* <Breathe /> */}
|
|
257
|
+
</Pressable>
|
|
258
|
+
</Swipeable>
|
|
259
|
+
</View>
|
|
260
|
+
);
|
|
261
|
+
},
|
|
262
|
+
);
|
|
263
|
+
|
|
264
|
+
export const renderItem = (props: LegendListRenderItemProps<Item>) => <ItemCard {...props} />;
|
|
265
|
+
|
|
266
|
+
const styles = StyleSheet.create({
|
|
267
|
+
nestedListContainer: {
|
|
268
|
+
paddingVertical: 8,
|
|
269
|
+
paddingHorizontal: 8,
|
|
270
|
+
height: 200,
|
|
271
|
+
},
|
|
272
|
+
nestedListItem: {
|
|
273
|
+
backgroundColor: "white",
|
|
274
|
+
height: 200,
|
|
275
|
+
width: 200,
|
|
276
|
+
justifyContent: "center",
|
|
277
|
+
alignItems: "center",
|
|
278
|
+
},
|
|
279
|
+
itemOuterContainer: {
|
|
280
|
+
paddingVertical: 8,
|
|
281
|
+
paddingHorizontal: 8,
|
|
282
|
+
//width: 380,
|
|
283
|
+
//marginLeft: 6,
|
|
284
|
+
},
|
|
285
|
+
itemContainer: {
|
|
286
|
+
padding: 16,
|
|
287
|
+
// borderBottomWidth: 1,
|
|
288
|
+
// borderBottomColor: "#ccc",
|
|
289
|
+
},
|
|
290
|
+
titleContainer: {
|
|
291
|
+
flexDirection: "row",
|
|
292
|
+
alignItems: "center",
|
|
293
|
+
gap: 8,
|
|
294
|
+
},
|
|
295
|
+
stepContainer: {
|
|
296
|
+
gap: 8,
|
|
297
|
+
marginBottom: 8,
|
|
298
|
+
},
|
|
299
|
+
listContainer: {
|
|
300
|
+
paddingHorizontal: 16,
|
|
301
|
+
},
|
|
302
|
+
itemTitle: {
|
|
303
|
+
fontSize: 18,
|
|
304
|
+
fontWeight: "bold",
|
|
305
|
+
marginBottom: 8,
|
|
306
|
+
color: "#1a1a1a",
|
|
307
|
+
},
|
|
308
|
+
itemBody: {
|
|
309
|
+
fontSize: 14,
|
|
310
|
+
color: "#666666",
|
|
311
|
+
lineHeight: 20,
|
|
312
|
+
// flex: 1,
|
|
313
|
+
},
|
|
314
|
+
itemFooter: {
|
|
315
|
+
flexDirection: "row",
|
|
316
|
+
justifyContent: "flex-start",
|
|
317
|
+
gap: 16,
|
|
318
|
+
marginTop: 12,
|
|
319
|
+
paddingTop: 12,
|
|
320
|
+
borderTopWidth: 1,
|
|
321
|
+
borderTopColor: "#f0f0f0",
|
|
322
|
+
},
|
|
323
|
+
footerText: {
|
|
324
|
+
fontSize: 14,
|
|
325
|
+
color: "#888888",
|
|
326
|
+
},
|
|
327
|
+
headerContainer: {
|
|
328
|
+
flexDirection: "row",
|
|
329
|
+
alignItems: "center",
|
|
330
|
+
marginBottom: 12,
|
|
331
|
+
},
|
|
332
|
+
avatar: {
|
|
333
|
+
width: 40,
|
|
334
|
+
height: 40,
|
|
335
|
+
borderRadius: 20,
|
|
336
|
+
marginRight: 12,
|
|
337
|
+
},
|
|
338
|
+
headerText: {
|
|
339
|
+
flex: 1,
|
|
340
|
+
},
|
|
341
|
+
authorName: {
|
|
342
|
+
fontSize: 16,
|
|
343
|
+
fontWeight: "600",
|
|
344
|
+
color: "#1a1a1a",
|
|
345
|
+
},
|
|
346
|
+
timestamp: {
|
|
347
|
+
fontSize: 12,
|
|
348
|
+
color: "#888888",
|
|
349
|
+
marginTop: 2,
|
|
350
|
+
},
|
|
351
|
+
swipeableContainer: { backgroundColor: "#4CAF50", borderRadius: 12 },
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
export default renderItem;
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { LegendList } from "@legendapp/list";
|
|
2
|
+
import { useHeaderHeight } from "@react-navigation/elements";
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import { Button, KeyboardAvoidingView, Platform, StyleSheet, Text, TextInput, 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",
|
|
21
|
+
sender: "user",
|
|
22
|
+
timeStamp: Date.now() - MS_PER_SECOND * 5,
|
|
23
|
+
},
|
|
24
|
+
{ id: String(idCounter++), text: "Hello", sender: "bot", timeStamp: Date.now() - MS_PER_SECOND * 4 },
|
|
25
|
+
{ id: String(idCounter++), text: "How can I help you?", sender: "bot", timeStamp: Date.now() - MS_PER_SECOND * 3 },
|
|
26
|
+
];
|
|
27
|
+
|
|
28
|
+
const ChatExample = () => {
|
|
29
|
+
const [messages, setMessages] = useState<Message[]>(defaultChatMessages);
|
|
30
|
+
const [inputText, setInputText] = useState("");
|
|
31
|
+
const headerHeight = Platform.OS === "ios" ? useHeaderHeight() : 80;
|
|
32
|
+
|
|
33
|
+
const sendMessage = () => {
|
|
34
|
+
const text = inputText || "Empty message";
|
|
35
|
+
if (text.trim()) {
|
|
36
|
+
setMessages((messages) => [
|
|
37
|
+
...messages,
|
|
38
|
+
{ id: String(idCounter++), text: text, sender: "user", timeStamp: Date.now() },
|
|
39
|
+
]);
|
|
40
|
+
setInputText("");
|
|
41
|
+
setTimeout(() => {
|
|
42
|
+
setMessages((messages) => [
|
|
43
|
+
...messages,
|
|
44
|
+
{
|
|
45
|
+
id: String(idCounter++),
|
|
46
|
+
text: `Answer: ${text.toUpperCase()}`,
|
|
47
|
+
sender: "bot",
|
|
48
|
+
timeStamp: Date.now(),
|
|
49
|
+
},
|
|
50
|
+
]);
|
|
51
|
+
}, 300);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
return (
|
|
56
|
+
<SafeAreaView style={styles.container} edges={["bottom"]}>
|
|
57
|
+
<KeyboardAvoidingView
|
|
58
|
+
style={styles.container}
|
|
59
|
+
behavior="padding"
|
|
60
|
+
keyboardVerticalOffset={headerHeight}
|
|
61
|
+
contentContainerStyle={{ flex: 1 }}
|
|
62
|
+
>
|
|
63
|
+
<LegendList
|
|
64
|
+
data={messages}
|
|
65
|
+
contentContainerStyle={styles.contentContainer}
|
|
66
|
+
keyExtractor={(item) => item.id}
|
|
67
|
+
estimatedItemSize={10} // A size that's way too small to check the behavior is correct
|
|
68
|
+
initialScrollIndex={messages.length - 1}
|
|
69
|
+
maintainVisibleContentPosition
|
|
70
|
+
maintainScrollAtEnd
|
|
71
|
+
alignItemsAtEnd
|
|
72
|
+
renderItem={({ item }) => (
|
|
73
|
+
<>
|
|
74
|
+
<View
|
|
75
|
+
style={[
|
|
76
|
+
styles.messageContainer,
|
|
77
|
+
item.sender === "bot" ? styles.botMessageContainer : styles.userMessageContainer,
|
|
78
|
+
item.sender === "bot" ? styles.botStyle : styles.userStyle,
|
|
79
|
+
]}
|
|
80
|
+
>
|
|
81
|
+
<Text style={[styles.messageText, item.sender === "user" && styles.userMessageText]}>
|
|
82
|
+
{item.text}
|
|
83
|
+
</Text>
|
|
84
|
+
</View>
|
|
85
|
+
<View
|
|
86
|
+
style={[styles.timeStamp, item.sender === "bot" ? styles.botStyle : styles.userStyle]}
|
|
87
|
+
>
|
|
88
|
+
<Text style={styles.timeStampText}>
|
|
89
|
+
{new Date(item.timeStamp).toLocaleTimeString()}
|
|
90
|
+
</Text>
|
|
91
|
+
</View>
|
|
92
|
+
</>
|
|
93
|
+
)}
|
|
94
|
+
/>
|
|
95
|
+
<View style={styles.inputContainer}>
|
|
96
|
+
<TextInput
|
|
97
|
+
style={styles.input}
|
|
98
|
+
value={inputText}
|
|
99
|
+
onChangeText={setInputText}
|
|
100
|
+
placeholder="Type a message"
|
|
101
|
+
/>
|
|
102
|
+
<Button title="Send" onPress={sendMessage} />
|
|
103
|
+
</View>
|
|
104
|
+
</KeyboardAvoidingView>
|
|
105
|
+
</SafeAreaView>
|
|
106
|
+
);
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
const styles = StyleSheet.create({
|
|
110
|
+
container: {
|
|
111
|
+
flex: 1,
|
|
112
|
+
backgroundColor: "#fff",
|
|
113
|
+
},
|
|
114
|
+
contentContainer: {
|
|
115
|
+
paddingHorizontal: 16,
|
|
116
|
+
},
|
|
117
|
+
messageContainer: {
|
|
118
|
+
padding: 16,
|
|
119
|
+
borderRadius: 16,
|
|
120
|
+
marginVertical: 4,
|
|
121
|
+
},
|
|
122
|
+
messageText: {
|
|
123
|
+
fontSize: 16,
|
|
124
|
+
},
|
|
125
|
+
userMessageText: {
|
|
126
|
+
color: "white",
|
|
127
|
+
},
|
|
128
|
+
inputContainer: {
|
|
129
|
+
flexDirection: "row",
|
|
130
|
+
alignItems: "center",
|
|
131
|
+
padding: 10,
|
|
132
|
+
borderTopWidth: 1,
|
|
133
|
+
borderColor: "#ccc",
|
|
134
|
+
},
|
|
135
|
+
botMessageContainer: {
|
|
136
|
+
backgroundColor: "#f1f1f1",
|
|
137
|
+
},
|
|
138
|
+
userMessageContainer: {
|
|
139
|
+
backgroundColor: "#007AFF",
|
|
140
|
+
},
|
|
141
|
+
botStyle: {
|
|
142
|
+
maxWidth: "75%",
|
|
143
|
+
alignSelf: "flex-start",
|
|
144
|
+
},
|
|
145
|
+
userStyle: {
|
|
146
|
+
maxWidth: "75%",
|
|
147
|
+
alignSelf: "flex-end",
|
|
148
|
+
alignItems: "flex-end",
|
|
149
|
+
},
|
|
150
|
+
input: {
|
|
151
|
+
flex: 1,
|
|
152
|
+
borderWidth: 1,
|
|
153
|
+
borderColor: "#ccc",
|
|
154
|
+
borderRadius: 5,
|
|
155
|
+
padding: 10,
|
|
156
|
+
marginRight: 10,
|
|
157
|
+
},
|
|
158
|
+
timeStamp: {
|
|
159
|
+
marginVertical: 5,
|
|
160
|
+
},
|
|
161
|
+
timeStampText: {
|
|
162
|
+
fontSize: 12,
|
|
163
|
+
color: "#888",
|
|
164
|
+
},
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
export default ChatExample;
|