BrandArticleCell.js
4.02 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
/*
* 明星原创--资讯组件
* 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 {SlicedImage} from '../../../common/components/SlicedImage';
export default class BrandArticleCell extends Component {
constructor(props) {
super(props);
this._renderTimeAndVisit = this._renderTimeAndVisit.bind(this);
}
componentDidMount() {
}
//时间和访问次数以及是否喜欢
_renderTimeAndVisit(time, visit, likeNum, id, isliked){
let likeicon = isliked ? require("../../images/like_on.png") : require("../../images/like_off.png");
return (
<View style={styles.timebar}>
<Text style={styles.time} numberOfLines={1}>{time} </Text>
<Text style={styles.time} numberOfLines={1}>{visit} </Text>
<TouchableOpacity
activeOpacity={1}
onPress={()=>{
this.props.onPressArticleLike && this.props.onPressArticleLike(id, !isliked)
}}>
<Image style={styles.likeicon} source={likeicon} />
<Text style={styles.time} numberOfLines={1}>{likeNum}</Text>
</TouchableOpacity>
</View>
);
}
render() {
let {rowData} = 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}', 290).replace('{height}', 386);
//imgUrl = SlicedImage.getSlicedUrl(rowData.get('src'), 290, 386, 2);
//let brandIconUrl = SlicedImage.getSlicedUrl(data.get('brand_img', ''), 150, 80, 2);
//介绍
let intro = rowData.get('intro');
//发布时间
let publishTime = rowData.get('publish_time');
//访问次数
let viewsNum = rowData.get('views_num');
//喜欢信息
let like = rowData.get('like');
//是否喜欢
let isLiked = like.get("isLiked");
//喜欢人数
let likeCount = like.get("count");
return (
<View style={styles.cellContainer}>
<TouchableOpacity
style={[styles.touchableContainer]}
activeOpacity={1}
onPress={()=>{
this.props.onPressArticle && this.props.onPressArticle(url)
}}>
<Image style={styles.image} source={{uri:imgUrl}} />
<Text style={styles.title}>{title}</Text>
</TouchableOpacity>
<Text style={styles.content} numberOfLines={4}>{intro}</Text>
{this._renderTimeAndVisit(publishTime, viewsNum, likeCount, id, isLiked)}
</View>
);
}
}
let {width, height} = Dimensions.get('window');
let styles = StyleSheet.create({
cellContainer: {
width: width,
backgroundColor: '#ffffff',
},
touchableContainer: {
width: width,
},
image: {
width: width,
height: width / 1.5,
},
title:{
width: width,
fontSize: 20,
fontWeight: 'bold',
paddingLeft: 15,
paddingRight: 15,
paddingTop:10,
paddingBottom:5,
},
content:{
width: width,
fontSize: 15,
color: '#999999',
paddingLeft: 15,
paddingRight: 15,
paddingBottom:5,
},
timebar:{
width: width,
flexDirection: 'row',
paddingLeft: 15,
paddingRight: 15,
paddingBottom:5,
},
time:{
fontSize: 15,
color: '#b0b0b0',
},
likeicon:{
width: 20,
height:20,
},
});