FourImages.js
5.52 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
'use strict';
import React from 'react';
import ReactNative from 'react-native';
const {
Image,
View,
StyleSheet,
Dimensions,
Text,
ListView,
TouchableOpacity,
Platform,
} = ReactNative;
import DeviceInfo from 'react-native-device-info';
import Immutable, {Map} from 'immutable';
import YH_Image from '../../../common/components/YH_Image';
export default class Recommend 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.resource, this.props.resource)) {
return false;
} else {
return true;
}
}
renderRow(rowData, sectionID, rowID, highlightRow) {
let linkType = rowData.get('linkType');
let linkReource = rowData.get('resource');
let title = rowData.get('title')?rowData.get('title'):'';
let url = '';
let yh_exposureData = this.props.yh_exposureData?this.props.yh_exposureData:null;
if (linkType == '0') {
url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.poollist","params":{"productPool":"${linkReource}","title":"${title}"}}`;
} else if (linkType == '1') {
url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.productDetail","params":{"product_skn":"${linkReource}","from_page_name":"${Platform.OS === 'ios'?'iFP_RedPersonBrand':'aFP_RedPersonBrand'}","from_page_param":"${yh_exposureData?yh_exposureData.P_PARAM:null}"}}`;
} else if (linkType == '2') {
url = linkReource;
}
if (yh_exposureData) {
yh_exposureData = {
I_INDEX: 0,
ACTION_URL: url,
...yh_exposureData,
};
}
let rowContainerHeight = itemWidth;
let {resource} = this.props;
let list = resource.get('module_data').get('data').toArray();
let moduleOrder = resource.get('module_order') + 1;
let moduleType = resource.get('module_type');
let showTitle = false;
let showBottomLine = resource.get('showBottomLine');
rowContainerHeight += 1;
if (rowData.get('text') && rowData.get('text') != '') {
rowContainerHeight += 20;
showTitle = true;
}
return (
<TouchableOpacity yh_exposureData={yh_exposureData} activeOpacity={1.0} onPress={() => {
this.props.onPressProduct && this.props.onPressProduct(url,moduleOrder,moduleType,rowID+1);
}}>
<View style={[styles.rowContainer,{height: rowContainerHeight}]}>
<YH_Image url={rowData.get('pic')} style={styles.thumbnail}/>
{showTitle?
<View style={styles.itemTitle}>
<Text style={styles.itemText} numberOfLines={1}>{rowData.get('text')}</Text>
</View>
:null
}
{showBottomLine?
<View style={{width: width,height: 1,backgroundColor: '#e5e5e5',}}/>
:null}
</View>
</TouchableOpacity>
);
}
render() {
let {resource} = this.props;
let list = resource.get('module_data').get('data').toArray();
let properties = resource.get('module_data').get('properties').toJS();
let isModuleMargin = properties.isModuleMargin;
if (!list || list.length == 0) {
return null;
}
let rowHeightArray = [];
for (var i = 0; i < Math.ceil(list.length / 4); i++) {
rowHeightArray.push(itemWidth);
}
list.map((item, i) => {
if (item.get('text') && item.get('text') != '') {
rowHeightArray[Math.floor(i/list.length)] = itemWidth + 20;
}
});
let backgroundWidth = width;
let backgroundHeight = 0;
for (var i = 0; i < rowHeightArray.length; i++) {
backgroundHeight += rowHeightArray[i];
}
if (isModuleMargin == '1') {
backgroundHeight += 10;
}
return (
<View style={{width: backgroundWidth, height:backgroundHeight, backgroundColor:'#f0f0f0'}}>
<ListView
contentContainerStyle={styles.contentContainer}
dataSource={this.dataSource.cloneWithRows(list)}
renderRow={this.renderRow}
enableEmptySections={true}
pageSize={Math.ceil(list.length/4)}
scrollEnabled={false}
scrollsToTop={false}
/>
</View>
);
}
};
let {width, height} = Dimensions.get('window');
let itemWidth = (width - 4)/4;
const styles = StyleSheet.create({
contentContainer: {
width: width + 1,
flexDirection: 'row',
flexWrap: 'wrap',
backgroundColor: '#f5f7f6',
alignItems:'flex-start',
},
header: {
},
rowContainer: {
width: itemWidth + 1,
height: itemWidth + 20,
backgroundColor: '#f5f7f6',
borderRightWidth: 1,
borderColor: '#e5e5e5',
},
thumbnail: {
width: itemWidth,
height: itemWidth - 1,
backgroundColor: '#f5f7f6',
resizeMode: 'contain',
},
itemTitle: {
height: 20,
width: itemWidth,
},
itemText: {
fontWeight: 'bold',
textAlign: 'center',
color: 'gray',
fontSize: 9,
backgroundColor: '#f5f7f6',
},
text: {
textAlign: 'center',
fontSize: 16,
fontWeight: 'bold',
color: '#444',
},
});