forked from jeanpan/react-native-camera-roll-picker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ImageItem.js
76 lines (64 loc) · 1.69 KB
/
ImageItem.js
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
import React, {Component} from 'react';
import {
Image,
StyleSheet,
Dimensions,
TouchableOpacity,
} from 'react-native';
class ImageItem extends Component {
constructor(props){
super(props)
}
componentWillMount() {
var {width} = Dimensions.get('window');
var {imageMargin, imagesPerRow, containerWidth} = this.props;
if(typeof containerWidth != "undefined") {
width = containerWidth;
}
this._imageSize = (width - (imagesPerRow + 1) * imageMargin) / imagesPerRow;
}
render() {
var {item, selected, selectedMarker, imageMargin} = this.props;
var marker = selectedMarker ? selectedMarker :
<Image
style={[styles.marker, {width: 25, height: 25}]}
source={require('./circle-check.png')}
/>;
var image = item.node.image;
return (
<TouchableOpacity
style={{marginBottom: imageMargin, marginRight: imageMargin}}
onPress={() => this._handleClick(image)}>
<Image
source={{uri: image.uri}}
style={{height: this._imageSize, width: this._imageSize}} >
{ (selected) ? marker : null }
</Image>
</TouchableOpacity>
);
}
_handleClick(item) {
this.props.onClick(item);
}
}
const styles = StyleSheet.create({
marker: {
position: 'absolute',
top: 5,
right: 5,
backgroundColor: 'transparent',
},
})
ImageItem.defaultProps = {
item: {},
selected: false,
}
ImageItem.propTypes = {
item: React.PropTypes.object,
selected: React.PropTypes.bool,
selectedMarker: React.PropTypes.element,
imageMargin: React.PropTypes.number,
imagesPerRow: React.PropTypes.number,
onClick: React.PropTypes.func,
}
export default ImageItem;