thegamenicorus / react-native-phone-input

Phone input box for React Native
https://www.npmjs.com/package/react-native-phone-input
MIT License
394 stars 447 forks source link

Cannot remove multi-digit country codes with delete key, with autoformat #108

Open ziaulrehman40 opened 5 years ago

ziaulrehman40 commented 5 years ago

Screen Recording 2019-07-02 at 12 19 AM

As seen in this gif, i am actually trying to delete digits from country code when country code is multi digit, it does not seem to be able to remove them. But works fine with single digit country codes.

This issue only appears when auto-format is enabled, and i seem to be able to select the country code with double tap and can remove it than, but not normally.

I am testing on iOS simulator(iphone Xs max) as i am still in dev mode. Version of library: 0.2.2 RN: 0.59.9

m4manjesh commented 4 years ago

Same happening with RN 0.60.1. Removing "autoFormat" fixed the issue.

KawaljeetSBagga commented 4 years ago

Hey guys. I know I am pretty late here but I recently started using this library and I also faced the same issue and I resolved this with a simple listener on onChangePhoneNumber, simply create a boolean state and check the length of your text and toggle auto formatting accordingly. Refer below:

const [autoFormatPhoneNumber, setAutoFormatPhoneNumber] = useState(true); <PhoneInput textStyle={{color: 'black', fontSize: 17}} ref={phoneNumber} onChangePhoneNumber={text => text.length < 5 ? setAutoFormatPhoneNumber(false) : setAutoFormatPhoneNumber(true)} autoFormat={autoFormatPhoneNumber} />

Hope this helps someone.