SmallPic.js
2.08 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
'use strict';
import React from 'react';
import ReactNative from 'react-native';
import {getSlicedUrl} from '../../../classify/utils/Utils';
const {
Image,
View,
StyleSheet,
Dimensions,
TouchableOpacity,
} = ReactNative;
import Immutable, {Map} from 'immutable';
export default class SmallPic extends React.Component {
constructor(props) {
super (props);
}
shouldComponentUpdate(nextProps){
if (Immutable.is(nextProps.resource, this.props.resource)) {
return false;
} else {
return true;
}
}
render() {
if (this.props.resource.size == 0) {
return null;
}
let res = this.props.resource.get('data');
let list = res.toJS();
let image0 = getSlicedUrl(list[0].src, 100, 50, 2);
let image0_url = list[0].url;
let image1 = getSlicedUrl(list[1].src, 100, 50, 2);
let image1_url = list[1].url;
return (
<View style={styles.viewStyle}>
<TouchableOpacity activeOpacity={0.5} onPress={() => {
this.props.onPressRecommendItem && this.props.onPressRecommendItem(image0_url);
}}>
<Image
source={{uri: image0}}
style={styles.thumbnail}
resizeMode={'cover'}
></Image>
</TouchableOpacity>
<TouchableOpacity activeOpacity={0.5} onPress={() => {
this.props.onPressRecommendItem && this.props.onPressRecommendItem(image1_url);
}}>
<Image
source={{uri: image1}}
style={styles.thumbnail}
resizeMode={'cover'}
></Image>
</TouchableOpacity>
</View>
);
}
};
let width = (Dimensions.get('window').width - 45)/2;
let height = (9*width)/16;
const styles = StyleSheet.create({
thumbnail: {
width: width,
height: height,
borderRadius: 10,
marginLeft: 15,
},
viewStyle:{
flexDirection: 'row',
alignItems: 'center',
width: Dimensions.get('window').width,
height: height,
backgroundColor: '#f0f0f0',
},
});