Skip to content

Commit ef3cd23

Browse files
committed
Merge pull request FaridSafi#100 from FaridSafi/0.1.0
0.1.0
2 parents 87b90e3 + 1546169 commit ef3cd23

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1182
-1066
lines changed

.eslintrc.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module.exports = {
2+
extends: 'airbnb',
3+
plugins: [
4+
'react',
5+
],
6+
rules: {
7+
"max-len": ["error", 160, 4, {"ignoreUrls": true}],
8+
"react/jsx-boolean-value": 0
9+
}
10+
};

Bubble.js

Lines changed: 61 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
import React, {Text, View, Animated, Image, StyleSheet} from 'react-native';
1+
import React, { Text, View, StyleSheet } from 'react-native';
22

3-
let styles = StyleSheet.create({
3+
import ParsedText from 'react-native-parsed-text';
4+
5+
const styles = StyleSheet.create({
46
bubble: {
57
borderRadius: 15,
68
paddingLeft: 14,
@@ -19,63 +21,101 @@ let styles = StyleSheet.create({
1921
bubbleLeft: {
2022
marginRight: 70,
2123
backgroundColor: '#e6e6eb',
22-
alignSelf: "flex-start",
24+
alignSelf: 'flex-start',
2325
},
2426
bubbleRight: {
2527
marginLeft: 70,
2628
backgroundColor: '#007aff',
27-
alignSelf: "flex-end"
29+
alignSelf: 'flex-end',
2830
},
2931
bubbleError: {
30-
backgroundColor: '#e01717'
32+
backgroundColor: '#e01717',
3133
},
32-
3334
});
3435

3536
export default class Bubble extends React.Component {
3637

37-
constructor(props) {
38-
super(props);
39-
}
40-
4138
componentWillMount() {
4239
Object.assign(styles, this.props.styles);
4340
}
4441

45-
renderText(text = "", position) {
46-
42+
renderText(text = '', position) {
4743
if (this.props.renderCustomText) {
4844
return this.props.renderCustomText(this.props);
4945
}
46+
47+
if (this.props.parseText === true) {
48+
return (
49+
<ParsedText
50+
style={[styles.text, (position === 'left' ? styles.textLeft : styles.textRight)]}
51+
parse={
52+
[
53+
{
54+
type: 'url',
55+
style: {
56+
textDecorationLine: 'underline',
57+
},
58+
onPress: this.props.handleUrlPress,
59+
},
60+
{
61+
type: 'phone',
62+
style: {
63+
textDecorationLine: 'underline',
64+
},
65+
onPress: this.props.handlePhonePress,
66+
},
67+
{
68+
type: 'email',
69+
style: {
70+
textDecorationLine: 'underline',
71+
},
72+
onPress: this.props.handleEmailPress,
73+
},
74+
]
75+
}
76+
>
77+
{text}
78+
</ParsedText>
79+
);
80+
}
81+
5082
return (
5183
<Text style={[styles.text, (position === 'left' ? styles.textLeft : styles.textRight)]}>
5284
{text}
5385
</Text>
5486
);
5587
}
5688

57-
render(){
58-
var flexStyle = {};
59-
if ( this.props.text.length > 40 ) {
60-
flexStyle.flex = 1;
89+
render() {
90+
const flexStyle = {};
91+
if (this.props.text) {
92+
if (this.props.text.length > 40) {
93+
flexStyle.flex = 1;
94+
}
6195
}
6296

6397
return (
6498
<View style={[styles.bubble,
6599
(this.props.position === 'left' ? styles.bubbleLeft : styles.bubbleRight),
66100
(this.props.status === 'ErrorButton' ? styles.bubbleError : null),
67-
flexStyle]}>
101+
flexStyle]}
102+
>
68103
{this.props.name}
69104
{this.renderText(this.props.text, this.props.position)}
70105
</View>
71-
)
106+
);
72107
}
73108
}
74109

75110
Bubble.propTypes = {
76-
position: React.PropTypes.oneOf(['left','right']),
111+
position: React.PropTypes.oneOf(['left', 'right']),
77112
status: React.PropTypes.string,
78113
text: React.PropTypes.string,
79114
renderCustomText: React.PropTypes.func,
80-
name: React.PropTypes.element
81-
}
115+
styles: React.PropTypes.object,
116+
parseText: React.PropTypes.bool,
117+
name: React.PropTypes.element,
118+
handleUrlPress: React.PropTypes.func,
119+
handlePhonePress: React.PropTypes.func,
120+
handleEmailPress: React.PropTypes.func,
121+
};

ErrorButton.js

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import React, {View, Text, TouchableHighlight, StyleSheet} from 'react-native';
1+
import React, { View, Text, TouchableHighlight, StyleSheet } from 'react-native';
22
import GiftedSpinner from 'react-native-gifted-spinner';
33

4-
let styles = StyleSheet.create({
4+
const styles = StyleSheet.create({
55
errorButtonContainer: {
66
marginLeft: 8,
77
alignSelf: 'center',
@@ -19,43 +19,45 @@ let styles = StyleSheet.create({
1919

2020
export default class ErrorButton extends React.Component {
2121

22-
constructor(props){
22+
constructor(props) {
2323
super(props);
2424
this.state = {
2525
isLoading: false,
2626
};
27-
}
2827

28+
this.onPress = this.onPress.bind(this);
29+
}
2930

3031
componentWillMount() {
3132
Object.assign(styles, this.props.styles);
3233
}
33-
34-
34+
3535
onPress() {
3636
this.setState({
3737
isLoading: true,
3838
});
3939

40-
this.props.onErrorButtonPress(this.props.rowData, this.props.rowID);
40+
this.props.onErrorButtonPress(this.props.rowData);
4141
}
4242

4343
render() {
4444
if (this.state.isLoading === true) {
4545
return (
46-
<View style={[styles.errorButtonContainer, {
47-
backgroundColor: 'transparent',
48-
borderRadius: 0,
49-
}]}>
46+
<View
47+
style={[styles.errorButtonContainer, {
48+
backgroundColor: 'transparent',
49+
borderRadius: 0,
50+
}]}
51+
>
5052
<GiftedSpinner />
5153
</View>
5254
);
5355
}
5456
return (
5557
<View style={styles.errorButtonContainer}>
5658
<TouchableHighlight
57-
underlayColor='transparent'
58-
onPress={this.onPress.bind(this)}
59+
underlayColor="transparent"
60+
onPress={this.onPress}
5961
>
6062
<Text style={styles.errorButton}></Text>
6163
</TouchableHighlight>
@@ -64,9 +66,14 @@ export default class ErrorButton extends React.Component {
6466
}
6567
}
6668

69+
ErrorButton.propTypes = {
70+
styles: React.PropTypes.object,
71+
onErrorButtonPress: React.PropTypes.func,
72+
rowData: React.PropTypes.object,
73+
};
74+
6775
ErrorButton.defaultProps = {
6876
onErrorButtonPress: () => {},
6977
rowData: {},
70-
rowID: null,
7178
styles: {},
72-
};
79+
};

0 commit comments

Comments
 (0)