|
1 | | -'use strict'; |
| 1 | +import React, { StyleSheet, Text, TouchableHighlight, Image, View, PropTypes } from 'react-native'; |
2 | 2 |
|
3 | | -var React = require('react-native'); |
| 3 | +const propTypes = { |
| 4 | + goToTweet: PropTypes.func.isRequired, |
| 5 | + text: PropTypes.string, |
| 6 | + user: PropTypes.object, |
| 7 | +}; |
4 | 8 |
|
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 | + } |
13 | 52 |
|
14 | | -var Tweet = React.createClass({ |
15 | | - |
16 | | - goToTweet: function() { |
| 53 | + goToTweet() { |
17 | 54 | this.props.goToTweet(this.props); |
18 | | - }, |
| 55 | + } |
19 | 56 |
|
20 | 57 | render() { |
21 | | - var { |
| 58 | + const { |
22 | 59 | text, |
23 | | - user |
| 60 | + user, |
24 | 61 | } = this.props; |
25 | 62 |
|
26 | 63 | return ( |
27 | 64 | <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> |
34 | 71 | </View> |
35 | | - <Text style={styles.text}>{text}</Text> |
| 72 | + <Text style={this.styles.text}>{text}</Text> |
36 | 73 | </View> |
37 | 74 | </View> |
38 | 75 | </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 | + ); |
79 | 77 | } |
80 | | -}); |
| 78 | +} |
81 | 79 |
|
| 80 | +Tweet.propTypes = propTypes; |
82 | 81 |
|
83 | | -module.exports = Tweet; |
| 82 | +export default Tweet; |
0 commit comments