HotCategoryIndividualization.js
4.65 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
/**
* Description:
* hot_category_individualization:热门品类楼层 + title,大数据版
* Author: Bruce.Lu
* Version: 1.0
* Created on 2017/2/14.
*/
import React, {Component} from 'react';
import ReactNative, {
Image,
Text,
StyleSheet,
ListView,
View,
TouchableOpacity,
Dimensions,
} from 'react-native';
import ImmutablePropTypes from 'react-immutable-proptypes';
import Immutable from 'immutable';
import SlicedImage from '../../../common/components/SlicedImage';
import HeadTitleCell from '../cell/HeadTitleCell';
import YH_Image from '../../../common/components/YH_Image';
export default class HotCategoryIndividualization extends Component {
constructor(props) {
super(props);
this.dataSource = new ListView.DataSource({
rowHasChanged: (r1, r2) => !Immutable.is(r1, r2),
});
}
render() {
let title = this.props.data.get('title');
let data = this.props.data.get('list').toArray();
let lineNumber = parseInt((data.length + 3) / 4);
let listHeight = Math.floor(lineNumber * cellHeight);
let containerHeight = listHeight + 40;
let yh_exposureDataTitle = (title && title.get('yh_exposureData')) ? title.get('yh_exposureData').toJS() : null;
return (
<View style={[styles.container, {height: containerHeight}]}>
<HeadTitleCell title={title.get('title')} moreUrl={title.get('more_url')}
onPressTitleMore={this.props.onPressTitleMore} yh_exposureData={yh_exposureDataTitle}/>
<View style={[styles.list, {height: listHeight}]}>
{data.map((item, i) => {
let url = YH_Image.getSlicedUrl(item.get('src'), imageWidth, imageHeight, 2);
let yh_exposureData = item.get('yh_exposureData') ? item.get('yh_exposureData').toJS() : null;
return (
<TouchableOpacity
key={i}
style={styles.cellContainer}
activeOpacity={1}
yh_exposureData={yh_exposureData}
onPress={() => {
this.props.onPressVipBannerItem && this.props.onPressVipBannerItem(item.get('url'), url, i + 1);
}}>
<YH_Image url={url} style={styles.image} />
<Text style={styles.text}>{item.get('title')}</Text>
</TouchableOpacity>
);
})}
<View style={[styles.vLine1, {height: listHeight}]} />
<View style={[styles.vLine2, {height: listHeight}]} />
<View style={[styles.vLine3, {height: listHeight}]} />
<View style={styles.hLine1} />
<View style={styles.hLine2} />
</View>
</View>
);
}
}
let {width, height} = Dimensions.get('window');
let cellWidth = width / 4;
let imageWidth = cellWidth;
let imageHeight = Math.floor(imageWidth * 249 / 187);
let cellHeight = imageHeight;
const styles = StyleSheet.create({
container: {
width: width,
flexDirection: 'column',
},
list: {
flexDirection: 'row',
flexWrap: 'wrap',
width:width,
},
cellContainer: {
backgroundColor: '#f5f7f6',
width:cellWidth,
height:cellHeight,
alignItems:'center',
flexDirection:'column'
},
image: {
width: imageWidth,
height: imageHeight,
},
text: {
backgroundColor: '#ffffff99',
fontSize: 12,
color: '#444444',
textAlign: 'center',
width:cellWidth,
height:20,
position:'absolute',
top:imageHeight-20,
left:0,
},
vLine1: {
position: 'absolute',
backgroundColor: '#e5e5e5',
width: 0.5,
top: 0,
left: cellWidth,
},
vLine2: {
position: 'absolute',
backgroundColor: '#e5e5e5',
width: 0.5,
top: 0,
left: cellWidth * 2,
},
vLine3: {
position: 'absolute',
backgroundColor: '#e5e5e5',
width: 0.5,
top: 0,
left: cellWidth * 3,
},
hLine1: {
position: 'absolute',
backgroundColor: '#e5e5e5',
width,
height: 0.5,
top: cellHeight,
left: 0,
},
hLine2: {
position: 'absolute',
backgroundColor: '#e5e5e5',
width,
height: 0.5,
top: cellHeight * 2,
left: 0,
},
});