SmallPic.js
2.49 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
'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 SmallPic extends React.Component {
constructor(props) {
super(props);
this.state = {
width0: 1,
width1: 1,
height0: 0,
height1: 0,
};
}
componentDidMount() {
let {resource} = this.props;
let data = resource.get('data')?resource.get('data').toJS():null;
let imageHeight = data?data[0].height:null;
let imageWidth = data?data[0].width:null;
if (!imageHeight || !imageWidth) {
let url1 = data?data[0].src:null;
let url2 = data?data[1].src:null;
Image.getSize(url1, (width, height) => {
this.setState({width0 : width, height0 : height});
});
Image.getSize(url2, (width, height) => {
this.setState({width1 : width, height1 : height});
});
}
}
render() {
let {resource} = this.props;
let data = resource.get('data')?resource.get('data').toJS():null;
let url1 = data?data[0].src:null;
let url2 = data?data[1].src:null;
if (!url1 || !url2) {
return (<View style={{height:1,width:width,backgroundColor:'white'}}/>);
}
let imageHeight0 = data?data[0].height:null;
let imageWidth0 = data?data[0].width:null;
let imageHeight1 = data?data[1].height:null;
let imageWidth1 = data?data[1].width:null;
if (imageHeight0 && imageWidth0 && imageHeight1 && imageWidth1) {
return (
<View style={styles.Small_pic}>
<Image source={{uri: url1}} style={{width: width/2,height: (width/2)*(imageHeight0/imageWidth0)}} />
<Image source={{uri: url2}} style={{width: width/2,height: (width/2)*(imageHeight1/imageWidth1)}} />
</View>
);
}else {
return (
<View style={styles.Small_pic}>
<Image source={{uri: url1}} style={{width: width/2,height: (width/2)*(this.state.height0/this.state.width0)}} />
<Image source={{uri: url2}} style={{width: width/2,height: (width/2)*(this.state.height1/this.state.width1)}} />
</View>
);
}
}
};
let {width, height} = Dimensions.get('window');
let styles = StyleSheet.create({
Small_pic: {
flexDirection: 'row',
flex: 1,
backgroundColor: 'white'
},
thumb: {
}
});