<commit_before>/* @flow */
import React, { PropTypes } from 'react';
import StyleSheet from '../stylesheet';
import ViewStylePropTypes from './ViewStylePropTypes';

// TODO: handle other types, like React Native does
// https://github.com/facebook/react-native/blob/master/Libraries/Image/ImageSourcePropType.js
const ImageSourcePropType = PropTypes.oneOfType([
  PropTypes.shape({
    uri: PropTypes.string.isRequired,
  }),
  PropTypes.string,
]);

const ResizeModePropType = PropTypes.oneOf([
  'contain',
  'cover',
  'stretch',
  'center',
  'repeat',
  'none',
]);

const propTypes = {
  children: PropTypes.any,
  defaultSource: ImageSourcePropType,
  resizeMode: ResizeModePropType,
  source: ImageSourcePropType,
  style: PropTypes.shape({
    ...ViewStylePropTypes,
    resizeMode: ResizeModePropType,
  }),
};

const ResizeModes = {
  contain: 'Fit',
  cover: 'Fill',
  stretch: 'Stretch',
  // center: 'Center', // TODO
  // repeat: 'Repeat', // TODO
  // none: 'Fill',
};

class Image extends React.Component {
  render() {
    const {
      children,
      source,
      defaultSource,
      resizeMode,
    } = this.props;

    const style = StyleSheet.flatten(this.props.style);

    const sketchResizeMode = ResizeModes[resizeMode || style.resizeMode];

    // TODO: check to see if `source` specifies a width/height as well, and pass into `style` if so

    return (
      <image
        style={style}
        source={source || defaultSource}
        resizeMode={sketchResizeMode}
      >
        { children }
      </image>
    );
  }
}

Image.propTypes = propTypes;<commit_msg>render Images without resizeMode specified<commit_after>/* @flow */
import React, { PropTypes } from 'react';
import StyleSheet from '../stylesheet';
import ViewStylePropTypes from './ViewStylePropTypes';

// TODO: handle other types, like React Native does
// https://github.com/facebook/react-native/blob/master/Libraries/Image/ImageSourcePropType.js
const ImageSourcePropType = PropTypes.oneOfType([
  PropTypes.shape({
    uri: PropTypes.string.isRequired,
  }),
  PropTypes.string,
]);

const ResizeModePropType = PropTypes.oneOf([
  'contain',
  'cover',
  'stretch',
  'center',
  'repeat',
  'none',
]);

const propTypes = {
  children: PropTypes.any,
  defaultSource: ImageSourcePropType,
  resizeMode: ResizeModePropType,
  source: ImageSourcePropType,
  style: PropTypes.shape({
    ...ViewStylePropTypes,
    resizeMode: ResizeModePropType,
  }),
};

const ResizeModes = {
  contain: 'Fit',
  cover: 'Fill',
  stretch: 'Stretch',
  center: 'Fill', // TODO
  repeat: 'Fill', // TODO
  none: 'Fill',
};

class Image extends React.Component {
  render() {
    const {
      children,
      source,
      defaultSource,
      resizeMode,
    } = this.props;

    const style = StyleSheet.flatten(this.props.style);

    const sketchResizeMode = ResizeModes[resizeMode || (style && style.resizeMode) || 'contain'];

    // TODO: check to see if `source` specifies a width/height as well, and pass into `style` if so

    return (
      <image
        style={style}
        source={source || defaultSource}
        resizeMode={sketchResizeMode}
      >
        { children }
      </image>
    );
  }
}

Image.propTypes = propTypes;
{'fraction_non_alphanumeric': 0.13358070500927643, 'fraction_numerical': 0.0, 'mean_word_length': 3.2565789473684212, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1038295', 'n_tokens_mistral': 1007, 'n_tokens_neox': 1006, 'n_words': 237}