SmallPic.js
2.76 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
'use strict';
import React from 'react';
import ReactNative from 'react-native';
import YH_Image from '../../../common/components/YH_Image';
import Immutable, {Map} from 'immutable';
const {
View,
TouchableOpacity,
StyleSheet,
Dimensions,
Platform,
} = ReactNative;
export default class SmallPic extends React.Component {
constructor(props) {
super (props);
}
shouldComponentUpdate(nextProps){
if (Immutable.is(nextProps.data, this.props.data)) {
return false;
} else {
return true;
}
}
render() {
let {data} = this.props;
if (!data || data.size == 0) {
return null;
}
let url1 = YH_Image.getSlicedUrl(data.get(0).get('src'), imageWidth, imageHeight, 2);
let url2 = YH_Image.getSlicedUrl(data.get(1).get('src'), imageWidth, imageHeight, 2);
return (
<View style={styles.container}>
<TouchableOpacity
activeOpacity={1}
onPress={() => {
this.props.onPressPicItem && this.props.onPressPicItem(data.get(0).get('url'), url1, 0);
}}
>
<YH_Image
url={url1}
masksToBounds={true}
radius={{'topLeft':'3','topRight':'3','bottomRight':'3','bottomLeft':'3'}}
style={[styles.image, styles.left]}
/>
</TouchableOpacity>
<TouchableOpacity
activeOpacity={1}
onPress={() => {
this.props.onPressPicItem && this.props.onPressPicItem(data.get(1).get('url'), url2, 1);
}}
>
<YH_Image
url={url2}
masksToBounds={true}
radius={{'topLeft':'3','topRight':'3','bottomRight':'3','bottomLeft':'3'}}
style={[styles.image, styles.right]}
/>
</TouchableOpacity>
</View>
);
}
}
let {width, height} = Dimensions.get('window');
const DEVICE_WIDTH_RATIO = width / 320;
let containerHeight = Math.ceil(80 * (width - 45) / 2 / 137.5);
let imageWidth = Math.ceil((width - 45) / 2);
let imageHeight = Math.ceil(80 * (imageWidth / 137.5));
let styles = StyleSheet.create({
container: {
width: width,
height: containerHeight,
flexDirection: 'row',
backgroundColor: '#f0f0f0',
},
image: {
width: imageWidth,
height: imageHeight,
borderRadius: 3,
backgroundColor: 'white',
marginLeft: 15,
},
left: {
},
right: {
},
});