KidsBrandFloor.js
4.83 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
/**
* Description:
* <p> kids_brands:热门品牌推荐 潮童
* Author: Bruce.Lu
* Version: 1.0
* Created on 2017/2/9.
*/
'use strict'
import React, {
Component
} from 'react';
import ReactNative, {
Text,
Image,
View,
StyleSheet,
Dimensions,
TouchableOpacity
} from 'react-native';
import ListView from 'deprecated-react-native-listview'
import Immutable, {
Map
} from 'immutable';
import HeadTitleCell from '../cell/HeadTitleCell';
import YH_Image from '../../../common/components/YH_Image';
import SlicedImage from '../../../common/components/SlicedImage';
export default class KidsBrandFloor extends Component {
constructor(props) {
super(props);
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, highlightRow) {
let moreUrl = this.props.data.get('title').get('more_url');
let imgUrl = SlicedImage.getSlicedUrl(rowData.get('src'), itemWidth, itemWidth, 2);
let title = rowData.get('title');
let actionUrl = rowData.get('url');
if (rowID <= 7) {
if (rowID == 7) {
return (
<TouchableOpacity
onPress={()=>{this.props.onPressBrandItem&&this.props.onPressBrandItem(moreUrl, '', rowID)}}
yh_exposureData={this.props.data.get('title').get('yh_exposureData')}>
<View style={styles.row}>
<View style={styles.imageContainer}>
<Image
source={require('../../images/brandicon_more.png')}/>
</View>
<Text style={styles.text} numberOfLines={1}>
MORE
</Text>
</View>
</TouchableOpacity>
);
} else {
return (
<TouchableOpacity style={styles.cellContainer}
activeOpacity={1}
yh_exposureData={rowData.get('yh_exposureData')}
onPress={()=>{this.props.onPressBrandItem&&this.props.onPressBrandItem(actionUrl, imgUrl, rowID)}}>
<YH_Image style={styles.image}
url={imgUrl}/>
<Text style={styles.text} numberOfLines={1}>
{title}
</Text>
</TouchableOpacity>
);
}
} else {
return null;
}
}
render() {
let data = this.props.data;
let title = data.get('title').get('title');
let moreurl = data.get('title').get('more_url');
let dataList = data.get('list');
let floorH = 40 + itemHeight * 2 + 0.5;
return (
<View style={{backgroundColor:'white',width:width,height:floorH}}>
<HeadTitleCell title={title} moreUrl={moreurl}
onPressTitleMore={this.props.onPressTitleMore} yh_exposureData={data.get('title').get('yh_exposureData')}/>
<ListView
contentContainerStyle={styles.list}
dataSource={this.dataSource.cloneWithRows(dataList.toArray())}
initialListSize={data.length}
renderRow={this._renderRow.bind(this)}
/>
</View>
);
}
}
let {width, height} = Dimensions.get('window');
let itemWidth = width / 4 - 0.5;
let itemHeight = itemWidth + 20;
let styles = StyleSheet.create({
list: {
backgroundColor: '#7f808080',
flexDirection: 'row',
flexWrap: 'wrap',
justifyContent: 'flex-start',
alignItems: 'flex-start',
},
cell: {
marginLeft: 0,
width: itemWidth,
height: itemWidth + 20,
backgroundColor: 'white',
flexDirection: 'column'
},
image: {
width: itemWidth,
height: itemWidth,
},
text: {
width: itemWidth,
height: 20,
backgroundColor: 'white',
color: 'gray',
textAlign: 'center',
fontSize: 12,
},
imageContainer: {
width: itemWidth,
height: itemWidth,
backgroundColor: 'white',
justifyContent: 'center',
alignItems: 'center'
},
cellContainer: {
backgroundColor: 'white',
width: itemWidth,
justifyContent: 'center',
alignItems: 'center',
marginRight: 0.5,
marginBottom: 0.5
},
});