react-native-international-phone-number 0.10.4 → 0.10.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.js +7 -28
- package/lib/utils/getCountryByPhoneNumber.js +16 -4
- package/package.json +2 -2
package/lib/index.js
CHANGED
|
@@ -213,8 +213,9 @@ const PhoneInput = forwardRef(
|
|
|
213
213
|
let formattedNumber = '';
|
|
214
214
|
|
|
215
215
|
const metadata = new Metadata();
|
|
216
|
-
metadata.selectNumberingPlan(
|
|
217
|
-
|
|
216
|
+
metadata.selectNumberingPlan(countryValue?.cca2);
|
|
217
|
+
|
|
218
|
+
const possibleLengths = countryValue ? metadata.possibleLengths() : [];
|
|
218
219
|
|
|
219
220
|
let validCallingCode = callingCode
|
|
220
221
|
? callingCode
|
|
@@ -308,12 +309,6 @@ const PhoneInput = forwardRef(
|
|
|
308
309
|
}, [defaultCountry]);
|
|
309
310
|
|
|
310
311
|
useEffect(() => {
|
|
311
|
-
if (ref) {
|
|
312
|
-
setInputValue('');
|
|
313
|
-
} else {
|
|
314
|
-
onChangePhoneNumber('');
|
|
315
|
-
}
|
|
316
|
-
|
|
317
312
|
if (defaultValue) {
|
|
318
313
|
const matchingCountry = getCountryByPhoneNumber(defaultValue);
|
|
319
314
|
|
|
@@ -327,31 +322,15 @@ const PhoneInput = forwardRef(
|
|
|
327
322
|
onChangeSelectedCountry(matchingCountry);
|
|
328
323
|
}
|
|
329
324
|
} else {
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
setCountryValue(null);
|
|
334
|
-
updateRef('', null);
|
|
335
|
-
} else {
|
|
336
|
-
onChangeSelectedCountry(null);
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
onChangeText('', null);
|
|
340
|
-
|
|
341
|
-
console.warn(
|
|
342
|
-
"The default number provided (defaultValue) don't match with anyone country. Please, correct it to be shown in the input. For more information: https://github.com/AstrOOnauta/react-native-international-phone-number#intermediate-usage---typescript--default-phone-number-value",
|
|
343
|
-
);
|
|
325
|
+
// console.warn(
|
|
326
|
+
// "The default number provided (defaultValue) don't match with anyone country. Please, correct it to be shown in the input. For more information: https://github.com/AstrOOnauta/react-native-international-phone-number#intermediate-usage---typescript--default-phone-number-value",
|
|
327
|
+
// );
|
|
344
328
|
}
|
|
345
329
|
}
|
|
346
330
|
}, [defaultValue]);
|
|
347
331
|
|
|
348
332
|
useEffect(() => {
|
|
349
|
-
if (
|
|
350
|
-
defaultValue &&
|
|
351
|
-
countryValue &&
|
|
352
|
-
countryValue.cca2 === defaultCca2 &&
|
|
353
|
-
!inputValue
|
|
354
|
-
) {
|
|
333
|
+
if (defaultValue && countryValue && countryValue.cca2 === defaultCca2) {
|
|
355
334
|
const callingCode = countryValue?.idd?.root;
|
|
356
335
|
|
|
357
336
|
let phoneNumber = defaultValue;
|
|
@@ -1,10 +1,22 @@
|
|
|
1
1
|
import parsePhoneNumber from 'libphonenumber-js';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
getCountryByCca2,
|
|
4
|
+
getCountriesByCallingCode,
|
|
5
|
+
} from 'react-native-country-select';
|
|
3
6
|
|
|
4
7
|
export default function getCountryByPhoneNumber(phoneNumber) {
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
+
const country = parsePhoneNumber(phoneNumber)?.getPossibleCountries()[0];
|
|
9
|
+
let matchingCountry = getCountryByCca2(country);
|
|
10
|
+
|
|
11
|
+
if (!matchingCountry) {
|
|
12
|
+
const callingCode = parsePhoneNumber(
|
|
13
|
+
phoneNumber,
|
|
14
|
+
)?.countryCallingCode.includes('+')
|
|
15
|
+
? parsePhoneNumber(phoneNumber)?.countryCallingCode
|
|
16
|
+
: `+${parsePhoneNumber(phoneNumber)?.countryCallingCode}`;
|
|
17
|
+
|
|
18
|
+
matchingCountry = getCountriesByCallingCode(callingCode)[0];
|
|
19
|
+
}
|
|
8
20
|
|
|
9
21
|
return matchingCountry;
|
|
10
22
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-international-phone-number",
|
|
3
3
|
"author": "AstrOOnauta (https://github.com/AstrOOnauta)",
|
|
4
|
-
"version": "0.10.
|
|
4
|
+
"version": "0.10.6",
|
|
5
5
|
"description": "International mobile phone input component with mask for React Native",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"types": "lib/index.d.ts",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"react-native-country-select": "0.2.3",
|
|
48
|
-
"libphonenumber-js": "1.12.
|
|
48
|
+
"libphonenumber-js": "1.12.17"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"metro-react-native-babel-preset": "^0.61.0"
|