Skip to content

Instantly share code, notes, and snippets.

@vishalnarkhede
Last active March 1, 2021 09:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vishalnarkhede/22394f80d629daea1f438ddf42a10ba0 to your computer and use it in GitHub Desktop.
Save vishalnarkhede/22394f80d629daea1f438ddf42a10ba0 to your computer and use it in GitHub Desktop.
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