Last active
March 1, 2021 09:24
-
-
Save vishalnarkhede/22394f80d629daea1f438ddf42a10ba0 to your computer and use it in GitHub Desktop.
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
import React from 'react'; | |
import {StyleSheet, Text, View} from 'react-native'; | |
/** | |
* UI Component for message item, in message list (FlatList). | |
*/ | |
export const MessageBubble = ({item}) => { | |
if (item.isMyMessage) { | |
// Align sent messages to right side of the screen, with a grey'ish background. | |
return ( | |
<View | |
key={`${item.id}`} | |
style={[styles.messageBubble, styles.myMessageBubble]}> | |
<Text style={styles.myMessageText}>{item.text}</Text> | |
</View> | |
); | |
} | |
// Align received messages to left side of the screen, with blue background. | |
return ( | |
<View key={`${item.id}`} style={styles.messageBubble}> | |
<Text style={styles.messageText}>{item.text}</Text> | |
</View> | |
); | |
}; | |
const styles = StyleSheet.create({ | |
messageBubble: { | |
maxWidth: 300, | |
padding: 10, | |
borderRadius: 10, | |
marginVertical: 5, | |
marginHorizontal: 5, | |
backgroundColor: '#F1F0F0', | |
}, | |
myMessageBubble: { | |
alignSelf: 'flex-end', | |
backgroundColor: '#3784FF', | |
}, | |
messageText: { | |
fontSize: 15, | |
}, | |
myMessageText: { | |
color: 'white', | |
fontSize: 15, | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment