Skip to content

Commit 0467599

Browse files
committed
Convert twitter-example to ES6
1 parent eb79e9e commit 0467599

File tree

13 files changed

+422
-461
lines changed

13 files changed

+422
-461
lines changed
Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,21 @@
1-
'use strict';
2-
3-
var React = require('react-native');
4-
5-
var {
6-
StyleSheet,
7-
TouchableHighlight,
8-
Image,
9-
View,
10-
} = React;
11-
12-
13-
var styles = StyleSheet.create({
14-
backButton: {
15-
width: 10,
16-
height: 17,
17-
marginLeft: 10,
18-
marginTop: 3,
19-
marginRight: 10
1+
import React, { StyleSheet, Image } from 'react-native';
2+
3+
export default class BackButton extends React.Component {
4+
constructor(props) {
5+
super(props);
6+
this.styles = StyleSheet.create({
7+
backButton: {
8+
width: 10,
9+
height: 17,
10+
marginLeft: 10,
11+
marginTop: 3,
12+
marginRight: 10,
13+
},
14+
});
2015
}
21-
});
22-
23-
24-
var BackButton = React.createClass({
2516
render() {
2617
return (
27-
<Image source={require('image!back_button')} style={styles.backButton} />
28-
)
18+
<Image source={require('../images/back_button.png')} style={this.styles.backButton} />
19+
);
2920
}
30-
});
31-
32-
33-
module.exports = BackButton;
21+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React, { StyleSheet, View } from 'react-native';
2+
3+
export default class RightCorner extends React.Component {
4+
constructor(props) {
5+
super(props);
6+
this.styles = StyleSheet.create({
7+
button: {
8+
width: 100,
9+
height: 50,
10+
backgroundColor: 'orange',
11+
},
12+
});
13+
}
14+
15+
render() {
16+
return (
17+
<View style={this.styles.button} />
18+
);
19+
}
20+
}
Lines changed: 64 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,82 @@
1-
'use strict';
1+
import React, { StyleSheet, Text, TouchableHighlight, Image, View, PropTypes } from 'react-native';
22

3-
var React = require('react-native');
3+
const propTypes = {
4+
goToTweet: PropTypes.func.isRequired,
5+
text: PropTypes.string,
6+
user: PropTypes.object,
7+
};
48

5-
var {
6-
AppRegistry,
7-
StyleSheet,
8-
Text,
9-
TouchableHighlight,
10-
Image,
11-
View,
12-
} = React;
9+
class Tweet extends React.Component {
10+
constructor(props) {
11+
super(props);
12+
this.styles = StyleSheet.create({
13+
tweetContainer: {
14+
flexDirection: 'row',
15+
alignItems: 'center',
16+
backgroundColor: 'white',
17+
borderBottomWidth: 1,
18+
borderColor: '#DAE6F0',
19+
paddingTop: 4,
20+
paddingBottom: 10,
21+
},
22+
avatar: {
23+
backgroundColor: 'gray',
24+
width: 50,
25+
height: 50,
26+
marginLeft: 10,
27+
borderRadius: 4,
28+
},
29+
userContainer: {
30+
flexDirection: 'row',
31+
},
32+
username: {
33+
marginLeft: 4,
34+
fontSize: 13,
35+
color: '#8999a5',
36+
marginTop: 2,
37+
},
38+
name: {
39+
fontWeight: '600',
40+
fontSize: 15,
41+
},
42+
text: {
43+
marginTop: 5,
44+
},
45+
rightContainer: {
46+
flex: 1,
47+
padding: 10,
48+
},
49+
});
50+
this.goToTweet = this.goToTweet.bind(this);
51+
}
1352

14-
var Tweet = React.createClass({
15-
16-
goToTweet: function() {
53+
goToTweet() {
1754
this.props.goToTweet(this.props);
18-
},
55+
}
1956

2057
render() {
21-
var {
58+
const {
2259
text,
23-
user
60+
user,
2461
} = this.props;
2562

2663
return (
2764
<TouchableHighlight underlayColor="transparent" onPress={this.goToTweet}>
28-
<View style={styles.tweetContainer}>
29-
<Image source={{uri: user.avatar}} style={styles.avatar} />
30-
<View style={styles.rightContainer}>
31-
<View style={styles.userContainer}>
32-
<Text style={styles.name}>{user.name}</Text>
33-
<Text style={styles.username}>@{user.username}</Text>
65+
<View style={this.styles.tweetContainer}>
66+
<Image source={{ uri: user.avatar }} style={this.styles.avatar} />
67+
<View style={this.styles.rightContainer}>
68+
<View style={this.styles.userContainer}>
69+
<Text style={this.styles.name}>{user.name}</Text>
70+
<Text style={this.styles.username}>@{user.username}</Text>
3471
</View>
35-
<Text style={styles.text}>{text}</Text>
72+
<Text style={this.styles.text}>{text}</Text>
3673
</View>
3774
</View>
3875
</TouchableHighlight>
39-
)
40-
}
41-
});
42-
43-
var styles = StyleSheet.create({
44-
tweetContainer: {
45-
flexDirection: 'row',
46-
alignItems: 'center',
47-
backgroundColor: 'white',
48-
borderBottomWidth: 1,
49-
borderColor: '#DAE6F0',
50-
paddingTop: 4,
51-
paddingBottom: 10
52-
},
53-
avatar: {
54-
backgroundColor: 'gray',
55-
width: 50,
56-
height: 50,
57-
marginLeft: 10,
58-
borderRadius: 4
59-
},
60-
userContainer: {
61-
flexDirection: 'row'
62-
},
63-
username: {
64-
marginLeft: 4,
65-
fontSize: 13,
66-
color: '#8999a5',
67-
marginTop: 2
68-
},
69-
name: {
70-
fontWeight: '600',
71-
fontSize: 15
72-
},
73-
text: {
74-
marginTop: 5
75-
},
76-
rightContainer: {
77-
flex: 1,
78-
padding: 10
76+
);
7977
}
80-
});
78+
}
8179

80+
Tweet.propTypes = propTypes;
8281

83-
module.exports = Tweet;
82+
export default Tweet;

0 commit comments

Comments
 (0)