RecommendContentOne.js
6.37 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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
'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;
export default class RecommendContentOne extends React.Component {
constructor(props) {
super(props);
}
shouldComponentUpdate(nextProps){
if (Immutable.is(nextProps.resource, this.props.resource)) {
return false;
} else {
return true;
}
}
render() {
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 list = res.list;
let newSrc = getSlicedUrl(big_imageData[0].src, 320, 200, 2);
let newSrcUrl = big_imageData[0].url;
let image0 = getSlicedUrl(list[0].src, 320, 200, 2);
let image0_url = list[0].url;
let image1 = getSlicedUrl(list[1].src, 320, 200, 2);
let image1_url = list[1].url;
let image2 = getSlicedUrl(list[2].src, 320, 200, 2);
let image2_url = list[2].url;
let image3 = getSlicedUrl(list[3].src, 320, 200, 2);
let image3_url = list[3].url;
let image4 = getSlicedUrl(list[4].src, 320, 200, 2);
let image4_url = list[4].url;
let title = res.title;
if (!this.props.resource) {
return null;
}
return(
<View style={styles.container}>
<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.onPressRecommendItem && this.props.onPressRecommendItem(newSrcUrl);
}}>
<Image
source={{uri: newSrc}}
style={styles.largeImage}
resizeMode={'contain'}
></Image>
</TouchableOpacity>
<View style={styles.detailContainer}>
<TouchableOpacity activeOpacity={0.5} onPress={() => {
this.props.onPressRecommendItem && this.props.onPressRecommendItem(image0_url);
}}>
<View style={styles.thumbnailLeft}>
<Image
source={{uri: image0}}
style={styles.thumbnailLeft}
></Image>
</View>
</TouchableOpacity>
<View style={{width: 0.5,height: detailImageH,backgroundColor: '#e5e5e5',}}/>
<View style={styles.thumbnailRight}>
<TouchableOpacity activeOpacity={0.5} onPress={() => {
this.props.onPressRecommendItem && this.props.onPressRecommendItem(image1_url);
}}>
<View style={styles.thumbnail}>
<Image
source={{uri: image1}}
style={styles.thumbnail}
resizeMode={'contain'}
></Image>
</View>
</TouchableOpacity>
<View style={{width: thumbW,height: 0.5,backgroundColor: '#e5e5e5',}}/>
<TouchableOpacity activeOpacity={0.5} onPress={() => {
this.props.onPressRecommendItem && this.props.onPressRecommendItem(image2_url);
}}>
<View style={styles.thumbnail}>
<Image
source={{uri: image3}}
style={styles.thumbnail}
resizeMode={'contain'}
></Image>
</View>
</TouchableOpacity>
</View>
<View style={{width: 0.5,height: detailImageH,backgroundColor: '#e5e5e5',}}/>
<View style={styles.thumbnailRight}>
<TouchableOpacity activeOpacity={0.5} onPress={() => {
this.props.onPressRecommendItem && this.props.onPressRecommendItem(image3_url);
}}>
<View style={styles.thumbnail}>
<Image
source={{uri: image2}}
style={styles.thumbnail}
resizeMode={'contain'}
></Image>
</View>
</TouchableOpacity>
<View style={{width: thumbW,height: 0.5,backgroundColor: '#e5e5e5',}}/>
<TouchableOpacity activeOpacity={0.5} onPress={() => {
this.props.onPressRecommendItem && this.props.onPressRecommendItem(image4_url);
}}>
<View style={styles.thumbnail}>
<Image
source={{uri: image4}}
style={styles.thumbnail}
resizeMode={'contain'}
></Image>
</View>
</TouchableOpacity>
</View>
</View>
<View style={{width: width,height: 0.5,backgroundColor: '#e5e5e5',}}/>
</View>
);
}
};
let {width, height} = Dimensions.get('window');
let itemWidth= Math.ceil(width/3);
let itemHeight = itemWidth;
let largeImageW = width;
let largeImageH = Math.ceil((200/320)*width);
let detailImageH = Math.ceil((190/320)*width);
let image0W = Math.ceil((258/380)*detailImageH);
let thumbW = (width - image0W)/2;
let thumbH = detailImageH/2;
let styles = StyleSheet.create({
container: {
height: detailImageH + 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',
},
detailContainer: {
flexDirection: 'row',
alignItems: 'center',
width: width - 1,
height: detailImageH - 0.5,
backgroundColor: '#f0f0f0',
},
thumbnailLeft: {
width: image0W,
height: detailImageH,
backgroundColor: '#f0f0f0',
},
thumbnailRight: {
width: (width - image0W)/2,
height: detailImageH,
backgroundColor: '#f0f0f0',
flexDirection: 'column',
},
thumbnail: {
width: thumbW,
height: thumbH,
backgroundColor: '#f0f0f0',
},
});