<NME> index.js
<BEF> import React, { Component } from "react";
import { Image, TextInput, TouchableWithoutFeedback, View } from "react-native";
import PropTypes from "prop-types";

import Country from "./country";
import Flags from "./resources/flags";
import PhoneNumber from "./phoneNumber";
import styles from "./styles";
import CountryPicker from "./countryPicker";

export default class PhoneInput extends Component {
  static setCustomCountriesData(json) {
    Country.setCustomCountriesData(json);
  }

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

    this.onChangePhoneNumber = this.onChangePhoneNumber.bind(this);
    this.onPressFlag = this.onPressFlag.bind(this);
    this.selectCountry = this.selectCountry.bind(this);
    this.getFlag = this.getFlag.bind(this);
    this.getISOCode = this.getISOCode.bind(this);

    const { countriesList, disabled, initialCountry } = this.props;
        this.selectCountry = this.selectCountry.bind(this)
        this.getFlag = this.getFlag.bind(this)

        var iso2 = this.props.initialCountry || 'us'
        var countryData = PhoneNumber.getCountryDataByCode(iso2)
        this.state = {
            iso2,
      iso2: initialCountry,
      disabled,
      formattedNumber: countryData ? `+${countryData.dialCode}` : "",
      value: null,
      inputValue: "",
    };
  }

  componentDidMount() {
    if (this.props.value) {
      this.updateFlagAndFormatNumber(this.props.value);
    }
  }

  componentDidUpdate() {
    const { value, disabled } = this.props;
    this.setState({ disabled });

    if (value && value !== this.state.value) {
      this.setState({ value });
      this.updateFlagAndFormatNumber(value);
    }
  }

  onChangePhoneNumber(number) {
    const actionAfterSetState = this.props.onChangePhoneNumber
      ? () => {
          this.props.onChangePhoneNumber(number);
        }
      : null;
    this.updateFlagAndFormatNumber(number, actionAfterSetState);
  }

  onPressFlag() {
    if (this.props.onPressFlag) {
      this.props.onPressFlag();
    } else {
      if (this.state.iso2) this.picker.selectCountry(this.state.iso2);
      this.picker.show();
    }
  }

  getPickerData() {
    return PhoneNumber.getAllCountries().map((country, index) => ({
      key: index,
      image: Flags.get(country.iso2),
      label: country.name,
      dialCode: `+${country.dialCode}`,
      iso2: country.iso2
    }));
  }

  getCountryCode() {
    const countryData = PhoneNumber.getCountryDataByCode(this.state.iso2);
    return countryData ? countryData.dialCode : null;
  }

  getAllCountries() {
    return PhoneNumber.getAllCountries();
  }

  getFlag(iso2) {
    return Flags.get(iso2);
  }

  getDialCode() {
    return PhoneNumber.getDialCode(this.state.formattedNumber);
  }

  getValue() {
    return this.state.formattedNumber.replace(/\s/g,'');
  }

  getNumberType() {
    return PhoneNumber.getNumberType(
      this.state.formattedNumber,
      this.state.iso2
    );
  }

  getISOCode() {
    return this.state.iso2;
  }

  selectCountry(iso2) {
    if (this.state.iso2 !== iso2) {
      const countryData = PhoneNumber.getCountryDataByCode(iso2);
      if (countryData) {
        this.setState(
          {
            iso2,
            formattedNumber: `+${countryData.dialCode}`
          },
          () => {
            this.updateFlagAndFormatNumber(this.state.inputValue)
            if (this.props.onSelectCountry) this.props.onSelectCountry(iso2);
          }
        );
      }
    }
  }

  isValidNumber() {
    if (this.state.inputValue.length < 3) return false;
    return PhoneNumber.isValidNumber(
      this.state.formattedNumber,
      this.state.iso2
    );
  }

  format(text) {
    return this.props.autoFormat
      ? PhoneNumber.format(text, this.state.iso2)
      : text;
  }

  updateFlagAndFormatNumber(number, actionAfterSetState = null) {
    const { allowZeroAfterCountryCode, initialCountry } = this.props;
    let iso2 = this.getISOCode() || initialCountry;
    let formattedPhoneNumber = number;
    if (number) {
      const countryCode = this.getCountryCode();
      if (formattedPhoneNumber[0] !== "+" && countryCode !== null) {
        formattedPhoneNumber = '+' + countryCode.toString() + formattedPhoneNumber.toString();
      }
      formattedPhoneNumber = allowZeroAfterCountryCode
        ? formattedPhoneNumber
        : this.possiblyEliminateZeroAfterCountryCode(formattedPhoneNumber);
      iso2 = PhoneNumber.getCountryCodeOfNumber(formattedPhoneNumber);
    }
    this.setState({ iso2, formattedNumber: formattedPhoneNumber, inputValue: number }, actionAfterSetState);
  }

  possiblyEliminateZeroAfterCountryCode(number) {
    const dialCode = PhoneNumber.getDialCode(number);
    return number.startsWith(`${dialCode}0`)
      ? dialCode + number.substr(dialCode.length + 1)
      : number;
  }

  focus() {
    this.inputPhone.focus();
  }

  blur() {
    this.inputPhone.blur();
  }

  render() {
    const { iso2, inputValue, disabled } = this.state;
    const TextComponent = this.props.textComponent || TextInput;
    return (
      <View style={[styles.container, this.props.style]}>
        <TouchableWithoutFeedback
          onPress={this.onPressFlag}
          disabled={disabled}
        >
          <Image
            source={Flags.get(iso2)}
            style={[styles.flag, this.props.flagStyle]}
            onPress={this.onPressFlag}
          />
        </TouchableWithoutFeedback>
        <View style={{ flex: 1, marginLeft: this.props.offset || 10 }}>
          <TextComponent
            ref={ref => {
              this.inputPhone = ref;
            }}
            editable={!disabled}
            autoCorrect={false}
            style={[styles.text, this.props.textStyle]}
            onChangeText={text => {
              this.onChangePhoneNumber(text);
            }}
            keyboardType="phone-pad"
            underlineColorAndroid="rgba(0,0,0,0)"
            value={inputValue}
            {...this.props.textProps}
          />
        </View>

        <CountryPicker
          ref={ref => {
            this.picker = ref;
          }}
          selectedCountry={iso2}
          onSubmit={this.selectCountry}
          buttonColor={this.props.pickerButtonColor}
          buttonTextStyle={this.props.pickerButtonTextStyle}
          cancelText={this.props.cancelText}
          cancelTextStyle={this.props.cancelTextStyle}
          confirmText={this.props.confirmText}
          confirmTextStyle={this.props.confirmTextStyle}
          pickerBackgroundColor={this.props.pickerBackgroundColor}
          itemStyle={this.props.pickerItemStyle}
          onPressCancel={this.props.onPressCancel}
          onPressConfirm={this.props.onPressConfirm}
        />
      </View>
    );
  }
}

