Created
March 17, 2022 01:55
-
-
Save wesleyguirra/9b6ffdfeceeebeff0a43167c92de0904 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'; | |
import {Colors} from 'react-native/Libraries/NewAppScreen'; | |
const styles = StyleSheet.create({ | |
bubbleWrapper: { | |
flexDirection: 'column', | |
}, | |
bubbleWrapperSent: { | |
alignSelf: 'flex-end', | |
marginLeft: 40, | |
}, | |
bubbleWrapperReceived: { | |
alignSelf: 'flex-start', | |
marginRight: 40, | |
}, | |
balloon: { | |
paddingHorizontal: 8, | |
paddingVertical: 8, | |
borderRadius: 16, | |
}, | |
balloonSent: { | |
backgroundColor: Colors.white, | |
}, | |
balloonReceived: { | |
backgroundColor: Colors.primary, | |
}, | |
balloonText: { | |
fontSize: 18, | |
}, | |
balloonTextSent: { | |
color: Colors.black, | |
}, | |
balloonTextReceived: { | |
color: Colors.white, | |
}, | |
}); | |
const Balloon = ({message, currentUser}) => { | |
const sent = currentUser === message.sentBy; | |
const balloonColor = sent ? styles.balloonSent : styles.balloonReceived; | |
const balloonTextColor = sent | |
? styles.balloonTextSent | |
: styles.balloonTextReceived; | |
const bubbleWrapper = sent | |
? styles.bubbleWrapperSent | |
: styles.bubbleWrapperReceived; | |
return ( | |
<View> | |
<View style={{...styles.bubbleWrapper, ...bubbleWrapper}}> | |
<View style={{...styles.balloon, ...balloonColor}}> | |
<Text style={{...styles.balloonText, ...balloonTextColor}}> | |
{message.content} | |
</Text> | |
</View> | |
</View> | |
</View> | |
); | |
}; | |
export default Balloon; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment