-
-
Notifications
You must be signed in to change notification settings - Fork 87
/
Copy pathindex.tsx
71 lines (57 loc) · 1.61 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import React from "react";
import { FlatList, TextInput, View } from "react-native";
import { useKeyboardHandler } from "react-native-keyboard-controller";
import Animated, {
useAnimatedStyle,
useSharedValue,
} from "react-native-reanimated";
import Message from "../../../components/Message";
import { history } from "../../../components/Message/data";
import styles from "./styles";
import type { MessageProps } from "../../../components/Message/types";
import type { ListRenderItem } from "react-native";
const reversedMessages = [...history].reverse();
const RenderItem: ListRenderItem<MessageProps> = ({ item, index }) => {
return <Message key={index} {...item} />;
};
const useGradualAnimation = () => {
const height = useSharedValue(0);
useKeyboardHandler(
{
onMove: (e) => {
"worklet";
// eslint-disable-next-line react-compiler/react-compiler
height.value = e.height;
},
onEnd: (e) => {
"worklet";
height.value = e.height;
},
},
[],
);
return { height };
};
function ReanimatedChatFlatList() {
const { height } = useGradualAnimation();
const fakeView = useAnimatedStyle(
() => ({
height: Math.abs(height.value),
}),
[],
);
return (
<View style={styles.container}>
<FlatList
inverted
contentContainerStyle={styles.contentContainer}
data={reversedMessages}
initialNumToRender={15}
renderItem={RenderItem}
/>
<TextInput style={styles.textInput} />
<Animated.View style={fakeView} />
</View>
);
}
export default ReanimatedChatFlatList;