forked from FaridSafi/react-native-gifted-chat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBubble.js
156 lines (145 loc) · 3.91 KB
/
Bubble.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import React from 'react';
import { Text, View, Image, StyleSheet } from 'react-native';
import ParsedText from 'react-native-parsed-text';
const styles = StyleSheet.create({
bubbleContainer: {
flexDirection: 'row',
flex: 1,
},
bubbleContainerRight: {
justifyContent: 'flex-end'
},
chatArrow: {
marginTop: 8,
},
bubble: {
borderRadius: 15,
paddingLeft: 14,
paddingRight: 14,
paddingBottom: 10,
paddingTop: 8,
flex: 1,
alignSelf:'stretch'
},
text: {
color: '#000',
},
textLeft: {
},
textRight: {
color: '#fff',
},
textCenter: {
textAlign: 'center',
},
bubbleLeft: {
marginRight: 70,
backgroundColor: '#e6e6eb',
alignSelf: 'flex-start',
},
bubbleRight: {
marginLeft: 70,
backgroundColor: '#007aff',
alignSelf: 'flex-end',
},
bubbleCenter: {
backgroundColor: '#007aff',
alignSelf: 'center',
},
bubbleError: {
backgroundColor: '#e01717',
},
});
export default class Bubble extends React.Component {
componentWillMount() {
Object.assign(styles, this.props.styles);
}
renderText(text = '', position) {
if (this.props.renderCustomText) {
return this.props.renderCustomText(this.props);
}
if (this.props.parseText === true) {
return (
<ParsedText
style={[styles.text, (position === 'left' ? styles.textLeft : position === 'right' ? styles.textRight : styles.textCenter)]}
parse={
[
{
type: 'url',
style: {
textDecorationLine: 'underline',
},
onPress: this.props.handleUrlPress,
},
{
type: 'phone',
style: {
textDecorationLine: 'underline',
},
onPress: this.props.handlePhonePress,
},
{
type: 'email',
style: {
textDecorationLine: 'underline',
},
onPress: this.props.handleEmailPress,
},
]
}
>
{text}
</ParsedText>
);
}
return (
<Text style={[styles.text, (position === 'left' ? styles.textLeft : position === 'right' ? styles.textRight : styles.textCenter)]}>
{text}
</Text>
);
}
render() {
const flexStyle = {};
if (this.props.text) {
if (this.props.text.length > 40) {
flexStyle.flex = 1;
}
}
var arrowLeft;
var arrowRight;
var bubbleContainerStyle;
if(this.props.position === 'left') {
arrowLeft = <Image style={styles.chatArrow} source={require('./assets/chat_arrow_left.png')} />
} else if(this.props.position === 'right') {
console.log("RENDEIRNG RIGHT");
arrowRight = <Image style={styles.chatArrow} source={require('./assets/chat_arrow_right.png')} />
bubbleContainerStyle = styles.bubbleContainerRight;
}
return (
<View style={[styles.bubbleContainer, bubbleContainerStyle]}>
{arrowLeft}
<View style={[styles.bubble,
(this.props.position === 'left' ? styles.bubbleLeft : this.props.position === 'right' ? styles.bubbleRight : styles.bubbleCenter),
(this.props.status === 'ErrorButton' ? styles.bubbleError : null),
flexStyle]}
>
{this.props.name}
{this.renderText(this.props.text, this.props.position)}
</View>
{arrowRight}
</View>
);
}
}
Bubble.propTypes = {
position: React.PropTypes.oneOf(['left', 'right', 'center']),
status: React.PropTypes.string,
text: React.PropTypes.string,
renderCustomText: React.PropTypes.func,
styles: React.PropTypes.object,
parseText: React.PropTypes.bool,
name: React.PropTypes.element,
handleUrlPress: React.PropTypes.func,
handlePhonePress: React.PropTypes.func,
handleEmailPress: React.PropTypes.func,
};