const styleType = PropTypes.oneOfType([PropTypes.object, PropTypes.number]);

PhoneInput.propTypes = {
  textComponent: PropTypes.func,
  initialCountry: PropTypes.string,
  onChangePhoneNumber: PropTypes.func,
  value: PropTypes.string,
  style: styleType,
  flagStyle: styleType,
  textStyle: styleType,
  offset: PropTypes.number,
  textProps: PropTypes.object,
  onSelectCountry: PropTypes.func,
  onPressCancel: PropTypes.func,
  onPressConfirm: PropTypes.func,
  pickerButtonColor: PropTypes.string,
  pickerBackgroundColor: PropTypes.string,
  pickerItemStyle: styleType,
  countriesList: PropTypes.arrayOf(
    PropTypes.shape({
      name: PropTypes.string,
      iso2: PropTypes.string,
      dialCode: PropTypes.string,
      priority: PropTypes.number,
      areaCodes: PropTypes.arrayOf(PropTypes.string)
    })
  ),
  cancelText: PropTypes.string,
  cancelTextStyle: styleType,
  confirmText: PropTypes.string,
  confirmTextTextStyle: styleType,
  disabled: PropTypes.bool,
  allowZeroAfterCountryCode: PropTypes.bool
};

PhoneInput.defaultProps = {
  initialCountry: "us",
  disabled: false,
  allowZeroAfterCountryCode: true
};

