UserBrief.js
2.32 KB
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
'use strict';
import React from 'react';
import ReactNative from 'react-native';
import ImmutablePropTypes from 'react-immutable-proptypes';
import SlicedImage from '../../../common/components/SlicedImage';
const {
View,
Text,
Image,
TouchableOpacity,
StyleSheet,
Dimensions,
} = ReactNative;
export default class UserBrief extends React.Component {
static propTypes = {
avatar: React.PropTypes.string,
name: React.PropTypes.string,
timeago: React.PropTypes.string,
isOwner: React.PropTypes.bool,
onPressAvatar: React.PropTypes.func,
};
constructor(props) {
super (props);
}
_renderUserName() {
if (this.props.isOwner) {
return (
<Text style={styles.name} numberOfLines={1}>
{this.props.name + ' | '}
<Text style={styles.owner}>楼主</Text>
</Text>
);
} else {
return (
<Text style={styles.name} numberOfLines={1}>
{this.props.name}
</Text>
);
}
}
render() {
return (
<View style={styles.container}>
<TouchableOpacity onPress={() => {
this.props.onPressAvatar && this.props.onPressAvatar();
}}>
<SlicedImage style={styles.avatar} source={{uri: this.props.avatar}} resizeMode={'cover'} defaultSource={require('../../images/user/avatar-default.png')}/>
</TouchableOpacity>
<View style={styles.text}>
{this._renderUserName()}
<Text style={styles.timeago}>{this.props.timeago}</Text>
</View>
</View>
);
}
}
let styles = StyleSheet.create({
container: {
flexDirection: 'row',
alignItems: 'center',
backgroundColor: 'white',
},
avatar: {
width: 30,
height: 30,
borderRadius: 15,
},
text: {
marginLeft: 5,
},
name: {
fontFamily: 'Helvetica Light',
color: 'black',
fontSize: 13,
maxWidth: 130,
},
owner: {
color: '#4a90e2',
},
timeago: {
fontFamily: 'Helvetica Light',
color: '#b0b0b0',
fontSize: 10,
},
});