ListCell.js
6.71 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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
'use strict';
import React, {Component} from 'react';
import ReactNative, {
View,
Text,
Image,
ListView,
StyleSheet,
Dimensions,
TouchableOpacity,
InteractionManager,
Platform,
} from 'react-native';
import {getSlicedUrl} from '../../../classify/utils/Utils';
export default class List extends Component {
constructor(props) {
super(props);
this._renderHeader = this._renderHeader.bind(this);
this.state = {
width: Dimensions.get('window').width,
height: 0,
};
}
componentDidMount() {
let src = this.props.resource.src;
let bigPic = getSlicedUrl(src, 640, 640, 2);
Image.getSize(bigPic, (width, height) => {
let newWidth = Dimensions.get('window').width;
let newHeight = Dimensions.get('window').width/width*height;
this.setState({width: newWidth, height: newHeight });
});
}
_renderHeader() {
if (this.props.type == 'editor') {
return null;
}
return (
<TouchableOpacity onPress={()=>{this.props.onPressHeader&&this.props.onPressHeader(this.props.resource.author.url)}}>
<View style={styles.headerContainer}>
<Image style={styles.avatar} source={{uri:this.props.resource.author.avatar}}/>
<Text style={styles.name}>Sphinx</Text>
</View>
</TouchableOpacity>
)
}
render() {
let tagMap = {
'潮品' :require('../../image/chaopin_icon.png'),
'话题' :require('../../image/huati_icon.png'),
'潮人' :require('../../image/chaoren_icon.png'),
'搭配' :require('../../image/dapei_icon.png'),
'小贴士' :require('../../image/xiaotieshi_icon.png'),
'专题' :require('../../image/zuanti_icon.png')
};
let {
browse,
category_name,
intro,
isPraise,
praise_num,
publish_time,
src,
title,
views_num,
url,
share,
id,
} = this.props.resource;
console.log(this.props.resource);
let urlAry = url.split('&');
let shareParam = {
title,
'content': intro,
'image': src,
'url': urlAry[0],
};
let bigPic = getSlicedUrl(src, 640, 640, 2);
let tagImg = tagMap[category_name];
if (!tagImg) {
tagImg = "../../image/chaopin_icon.png";
}
let likeImg = isPraise == 'N'?require('../../image/wsc_icon.png'):require('../../image/sc_icon.png');
let isLike = isPraise == 'N';
return (
<TouchableOpacity activeOpacity={0.5} onPress={() => {
this.props.onPressCell&&this.props.onPressCell(url);
}}>
<View style={styles.container}>
<View style={styles.sapatorView}/>
{this._renderHeader()}
<Image style={styles.image,{width: this.state.width, height: this.state.height}} source={{uri:bigPic}}>
<Image style={styles.tagContainer} source={tagImg}>
<Text style={styles.tagText}>{category_name}</Text>
</Image>
</Image>
<Text style={styles.titleText}>{title}</Text>
<Text style={styles.contentText} numberOfLines={3}>{intro}</Text>
<View style={styles.toolContainer}>
<Image source={require('../../image/time_icon.png')} style={styles.iconThumb}resizeMode={'contain'}></Image>
<Text style={styles.text}>{publish_time}</Text>
<Image source={require('../../image/shared_view_icon.png')} style={styles.iconThumb}resizeMode={'contain'}></Image>
<Text style={styles.text}>{views_num}</Text>
<TouchableOpacity style={styles.likeButton} onPress={()=>{this.props.onPressLike&&this.props.onPressLike(id, isLike)}}>
<Image source={likeImg}/>
</TouchableOpacity>
<TouchableOpacity style={styles.shareButton} onPress={()=>{this.props.onPressShare&&this.props.onPressShare(shareParam)}}>
<Image source={require('../../image/shared_sharebuttom_highlighted.png')}/>
</TouchableOpacity>
</View>
</View>
</TouchableOpacity>
);
}
}
let {width, height} = Dimensions.get('window');
let styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: 'white',
},
contentContainer: {
backgroundColor: 'white',
},
sapatorView: {
backgroundColor: 'white',
width: width,
height: 16,
borderColor: 'rgb(215, 215, 215)',
borderTopWidth: 1,
borderBottomWidth: 1,
},
headerContainer: {
height: 60,
width: width,
backgroundColor: 'white',
flexDirection: 'row',
},
avatar: {
width: 30,
height: 30,
borderRadius: 15,
marginLeft: 17,
marginTop: 15,
},
name: {
fontSize: 17,
color: 'rgb(83, 83, 83)',
textAlign: 'left',
width: width - 80,
marginTop: 22,
marginLeft: 17,
},
image: {
width: width,
backgroundColor: 'gray',
height: width,
},
tagContainer: {
width: 88,
height: 25,
alignItems: 'center',
flexDirection: 'column',
},
tagText: {
backgroundColor: 'transparent',
color: 'white',
fontSize: 15,
textAlign: 'center',
paddingTop: 5,
paddingRight: 20,
},
titleText: {
backgroundColor: 'white',
color: 'black',
fontSize: 22,
marginLeft: 16,
width: width -32,
marginTop: 20,
},
contentText: {
backgroundColor: 'white',
color: 'gray',
fontSize: 14,
marginLeft: 16,
width: width - 32,
lineHeight: 25,
},
likeButton: {
position: 'absolute',
width: 17,
height: 16,
left: width - 100,
top:14,
},
shareButton: {
position: 'absolute',
width: 44,
height: 44,
left: width - 60,
top:0,
},
toolContainer: {
flexDirection: 'row',
height: 45,
width:width,
alignItems: 'center',
marginTop: 5,
},
iconThumb: {
marginLeft: 16,
height: 12,
width:20,
},
text: {
marginLeft: 5,
fontSize: 12,
color: 'gray'
},
});