<MSG> no init Country Value
<DFF> @@ -26,7 +26,7 @@ export default class PhoneInput extends Component {
         this.selectCountry = this.selectCountry.bind(this)
         this.getFlag = this.getFlag.bind(this)
 
-        var iso2 = this.props.initialCountry || 'us'
+        var iso2 = this.props.initialCountry
         var countryData = PhoneNumber.getCountryDataByCode(iso2)
         this.state = {
             iso2,

{'commit': "diff --git a/lib/index.js b/lib/index.js\nindex 1882fcb..0f5d0aa 100644\n--- a/lib/index.js\n+++ b/lib/index.js\n@@ -26,7 +26,7 @@ export default class PhoneInput extends Component {\n         this.selectCountry = this.selectCountry.bind(this)\n         this.getFlag = this.getFlag.bind(this)\n \n-        var iso2 = this.props.initialCountry || 'us'\n+        var iso2 = this.props.initialCountry\n         var countryData = PhoneNumber.getCountryDataByCode(iso2)\n         this.state = {\n             iso2,\n", 'commit_subject': 'no init Country Value', 'repo_name': 'thegamenicorus/react-native-phone-input', 'committer': {'name': 'GitHub', 'email': '1505422b2465e9a84f6fdfaa161078890c593f06@github.com', 'time_sec': '1514492090', 'tz_offset': '600', 'date': {'seconds': '1514492090'}}, 'commit_tree': '529b2fae77255a34855b1f1a2fe147484f1ac45a', 'commit_message': 'no init Country Value', 'language_name': 'JavaScript', 'license': 'mit', 'hunks': "@@ -26,7 +26,7 @@ export default class PhoneInput extends Component {\n         this.selectCountry = this.selectCountry.bind(this)\n         this.getFlag = this.getFlag.bind(this)\n \n-        var iso2 = this.props.initialCountry || 'us'\n+        var iso2 = this.props.initialCountry\n         var countryData = PhoneNumber.getCountryDataByCode(iso2)\n         this.state = {\n             iso2,\n", 'addition_count': 1, 'deletion_count': 1, 'src_file': 'a/lib/index.js', 'tgt_file': 'b/lib/index.js', 'file_extension': '.js', 'before_file': 'import React, { Component } from "react";\nimport { Image, TextInput, TouchableWithoutFeedback, View } from "react-native";\nimport PropTypes from "prop-types";\n\nimport Country from "./country";\nimport Flags from "./resources/flags";\nimport PhoneNumber from "./phoneNumber";\nimport styles from "./styles";\nimport CountryPicker from "./countryPicker";\n\nexport default class PhoneInput extends Component {\n  static setCustomCountriesData(json) {\n    Country.setCustomCountriesData(json);\n  }\n\n  constructor(props, context) {\n    super(props, context);\n\n    this.onChangePhoneNumber = this.onChangePhoneNumber.bind(this);\n    this.onPressFlag = this.onPressFlag.bind(this);\n    this.selectCountry = this.selectCountry.bind(this);\n    this.getFlag = this.getFlag.bind(this);\n    this.getISOCode = this.getISOCode.bind(this);\n\n    const { countriesList, disabled, initialCountry } = this.props;\n        this.selectCountry = this.selectCountry.bind(this)\n        this.getFlag = this.getFlag.bind(this)\n\n        var iso2 = this.props.initialCountry || \'us\'\n        var countryData = PhoneNumber.getCountryDataByCode(iso2)\n        this.state = {\n            iso2,\n      iso2: initialCountry,\n      disabled,\n      formattedNumber: countryData ? `+${countryData.dialCode}` : "",\n      value: null,\n      inputValue: "",\n    };\n  }\n\n  componentDidMount() {\n    if (this.props.value) {\n      this.updateFlagAndFormatNumber(this.props.value);\n    }\n  }\n\n  componentDidUpdate() {\n    const { value, disabled } = this.props;\n    this.setState({ disabled });\n\n    if (value && value !== this.state.value) {\n      this.setState({ value });\n      this.updateFlagAndFormatNumber(value);\n    }\n  }\n\n  onChangePhoneNumber(number) {\n    const actionAfterSetState = this.props.onChangePhoneNumber\n      ? () => {\n          this.props.onChangePhoneNumber(number);\n        }\n      : null;\n    this.updateFlagAndFormatNumber(number, actionAfterSetState);\n  }\n\n  onPressFlag() {\n    if (this.props.onPressFlag) {\n      this.props.onPressFlag();\n    } else {\n      if (this.state.iso2) this.picker.selectCountry(this.state.iso2);\n      this.picker.show();\n    }\n  }\n\n  getPickerData() {\n    return PhoneNumber.getAllCountries().map((country, index) => ({\n      key: index,\n      image: Flags.get(country.iso2),\n      label: country.name,\n      dialCode: `+${country.dialCode}`,\n      iso2: country.iso2\n    }));\n  }\n\n  getCountryCode() {\n    const countryData = PhoneNumber.getCountryDataByCode(this.state.iso2);\n    return countryData ? countryData.dialCode : null;\n  }\n\n  getAllCountries() {\n    return PhoneNumber.getAllCountries();\n  }\n\n  getFlag(iso2) {\n    return Flags.get(iso2);\n  }\n\n  getDialCode() {\n    return PhoneNumber.getDialCode(this.state.formattedNumber);\n  }\n\n  getValue() {\n    return this.state.formattedNumber.replace(/\\s/g,\'\');\n  }\n\n  getNumberType() {\n    return PhoneNumber.getNumberType(\n      this.state.formattedNumber,\n      this.state.iso2\n    );\n  }\n\n  getISOCode() {\n    return this.state.iso2;\n  }\n\n  selectCountry(iso2) {\n    if (this.state.iso2 !== iso2) {\n      const countryData = PhoneNumber.getCountryDataByCode(iso2);\n      if (countryData) {\n        this.setState(\n          {\n            iso2,\n            formattedNumber: `+${countryData.dialCode}`\n          },\n          () => {\n            this.updateFlagAndFormatNumber(this.state.inputValue)\n            if (this.props.onSelectCountry) this.props.onSelectCountry(iso2);\n          }\n        );\n      }\n    }\n  }\n\n  isValidNumber() {\n    if (this.state.inputValue.length < 3) return false;\n    return PhoneNumber.isValidNumber(\n      this.state.formattedNumber,\n      this.state.iso2\n    );\n  }\n\n  format(text) {\n    return this.props.autoFormat\n      ? PhoneNumber.format(text, this.state.iso2)\n      : text;\n  }\n\n  updateFlagAndFormatNumber(number, actionAfterSetState = null) {\n    const { allowZeroAfterCountryCode, initialCountry } = this.props;\n    let iso2 = this.getISOCode() || initialCountry;\n    let formattedPhoneNumber = number;\n    if (number) {\n      const countryCode = this.getCountryCode();\n      if (formattedPhoneNumber[0] !== "+" && countryCode !== null) {\n        formattedPhoneNumber = \'+\' + countryCode.toString() + formattedPhoneNumber.toString();\n      }\n      formattedPhoneNumber = allowZeroAfterCountryCode\n        ? formattedPhoneNumber\n        : this.possiblyEliminateZeroAfterCountryCode(formattedPhoneNumber);\n      iso2 = PhoneNumber.getCountryCodeOfNumber(formattedPhoneNumber);\n    }\n    this.setState({ iso2, formattedNumber: formattedPhoneNumber, inputValue: number }, actionAfterSetState);\n  }\n\n  possiblyEliminateZeroAfterCountryCode(number) {\n    const dialCode = PhoneNumber.getDialCode(number);\n    return number.startsWith(`${dialCode}0`)\n      ? dialCode + number.substr(dialCode.length + 1)\n      : number;\n  }\n\n  focus() {\n    this.inputPhone.focus();\n  }\n\n  blur() {\n    this.inputPhone.blur();\n  }\n\n  render() {\n    const { iso2, inputValue, disabled } = this.state;\n    const TextComponent = this.props.textComponent || TextInput;\n    return (\n      <View style={[styles.container, this.props.style]}>\n        <TouchableWithoutFeedback\n          onPress={this.onPressFlag}\n          disabled={disabled}\n        >\n          <Image\n            source={Flags.get(iso2)}\n            style={[styles.flag, this.props.flagStyle]}\n            onPress={this.onPressFlag}\n          />\n        </TouchableWithoutFeedback>\n        <View style={{ flex: 1, marginLeft: this.props.offset || 10 }}>\n          <TextComponent\n            ref={ref => {\n              this.inputPhone = ref;\n            }}\n            editable={!disabled}\n            autoCorrect={false}\n            style={[styles.text, this.props.textStyle]}\n            onChangeText={text => {\n              this.onChangePhoneNumber(text);\n            }}\n            keyboardType="phone-pad"\n            underlineColorAndroid="rgba(0,0,0,0)"\n            value={inputValue}\n            {...this.props.textProps}\n          />\n        </View>\n\n        <CountryPicker\n          ref={ref => {\n            this.picker = ref;\n          }}\n          selectedCountry={iso2}\n          onSubmit={this.selectCountry}\n          buttonColor={this.props.pickerButtonColor}\n          buttonTextStyle={this.props.pickerButtonTextStyle}\n          cancelText={this.props.cancelText}\n          cancelTextStyle={this.props.cancelTextStyle}\n          confirmText={this.props.confirmText}\n          confirmTextStyle={this.props.confirmTextStyle}\n          pickerBackgroundColor={this.props.pickerBackgroundColor}\n          itemStyle={this.props.pickerItemStyle}\n          onPressCancel={this.props.onPressCancel}\n          onPressConfirm={this.props.onPressConfirm}\n        />\n      </View>\n    );\n  }\n}\n\nconst styleType = PropTypes.oneOfType([PropTypes.object, PropTypes.number]);\n\nPhoneInput.propTypes = {\n  textComponent: PropTypes.func,\n  initialCountry: PropTypes.string,\n  onChangePhoneNumber: PropTypes.func,\n  value: PropTypes.string,\n  style: styleType,\n  flagStyle: styleType,\n  textStyle: styleType,\n  offset: PropTypes.number,\n  textProps: PropTypes.object,\n  onSelectCountry: PropTypes.func,\n  onPressCancel: PropTypes.func,\n  onPressConfirm: PropTypes.func,\n  pickerButtonColor: PropTypes.string,\n  pickerBackgroundColor: PropTypes.string,\n  pickerItemStyle: styleType,\n  countriesList: PropTypes.arrayOf(\n    PropTypes.shape({\n      name: PropTypes.string,\n      iso2: PropTypes.string,\n      dialCode: PropTypes.string,\n      priority: PropTypes.number,\n      areaCodes: PropTypes.arrayOf(PropTypes.string)\n    })\n  ),\n  cancelText: PropTypes.string,\n  cancelTextStyle: styleType,\n  confirmText: PropTypes.string,\n  confirmTextTextStyle: styleType,\n  disabled: PropTypes.bool,\n  allowZeroAfterCountryCode: PropTypes.bool\n};\n\nPhoneInput.defaultProps = {\n  initialCountry: "us",\n  disabled: false,\n  allowZeroAfterCountryCode: true\n};\n', 'message': 'no init Country Value', 'author_name': 'GitHub', 'lang': 'js'}