Skip to content

Commit 4384a06

Browse files
committed
Merge pull request #14 from charpeni/issue-3
Convert twitter-example to ES6
2 parents eb79e9e + 84978fd commit 4384a06

File tree

14 files changed

+428
-470
lines changed

14 files changed

+428
-470
lines changed

README.md

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class HelloPage extends Component {
2828
render() {
2929
return <Text>Hello world!</Text>;
3030
}
31-
31+
3232
}
3333

3434
// Your route object should contain at least:
@@ -47,7 +47,7 @@ class MyApp extends Component {
4747
<Router firstRoute={firstRoute} />
4848
);
4949
}
50-
50+
5151
}
5252

5353
AppRegistry.registerComponent('routerTest', () => MyApp);
@@ -76,7 +76,7 @@ class HelloPage extends Component {
7676
</View>
7777
);
7878
}
79-
79+
8080
}
8181
```
8282

@@ -146,16 +146,13 @@ Events emitted by the router:
146146
A more advanced example: Twitter app
147147
------------------------------------
148148

149-
To see more of the router in action, you can check out the Twitter example app that comes with the package. Just make sure that you first drag all the images from ```node_modules/react-native-simple-router/twitter-example/images``` to your project's Images.xcassets
149+
To see more of the router in action, you can check out the Twitter example app that comes with the package.
150150

151-
After that, don't forget to rebuild the app in XCode before you launch the simulator. Then test the app by requiring the TwitterApp component:
151+
Test the app by requiring the TwitterApp component:
152152

153153
```javascript
154+
import React, { AppRegistry } from 'react-native';
154155
import TwitterApp from './node_modules/react-native-simple-router/twitter-example';
155156

156-
var {
157-
AppRegistry
158-
} = React;
159-
160157
AppRegistry.registerComponent('routerTest', () => TwitterApp);
161158
```
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)