<commit_before>// flow

import React, { PropTypes, Component } from 'react';
import { View, StyleSheet, Animated, Dimensions } from 'react-native';
import Overlay from './Overlay';

const SCRREN_WIDTH = Dimensions.get('window').width;
const SCRREN_HEIGHT = Dimensions.get('window').height;

const propTypes = {
  animation: PropTypes.string,
  width: PropTypes.number,
  height: PropTypes.number,
  overlayBackgroundColor: PropTypes.string,
  overlayOpacity: PropTypes.number,
  dialogAnimation: PropTypes.object,
  animationDuration: PropTypes.number,
  closeOnTouchOutside: PropTypes.bool,
  open: PropTypes.bool,
  onOpened: PropTypes.func,
  onClosed: PropTypes.func,
  children: PropTypes.any,
};

const defaultProps = {
  animation: 'scale',
  animationDuration: 200,
  width: SCRREN_WIDTH,
  height: 300,
  closeOnTouchOutside: true,
};

class Dialog extends Component {
  static propTypes = propTypes
  static defaultProps = defaultProps

  constructor(props) {
    super(props);

    // get animation from props
    if (props.dialogAnimation) {
      this.dialogAnimation = props.dialogAnimation;
    }

    // opened, opening, closed, closing,
    this.state = {
      dialogState: 'closed',
    };

    this.onOverlayPress = this.onOverlayPress.bind(this);
  }

  componentDidMount() {
    if (this.props.open) {
      this.open(this.props.onOpened);
    } else {
      this.close(this.props.onClosed);
    }
  }

  componentWillReceiveProps(nextProps) {
    if (this.props.open !== nextProps.open) {
      if (nextProps.open) {
        return this.open(this.nextProps.onOpened);
      }
      return this.close(this.nextProps.onClosed);
    }
    return nextProps;
  }

  onOverlayPress() {
    this.close();
  }

  setDialogState(toValue, callback) {
    this.dialogAnimation.toValue(toValue);
    let dialogState = toValue ? 'opening' : 'closing';

    this.setState({ dialogState });

    setTimeout(() => {
      dialogState = dialogState === 'closing' ? 'closed' : 'opened';
      this.setState({ dialogState });
      if (callback) callback();
    }, this.props.animationDuration);
  }

  getDialogSize({ width, height }): Object {
    const size = { width, height };
    if (width > 0.0 && width < 1.0) {
      size.width = width * SCRREN_WIDTH;
    }
    if (height > 0.0 && height < 1.0) {
      size.height = height * SCRREN_HEIGHT;
    }
    return size;
  }<commit_msg>bug fix - replace this.nextProps to nextProps on componentWillReceiveProps method<commit_after>// flow

import React, { PropTypes, Component } from 'react';
import { View, StyleSheet, Animated, Dimensions } from 'react-native';
import Overlay from './Overlay';

const SCRREN_WIDTH = Dimensions.get('window').width;
const SCRREN_HEIGHT = Dimensions.get('window').height;

const propTypes = {
  animation: PropTypes.string,
  width: PropTypes.number,
  height: PropTypes.number,
  overlayBackgroundColor: PropTypes.string,
  overlayOpacity: PropTypes.number,
  dialogAnimation: PropTypes.object,
  animationDuration: PropTypes.number,
  closeOnTouchOutside: PropTypes.bool,
  open: PropTypes.bool,
  onOpened: PropTypes.func,
  onClosed: PropTypes.func,
  children: PropTypes.any,
};

const defaultProps = {
  animation: 'scale',
  animationDuration: 200,
  width: SCRREN_WIDTH,
  height: 300,
  closeOnTouchOutside: true,
};

class Dialog extends Component {
  static propTypes = propTypes
  static defaultProps = defaultProps

  constructor(props) {
    super(props);

    // get animation from props
    if (props.dialogAnimation) {
      this.dialogAnimation = props.dialogAnimation;
    }

    // opened, opening, closed, closing,
    this.state = {
      dialogState: 'closed',
    };

    this.onOverlayPress = this.onOverlayPress.bind(this);
  }

  componentDidMount() {
    if (this.props.open) {
      this.open(this.props.onOpened);
    }
  }

  componentWillReceiveProps(nextProps) {
    if (this.props.open !== nextProps.open) {
      if (nextProps.open) {
        return this.open(nextProps.onOpened);
      }
      return this.close(nextProps.onClosed);
    }
    return nextProps;
  }

  onOverlayPress() {
    this.close();
  }

  setDialogState(toValue, callback) {
    this.dialogAnimation.toValue(toValue);
    let dialogState = toValue ? 'opening' : 'closing';

    this.setState({ dialogState });

    setTimeout(() => {
      dialogState = dialogState === 'closing' ? 'closed' : 'opened';
      this.setState({ dialogState });
      if (callback) callback();
    }, this.props.animationDuration);
  }

  getDialogSize({ width, height }): Object {
    const size = { width, height };
    if (width > 0.0 && width < 1.0) {
      size.width = width * SCRREN_WIDTH;
    }
    if (height > 0.0 && height < 1.0) {
      size.height = height * SCRREN_HEIGHT;
    }
    return size;
  }
{'fraction_non_alphanumeric': 0.12646076794657762, 'fraction_numerical': 0.005843071786310518, 'mean_word_length': 3.314131413141314, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '7116350', 'n_tokens_mistral': 1533, 'n_tokens_neox': 1505, 'n_words': 326}