RecommendContentTwo.js
4.63 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
'use strict';
import React from 'react';
import ReactNative from 'react-native';
import {getSlicedUrl} from '../../../classify/utils/Utils';
import Immutable, {Map} from 'immutable';
import DeviceInfo from 'react-native-device-info';
const {
AppRegistry,
StyleSheet,
Text,
View,
Image,
Dimensions,
TouchableOpacity,
PixelRatio,
Platform,
} = ReactNative;
import ListView from 'deprecated-react-native-listview'
export default class RecommendContentTwo extends React.Component {
constructor(props) {
super(props);
this.dataSource = new ListView.DataSource({
rowHasChanged: (r1, r2) => !Immutable.is(r1, r2),
});
this.renderHeader = this.renderHeader.bind(this);
this.renderRow = this.renderRow.bind(this);
}
shouldComponentUpdate(nextProps){
if (Immutable.is(nextProps.resource, this.props.resource)) {
return false;
} else {
return true;
}
}
renderHeader() {
let fontFamilyStyle = {};
if (Platform.OS === 'ios') {
let systemVersion = DeviceInfo.getSystemVersion();
systemVersion = parseFloat(systemVersion);
if (systemVersion >= 9.0) {
fontFamilyStyle = {fontFamily: 'PingFang SC'};
}
}
let data = this.props.resource.get('data');
let res = data.toJS();
let big_imageData = res.big_image;
let newSrc = getSlicedUrl(big_imageData[0].src, 320, 200, 2);
let url = big_imageData[0].url;
let title = res.title;
return(
<View style={styles.titleView}>
<View style={{width: width,height: 0.5,backgroundColor: '#e5e5e5',}}/>
<View style={styles.title}>
<Text style={[styles.text, fontFamilyStyle]}>{title.title}</Text>
</View>
<TouchableOpacity activeOpacity={0.5} onPress={() => {
this.props.onPressBrandItem && this.props.onPressBrandItem(url);
}}>
<Image
source={{uri: newSrc}}
style={styles.largeImage}
resizeMode={'contain'}
/>
</TouchableOpacity>
<View style={{width: width,height: 0.5,backgroundColor: '#e5e5e5',}}/>
</View>
);
}
renderRow(rowData,sectionID,rowID,highlightRow) {
let newSrc = getSlicedUrl(rowData.src, 100, 100, 2);
return (
<TouchableOpacity activeOpacity={0.5} onPress={() => {
this.props.onPressBrandItem && this.props.onPressBrandItem(rowData.url);
}}>
<View style={styles.row}>
<View style={styles.thumbnailV}>
<Image
source={{uri: newSrc}}
style={styles.thumbnail}
// resizeMode={'contain'}
/>
</View>
</View>
</TouchableOpacity>
);
}
render() {
let {resource} = this.props;
let data = resource.get('data');
let res = data.toJS();
let big_imageData = res.big_image;
let title = res.title;
let list = res.list;
if (resource && list.length == 0) {
return null;
}
let backgroundWidth = width;
let backgroundHeight = largeImageH + Math.ceil(list.length / 3) * itemWidth + 40;
return (
<View style={{width: backgroundWidth, height:backgroundHeight, backgroundColor:'#f0f0f0'}}>
<ListView
contentContainerStyle={styles.contentContainer}
dataSource={this.dataSource.cloneWithRows(list)}
renderRow={this.renderRow}
renderHeader={this.renderHeader}
enableEmptySections={true}
scrollEnabled={false}
scrollsToTop={false}
/>
</View>
);
}
};
let {width, height} = Dimensions.get('window');
let itemWidth= width/3;
let itemHeight = itemWidth;
let largeImageW = width;
let largeImageH = Math.ceil((200/320)*width);
let styles = StyleSheet.create({
contentContainer: {
flexDirection: 'row',
flexWrap: 'wrap',
alignItems:'flex-start',
},
row: {
width: itemWidth,
height: itemWidth,
backgroundColor: '#e5e5e5',
},
thumbnailV: {
width: itemWidth,
height: itemHeight,
},
thumbnail: {
width: itemWidth-0.5,
height: itemHeight-0.5,
backgroundColor: 'white',
borderRightWidth: 0.5,
borderBottomWidth: 0.5,
borderColor: '#e5e5e5',
},
titleView: {
height: largeImageH+40,
width:width,
backgroundColor: 'white',
},
title: {
alignItems: 'center',
justifyContent: 'center',
height: 39,
width:width,
backgroundColor: 'white',
},
text: {
textAlign: 'center',
fontSize: 16,
fontWeight: 'bold',
color: '#444',
},
largeImage: {
width: largeImageW,
height: largeImageH,
backgroundColor: 'white',
},
});