forked from jeanpan/react-native-camera-roll-picker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImageItem.js
More file actions
87 lines (74 loc) · 2.01 KB
/
ImageItem.js
File metadata and controls
87 lines (74 loc) · 2.01 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
import React, { Component } from 'react';
import { Image, StyleSheet, Dimensions, TouchableOpacity } from 'react-native';
import PropTypes from 'prop-types';
import Icon from 'react-native-vector-icons/MaterialIcons';
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, isVideo } = this.props;
var marker = selectedMarker ? (
selectedMarker
) : (
<Image
style={[styles.marker, { width: 25, height: 25 }]}
source={require('./circle-check.png')}
/>
);
const videoIndicator = isVideo ? <Icon name={'videocam'} size={20} style={styles.video} /> : null;
var image = item;
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}
{videoIndicator}
</TouchableOpacity>
);
}
_handleClick(item) {
this.props.onClick(item);
}
}
const styles = StyleSheet.create({
marker: {
position: 'absolute',
top: 5,
right: 5,
backgroundColor: 'transparent'
},
video: {
position: 'absolute',
top: 5,
left: 5,
backgroundColor: 'transparent',
color: 'white'
}
});
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;