Skip to content

Commit

Permalink
Merge pull request FaridSafi#107 from gnl/support-centered-message
Browse files Browse the repository at this point in the history
Support centered messages (p.ex. for server messages)
  • Loading branch information
FaridSafi committed Apr 21, 2016
2 parents ca4c011 + eed23b0 commit adaf916
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
15 changes: 11 additions & 4 deletions Bubble.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ const styles = StyleSheet.create({
textRight: {
color: '#fff',
},
textCenter: {
textAlign: 'center',
},
bubbleLeft: {
marginRight: 70,
backgroundColor: '#e6e6eb',
Expand All @@ -28,6 +31,10 @@ const styles = StyleSheet.create({
backgroundColor: '#007aff',
alignSelf: 'flex-end',
},
bubbleCenter: {
backgroundColor: '#007aff',
alignSelf: 'center',
},
bubbleError: {
backgroundColor: '#e01717',
},
Expand All @@ -47,7 +54,7 @@ export default class Bubble extends React.Component {
if (this.props.parseText === true) {
return (
<ParsedText
style={[styles.text, (position === 'left' ? styles.textLeft : styles.textRight)]}
style={[styles.text, (position === 'left' ? styles.textLeft : position === 'right' ? styles.textRight : styles.textCenter)]}
parse={
[
{
Expand Down Expand Up @@ -80,7 +87,7 @@ export default class Bubble extends React.Component {
}

return (
<Text style={[styles.text, (position === 'left' ? styles.textLeft : styles.textRight)]}>
<Text style={[styles.text, (position === 'left' ? styles.textLeft : position === 'right' ? styles.textRight : styles.textCenter)]}>
{text}
</Text>
);
Expand All @@ -96,7 +103,7 @@ export default class Bubble extends React.Component {

return (
<View style={[styles.bubble,
(this.props.position === 'left' ? styles.bubbleLeft : styles.bubbleRight),
(this.props.position === 'left' ? styles.bubbleLeft : this.props.position === 'right' ? styles.bubbleRight : styles.bubbleCenter),
(this.props.status === 'ErrorButton' ? styles.bubbleError : null),
flexStyle]}
>
Expand All @@ -108,7 +115,7 @@ export default class Bubble extends React.Component {
}

Bubble.propTypes = {
position: React.PropTypes.oneOf(['left', 'right']),
position: React.PropTypes.oneOf(['left', 'right', 'center']),
status: React.PropTypes.string,
text: React.PropTypes.string,
renderCustomText: React.PropTypes.func,
Expand Down
2 changes: 1 addition & 1 deletion Message.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export default class Message extends Component {
{position === 'left' && !this.props.displayNamesInsideBubble ? this.renderName(rowData.name, displayNames, diffMessage) : null}
<View
style={[styles.rowContainer, {
justifyContent: position === 'left' ? 'flex-start' : 'flex-end',
justifyContent: position === 'left' ? 'flex-start' : position === 'right' ? 'flex-end' : 'center',
}]}
>
{position === 'left' ? this.renderImage(rowData, diffMessage, forceRenderImage, onImagePress) : null}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ var message = {
text: 'Message content',
name: "Sender's name",
image: {uri: 'https://facebook.github.io/react/img/logo_og.png'},
position: 'left', // left for received messages, right for sent messages
position: 'left', // left for received messages, right for sent messages, center for server messages
date: new Date(),
view: null, // A custom Bubble view - the view will receive the message attributes as props
status: 'Seen', // if status is 'ErrorButton', a re-send button will be displayed
Expand Down

0 comments on commit adaf916

Please sign in to comment.