react-native-international-phone-number 0.6.8 → 0.7.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
@@ -45,7 +45,7 @@
45
45
 
46
46
  - [Old Versions](#old-versions)
47
47
  - [Installation](#installation)
48
- - [Additional Config](#additional-config)
48
+ - [Additional Config to Web](#additional-config-to-web)
49
49
  - [Features](#features)
50
50
  - [Basic Usage](#basic-usage)
51
51
  - [With Class Component](#class-component)
@@ -58,6 +58,7 @@
58
58
  - [Customizing Lib](#customizing-lib)
59
59
  - [Dark Mode](#dark-mode)
60
60
  - [Custom Lib Styles](#custom-lib-styles)
61
+ - [Custom Caret](#custom-caret)
61
62
  - [Custom Placeholders/Messages](#custom-placeholdersmessages)
62
63
  - [Custom Modal Height](#custom-modal-height)
63
64
  - [Country Modal Disabled Mode](#country-modal-disabled-mode)
@@ -69,6 +70,7 @@
69
70
  - [Default Phone Number Value](#default-phone-number-value)
70
71
  - [Show Only Some Countries Inside Modal](#show-only-some-countries)
71
72
  - [Exclude some countries Inside Modal](#exclude-some-countries)
73
+ - [Show Popular Countries at the Top of the Countries List Inside Modal](#show-popular-countries-at-the-top-of-the-countries-list-inside-modal)
72
74
  - [Lib Props](#component-props-phoneinputprops)
73
75
  - [Lib Functions](#functions)
74
76
  - [Supported languages](#🎌-supported-languages-🎌)
@@ -79,8 +81,9 @@
79
81
 
80
82
  ## Old Versions
81
83
 
82
- - [Version 0.4.x](https://github.com/AstrOOnauta/react-native-international-phone-number/tree/v0.4.x)
84
+ - [Version 0.6.x](https://github.com/AstrOOnauta/react-native-international-phone-number/tree/v0.6.x)
83
85
  - [Version 0.5.x](https://github.com/AstrOOnauta/react-native-international-phone-number/tree/v0.5.x)
86
+ - [Version 0.4.x](https://github.com/AstrOOnauta/react-native-international-phone-number/tree/v0.4.x)
84
87
 
85
88
  <br>
86
89
 
@@ -96,9 +99,7 @@ OR
96
99
  $ yarn add react-native-international-phone-number
97
100
  ```
98
101
 
99
- ## Additional config
100
-
101
- ### iOS and Web
102
+ ## Additional config to `Web`
102
103
 
103
104
  - Using React Native CLI:
104
105
 
@@ -141,23 +142,6 @@ npx react-native-asset
141
142
 
142
143
  > Observation: _you need to recompile your project after adding new fonts._
143
144
 
144
- ## only iOS
145
-
146
- - Edit `Info.plist` inside `ios` folder with following code:
147
-
148
- ```bash
149
- ...
150
- <key>UIAppFonts</key>
151
- <array>
152
- <string>TwemojiMozilla.woff2</string>
153
- ...
154
- </array>
155
- ```
156
-
157
- and add the font `Twemoji Mozilla` to the Copy Bundle Resources, in Build Phases inside your project XCode.
158
-
159
- > Observation: _you need to recompile your project after adding new fonts._
160
-
161
145
  <br>
162
146
 
163
147
  ## Features
@@ -166,7 +150,7 @@ and add the font `Twemoji Mozilla` to the Copy Bundle Resources, in Build Phases
166
150
  - 🎨 Lib with UI customizable;
167
151
  - 🌎 Phone Input Mask according with the selected country;
168
152
  - 👨‍💻 Functional and class component support;
169
- - 🈶 18 languages supported.
153
+ - 🈶 20 languages supported.
170
154
 
171
155
  <br>
172
156
 
@@ -482,6 +466,13 @@ export default function App() {
482
466
  justifyContent: 'center',
483
467
  },
484
468
  flag: {},
469
+ caret: {
470
+ color: '#F3F3F3',
471
+ fontSize: 16,
472
+ },
473
+ divider: {
474
+ backgroundColor: '#F3F3F3',
475
+ }
485
476
  callingCode: {
486
477
  fontSize: 16,
487
478
  fontWeight: 'bold',
@@ -534,6 +525,17 @@ export default function App() {
534
525
  ...
535
526
  ```
536
527
 
528
+ - ### Custom Caret:
529
+
530
+ ```jsx
531
+ ...
532
+ <PhoneInput
533
+ ...
534
+ customCaret={<Icon name="chevron-down" size={30} color="#000000" />} // react-native-vector-icons
535
+ />
536
+ ...
537
+ ```
538
+
537
539
  - ### Custom Placeholders/Messages:
538
540
 
539
541
  ```jsx
@@ -664,6 +666,17 @@ export default function App() {
664
666
  ...
665
667
  ```
666
668
 
669
+ - ### Show Popular Countries at the Top of the Countries List Inside Modal:
670
+
671
+ ```jsx
672
+ ...
673
+ <PhoneInput
674
+ ...
675
+ popularCountriess={['BR', 'PT', 'CA', 'US']}
676
+ />
677
+ ...
678
+ ```
679
+
667
680
  </br>
668
681
 
669
682
  ## Component Props ([PhoneInputProps](lib/interfaces/phoneInputProps.ts))
@@ -678,6 +691,7 @@ export default function App() {
678
691
  - `onChangeSelectedCountry?:` (country: [ICountry](lib/interfaces/country.ts)) => void;
679
692
  - `showOnly?:` [ICountryCca2[]](lib/interfaces/countryCca2.ts);
680
693
  - `excludedCountries?:` [ICountryCca2[]](lib/interfaces/countryCca2.ts);
694
+ - `popularCountries?:` [ICountryCca2[]](lib/interfaces/countryCca2.ts);
681
695
  - `disabled?:` boolean;
682
696
  - `modalDisabled?:` boolean;
683
697
  - `modalHeight?:` number | string;
@@ -686,6 +700,7 @@ export default function App() {
686
700
  - `modalStyles?:` [IModalStyles](lib/interfaces/modalStyles.ts);
687
701
  - `modalSearchInputPlaceholder?:` string;
688
702
  - `modalNotFoundCountryMessage?:` string;
703
+ - `customCaret?:` [ReactNode](https://reactnative.dev/docs/react-node);
689
704
  - `ref?:` [Ref](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/663f439d11d78b65f1dfd38d120f3728ea2cc207/types/react/index.d.ts#L100)<[IPhoneInputRef](lib/interfaces/phoneInputRef.ts)>
690
705
 
691
706
  <br>
@@ -704,24 +719,26 @@ export default function App() {
704
719
 
705
720
  ```js
706
721
  "name": {
707
- "en": "English",
708
- "ru": "Russian",
709
- "pl": "Polish",
710
- "ua": "Ukrainian",
711
- "cz": "Czech",
712
- "by": "Belarusian",
713
- "pt": "Portuguese",
714
- "es": "Espanol",
715
- "ro": "Romanian",
716
722
  "bg": "Bulgarian",
723
+ "by": "Belarusian",
724
+ "cn": "Chinese",
725
+ "cz": "Czech",
717
726
  "de": "German",
727
+ "ee": "Estonian",
728
+ "el": "Greek",
729
+ "en": "English",
730
+ "es": "Espanol",
718
731
  "fr": "French",
719
- "nl": "Dutch",
732
+ "he": "Hebrew",
720
733
  "it": "Italian",
721
- "cn": "Chinese",
722
- "ee": "Estonian",
723
734
  "jp": "Japanese",
724
- "he": "Hebrew"
735
+ "nl": "Dutch",
736
+ "pl": "Polish",
737
+ "pt": "Portuguese",
738
+ "ro": "Romanian",
739
+ "ru": "Russian",
740
+ "ua": "Ukrainian",
741
+ "zh": "Chinese (Simplified)"
725
742
  },
726
743
  ```
727
744
 
Binary file
Binary file
@@ -2863,7 +2863,7 @@ export const countries = [
2863
2863
  ua: 'Ізраїль',
2864
2864
  zh: '以色列',
2865
2865
  },
2866
- phoneMasks: ['# ### ####'],
2866
+ phoneMasks: ['# ### ####', '## ### ####'],
2867
2867
  },
2868
2868
  {
2869
2869
  callingCode: '+44',
@@ -3255,7 +3255,7 @@ export const countries = [
3255
3255
  ua: 'Камбоджа',
3256
3256
  zh: '柬埔寨',
3257
3257
  },
3258
- phoneMasks: ['## ### ##'],
3258
+ phoneMasks: ['## ### ###', '## ### ####'],
3259
3259
  },
3260
3260
  {
3261
3261
  callingCode: '+686',
package/lib/index.js CHANGED
@@ -10,7 +10,10 @@ import {
10
10
  TouchableOpacity,
11
11
  TextInput,
12
12
  } from 'react-native';
13
- import { CountryPicker } from 'react-native-country-codes-picker';
13
+ import {
14
+ CountryPicker,
15
+ CountryButton,
16
+ } from 'react-native-country-codes-picker';
14
17
 
15
18
  import getInputMask from './utils/getInputMask';
16
19
  import getAllCountries from './utils/getAllCountries';
@@ -24,8 +27,10 @@ import {
24
27
  getSearchInputPlaceholder,
25
28
  } from './utils/getPlaceholders';
26
29
  import {
30
+ getCaretStyle,
27
31
  getContainerStyle,
28
32
  getCountryPickerStyle,
33
+ getDividerStyle,
29
34
  getFlagContainerStyle,
30
35
  getFlagStyle,
31
36
  getFlagTextStyle,
@@ -53,8 +58,10 @@ const PhoneInput = forwardRef(
53
58
  customMask,
54
59
  showOnly,
55
60
  excludedCountries,
61
+ popularCountries,
56
62
  modalSearchInputPlaceholder,
57
63
  modalNotFoundCountryMessage,
64
+ customCaret,
58
65
  ...rest
59
66
  },
60
67
  ref
@@ -96,8 +103,10 @@ const PhoneInput = forwardRef(
96
103
  customMask,
97
104
  showOnly,
98
105
  excludedCountries,
106
+ popularCountries,
99
107
  modalSearchInputPlaceholder,
100
108
  modalNotFoundCountryMessage,
109
+ customCaret,
101
110
  ...rest,
102
111
  },
103
112
  };
@@ -306,6 +315,20 @@ const PhoneInput = forwardRef(
306
315
  <Text style={getFlagStyle(phoneInputStyles?.flag)}>
307
316
  {countryValue?.flag}
308
317
  </Text>
318
+ {customCaret || (
319
+ <View
320
+ style={getCaretStyle(
321
+ theme,
322
+ phoneInputStyles?.caret
323
+ )}
324
+ />
325
+ )}
326
+ <View
327
+ style={getDividerStyle(
328
+ theme,
329
+ phoneInputStyles?.divider
330
+ )}
331
+ />
309
332
  <Text
310
333
  style={getFlagTextStyle(
311
334
  theme,
@@ -318,8 +341,9 @@ const PhoneInput = forwardRef(
318
341
  <TextInput
319
342
  style={getInputStyle(theme, phoneInputStyles?.input)}
320
343
  placeholder={
321
- placeholder ||
322
- getPhoneNumberInputPlaceholder(language || 'en')
344
+ placeholder === '' || placeholder
345
+ ? placeholder
346
+ : getPhoneNumberInputPlaceholder(language || 'en')
323
347
  }
324
348
  placeholderTextColor={
325
349
  placeholderTextColor ||
@@ -361,6 +385,24 @@ const PhoneInput = forwardRef(
361
385
  onBackdropPress={() => setShow(false)}
362
386
  showOnly={showOnly}
363
387
  excludedCountries={excludedCountries}
388
+ popularCountries={popularCountries}
389
+ ListHeaderComponent={({ countries, lang, onPress }) => {
390
+ return countries.map((country, index) => {
391
+ return (
392
+ <CountryButton
393
+ key={index}
394
+ item={country}
395
+ name={country?.name?.[lang || 'en']}
396
+ onPress={() => onPress(country)}
397
+ style={getCountryPickerStyle(
398
+ theme,
399
+ modalHeight,
400
+ modalStyles
401
+ )}
402
+ />
403
+ );
404
+ });
405
+ }}
364
406
  />
365
407
  ) : null}
366
408
  </>
@@ -1,4 +1,4 @@
1
- import { Ref } from 'react';
1
+ import React, { Ref, ReactNode } from 'react';
2
2
  import { TextInputProps } from 'react-native';
3
3
 
4
4
  import { ICountry } from './country';
@@ -25,8 +25,10 @@ interface BasePhoneInput extends TextInputProps {
25
25
  customMask?: Array<string>;
26
26
  showOnly?: Array<ICountryCca2>;
27
27
  excludedCountries?: Array<ICountryCca2>;
28
+ popularCountries?: Array<ICountryCca2>;
28
29
  modalSearchInputPlaceholder?: string;
29
30
  modalNotFoundCountryMessage?: string;
31
+ customCaret?: ReactNode;
30
32
  }
31
33
 
32
34
  interface IPhoneInputPropsWithoutRef extends BasePhoneInput {
@@ -7,6 +7,10 @@ export interface IPhoneInputStyles {
7
7
  flagContainer?: StyleProp<ViewStyle>;
8
8
  // Flag styles [Text]
9
9
  flag?: StyleProp<TextStyle>;
10
+ // Caret (dropdown icon) styles [Text]
11
+ caret?: StyleProp<TextStyle>;
12
+ // Divider between caret and callingCode [View]
13
+ divider?: StyleProp<ViewStyle>;
10
14
  // Calling/Dial code styles [Text]
11
15
  callingCode?: StyleProp<TextStyle>;
12
16
  // Styles for search input [TextInput]
package/lib/styles.js CHANGED
@@ -1,4 +1,4 @@
1
- import { Dimensions, StyleSheet } from 'react-native';
1
+ import { Platform, StyleSheet } from 'react-native';
2
2
 
3
3
  const containerBase = {
4
4
  flexDirection: 'row',
@@ -8,26 +8,44 @@ const containerBase = {
8
8
  borderStyle: 'solid',
9
9
  borderRadius: 8,
10
10
  width: '100%',
11
- height: 45,
11
+ height: 48,
12
12
  };
13
13
 
14
14
  const flagContainerBase = {
15
15
  justifyContent: 'center',
16
- height: '99.5%',
16
+ height: '100%',
17
17
  paddingHorizontal: 20,
18
- borderTopLeftRadius: 6,
19
- borderBottomLeftRadius: 6,
18
+ borderTopLeftRadius: 7,
19
+ borderBottomLeftRadius: 7,
20
20
  flexDirection: 'row',
21
21
  alignItems: 'center',
22
22
  };
23
23
 
24
+ const caretBase = {
25
+ width: 0,
26
+ height: 0,
27
+ marginTop: 4,
28
+ borderWidth: 7,
29
+ borderBottomWidth: 0,
30
+ borderLeftColor: 'transparent',
31
+ borderRightColor: 'transparent',
32
+ };
33
+
34
+ const dividerBase = {
35
+ width: 1,
36
+ height: '60%',
37
+ marginLeft: 16,
38
+ marginRight: 10,
39
+ };
40
+
24
41
  const flagTextBase = {
25
42
  fontSize: 16,
26
43
  fontWeight: '500',
27
44
  };
28
45
 
29
46
  const inputBase = {
30
- width: Dimensions.get('window').width,
47
+ flex: 1,
48
+ width: '100%',
31
49
  paddingVertical: 8,
32
50
  paddingHorizontal: 16,
33
51
  fontSize: 16,
@@ -55,8 +73,24 @@ const styles = StyleSheet.create({
55
73
  flag: {
56
74
  color: '#FFFFFF',
57
75
  fontSize: 20,
58
- marginRight: 10,
59
- fontFamily: 'TwemojiMozilla',
76
+ marginRight: 6,
77
+ fontFamily: Platform.OS === 'web' ? 'TwemojiMozilla' : 'System',
78
+ },
79
+ lightCaret: {
80
+ ...caretBase,
81
+ borderTopColor: '#0A0A0A',
82
+ },
83
+ darkCaret: {
84
+ ...caretBase,
85
+ borderTopColor: '#F3F3F3',
86
+ },
87
+ lightDivider: {
88
+ ...dividerBase,
89
+ backgroundColor: '#AAAAAA',
90
+ },
91
+ darkDivider: {
92
+ ...dividerBase,
93
+ backgroundColor: '#F3F3F3',
60
94
  },
61
95
  lightFlagText: {
62
96
  ...flagTextBase,
@@ -103,7 +137,7 @@ const styles = StyleSheet.create({
103
137
  flag: {
104
138
  color: '#FFFFFF',
105
139
  fontSize: 20,
106
- fontFamily: 'TwemojiMozilla',
140
+ fontFamily: Platform.OS === 'web' ? 'TwemojiMozilla' : 'System',
107
141
  },
108
142
  dialCode: {},
109
143
  countryName: {},
@@ -139,7 +173,7 @@ const styles = StyleSheet.create({
139
173
  flag: {
140
174
  color: '#FFFFFF',
141
175
  fontSize: 20,
142
- fontFamily: 'TwemojiMozilla',
176
+ fontFamily: Platform.OS === 'web' ? 'TwemojiMozilla' : 'System',
143
177
  },
144
178
  dialCode: {
145
179
  color: '#F3F3F3',
@@ -1,3 +1,5 @@
1
+ import { Platform } from 'react-native';
2
+
1
3
  import styles from '../styles';
2
4
 
3
5
  export function getContainerStyle(theme, containerStyle, disabled) {
@@ -30,6 +32,33 @@ export function getFlagStyle(flagStyle) {
30
32
  return [styles.flag, flagStyle ? flagStyle : {}];
31
33
  }
32
34
 
35
+ export function getCaretStyle(theme, caretStyle) {
36
+ return [
37
+ theme === 'dark' ? styles.darkCaret : styles.lightCaret,
38
+ caretStyle
39
+ ? {
40
+ borderTopColor: caretStyle?.color
41
+ ? caretStyle?.color
42
+ : theme === 'dark'
43
+ ? styles.darkCaret.borderTopColor
44
+ : styles.lightCaret.borderTopColor,
45
+ borderWidth: caretStyle?.fontSize
46
+ ? caretStyle?.fontSize * 0.45
47
+ : theme === 'dark'
48
+ ? styles.darkCaret.borderWidth
49
+ : styles.lightCaret.borderWidth,
50
+ }
51
+ : {},
52
+ ];
53
+ }
54
+
55
+ export function getDividerStyle(theme, dividerStyle) {
56
+ return [
57
+ theme === 'dark' ? styles.darkDivider : styles.lightDivider,
58
+ dividerStyle ? dividerStyle : {},
59
+ ];
60
+ }
61
+
33
62
  export function getFlagTextStyle(theme, flagTextStyle) {
34
63
  return [
35
64
  theme === 'dark' ? styles.darkFlagText : styles.lightFlagText,
@@ -52,11 +81,16 @@ export function getCountryPickerStyle(theme, height, modalStyle) {
52
81
 
53
82
  const countryPickerStyle = {
54
83
  ...themeStyle,
55
- modal: {
56
- ...themeStyle.modal,
57
- height: height || '50%',
58
- ...modalStyle?.modal,
59
- },
84
+ modal: [
85
+ {
86
+ ...themeStyle.modal,
87
+ },
88
+ { height: height || '50%' },
89
+ Platform.OS === 'web'
90
+ ? { padding: 25, borderRadius: 15, margin: 'auto' }
91
+ : {},
92
+ { ...modalStyle?.modal },
93
+ ],
60
94
  backdrop: { ...themeStyle.backdrop, ...modalStyle?.backdrop },
61
95
  textInput: {
62
96
  ...themeStyle.textInput,
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.6.8",
4
+ "version": "0.7.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",