ListCell.js
5.16 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
'use strict';
import React from 'react';
import ReactNative from 'react-native';
import ImmutablePropTypes from 'react-immutable-proptypes';
import UserBrief from './UserBrief';
import Thumbs from './Thumbs';
import SectionItem from './SectionItem';
import NumberButton from './NumberButton';
const {
View,
Text,
Image,
TouchableOpacity,
StyleSheet,
Dimensions,
} = ReactNative;
export default class ListCell extends React.Component {
static propTypes = {
data: ImmutablePropTypes.contains({
author: ImmutablePropTypes.contains({
avatar: React.PropTypes.string,
uid: React.PropTypes.number,
name: React.PropTypes.string,
}),
timeago: React.PropTypes.string.isRequired,
isOwner: React.PropTypes.bool,
isTop: React.PropTypes.bool,
isLike: React.PropTypes.bool,
title: React.PropTypes.string,
desc: React.PropTypes.string,
thumbs: ImmutablePropTypes.listOf(
ImmutablePropTypes.contains({
src: React.PropTypes.string,
})
),
section: ImmutablePropTypes.contains({
id: React.PropTypes.number,
name: React.PropTypes.string,
}),
commentCount: React.PropTypes.number,
likeCount: React.PropTypes.number,
}),
onPressPost: React.PropTypes.func,
onPressAvatar: React.PropTypes.func,
onPressSectionTag: React.PropTypes.func,
onPressComment: React.PropTypes.func,
onPressLike: React.PropTypes.func,
};
constructor(props) {
super (props);
}
render() {
let data = this.props.data.toJS();
let {author, timeago, isOwner, isTop, isLike, title, desc, thumbs, section, commentCount, likeCount} = data;
let likeImage = isLike ? require('../../images/home/like.png') : require('../../images/home/unlike.png')
return (
<TouchableOpacity
style={styles.row}
activeOpacity={0.8}
onPress={() => {
this.props.onPressPost && this.props.onPressPost();
}}
>
<View style={styles.top}>
<UserBrief
avatar={author.avatar}
name={author.name}
timeago={timeago}
isOwner={isOwner}
onPressAvatar={() => {
this.props.onPressAvatar && this.props.onPressAvatar();
}}
/>
{isTop ? <Text style={styles.topTag}>置顶</Text> : null}
</View>
<Text style={styles.title} numberOfLines={2}>
{title}
</Text>
<Text style={styles.desc} numberOfLines={2}>
{desc}
</Text>
<Thumbs
style={styles.thumbs}
data={thumbs}
/>
<View style={styles.bottom}>
<SectionItem
name={section.name}
onPressSection={() => {
this.props.onPressSectionTag && this.props.onPressSectionTag();
}}
/>
<View style={styles.buttonContainer}>
<NumberButton
source={require('../../images/home/mes.png')}
number={commentCount}
onPressButton={() => {
this.props.onPressComment && this.props.onPressComment();
}}
/>
<NumberButton
style={{marginLeft: 20}}
source={likeImage}
number={likeCount}
onPressButton={() => {
this.props.onPressLike && this.props.onPressLike();
}}
/>
</View>
</View>
</TouchableOpacity>
);
}
}
let styles = StyleSheet.create({
row: {
backgroundColor: 'white',
paddingLeft: 17,
paddingRight: 17,
},
top: {
flexDirection: 'row',
height: 60,
},
topTag: {
position: 'absolute',
top: 20,
right: 0,
width: 35,
height: 20,
fontSize: 11,
textAlign: 'center',
color: 'white',
backgroundColor: 'black',
paddingTop: 4.5,
},
title: {
fontSize: 18,
lineHeight: 28,
},
desc: {
fontSize: 14,
lineHeight: 23,
color: '#888888',
},
thumbs: {
marginTop: 15,
marginBottom: 15,
},
bottom: {
flexDirection: 'row',
justifyContent: 'space-between',
marginBottom: 15,
},
buttonContainer: {
flexDirection: 'row',
justifyContent: 'space-between',
},
});