<commit_before>import React, { Component, PropTypes } from 'react';
import { Image, Dimensions } from 'react-native';

const maxWidth = Dimensions.get('window').width - 30;
class Img extends Component {
  static componentName = 'Img';

  static propTypes = {
    uri: PropTypes.string.isRequired,
    component: PropTypes.node,
  };

  static defaultProps = {
    uri: '',
    component: null,
  };

  constructor(props) {
    super(props);
    this.state = {
      imgWidth: maxWidth,
      imgHeight: 100,
    };
  }

  componentDidMount() {
    Image.getSize(this.props.uri, (width, height) => {
      this.setState({
        imgHeight: (maxWidth / width) * height,
      });
    });
  }
  render() {
    return (
      <Image
        source={{ uri: this.props.uri }}
        style={{ height: this.state.imgHeight, width: this.state.imgWidth }}
      >{this.props.component}</Image>
    );
  }
}
export default Img;
<commit_msg>[T] img: Try to fix the component will unmount call setState method after<commit_after>import React, { Component, PropTypes } from 'react';
import { Image, Dimensions } from 'react-native';

const maxWidth = Dimensions.get('window').width - 30;

class Img extends Component {
  static componentName = 'Img';

  static propTypes = {
    uri: PropTypes.string.isRequired,
  };

  static defaultProps = {
    uri: '',
  };

  constructor(props) {
    super(props);
    this.state = {
      imgWidth: maxWidth,
      imgHeight: 100,
      notdestroy: true,
    };
  }

  componentDidMount() {
    Image.getSize(this.props.uri, (width, height) => {
      if (this.state.notdestroy) {
        this.setState({
          imgHeight: (maxWidth / width) * height,
        });
      }
    });
  }

  componentWillUnmount() {
    this.state.notdestroy = false;
    console.log('componentWillUnmount');
  }
  render() {
    return (
      <Image
        source={{ uri: this.props.uri }}
        style={{ height: this.state.imgHeight, width: this.state.imgWidth }}
      />
    );
  }
}
export default Img;

{'fraction_non_alphanumeric': 0.14137419673751853, 'fraction_numerical': 0.004943153732081068, 'mean_word_length': 2.6272401433691757, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 8, 'https://': 0, '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': '2989435', 'n_tokens_mistral': 646, 'n_tokens_neox': 635, 'n_words': 143}