-
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add reanimated chat flatlist example (#236)
## 馃摐 Description <!-- Describe your changes in detail --> Add an example for a chat with reanimated and flatlist ## 馃挕 Motivation and Context <!-- Why is this change required? What problem does it solve? --> <!-- If it fixes an open issue, please link to the issue here. --> There is only an example with a ScrollView, in a real chat app it's more common to encounter a FlatList It may solve this issue #156 ## 馃 How Has This Been Tested? Tested iPhone 14 Pro ## 馃摳 Screenshots (if appropriate): https://github.com/kirillzyusko/react-native-keyboard-controller/assets/11976270/9d73f4f0-e1a4-4ea6-a0f8-a870284c0322 ## 馃摑 Checklist - [ ] CI successfully passed --------- Co-authored-by: kirillzyusko <zyusko.kirik@gmail.com>
- Loading branch information
1 parent
5e8d45d
commit 8b2041c
Showing
5 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
example/src/screens/Examples/ReanimatedChatFlatlist/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import React from 'react'; | ||
import { FlatList, ListRenderItem, TextInput, View } from 'react-native'; | ||
import { useReanimatedKeyboardAnimation } from 'react-native-keyboard-controller'; | ||
import Animated, { useAnimatedStyle } from 'react-native-reanimated'; | ||
|
||
import Message from '../../../components/Message'; | ||
import { history } from '../../../components/Message/data'; | ||
import { MessageProps } from '../../../components/Message/types'; | ||
|
||
import styles from './styles'; | ||
|
||
const reversedMessages = [...history].reverse(); | ||
|
||
const RenderItem: ListRenderItem<MessageProps> = ({ item, index }) => { | ||
return <Message key={index} {...item} />; | ||
}; | ||
|
||
function ReanimatedChatFlatlist() { | ||
const { height } = useReanimatedKeyboardAnimation(); | ||
|
||
const fakeView = useAnimatedStyle( | ||
() => ({ | ||
height: Math.abs(height.value), | ||
}), | ||
[] | ||
); | ||
|
||
return ( | ||
<View style={styles.container}> | ||
<FlatList | ||
inverted | ||
initialNumToRender={15} | ||
contentContainerStyle={styles.contentContainer} | ||
data={reversedMessages} | ||
renderItem={RenderItem} | ||
/> | ||
<TextInput style={styles.textInput} /> | ||
<Animated.View style={fakeView} /> | ||
</View> | ||
); | ||
} | ||
|
||
export default ReanimatedChatFlatlist; |
13 changes: 13 additions & 0 deletions
13
example/src/screens/Examples/ReanimatedChatFlatlist/styles.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { StyleSheet } from 'react-native'; | ||
|
||
export default StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
}, | ||
header: { | ||
color: 'black', | ||
marginRight: 12, | ||
}, | ||
contentContainer: { justifyContent: 'flex-end', flexGrow: 1 }, | ||
textInput: { height: 50, width: '100%', backgroundColor: '#BCBCBC' }, | ||
}); |