BLKBrandCell.js
3.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
'use strict';
import React from 'react';
import ReactNative from 'react-native';
import Immutable, {Map} from 'immutable';
const {
AppRegistry,
StyleSheet,
Text,
View,
Image,
ListView,
Dimensions,
TouchableOpacity,
} = ReactNative;
export default class BLKBrandCell extends React.Component {
constructor(props) {
super(props);
this._renderRow = this._renderRow.bind(this);
this._renderSeparator = this._renderSeparator.bind(this);
this.dataSource = new ListView.DataSource({
rowHasChanged: (r1, r2) => r1.key != r2.key,
});
}
shouldComponentUpdate(nextProps){
if (Immutable.is(nextProps.resource, this.props.resource)) {
return false;
} else {
return true;
}
}
_renderRow(rowData, sectionID, rowID) {
let img = rowData.get('brand_ico');
img = img.replace('{width}', cellWidth*2).replace('{height}', (cellWidth-10)*2).replace('{mode}',2);
let brandName = rowData.get('brand_name');
return (
<TouchableOpacity style={styles.cell} onPress={()=>{this.props.onPressBrandItem && this.props.onPressBrandItem(rowData.toJS());}}>
<Image style={styles.cellImg} source={{uri:img}} resizeMode={'contain'}/>
<Text style={styles.cellTitle}>{brandName}</Text>
</TouchableOpacity>
);
}
_renderSeparator(sectionID, rowID, adjacentRowHighlighted) {
return (
<View key={'sep' + rowID} style={styles.separatorB}>
</View>
);
}
render() {
let data = this.props.rowData;
if (!data.length) {
return null;
}
let title = this.props.title;
return(
<View style={styles.container}>
<View style={styles.separator}/>
<Text style={styles.title}>{title}</Text>
<ListView
contentContainerStyle={styles.brandContainer}
enableEmptySections={true}
initialListSize={data.length}
dataSource={this.dataSource.cloneWithRows(data)}
renderRow={this._renderRow}
renderSeparator={this._renderSeparator}
scrollEnabled={false}
scrollsToTop={false}
/>
</View>
);
return null;
}
};
let {width, height} = Dimensions.get('window');
let cellWidth = (width-30)/4.0;
let styles = StyleSheet.create({
container: {
backgroundColor: '#f0f0f0',
},
separator: {
width: width,
height: 10,
borderColor: '#e0e0e0',
borderTopWidth: 0.5,
borderBottomWidth: 0.5,
backgroundColor: '#f0f0f0',
},
title: {
color: 'black',
fontSize: 16,
paddingLeft: 15,
width: width,
height: 30,
paddingTop: 7,
backgroundColor: 'white'
},
brandContainer: {
backgroundColor: 'white',
borderColor: 'rgb(215, 215, 215)',
borderBottomWidth: 0.5,
flexDirection: 'row',
flexWrap: 'wrap',
width: width,
paddingBottom: 5,
paddingLeft: 15,
},
cell: {
width: cellWidth,
height: cellWidth,
marginTop: 0,
marginBottom: 10,
backgroundColor: 'white',
flexDirection: 'column',
},
separatorB: {
width: 0.5,
top: 0,
height: cellWidth,
backgroundColor: '#e0e0e0',
},
cellImg: {
backgroundColor: 'white',
marginLeft: 5,
marginTop: 0,
width: cellWidth-10,
height: cellWidth - 10,
},
cellTitle: {
backgroundColor: 'white',
fontSize: 9,
color: '#b0b0b0',
textAlign: 'center',
marginTop: 0,
marginLeft: 0,
marginRight: 0,
}
});