/
MainListCell.js
184 lines (172 loc) · 5.19 KB
/
MainListCell.js
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
'use strict';
const React = require('react-native');
const {
StyleSheet,
Image,
View,
TouchableHighlight,
ActivityIndicatorIOS,
ListView,
Text,
Component
} = React;
const MainListCell = ({data, onSelect = () => {} }) => {
const toUp = (id) => {
alert('up -> ' + id);
}
const toDown = (id) => {
alert('down -> ' + id);
}
const rowData = data
if (rowData.loadingCell) {
return <View style={styles.cellWrapperOuter}>
<View style={styles.cellWrapper}>
<Text style={styles.loadingBottom}>加载中...</Text>
</View>
</View>
}
const username = rowData.user && rowData.user.login ? rowData.user.login : '匿名';
let iconUrl;
if (rowData.user && rowData.user.id && rowData.user.icon) {
iconUrl = 'http://pic.qiushibaike.com/system/avtnew/' + rowData.user.id.toString().substring(0, 4) + '/' + rowData.user.id + '/thumb/' + rowData.user.icon
} else {
iconUrl = 'http://pic.qiushibaike.com/system/avtnew/1760/17607465/medium/nopic.jpg'
}
const userIcon = <Image
style={styles.thumbnail}
source={{ uri: iconUrl }}
/>
let up;
if (rowData.votes && rowData.votes.up) {
up = <Text style={styles.up}>{rowData.votes.up} 好笑</Text>
}
let comment
if (rowData.comments_count) {
comment = <Text style={styles.comment}> · {rowData.comments_count}评论</Text>
}
let image
if (rowData.image) {
const imageWidth = window.width - 44
const imageName = rowData.image.replace('app', '')
//http://pic.qiushibaike.com/system/pictures/10475/104759692/medium/104759692.jpg
const imageUrl = 'http://pic.qiushibaike.com/system/pictures/' + imageName.substring(0, 5) + '/' + imageName.substring(0, 9) + '/medium/' + rowData.image;
image = <Image
style={{flex: 1, height: 300, resizeMode: Image.resizeMode.contain, marginTop: 10}}
source={{ uri: imageUrl }}
/>
}
return <View style={styles.cellWrapperOuter}>
<View style={styles.cellWrapper}>
<TouchableHighlight
onPress={onSelect.bind(null, rowData)}
underlayColor={'#4c0f0f'}>
<View style={styles.cellContent}>
<View style={styles.titleWrapper}>
{userIcon}
<Text style={styles.username}>{username}</Text>
</View>
<Text style={styles.content}>{rowData.content}</Text>
{image}
<View style={styles.score}>
{up}
{comment}
</View>
<View style={styles.icons}>
<TouchableHighlight
onPress={() => toUp(rowData.id)}
underlayColor={'#d9d7d7'}>
<Image
style={styles.icon}
source={require('./images/ds.jpg')}
/>
</TouchableHighlight>
<TouchableHighlight
onPress={() => toDown(rowData.id)}
underlayColor={'#d9d7d7'}>
<Image
style={styles.icon}
source={require('./images/ds.jpg')}
/>
</TouchableHighlight>
<Image
style={styles.icon}
source={require('./images/ds.jpg')}
/>
</View>
</View>
</TouchableHighlight>
</View>
</View>
}
export default MainListCell;
const styles = StyleSheet.create({
cellWrapperOuter: {
backgroundColor: '#ededed'
},
cellWrapper: {
marginLeft: 8,
marginRight: 8,
marginTop: 4,
marginBottom: 4,
// backgroundColor: '#222121'
},
cellContent: {
paddingTop: 12,
paddingLeft: 12,
paddingRight: 12,
backgroundColor: '#fcfcfc'
},
titleWrapper: {
flex: 1,
flexDirection: 'row',
},
thumbnail: {
width: 40,
height: 40,
borderRadius: 20
},
username: {
marginTop: 10,
marginLeft: 10,
fontSize: 18
},
content: {
marginTop: 12,
color: '#63625e',
fontSize: 16
},
contentImage: {
width: 200,
height: 200,
resizeMode: Image.resizeMode.cover
},
score: {
marginTop: 16,
flex: 1,
flexDirection: 'row'
},
up: {
color: '#969696'
},
comment: {
color: '#969696'
},
icons: {
flex: 1,
flexDirection: 'row'
},
icon: {
width: 50,
height: 50
},
loadingBottom: {
fontSize: 16,
textAlign: 'center',
marginTop: 10,
marginBottom: 10,
marginLeft: 10,
marginRight: 10,
color: '#666E74',
flex: 1
},
});