react-native-international-phone-number 0.5.3 → 0.6.1

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/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  <br>
2
2
 
3
3
  <div align = "center">
4
- <img src="https://github.com/AstrOOnauta/react-native-international-phone-number/blob/master/images/preview.png" alt="React Native International Phone Number Input Lib preview">
4
+ <img src="lib/assets/images/preview.png" alt="React Native International Phone Number Input Lib preview">
5
5
  </div>
6
6
 
7
7
  <br>
@@ -24,7 +24,7 @@
24
24
  <a href="https://github.com/AstrOOnauta/react-native-international-phone-number/pulls">
25
25
  <img src="https://img.shields.io/github/issues-pr/AstrOOnauta/react-native-international-phone-number?style=flat-square&color=blue"/>
26
26
  </a>
27
- <a href="https://github.com/AstrOOnauta/react-native-international-phone-number/blob/master/LICENSE.md">
27
+ <a href="LICENSE.md">
28
28
  <img src="https://img.shields.io/:license-isc-yellow.svg?style=flat-square"/>
29
29
  </a>
30
30
  </p>
@@ -45,6 +45,7 @@
45
45
 
46
46
  - [Old Versions](#old-versions)
47
47
  - [Installation](#installation)
48
+ - [Additional Config to Web](#additional-config-to-web)
48
49
  - [Features](#features)
49
50
  - [Basic Usage](#basic-usage)
50
51
  - [With Class Component](#class-component)
@@ -65,6 +66,8 @@
65
66
  - [Custom Phone Mask](#custom-phone-mask)
66
67
  - [Custom Default Flag/Country](#custom-default-flagcountry)
67
68
  - [Default Phone Number Value](#default-phone-number-value)
69
+ - [Show Only Some Countries Inside Modal](#show-only-some-countries)
70
+ - [Exclude some countries Inside Modal](#exclude-some-countries)
68
71
  - [Lib Props](#component-props-phoneinputprops)
69
72
  - [Lib Functions](#functions)
70
73
  - [Supported languages](#🎌-supported-languages-🎌)
@@ -76,6 +79,7 @@
76
79
  ## Old Versions
77
80
 
78
81
  - [Version 0.4.x](https://github.com/AstrOOnauta/react-native-international-phone-number/tree/v0.4.x)
82
+ - [Version 0.5.x](https://github.com/AstrOOnauta/react-native-international-phone-number/tree/v0.5.x)
79
83
 
80
84
  <br>
81
85
 
@@ -91,24 +95,48 @@ OR
91
95
  $ yarn add react-native-international-phone-number
92
96
  ```
93
97
 
94
- AND
98
+ ## Additional config to `Web`
95
99
 
96
- > Update your `metro.config.js` file:
97
- >
98
- > ```bash
99
- > module.exports = {
100
- > ...
101
- > resolver: {
102
- > sourceExts: ['jsx', 'js', 'ts', 'tsx', 'cjs', 'json'],
103
- > },
104
- > };
105
- > ```
100
+ - Using React Native CLI:
101
+
102
+ create a `react-native.config.js` file at the root of your react-native project with:
103
+
104
+ ```bash
105
+ module.exports = {
106
+ project: {
107
+ ios: {},
108
+ android: {},
109
+ },
110
+ assets: [
111
+ './node_modules/react-native-international-phone-number/assets/fonts',
112
+ ],
113
+ };
114
+ ```
115
+
116
+ - Using Expo:
117
+
118
+ 1. Install [expo-fonts](https://docs.expo.dev/versions/latest/sdk/font/): `npx expo install expo-font`;
119
+ 2. Initialize the `expo-font`:
120
+
121
+ ```bash
122
+ import { useFonts } from 'expo-font';
123
+
124
+ ...
125
+
126
+ useFonts({
127
+ 'TwemojiMozilla': require('./node_modules/react-native-international-phone-number/assets/fonts/TwemojiMozilla.ttf'),
128
+ });
129
+
130
+ ...
131
+ ```
132
+
133
+ > Observation: _you need to recompile your project after adding new fonts._
106
134
 
107
135
  <br>
108
136
 
109
137
  ## Features
110
138
 
111
- - 📱 Works with iOS, Android (Cross-platform) and Expo;
139
+ - 📱 Works with iOS, Android (Cross-platform), Expo and Web;
112
140
  - 🎨 Lib with UI customizable;
113
141
  - 🌎 Phone Input Mask according with the selected country;
114
142
  - 👨‍💻 Functional and class component support;
@@ -395,6 +423,8 @@ export default function App() {
395
423
 
396
424
  ## Customizing lib
397
425
 
426
+ <img src="lib/assets/images/custom-styles.png" alt="Custom lib styles">
427
+
398
428
  - ### Dark Mode:
399
429
 
400
430
  ```jsx
@@ -408,35 +438,34 @@ export default function App() {
408
438
 
409
439
  - ### Custom Lib Styles:
410
440
 
411
- <div>
412
- <img src="https://github.com/AstrOOnauta/react-native-international-phone-number/blob/master/images/custom-styles.png" alt="Lib with custom styles">
413
- </div>
414
-
415
441
  ```jsx
416
442
  ...
417
443
  <PhoneInput
418
444
  ...
419
- inputStyle={{
420
- color: '#F3F3F3',
421
- }}
422
- containerStyle={{
423
- backgroundColor: '#575757',
424
- borderWidth: 1,
425
- borderStyle: 'solid',
426
- borderColor: '#F3F3F3',
427
- }}
428
- flagContainerStyle={{
429
- borderTopLeftRadius: 7,
430
- borderBottomLeftRadius: 7,
431
- backgroundColor: '#808080',
432
- justifyContent: 'center',
433
- }}
434
- flagTextStyle={{
445
+ phoneInputStyles={{
446
+ container: {
447
+ backgroundColor: '#575757',
448
+ borderWidth: 1,
449
+ borderStyle: 'solid',
450
+ borderColor: '#F3F3F3',
451
+ },
452
+ flagContainer: {
453
+ borderTopLeftRadius: 7,
454
+ borderBottomLeftRadius: 7,
455
+ backgroundColor: '#808080',
456
+ justifyContent: 'center',
457
+ },
458
+ flag: {},
459
+ callingCode: {
435
460
  fontSize: 16,
436
461
  fontWeight: 'bold',
437
462
  color: '#F3F3F3',
463
+ },
464
+ input: {
465
+ color: '#F3F3F3',
466
+ },
438
467
  }}
439
- modalStyle={{
468
+ modalStyles={{
440
469
  modal: {
441
470
  backgroundColor: '#333333',
442
471
  borderWidth: 1,
@@ -574,37 +603,59 @@ export default function App() {
574
603
  > 1. You need to use a default value with the following format: `+(country callling code)(area code)(number phone)`
575
604
  > 2. The lib has the mechanism to set the flag and mask of the supplied `defaultValue`. However, if the supplied `defaultValue` does not match any international standard, the `input mask of the defaultValue` will be set to "BR" (please make sure that the default value is in the format mentioned above).
576
605
 
606
+ - ### Show Only Some Countries Inside Modal:
607
+
608
+ ```jsx
609
+ ...
610
+ <PhoneInput
611
+ ...
612
+ showOnly={['BR', 'PT', 'CA', 'US']}
613
+ />
614
+ ...
615
+ ```
616
+
617
+ - ### Exclude Some Countries Inside Modal:
618
+
619
+ ```jsx
620
+ ...
621
+ <PhoneInput
622
+ ...
623
+ excludedCountries={['BR', 'PT', 'CA', 'US']}
624
+ />
625
+ ...
626
+ ```
627
+
577
628
  </br>
578
629
 
579
- ## Component Props ([PhoneInputProps](https://github.com/AstrOOnauta/react-native-international-phone-number/blob/master/lib/interfaces/phoneInputProps.ts))
630
+ ## Component Props ([PhoneInputProps](lib/interfaces/phoneInputProps.ts))
580
631
 
581
- - `language?:` [ILanguage](https://github.com/AstrOOnauta/react-native-international-phone-number/blob/master/lib/interfaces/language.ts);
632
+ - `language?:` [ILanguage](lib/interfaces/language.ts);
582
633
  - `customMask?:` string[];
583
634
  - `defaultValue?:` string;
584
635
  - `value?:` string;
585
636
  - `onChangePhoneNumber?:` (phoneNumber: string) => void;
586
- - `selectedCountry?:` [ICountry](https://github.com/AstrOOnauta/react-native-international-phone-number/blob/master/lib/interfaces/country.ts);
587
- - `onChangeSelectedCountry?:` (country: [ICountry](https://github.com/AstrOOnauta/react-native-international-phone-number/blob/master/lib/interfaces/country.ts)) => void;
637
+ - `defaultCountry?:` [ICountryCca2](lib/interfaces/countryCca2.ts);
638
+ - `selectedCountry?:` [ICountry](lib/interfaces/country.ts);
639
+ - `onChangeSelectedCountry?:` (country: [ICountry](lib/interfaces/country.ts)) => void;
640
+ - `showOnly?:` [ICountryCca2[]](lib/interfaces/countryCca2.ts);
641
+ - `excludedCountries?:` [ICountryCca2[]](lib/interfaces/countryCca2.ts);
588
642
  - `disabled?:` boolean;
589
643
  - `modalDisabled?:` boolean;
590
644
  - `modalHeight?:` number | string;
591
- - `theme?:` [ITheme](https://github.com/AstrOOnauta/react-native-international-phone-number/blob/master/lib/interfaces/theme.ts);
592
- - `containerStyle?:` [StyleProp](https://reactnative.dev/docs/style)<[ViewStyle](https://reactnative.dev/docs/view-style-props)>;
593
- - `flagContainerStyle?:` [StyleProp](https://reactnative.dev/docs/style)<[ViewStyle](https://reactnative.dev/docs/view-style-props)>;
594
- - `flagTextStyle?:` [StyleProp](https://reactnative.dev/docs/style)<[TextStyle](https://reactnative.dev/docs/text-style-props)>;
595
- - `inputStyle?:` [StyleProp](https://reactnative.dev/docs/style)<[TextStyle](https://reactnative.dev/docs/text-style-props)>;
596
- - `modalStyle?:` [IModalStyle](https://github.com/AstrOOnauta/react-native-international-phone-number/blob/master/lib/interfaces/modalStyle.ts);
597
- - `ref?:` [Ref](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/663f439d11d78b65f1dfd38d120f3728ea2cc207/types/react/index.d.ts#L100)<[IPhoneInputRef](https://github.com/AstrOOnauta/react-native-international-phone-number/blob/master/lib/interfaces/phoneInputRef.ts)>
645
+ - `theme?:` [ITheme](lib/interfaces/theme.ts);
646
+ - `phoneInputStyle?:` [IPhoneInputStyles](lib/interfaces/phoneInputStyles.ts);
647
+ - `modalStyles?:` [IModalStyles](lib/interfaces/modalStyles.ts);
648
+ - `ref?:` [Ref](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/663f439d11d78b65f1dfd38d120f3728ea2cc207/types/react/index.d.ts#L100)<[IPhoneInputRef](lib/interfaces/phoneInputRef.ts)>
598
649
 
599
650
  <br>
600
651
 
601
652
  ## Functions
602
653
 
603
- - `getAllCountries:` () => [ICountry](https://github.com/AstrOOnauta/react-native-international-phone-number/blob/master/lib/interfaces/country.ts)[];
604
- - `getCountriesByCallingCode:` (callingCode: string) => [ICountry](https://github.com/AstrOOnauta/react-native-international-phone-number/blob/master/lib/interfaces/country.ts)[] | undefined;
605
- - `getCountryByCca2:` (cca2: string) => [ICountry](https://github.com/AstrOOnauta/react-native-international-phone-number/blob/master/lib/interfaces/country.ts) | undefined;
606
- - `getCountriesByName:` (name: string, language: [ILanguage](https://github.com/AstrOOnauta/react-native-international-phone-number/blob/master/lib/interfaces/language.ts)) => [ICountry](https://github.com/AstrOOnauta/react-native-international-phone-number/blob/master/lib/interfaces/country.ts)[] | undefined;
607
- - `getCountryByPhoneNumber:` (phoneNumber: string) => [ICountry](https://github.com/AstrOOnauta/react-native-international-phone-number/blob/master/lib/interfaces/country.ts) | undefined;
654
+ - `getAllCountries:` () => [ICountry](lib/interfaces/country.ts)[];
655
+ - `getCountriesByCallingCode:` (callingCode: string) => [ICountry](lib/interfaces/country.ts)[] | undefined;
656
+ - `getCountryByCca2:` (cca2: string) => [ICountry](lib/interfaces/country.ts) | undefined;
657
+ - `getCountriesByName:` (name: string, language: [ILanguage](lib/interfaces/language.ts)) => [ICountry](lib/interfaces/country.ts)[] | undefined;
658
+ - `getCountryByPhoneNumber:` (phoneNumber: string) => [ICountry](lib/interfaces/country.ts) | undefined;
608
659
 
609
660
  </br>
610
661
 
@@ -651,7 +702,7 @@ export default function App() {
651
702
 
652
703
  ## License
653
704
 
654
- [ISC](https://github.com/AstrOOnauta/react-native-international-phone-number/blob/master/LICENSE.md)
705
+ [ISC](LICENSE.md)
655
706
 
656
707
  <br>
657
708
 
Binary file
@@ -277,7 +277,13 @@ export const countries = [
277
277
  ua: 'Антарктида',
278
278
  zh: '南極洲',
279
279
  },
280
- phoneMasks: ['## ####'],
280
+ phoneMasks: [
281
+ '10 ####',
282
+ '11 ####',
283
+ '12 ####',
284
+ '13 ####',
285
+ '14 ####',
286
+ ],
281
287
  },
282
288
  {
283
289
  callingCode: '+54',
@@ -389,7 +395,12 @@ export const countries = [
389
395
  ua: 'Австралія',
390
396
  zh: '澳大利亞',
391
397
  },
392
- phoneMasks: ['# #### ####'],
398
+ phoneMasks: [
399
+ '2 #### ####',
400
+ '3 #### ####',
401
+ '4## ### ###',
402
+ '7 #### ####',
403
+ ],
393
404
  },
394
405
  {
395
406
  callingCode: '+297',
@@ -445,7 +456,7 @@ export const countries = [
445
456
  ua: 'Аландські острови',
446
457
  zh: '奧蘭群島',
447
458
  },
448
- phoneMasks: ['## ### ##', '## ## ## ##', '### ### ####'],
459
+ phoneMasks: ['18 ### ##', '18 ## ## ##'],
449
460
  },
450
461
  {
451
462
  callingCode: '+994',
@@ -753,7 +764,7 @@ export const countries = [
753
764
  ua: 'Сен-Бартелемі',
754
765
  zh: '聖巴托洛繆島',
755
766
  },
756
- phoneMasks: ['### ## ## ##'],
767
+ phoneMasks: ['690 ## ## ##'],
757
768
  },
758
769
  {
759
770
  callingCode: '+1',
@@ -1112,7 +1123,7 @@ export const countries = [
1112
1123
  ua: 'Кокосові (Кілінг) острови',
1113
1124
  zh: '科科斯(基林)群島',
1114
1125
  },
1115
- phoneMasks: ['# #### ####'],
1126
+ phoneMasks: ['8 9162 ####'],
1116
1127
  },
1117
1128
  {
1118
1129
  callingCode: '+243',
@@ -1504,7 +1515,7 @@ export const countries = [
1504
1515
  ua: 'Острів Різдва',
1505
1516
  zh: '聖誕島',
1506
1517
  },
1507
- phoneMasks: ['# #### ####'],
1518
+ phoneMasks: ['8 9164 ####'],
1508
1519
  },
1509
1520
  {
1510
1521
  callingCode: '+357',
@@ -1931,7 +1942,7 @@ export const countries = [
1931
1942
  ua: 'Фінляндія',
1932
1943
  zh: '芬蘭',
1933
1944
  },
1934
- phoneMasks: ['### ### ## ##'],
1945
+ phoneMasks: ['4## ### ## ##', '5## ### ## ##'],
1935
1946
  },
1936
1947
  {
1937
1948
  callingCode: '+679',
@@ -1987,7 +1998,7 @@ export const countries = [
1987
1998
  ua: 'Фолклендські острови (Мальвінські острови)',
1988
1999
  zh: '福 克蘭群島(馬爾維納斯)',
1989
2000
  },
1990
- phoneMasks: ['#####'],
2001
+ phoneMasks: ['5# ###', '6# ###'],
1991
2002
  },
1992
2003
  {
1993
2004
  callingCode: '+691',
@@ -2127,7 +2138,26 @@ export const countries = [
2127
2138
  ua: "Об'єднане Королівство",
2128
2139
  zh: '英國',
2129
2140
  },
2130
- phoneMasks: ['## #### ####'],
2141
+ phoneMasks: [
2142
+ '160## ####',
2143
+ '169## ####',
2144
+ '160## #####',
2145
+ '169## #####',
2146
+ '2# #### ####',
2147
+ '11# ### ####',
2148
+ '12# ### ####',
2149
+ '13# ### ####',
2150
+ '141 ### ####',
2151
+ '151 ### ####',
2152
+ '161 ### ####',
2153
+ '12## ## ####',
2154
+ '13## ## ####',
2155
+ '1642 ## ####',
2156
+ '17## ## ####',
2157
+ '18## ## ####',
2158
+ '19## ## ####',
2159
+ '1539# ## ###',
2160
+ ],
2131
2161
  },
2132
2162
  {
2133
2163
  callingCode: '+1',
@@ -2239,7 +2269,7 @@ export const countries = [
2239
2269
  ua: 'Гернсі',
2240
2270
  zh: '根西島',
2241
2271
  },
2242
- phoneMasks: ['## #### ######'],
2272
+ phoneMasks: ['1481 ######'],
2243
2273
  },
2244
2274
  {
2245
2275
  callingCode: '+233',
@@ -2407,7 +2437,7 @@ export const countries = [
2407
2437
  ua: 'Гваделупа',
2408
2438
  zh: '瓜德羅普島',
2409
2439
  },
2410
- phoneMasks: ['### ## ## ##'],
2440
+ phoneMasks: ['69# ## ## ##'],
2411
2441
  },
2412
2442
  {
2413
2443
  callingCode: '+240',
@@ -2491,7 +2521,7 @@ export const countries = [
2491
2521
  ua: 'Південна Джорджія та Південні Сандвічеві острови',
2492
2522
  zh: '南喬治亞島和南桑威奇群島',
2493
2523
  },
2494
- phoneMasks: ['#####'],
2524
+ phoneMasks: ['4####'],
2495
2525
  },
2496
2526
  {
2497
2527
  callingCode: '+502',
@@ -2861,7 +2891,7 @@ export const countries = [
2861
2891
  ua: 'Острів Мен',
2862
2892
  zh: '馬恩島',
2863
2893
  },
2864
- phoneMasks: ['#### ######'],
2894
+ phoneMasks: ['1624 ######'],
2865
2895
  },
2866
2896
  {
2867
2897
  callingCode: '+91',
@@ -3057,7 +3087,7 @@ export const countries = [
3057
3087
  ua: 'Джерсі',
3058
3088
  zh: '球衣',
3059
3089
  },
3060
- phoneMasks: ['#### ######'],
3090
+ phoneMasks: ['1534 ######'],
3061
3091
  },
3062
3092
  {
3063
3093
  callingCode: '+1',
@@ -3903,7 +3933,7 @@ export const countries = [
3903
3933
  ua: 'Святий Мартін',
3904
3934
  zh: '聖馬丁',
3905
3935
  },
3906
- phoneMasks: ['### ## ## ##'],
3936
+ phoneMasks: ['690 ## ## ##'],
3907
3937
  },
3908
3938
  {
3909
3939
  callingCode: '+261',
@@ -4519,7 +4549,7 @@ export const countries = [
4519
4549
  ua: 'Острів Норфолк',
4520
4550
  zh: '諾福克島',
4521
4551
  },
4522
- phoneMasks: ['# #####'],
4552
+ phoneMasks: ['3 2# ###', '3 5# ###'],
4523
4553
  },
4524
4554
  {
4525
4555
  callingCode: '+234',
@@ -4631,7 +4661,16 @@ export const countries = [
4631
4661
  ua: 'Норвегія',
4632
4662
  zh: '挪威',
4633
4663
  },
4634
- phoneMasks: ['### ## ###'],
4664
+ phoneMasks: [
4665
+ '4## ## ###',
4666
+ '9## ## ###',
4667
+ '2# ## ## ##',
4668
+ '3# ## ## ##',
4669
+ '5# ## ## ##',
4670
+ '6# ## ## ##',
4671
+ '7# ## ## ##',
4672
+ '2# ## ## ##',
4673
+ ],
4635
4674
  },
4636
4675
  {
4637
4676
  callingCode: '+977',
@@ -5219,7 +5258,7 @@ export const countries = [
5219
5258
  ua: 'Реюньйон',
5220
5259
  zh: '團圓',
5221
5260
  },
5222
- phoneMasks: ['### ## ## ##'],
5261
+ phoneMasks: ['6## ## ## ##'],
5223
5262
  },
5224
5263
  {
5225
5264
  callingCode: '+40',
@@ -5583,7 +5622,7 @@ export const countries = [
5583
5622
  ua: 'Шпіцберген та Ян Маєн',
5584
5623
  zh: '斯瓦爾巴和揚· 馬延',
5585
5624
  },
5586
- phoneMasks: ['## ## ## ##'],
5625
+ phoneMasks: ['79 ## ## ##'],
5587
5626
  },
5588
5627
  {
5589
5628
  callingCode: '+421',
@@ -7074,7 +7113,7 @@ export const countries = [
7074
7113
  ua: 'Майотта',
7075
7114
  zh: '馬約特島',
7076
7115
  },
7077
- phoneMasks: ['262 ### ###', '639 ### ###'],
7116
+ phoneMasks: ['269 ### ###', '639 ### ###'],
7078
7117
  },
7079
7118
  {
7080
7119
  callingCode: '+27',
package/lib/index.js CHANGED
@@ -12,7 +12,6 @@ import {
12
12
  } from 'react-native';
13
13
  import { CountryPicker } from 'react-native-country-codes-picker';
14
14
 
15
- import styles from './styles';
16
15
  import getInputMask from './utils/getInputMask';
17
16
  import getAllCountries from './utils/getAllCountries';
18
17
  import getCountriesByName from './utils/getCountriesByName';
@@ -28,6 +27,7 @@ import {
28
27
  getContainerStyle,
29
28
  getCountryPickerStyle,
30
29
  getFlagContainerStyle,
30
+ getFlagStyle,
31
31
  getFlagTextStyle,
32
32
  getInputStyle,
33
33
  } from './utils/getStyles';
@@ -40,10 +40,7 @@ const PhoneInput = forwardRef(
40
40
  placeholder,
41
41
  placeholderTextColor,
42
42
  selectionColor,
43
- containerStyle,
44
- flagContainerStyle,
45
- flagTextStyle,
46
- inputStyle,
43
+ phoneInputStyle,
47
44
  modalStyle,
48
45
  disabled,
49
46
  modalDisabled,
@@ -54,6 +51,8 @@ const PhoneInput = forwardRef(
54
51
  selectedCountry,
55
52
  onChangeSelectedCountry,
56
53
  customMask,
54
+ showOnly,
55
+ excludedCountries,
57
56
  ...rest
58
57
  },
59
58
  ref
@@ -82,10 +81,7 @@ const PhoneInput = forwardRef(
82
81
  placeholder,
83
82
  placeholderTextColor,
84
83
  selectionColor,
85
- containerStyle,
86
- flagContainerStyle,
87
- flagTextStyle,
88
- inputStyle,
84
+ phoneInputStyle,
89
85
  modalStyle,
90
86
  disabled,
91
87
  modalDisabled,
@@ -96,6 +92,8 @@ const PhoneInput = forwardRef(
96
92
  selectedCountry,
97
93
  onChangeSelectedCountry,
98
94
  customMask,
95
+ showOnly,
96
+ excludedCountries,
99
97
  ...rest,
100
98
  },
101
99
  };
@@ -251,17 +249,6 @@ const PhoneInput = forwardRef(
251
249
  defaultValue.replace(/\D/g, '').length +
252
250
  callingCode.length
253
251
  );
254
- } else if (
255
- callingCode === '+39' &&
256
- countryValue.cca2 === 'VA'
257
- ) {
258
- phoneNumber = defaultValue
259
- .replace(/\s/g, '')
260
- .substring(
261
- callingCode.length + 5,
262
- defaultValue.replace(/\D/g, '').length +
263
- callingCode.length
264
- );
265
252
  } else {
266
253
  phoneNumber = defaultValue
267
254
  .replace(/\s/g, '')
@@ -296,22 +283,36 @@ const PhoneInput = forwardRef(
296
283
  return (
297
284
  <>
298
285
  <View
299
- style={getContainerStyle(theme, containerStyle, disabled)}
286
+ style={getContainerStyle(
287
+ theme,
288
+ phoneInputStyle?.container,
289
+ disabled
290
+ )}
300
291
  >
301
292
  <TouchableOpacity
302
293
  activeOpacity={disabled || modalDisabled ? 1 : 0.6}
303
294
  onPress={() =>
304
295
  disabled || modalDisabled ? null : setShow(true)
305
296
  }
306
- style={getFlagContainerStyle(theme, flagContainerStyle)}
297
+ style={getFlagContainerStyle(
298
+ theme,
299
+ phoneInputStyle?.flagContainer
300
+ )}
307
301
  >
308
- <Text style={styles.flag}>{countryValue?.flag}</Text>
309
- <Text style={getFlagTextStyle(theme, flagTextStyle)}>
302
+ <Text style={getFlagStyle(phoneInputStyle?.flag)}>
303
+ {countryValue?.flag}
304
+ </Text>
305
+ <Text
306
+ style={getFlagTextStyle(
307
+ theme,
308
+ phoneInputStyle?.callingCode
309
+ )}
310
+ >
310
311
  {countryValue?.callingCode}
311
312
  </Text>
312
313
  </TouchableOpacity>
313
314
  <TextInput
314
- style={getInputStyle(theme, inputStyle)}
315
+ style={getInputStyle(theme, phoneInputStyle?.input)}
315
316
  placeholder={
316
317
  placeholder ||
317
318
  getPhoneNumberInputPlaceholder(language || 'en')
@@ -352,6 +353,8 @@ const PhoneInput = forwardRef(
352
353
  )}
353
354
  pickerButtonOnPress={onSelect}
354
355
  onBackdropPress={() => setShow(false)}
356
+ showOnly={showOnly}
357
+ excludedCountries={excludedCountries}
355
358
  />
356
359
  ) : null}
357
360
  </>
@@ -1,6 +1,6 @@
1
1
  import { StyleProp, TextStyle, ViewStyle } from 'react-native';
2
2
 
3
- export interface IModalStyle {
3
+ export interface IModalStyles {
4
4
  // Styles for whole modal [View]
5
5
  modal?: StyleProp<ViewStyle>;
6
6
  // Styles for modal backdrop [View]
@@ -1,16 +1,12 @@
1
1
  import { Ref } from 'react';
2
- import {
3
- StyleProp,
4
- TextInputProps,
5
- TextStyle,
6
- ViewStyle,
7
- } from 'react-native';
2
+ import { TextInputProps } from 'react-native';
8
3
 
9
4
  import { ICountry } from './country';
10
5
  import { ICountryCca2 } from './countryCca2';
11
6
  import { ILanguage } from './language';
12
7
  import { ITheme } from './theme';
13
- import { IModalStyle } from './modalStyle';
8
+ import { IModalStyles } from './modalStyles';
9
+ import { IPhoneInputStyles } from './phoneInputStyles';
14
10
  import { IPhoneInputRef } from './phoneInputRef';
15
11
 
16
12
  interface IPhoneInputPropsWithoutRef extends TextInputProps {
@@ -18,11 +14,8 @@ interface IPhoneInputPropsWithoutRef extends TextInputProps {
18
14
  placeholder?: string;
19
15
  placeholderTextColor?: string;
20
16
  selectionColor?: string;
21
- containerStyle?: StyleProp<ViewStyle>;
22
- flagContainerStyle?: StyleProp<ViewStyle>;
23
- flagTextStyle?: StyleProp<TextStyle>;
24
- inputStyle?: StyleProp<TextStyle>;
25
- modalStyle?: IModalStyle;
17
+ phoneInputStyle?: IPhoneInputStyles;
18
+ modalStyle?: IModalStyles;
26
19
  theme?: ITheme;
27
20
  disabled?: boolean;
28
21
  modalDisabled?: boolean;
@@ -34,6 +27,8 @@ interface IPhoneInputPropsWithoutRef extends TextInputProps {
34
27
  selectedCountry: ICountry | undefined | null;
35
28
  onChangeSelectedCountry: (country: ICountry) => void;
36
29
  customMask?: Array<string>;
30
+ showOnly?: Array<ICountryCca2>;
31
+ excludedCountries?: Array<ICountryCca2>;
37
32
  ref?: never;
38
33
  }
39
34
 
@@ -42,11 +37,8 @@ interface IPhoneInputPropsWithRef extends TextInputProps {
42
37
  placeholder?: string;
43
38
  placeholderTextColor?: string;
44
39
  selectionColor?: string;
45
- containerStyle?: StyleProp<ViewStyle>;
46
- flagContainerStyle?: StyleProp<ViewStyle>;
47
- flagTextStyle?: StyleProp<TextStyle>;
48
- inputStyle?: StyleProp<TextStyle>;
49
- modalStyle?: IModalStyle;
40
+ phoneInputStyle?: IPhoneInputStyles;
41
+ modalStyle?: IModalStyles;
50
42
  theme?: ITheme;
51
43
  disabled?: boolean;
52
44
  modalDisabled?: boolean;
@@ -58,6 +50,8 @@ interface IPhoneInputPropsWithRef extends TextInputProps {
58
50
  selectedCountry?: never;
59
51
  onChangeSelectedCountry?: never;
60
52
  customMask?: Array<string>;
53
+ showOnly?: Array<ICountryCca2>;
54
+ excludedCountries?: Array<ICountryCca2>;
61
55
  ref: Ref<IPhoneInputRef>;
62
56
  }
63
57
 
@@ -0,0 +1,14 @@
1
+ import { StyleProp, TextStyle, ViewStyle } from 'react-native';
2
+
3
+ export interface IPhoneInputStyles {
4
+ // Styles for whole modal [View]
5
+ container?: StyleProp<ViewStyle>;
6
+ // Styles for modal backdrop [View]
7
+ flagContainer?: StyleProp<ViewStyle>;
8
+ // Flag styles [Text]
9
+ flag?: StyleProp<TextStyle>;
10
+ // Calling/Dial code styles [Text]
11
+ callingCode?: StyleProp<TextStyle>;
12
+ // Styles for search input [TextInput]
13
+ input?: StyleProp<TextStyle>;
14
+ }
package/lib/styles.js CHANGED
@@ -56,6 +56,7 @@ const styles = StyleSheet.create({
56
56
  color: '#FFFFFF',
57
57
  fontSize: 20,
58
58
  marginRight: 10,
59
+ fontFamily: 'TwemojiMozilla',
59
60
  },
60
61
  lightFlagText: {
61
62
  ...flagTextBase,
@@ -101,6 +102,8 @@ const styles = StyleSheet.create({
101
102
  countryMessageContainer: {},
102
103
  flag: {
103
104
  color: '#FFFFFF',
105
+ fontSize: 20,
106
+ fontFamily: 'TwemojiMozilla',
104
107
  },
105
108
  dialCode: {},
106
109
  countryName: {},
@@ -136,6 +139,7 @@ const styles = StyleSheet.create({
136
139
  flag: {
137
140
  color: '#FFFFFF',
138
141
  fontSize: 20,
142
+ fontFamily: 'TwemojiMozilla',
139
143
  },
140
144
  dialCode: {
141
145
  color: '#F3F3F3',
@@ -13,10 +13,16 @@ export default function getInputMask(
13
13
  const phoneMask =
14
14
  (Array.isArray(customMask) && customMask) || item.phoneMasks;
15
15
 
16
- if (callingCode && callingCode.includes(newCode)) {
16
+ if (
17
+ item.cca2 === cca2 &&
18
+ callingCode &&
19
+ callingCode.includes(newCode)
20
+ ) {
17
21
  if (phoneMask.length === 1) {
18
- if (cca2 !== 'CA' && cca2 !== 'US' && cca2 !== 'IT') {
22
+ if (newCode === '+1' && cca2 !== 'CA' && cca2 !== 'US') {
19
23
  matrix = phoneMask[0].replace(/[0-9]/g, '').trim();
24
+ } else {
25
+ matrix = phoneMask[0].replace(/[0-9]/g, '#').trim();
20
26
  }
21
27
  } else if (phoneMask.length > 1) {
22
28
  let hasDifferentLengthsOfPhoneNumbers = false;
@@ -34,7 +40,7 @@ export default function getInputMask(
34
40
  if (cca2 === 'CA' || cca2 === 'US') {
35
41
  matrix = phoneMask[0].replace(/\d/g, '#').trim();
36
42
  } else {
37
- matrix = phoneMask[0].replace(/[0-9]/g, '').trim();
43
+ matrix = phoneMask[0].replace(/[0-9]/g, '#').trim();
38
44
  }
39
45
  } else {
40
46
  for (let i = 0; i < phoneMask.length; i++) {
@@ -42,7 +48,7 @@ export default function getInputMask(
42
48
  phoneNumber.length > phoneMask[i].length &&
43
49
  phoneMask[i + 1]
44
50
  ) {
45
- matrix = phoneMask[i + 1].replace(/[0-9]/g, '').trim();
51
+ matrix = phoneMask[i + 1].replace(/[0-9]/g, '#').trim();
46
52
  }
47
53
  }
48
54
  }
@@ -26,6 +26,10 @@ export function getFlagContainerStyle(theme, flagContainerStyle) {
26
26
  ];
27
27
  }
28
28
 
29
+ export function getFlagStyle(flagStyle) {
30
+ return [styles.flag, flagStyle ? flagStyle : {}];
31
+ }
32
+
29
33
  export function getFlagTextStyle(theme, flagTextStyle) {
30
34
  return [
31
35
  theme === 'dark' ? styles.darkFlagText : styles.lightFlagText,
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.5.3",
4
+ "version": "0.6.1",
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",
@@ -44,7 +44,7 @@
44
44
  "react-native": "*"
45
45
  },
46
46
  "dependencies": {
47
- "react-native-country-codes-picker": "^2.3.3"
47
+ "react-native-country-codes-picker": "2.3.3"
48
48
  },
49
49
  "devDependencies": {
50
50
  "metro-react-native-babel-preset": "^0.61.0"
Binary file
Binary file