forked from testshallpass/react-native-dropdownalert
-
Notifications
You must be signed in to change notification settings - Fork 0
/
imageview.js
36 lines (35 loc) · 1.03 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
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: Image.propTypes.style,
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) {
const isRemote = typeof source === 'string';
if (!style['width']) {
style['width'] = DEFAULT_IMAGE_DIMENSIONS;
}
if (!style['height']) {
style['height'] = DEFAULT_IMAGE_DIMENSIONS;
}
return <Image style={style} source={isRemote ? { uri: source } : source} {...imageProps} />;
}
return null;
}
}