All files / react-native-dropdownalert imageview.js

100% Statements 9/9
100% Branches 8/8
100% Functions 1/1
100% Lines 9/9
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                                            5x 5x 4x 4x 1x   4x 1x   4x   1x      
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;
  }
}