Open ujwal-setlur opened 6 years ago
Here is a patch that addresses it:
--- a/node_modules/react-native-phone-input/lib/index.js
+++ b/node_modules/react-native-phone-input/lib/index.js
@@ -149,6 +149,14 @@ export default class PhoneInput extends Component {
: this.possiblyEliminateZeroAfterCountryCode(phoneNumber);
iso2 = PhoneNumber.getCountryCodeOfNumber(phoneNumber);
}
+
+ // some countries share dial prefix, so don't change country if we run into that
+ let oldDialCode = PhoneNumber.getCountryDataByCode(initialCountry).dialCode;
+ let newDialCode = PhoneNumber.getNumeric(PhoneNumber.getDialCode(phoneNumber));
+ if(oldDialCode === newDialCode) {
+ iso2 = initialCountry;
+ }
+
this.setState({ iso2, formattedNumber: phoneNumber }, actionAfterSetState);
}
When country is switched to another country that has the same international prefix, say USA and Canada, then when you start typing the phone number, the flag switches back to the first one. This is due to this code in
index.js
:This in turn calls
PhoneNumber.getCountryCodeOfNumber
from phoneNumber.js:You will notice that the first element (in this case US) gets returned. We should allow for overlapping prefixes.