Skip to content

Instantly share code, notes, and snippets.

@wesleyguirra
Created March 17, 2022 01:55
Show Gist options
  • Save wesleyguirra/9b6ffdfeceeebeff0a43167c92de0904 to your computer and use it in GitHub Desktop.
Save wesleyguirra/9b6ffdfeceeebeff0a43167c92de0904 to your computer and use it in GitHub Desktop.
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