BrandArticleCell.js
5.05 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
/*
* 明星原创--资讯组件
* create by 陈林 2016.12.13
*/
'use strict';
import React, {Component} from 'react';
import ReactNative, {
View,
Text,
Image,
TouchableOpacity,
Dimensions,
NativeAppEventEmitter,
StyleSheet,
} from 'react-native';
import Immutable from 'immutable';
import SingleImage from './SingleImage';
import {SlicedImage} from '../../../common/components/SlicedImage';
export default class BrandArticleCell extends Component {
constructor(props) {
super(props);
this._renderTimeAndVisit = this._renderTimeAndVisit.bind(this);
}
shouldComponentUpdate(nextProps,nextState){
if (Immutable.is(nextProps.rowData, this.props.rowData)) {
return false;
} else {
return true;
}
}
//时间和访问次数以及是否喜欢
_renderTimeAndVisit(time, visit, likeNum, id, rowID, isliked){
let likeicon = isliked ? require("../../images/like_on.png") : require("../../images/like_off.png");
let likestyle = isliked ? styles.darkgrayfont : styles.grayfont;
return (
<View style={styles.timebar}>
<Image style={styles.timeicon} source={require("../../images/time_icon.png")} />
<Text style={styles.grayfont} numberOfLines={1}>{time} </Text>
<Image style={styles.eyeicon} source={require("../../images/eye_icon.png")} />
<Text style={styles.grayfont} numberOfLines={1}>{visit} </Text>
<TouchableOpacity
style={styles.likecontainer}
activeOpacity={1}
onPress={()=>{
this.props.onPressArticleLike && this.props.onPressArticleLike(id, rowID, !isliked, likeNum)
}}>
<Image style={styles.likeicon} source={likeicon} />
<Text style={likestyle} numberOfLines={1}>{likeNum}</Text>
</TouchableOpacity>
</View>
);
}
render() {
let {rowData, rowID} = this.props;
//url跳转地址
let url = rowData.get('url');
//id
let id = rowData.get('id');
//标题
let title = rowData.get('title');
//图片
let imgUrl = rowData.get('src').replace('{mode}', 2).replace('{width}', width).replace('{height}', width);
// let imgUrl = SlicedImage.getSlicedUrl(rowData.get('src'), width, width, 2);
//介绍
let intro = rowData.get('intro');
//发布时间
let publishTime = rowData.get('publish_time');
//访问次数
let viewsNum = rowData.get('views_num');
//喜欢信息
let likedata = rowData.get('like');
//是否喜欢
let isLiked = likedata ? likedata.get("isLiked") : false;
//喜欢人数
let likeCount = likedata ? likedata.get("count") : "0";
return (
<View style={styles.cellContainer}>
<TouchableOpacity
style={[styles.touchableContainer]}
activeOpacity={1}
onPress={()=>{
this.props.onPressArticle && this.props.onPressArticle(url)
}}>
<SingleImage source={imgUrl} />
<Text style={styles.title}>{title}</Text>
</TouchableOpacity>
<Text style={styles.content} numberOfLines={4}>{intro}</Text>
{this._renderTimeAndVisit(publishTime, viewsNum, likeCount, id, rowID, isLiked)}
</View>
);
}
}
let {width, height} = Dimensions.get('window');
let styles = StyleSheet.create({
cellContainer: {
width: width,
backgroundColor: '#ffffff',
},
touchableContainer: {
width: width,
},
// image: {
// width: width,
// height: Math.ceil(width * 410 / 655),
// },
title:{
width: width,
fontSize: 20,
fontWeight: 'bold',
paddingLeft: 15,
paddingRight: 15,
paddingTop:10,
paddingBottom:5,
},
content:{
width: width,
fontSize: 15,
color: '#3E3A39',
paddingLeft: 15,
paddingRight: 15,
paddingBottom:5,
},
timebar:{
width: width,
height: 30,
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center',
paddingLeft: 15,
paddingRight: 15,
paddingBottom:5,
},
likecontainer:{
flex: 1,
flexDirection: 'row',
justifyContent: 'flex-end',
},
grayfont:{
fontSize: 15,
color: '#A5A5A5',
marginLeft: 5,
},
darkgrayfont:{
fontSize: 15,
color: '#444444',
marginLeft: 5,
},
timeicon:{
width: 12,
height:12,
},
eyeicon:{
width: 16,
height:12,
marginLeft: 6,
},
likeicon:{
width: 18,
height:17,
marginTop: 1,
},
});