-
Notifications
You must be signed in to change notification settings - Fork 176
/
ImageItem.js
77 lines (65 loc) · 1.67 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
77
import React, { Component } from 'react';
import {
Image,
StyleSheet,
Dimensions,
TouchableOpacity,
} from 'react-native';
import PropTypes from 'prop-types';
const checkIcon = require('./circle-check.png');
const styles = StyleSheet.create({
marker: {
position: 'absolute',
top: 5,
right: 5,
backgroundColor: 'transparent',
},
});
class ImageItem extends Component {
componentWillMount() {
let { width } = Dimensions.get('window');
const { imageMargin, imagesPerRow, containerWidth } = this.props;
if (typeof containerWidth !== 'undefined') {
width = containerWidth;
}
this.imageSize = (width - (imagesPerRow + 1) * imageMargin) / imagesPerRow;
}
handleClick(item) {
this.props.onClick(item);
}
render() {
const {
item, selected, selectedMarker, imageMargin,
} = this.props;
const marker = selectedMarker || (<Image
style={[styles.marker, { width: 25, height: 25 }]}
source={checkIcon}
/>);
const { image } = item.node;
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}
</TouchableOpacity>
);
}
}
ImageItem.defaultProps = {
item: {},
selected: false,
};
ImageItem.propTypes = {
item: PropTypes.object,
selected: PropTypes.bool,
selectedMarker: PropTypes.element,
imageMargin: PropTypes.number,
imagesPerRow: PropTypes.number,
onClick: PropTypes.func,
};
export default ImageItem;