forked from testshallpass/react-native-dropdownalert
-
Notifications
You must be signed in to change notification settings - Fork 0
/
imageview.js
37 lines (36 loc) · 1.01 KB
/
imageview.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
import React, {Component} from 'react';
import PropTypes from 'prop-types';
import {Image} from 'react-native';
import {DEFAULT_IMAGE_DIMENSIONS} from './constants';
export default class ImageView extends Component {
static propTypes = {
style: PropTypes.object,
source: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
imageProps: PropTypes.object,
};
static defaultProps = {
style: {
padding: 8,
width: DEFAULT_IMAGE_DIMENSIONS,
height: DEFAULT_IMAGE_DIMENSIONS,
alignSelf: 'center',
},
source: null,
imageProps: {},
};
render() {
const {source, style, imageProps} = this.props;
if (source == null) {
return null;
}
const isRemote = typeof source === 'string';
if (!style.width) {
style.width = DEFAULT_IMAGE_DIMENSIONS;
}
if (!style.height) {
style.height = DEFAULT_IMAGE_DIMENSIONS;
}
const src = isRemote ? {uri: source} : source;
return <Image {...imageProps} style={style} source={src} />;
}
}