UNPKG

@zwdvidal/react-native-dropdownalert

Version:

A simple alert to notify users about new chat messages, something went wrong or everything is ok.

37 lines (35 loc) 1.05 kB
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) { 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; } }