<commit_before>'use strict';
/**
 * @providesModule ItemCheckbox
 */

import React, { Component, PropTypes } from 'react';

import {
  View,
  StyleSheet,
  Text,
  TouchableWithoutFeedback,
} from 'react-native'

import Icon from 'react-native-vector-icons/FontAwesome';

export default class ItemCheckbox extends React.Component {
  static propTypes = {
    onCheck: React.PropTypes.func,
    onUncheck: React.PropTypes.func,
    icon: React.PropTypes.string,
    size: React.PropTypes.number,
    backgroundColor: React.PropTypes.string,
    color: React.PropTypes.string,
    iconSize: React.PropTypes.string,
    checked: React.PropTypes.bool,
    style: React.PropTypes.func,
    default: React.PropTypes.bool,
  };

  static defaultProps = {
    onCheck: null,
    onUncheck: null,
    icon: "check",
    size: 40,
    backgroundColor: 'white',
    color: 'grey',
    iconSize: 'normal',
    checked: false,
    default: false,
  };

  constructor(props, context) {
    super(props, context);

    this.state = {
      checked: false,
      bg_color: this.props.backgroundColor,
    }
  }

  _getCircleCheckStyle() {
    return {
      width: this.props.size,
      height: this.props.size,
      backgroundColor: this.state.bg_color,
      borderColor: this.props.color,
      borderWidth: 2,
      borderRadius: this.props.size/2,
      justifyContent: 'center',
      alignItems: 'center',
      padding: 2,
    };
  }

  _getIconSize() {
    if (this.props.iconSize == 'small') {
      return this.props.size * 0.5;
    } else if (this.props.iconSize == 'normal') {
      return this.props.size * 0.6;
    } else {
      return this.props.size * 0.7;
    }
  }

  _getCircleIconStyle() {
    return {
      color: this.props.backgroundColor,
      width: this._getIconSize(),
      height: this._getIconSize(),
    };
  }

  _completeProgress(defaultValue = false) {
    if (this.state.checked) {
      this.setState({
        checked: false,
        bg_color: this.props.backgroundColor,
      });
      if (this.props.onUncheck && !defaultValue) {
        this.props.onUncheck();
      }
    } else {
      this.setState({
        checked: true,
        bg_color: this.props.color,
      });
      if (this.props.onCheck && !defaultValue) {
        this.props.onCheck();
      }
    }
  }

  _initDefault() {
    this._completeProgress(true);
  }

  componentDidMount() {
    if (this.props.checked) {
      this._completeProgress();
    }

    if (this.props.default) {
      this._initDefault();
    }
  }

  render() {
    var icon = this.props.icon;
    return (
      <View style={this.props.style}>
        <TouchableWithoutFeedback
          onPress={this._completeProgress.bind(this)}
          >
          <View style={this._getCircleCheckStyle()}>
            <Icon
              name={this.props.icon}
              size={this._getIconSize()}<commit_msg>Small bug fix (onCheck did not respond)<commit_after>'use strict';
/**
 * @providesModule ItemCheckbox
 */

import React, { Component, PropTypes } from 'react';

import {
  View,
  StyleSheet,
  Text,
  TouchableWithoutFeedback,
} from 'react-native'

import Icon from 'react-native-vector-icons/FontAwesome';

export default class ItemCheckbox extends React.Component {
  static propTypes = {
    onCheck: React.PropTypes.func,
    onUncheck: React.PropTypes.func,
    icon: React.PropTypes.string,
    size: React.PropTypes.number,
    backgroundColor: React.PropTypes.string,
    color: React.PropTypes.string,
    iconSize: React.PropTypes.string,
    checked: React.PropTypes.bool,
    default: React.PropTypes.bool,
  };

  static defaultProps = {
    onCheck: null,
    onUncheck: null,
    icon: "check",
    size: 40,
    backgroundColor: 'white',
    color: 'grey',
    iconSize: 'normal',
    checked: false,
    default: false,
  };

  constructor(props, context) {
    super(props, context);

    this.state = {
      checked: false,
      bg_color: this.props.backgroundColor,
    }
  }

  _getCircleCheckStyle() {
    return {
      width: this.props.size,
      height: this.props.size,
      backgroundColor: this.state.bg_color,
      borderColor: this.props.color,
      borderWidth: 2,
      borderRadius: this.props.size/2,
      justifyContent: 'center',
      alignItems: 'center',
      padding: 2,
    };
  }

  _getIconSize() {
    if (this.props.iconSize == 'small') {
      return this.props.size * 0.5;
    } else if (this.props.iconSize == 'normal') {
      return this.props.size * 0.6;
    } else {
      return this.props.size * 0.7;
    }
  }

  _getCircleIconStyle() {
    return {
      color: this.props.backgroundColor,
      width: this._getIconSize(),
      height: this._getIconSize(),
    };
  }

  _completeProgress(defaultValue) {
    if (this.state.checked) {
      this.setState({
        checked: false,
        bg_color: this.props.backgroundColor,
      });
      if (this.props.onUncheck && !defaultValue) {
        this.props.onUncheck();
      }
    } else {
      this.setState({
        checked: true,
        bg_color: this.props.color,
      });
      if (this.props.onCheck && !defaultValue) {
        this.props.onCheck();
      }
    }
  }

  _initDefault() {
    this._completeProgress(true);
  }

  componentDidMount() {
    if (this.props.checked) {
      this._completeProgress(false);
    }

    if (this.props.default) {
      this._initDefault();
    }
  }

  render() {
    var icon = this.props.icon;
    return (
      <View style={this.props.style}>
        <TouchableWithoutFeedback
          onPress={this._completeProgress.bind(this, false)}
          >
          <View style={this._getCircleCheckStyle()}>
            <Icon
              name={this.props.icon}
              size={this._getIconSize()}
{'fraction_non_alphanumeric': 0.12967147575178167, 'fraction_numerical': 0.0038240917782026767, 'mean_word_length': 2.4087677725118484, 'pattern_counts': {'":': 0, '<': 11, '<?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': '4462227', 'n_tokens_mistral': 1863, 'n_tokens_neox': 1830, 'n_words': 343}