SPLikeCell.js
3.76 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
'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 SPLikeCell extends React.Component {
static propTypes = {
users: React.PropTypes.arrayOf(
React.PropTypes.shape({
nickName: React.PropTypes.string,
headIcon: React.PropTypes.string,
uid: React.PropTypes.number,
})),
like: React.PropTypes.string,
browse: React.PropTypes.string,
onPressLikeCell: React.PropTypes.func,
};
constructor(props) {
super (props);
}
_renderLikeAvatar(avatars) {
let users = this.props.users;
if (users.length) {
let space = 10;
let left = (users.length - 1) * space;
return (
<View style={[styles.avatarPannel, {left}]}>
{users.map((item, i)=> {
let headStr = item && item.headIcon ? item.headIcon : '';
return (
<SlicedImage
key={i}
style={[styles.likeAvatar, {right: space * i}]}
source={{uri: headStr}}
defaultSource={require('../../images/avatar/avatar_default.png')}
/>
);
})}
</View>
);
}
}
render() {
let {users, like, browse} = this.props;
let likeTextMarginLeft = users.length > 0 ?10 - (users.length - 1) * 10 : 0;
return (
<TouchableOpacity onPress={() => {
this.props.onPressLikeCell && this.props.onPressLikeCell()
}}>
<View style={styles.container}>
<View style={styles.leftLikeContainer}>
{this._renderLikeAvatar()}
<Text style={[styles.likeText, {left: likeTextMarginLeft}]}>{like + '人点赞'}</Text>
</View>
<View style={styles.rightLikeContainer}>
<Text style={styles.browseText}>{browse + '人看过'}</Text>
</View>
<View style={styles.topLine}/>
<View style={styles.bottomLine}/>
</View>
</TouchableOpacity>
);
}
}
let {width, height} = Dimensions.get('window');
let lineWidth = width - 30;
let styles = StyleSheet.create({
container: {
backgroundColor: 'white',
height: 51 ,
flexDirection: 'row',
justifyContent: 'space-between',
flex: 1,
},
topLine: {
position: 'absolute',
left: 0,
top: 0,
width: width,
height: 0.5,
backgroundColor: '#f2f2f2',
},
bottomLine: {
position: 'absolute',
left:0,
bottom: 0,
width: width,
height: 0.5,
backgroundColor: '#f2f2f2',
},
leftLikeContainer: {
flex: 1,
flexDirection: 'row',
alignItems: 'center',
left: 15,
},
avatarPannel: {
flexDirection: 'row-reverse',
justifyContent: 'flex-start',
},
rightLikeContainer: {
flex: 1,
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'flex-end',
right: 15,
},
likeAvatar: {
width: 30,
height: 30,
borderRadius: 15,
},
likeText: {
fontSize: 14,
},
browseText: {
fontSize: 14,
},
});