NewArrival.js
4.25 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
'use strict';
import React from 'react';
import ReactNative from 'react-native';
const {
Image,
View,
StyleSheet,
Dimensions,
Text,
ListView,
TouchableOpacity,
Platform,
} = ReactNative;
import Immutable, {Map} from 'immutable';
import BrandProductListCell from '../../../common/components/ListCell/ProductListCell';
import DeviceInfo from 'react-native-device-info';
export default class newArrive extends React.Component {
constructor(props) {
super (props);
this.renderRow = this.renderRow.bind(this);
this.renderHeader = this.renderHeader.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 paddingLeft = rowID % 2 == 1 ? rowMarginHorizontal / 2 : rowMarginHorizontal;
let customStyle = rowID == 0 || rowID == 1 ? {paddingLeft} : {paddingLeft};
return (
<BrandProductListCell
style={[styles.listContainer, customStyle]}
key={'row' + rowID}
rowID={rowID}
data={rowData}
onPressProduct={this.props.onPressProduct}
/>
);
}
renderHeader() {
let fontFamilyStyle = {};
if (Platform.OS === 'ios') {
let systemVersion = DeviceInfo.getSystemVersion();
systemVersion = parseFloat(systemVersion);
if (systemVersion >= 9.0) {
fontFamilyStyle = {fontFamily: 'PingFang SC'};
}
}
return(
<View style={styles.container}>
<View style={{
width: width,
height: 0.5,
backgroundColor: '#e5e5e5',
}}/>
<View style={styles.title}>
<Text style={styles.text}>NEW ARRIVAL</Text>
<TouchableOpacity activeOpacity={0.5} style={styles.thumbnail} onPress={() => {
this.props.onPressMoreProducts && this.props.onPressMoreProducts(this.props.moreProductUrl);
}}>
<Image
source={require('../../images/btn_more_p.png')}
style={{width: 22, height: 4,backgroundColor:'white',marginTop:10}}
resizeMode={'contain'}
/>
</TouchableOpacity>
</View>
</View>
);
}
render() {
let prodcutList = this.props.prodcutList;
if (!prodcutList || prodcutList.length == 0) {
return null;
}
let backgroundWidth = width;
let backgroundHeight = 64 + 20 + Math.ceil(prodcutList.length / 2) * (rowHeight + rowMarginHorizontal);
return (
<View style={{
width: backgroundWidth,
height: backgroundHeight,
backgroundColor: 'white',
}}>
<ListView
contentContainerStyle={styles.grid}
dataSource={this.dataSource.cloneWithRows(prodcutList)}
renderRow={this.renderRow}
renderHeader={this.renderHeader}
enableEmptySections = {true}
/>
<View style={{
width: width,
height: 0.5,
backgroundColor: '#e5e5e5',
}}/>
<View style={{
width: width,
height: 15,
backgroundColor: '#f0f0f0',
}}/>
</View>
);
}
};
let {width, height} = Dimensions.get('window');
let rowWidth = Math.ceil(137.5 * width / 320);
let rowHeight = Math.ceil(254 * width / 320);
let rowMarginTop = Math.ceil(10 * width / 320);
let rowMarginHorizontal = (width - rowWidth * 2) / 3;
const styles = StyleSheet.create({
grid: {
flex: 1,
flexDirection: 'row',
flexWrap: 'wrap',
alignItems: 'flex-start',
},
title: {
alignItems: 'center',
justifyContent: 'center',
height: 40,
width: width,
backgroundColor: 'white',
},
text: {
textAlign: 'left',
fontSize: 16,
fontWeight: 'bold',
color: '#000000',
marginTop: 16,
},
listContainer: {
width: width / 2,
},
thumbnail: {
position: 'absolute',
width: 40,
height: 38,
top: 1,
bottom: 1,
marginLeft: width - 40,
backgroundColor: 'transparent',
justifyContent: 'center',
},
});