TrendsetterCollocation.js
5.5 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
'use strict';
import React from 'react';
import ReactNative from 'react-native';
import Immutable, {Map} from 'immutable';
import HeadTitleCell from '../cell/HeadTitleCell';
import YH_Image from '../../../common/components/YH_Image';
const {
StyleSheet,
Text,
View,
Image,
ListView,
Dimensions,
TouchableOpacity,
} = ReactNative;
export default class TrendsetterCollocation extends React.Component {
constructor(props) {
super(props);
this.renderRow = this.renderRow.bind(this);
this.dataSource = new ListView.DataSource({
rowHasChanged: (r1, r2) => !Immutable.is(r1, r2),
});
}
shouldComponentUpdate(nextProps) {
if (Immutable.is(nextProps.data, this.props.data)) {
return false;
} else {
return true;
}
}
renderRow(rowData, sectionID, rowID) {
let url = YH_Image.getSlicedUrl(rowData.get('src'), cellWidth, cellWidth, 2);
let index = parseInt(rowID)+2;
let yh_exposureData = rowData.get('yh_exposureData')?rowData.get('yh_exposureData').toJS():'';
return (
<TouchableOpacity
style={styles.cell}
yh_exposureData={yh_exposureData}
activeOpacity={1}
onPress={() => {
this.props.onPressTrendRecommendItem && this.props.onPressTrendRecommendItem(rowData.get('url'), url, index);
}}
>
<YH_Image
url={url}
style={styles.cellImage}
/>
</TouchableOpacity>
);
}
render() {
let {title, article, recommend_collocation} = this.props.data.toObject();
let url1 = YH_Image.getSlicedUrl(article.get(0).get('src'), topCellWidth, topCellWidth, 2);
let url2 = YH_Image.getSlicedUrl(article.get(1).get('src'), topCellWidth, topCellWidth, 2);
let yh_exposureData_more = title.get('yh_exposureData')?title.get('yh_exposureData').toJS():'';
let yh_exposureData_1 = article.get(0).get('yh_exposureData')?article.get(0).get('yh_exposureData').toJS():'';
let yh_exposureData_2 = article.get(1).get('yh_exposureData')?article.get(1).get('yh_exposureData').toJS():'';
return (
<View style={styles.container}>
<HeadTitleCell yh_exposureData={yh_exposureData_more} title={title.get('title')} moreUrl={title.get('more_url')} onPressTitleMore={this.props.onPressTitleMore}/>
<View style={styles.topContainer}>
<TouchableOpacity
style={styles.topCell}
activeOpacity={1}
yh_exposureData={yh_exposureData_1}
onPress={() => {
this.props.onPressTrendRecommendItem && this.props.onPressTrendRecommendItem(article.get(0).get('url'), url1, 0);
}}
>
<YH_Image
url={url1}
style={styles.imageCover}
/>
</TouchableOpacity>
<TouchableOpacity
style={styles.topCell}
yh_exposureData={yh_exposureData_2}
activeOpacity={1}
onPress={() => {
this.props.onPressTrendRecommendItem && this.props.onPressTrendRecommendItem(article.get(1).get('url'), url2, 1);
}}
>
<YH_Image
url={url2}
style={styles.imageCover}
/>
</TouchableOpacity>
</View>
<Text style={styles.title}>推荐搭配</Text>
<ListView
contentContainerStyle={styles.collectionContainer}
enableEmptySections={true}
dataSource={this.dataSource.cloneWithRows(recommend_collocation.toArray())}
renderRow={this.renderRow}
showsHorizontalScrollIndicator={false}
horizontal={true}
scrollsToTop={false}
/>
</View>
);
}
};
let {width, height} = Dimensions.get('window');
let topCellWidth = (width - 45) / 2;
let cellWidth = Math.floor(82 * width / 375);
let containerHeight = 40 + topCellWidth + 15 * 2 + 40 + cellWidth;
let styles = StyleSheet.create({
container: {
backgroundColor: 'white',
paddingBottom: 10,
width: width,
height: containerHeight,
},
topContainer: {
width: width,
height: topCellWidth + 15,
flexDirection: 'row',
paddingTop: 15,
paddingLeft: 15,
},
topCell: {
width: topCellWidth,
height: topCellWidth,
marginRight: 15,
marginLeft: 0,
},
imageCover: {
width: topCellWidth,
height: topCellWidth,
backgroundColor: '#f0f0f0',
},
title: {
backgroundColor: 'white',
fontSize: 14,
color: '#444444',
textAlign: 'center',
width: width,
height: 40,
paddingTop: 13,
},
collectionContainer: {
height: cellWidth,
paddingLeft: 15,
},
cell: {
width: cellWidth,
height: cellWidth,
marginLeft: 0,
marginRight: 15,
},
cellImage: {
width: cellWidth,
height: cellWidth,
}
});