react-native-international-phone-number 0.6.8 → 0.7.0
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 +40 -36
- package/lib/assets/images/custom-styles.png +0 -0
- package/lib/assets/images/preview.png +0 -0
- package/lib/constants/countries.js +2 -2
- package/lib/index.js +21 -2
- package/lib/interfaces/phoneInputProps.ts +2 -1
- package/lib/interfaces/phoneInputStyles.ts +4 -0
- package/lib/styles.js +44 -10
- package/lib/utils/getStyles.js +39 -5
- package/package.json +1 -1
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)
|
|
@@ -79,8 +80,9 @@
|
|
|
79
80
|
|
|
80
81
|
## Old Versions
|
|
81
82
|
|
|
82
|
-
- [Version 0.
|
|
83
|
+
- [Version 0.6.x](https://github.com/AstrOOnauta/react-native-international-phone-number/tree/v0.6.x)
|
|
83
84
|
- [Version 0.5.x](https://github.com/AstrOOnauta/react-native-international-phone-number/tree/v0.5.x)
|
|
85
|
+
- [Version 0.4.x](https://github.com/AstrOOnauta/react-native-international-phone-number/tree/v0.4.x)
|
|
84
86
|
|
|
85
87
|
<br>
|
|
86
88
|
|
|
@@ -96,9 +98,7 @@ OR
|
|
|
96
98
|
$ yarn add react-native-international-phone-number
|
|
97
99
|
```
|
|
98
100
|
|
|
99
|
-
## Additional config
|
|
100
|
-
|
|
101
|
-
### iOS and Web
|
|
101
|
+
## Additional config to `Web`
|
|
102
102
|
|
|
103
103
|
- Using React Native CLI:
|
|
104
104
|
|
|
@@ -141,23 +141,6 @@ npx react-native-asset
|
|
|
141
141
|
|
|
142
142
|
> Observation: _you need to recompile your project after adding new fonts._
|
|
143
143
|
|
|
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
144
|
<br>
|
|
162
145
|
|
|
163
146
|
## Features
|
|
@@ -166,7 +149,7 @@ and add the font `Twemoji Mozilla` to the Copy Bundle Resources, in Build Phases
|
|
|
166
149
|
- 🎨 Lib with UI customizable;
|
|
167
150
|
- 🌎 Phone Input Mask according with the selected country;
|
|
168
151
|
- 👨💻 Functional and class component support;
|
|
169
|
-
- 🈶
|
|
152
|
+
- 🈶 20 languages supported.
|
|
170
153
|
|
|
171
154
|
<br>
|
|
172
155
|
|
|
@@ -482,6 +465,13 @@ export default function App() {
|
|
|
482
465
|
justifyContent: 'center',
|
|
483
466
|
},
|
|
484
467
|
flag: {},
|
|
468
|
+
caret: {
|
|
469
|
+
color: '#F3F3F3',
|
|
470
|
+
fontSize: 16,
|
|
471
|
+
},
|
|
472
|
+
divider: {
|
|
473
|
+
backgroundColor: '#F3F3F3',
|
|
474
|
+
}
|
|
485
475
|
callingCode: {
|
|
486
476
|
fontSize: 16,
|
|
487
477
|
fontWeight: 'bold',
|
|
@@ -534,6 +524,17 @@ export default function App() {
|
|
|
534
524
|
...
|
|
535
525
|
```
|
|
536
526
|
|
|
527
|
+
- ### Custom Caret:
|
|
528
|
+
|
|
529
|
+
```jsx
|
|
530
|
+
...
|
|
531
|
+
<PhoneInput
|
|
532
|
+
...
|
|
533
|
+
customCaret={<Icon name="chevron-down" size={30} color="#000000" />} // react-native-vector-icons
|
|
534
|
+
/>
|
|
535
|
+
...
|
|
536
|
+
```
|
|
537
|
+
|
|
537
538
|
- ### Custom Placeholders/Messages:
|
|
538
539
|
|
|
539
540
|
```jsx
|
|
@@ -686,6 +687,7 @@ export default function App() {
|
|
|
686
687
|
- `modalStyles?:` [IModalStyles](lib/interfaces/modalStyles.ts);
|
|
687
688
|
- `modalSearchInputPlaceholder?:` string;
|
|
688
689
|
- `modalNotFoundCountryMessage?:` string;
|
|
690
|
+
- `customCaret?:` [ReactNode](https://reactnative.dev/docs/react-node);
|
|
689
691
|
- `ref?:` [Ref](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/663f439d11d78b65f1dfd38d120f3728ea2cc207/types/react/index.d.ts#L100)<[IPhoneInputRef](lib/interfaces/phoneInputRef.ts)>
|
|
690
692
|
|
|
691
693
|
<br>
|
|
@@ -704,24 +706,26 @@ export default function App() {
|
|
|
704
706
|
|
|
705
707
|
```js
|
|
706
708
|
"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
709
|
"bg": "Bulgarian",
|
|
710
|
+
"by": "Belarusian",
|
|
711
|
+
"cn": "Chinese",
|
|
712
|
+
"cz": "Czech",
|
|
717
713
|
"de": "German",
|
|
714
|
+
"ee": "Estonian",
|
|
715
|
+
"el": "Greek",
|
|
716
|
+
"en": "English",
|
|
717
|
+
"es": "Espanol",
|
|
718
718
|
"fr": "French",
|
|
719
|
-
"
|
|
719
|
+
"he": "Hebrew",
|
|
720
720
|
"it": "Italian",
|
|
721
|
-
"cn": "Chinese",
|
|
722
|
-
"ee": "Estonian",
|
|
723
721
|
"jp": "Japanese",
|
|
724
|
-
"
|
|
722
|
+
"nl": "Dutch",
|
|
723
|
+
"pl": "Polish",
|
|
724
|
+
"pt": "Portuguese",
|
|
725
|
+
"ro": "Romanian",
|
|
726
|
+
"ru": "Russian",
|
|
727
|
+
"ua": "Ukrainian",
|
|
728
|
+
"zh": "Chinese (Simplified)"
|
|
725
729
|
},
|
|
726
730
|
```
|
|
727
731
|
|
|
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
|
@@ -24,8 +24,10 @@ import {
|
|
|
24
24
|
getSearchInputPlaceholder,
|
|
25
25
|
} from './utils/getPlaceholders';
|
|
26
26
|
import {
|
|
27
|
+
getCaretStyle,
|
|
27
28
|
getContainerStyle,
|
|
28
29
|
getCountryPickerStyle,
|
|
30
|
+
getDividerStyle,
|
|
29
31
|
getFlagContainerStyle,
|
|
30
32
|
getFlagStyle,
|
|
31
33
|
getFlagTextStyle,
|
|
@@ -55,6 +57,7 @@ const PhoneInput = forwardRef(
|
|
|
55
57
|
excludedCountries,
|
|
56
58
|
modalSearchInputPlaceholder,
|
|
57
59
|
modalNotFoundCountryMessage,
|
|
60
|
+
customCaret,
|
|
58
61
|
...rest
|
|
59
62
|
},
|
|
60
63
|
ref
|
|
@@ -98,6 +101,7 @@ const PhoneInput = forwardRef(
|
|
|
98
101
|
excludedCountries,
|
|
99
102
|
modalSearchInputPlaceholder,
|
|
100
103
|
modalNotFoundCountryMessage,
|
|
104
|
+
customCaret,
|
|
101
105
|
...rest,
|
|
102
106
|
},
|
|
103
107
|
};
|
|
@@ -306,6 +310,20 @@ const PhoneInput = forwardRef(
|
|
|
306
310
|
<Text style={getFlagStyle(phoneInputStyles?.flag)}>
|
|
307
311
|
{countryValue?.flag}
|
|
308
312
|
</Text>
|
|
313
|
+
{customCaret || (
|
|
314
|
+
<View
|
|
315
|
+
style={getCaretStyle(
|
|
316
|
+
theme,
|
|
317
|
+
phoneInputStyles?.caret
|
|
318
|
+
)}
|
|
319
|
+
/>
|
|
320
|
+
)}
|
|
321
|
+
<View
|
|
322
|
+
style={getDividerStyle(
|
|
323
|
+
theme,
|
|
324
|
+
phoneInputStyles?.divider
|
|
325
|
+
)}
|
|
326
|
+
/>
|
|
309
327
|
<Text
|
|
310
328
|
style={getFlagTextStyle(
|
|
311
329
|
theme,
|
|
@@ -318,8 +336,9 @@ const PhoneInput = forwardRef(
|
|
|
318
336
|
<TextInput
|
|
319
337
|
style={getInputStyle(theme, phoneInputStyles?.input)}
|
|
320
338
|
placeholder={
|
|
321
|
-
placeholder ||
|
|
322
|
-
|
|
339
|
+
placeholder === '' || placeholder
|
|
340
|
+
? placeholder
|
|
341
|
+
: getPhoneNumberInputPlaceholder(language || 'en')
|
|
323
342
|
}
|
|
324
343
|
placeholderTextColor={
|
|
325
344
|
placeholderTextColor ||
|
|
@@ -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';
|
|
@@ -27,6 +27,7 @@ interface BasePhoneInput extends TextInputProps {
|
|
|
27
27
|
excludedCountries?: Array<ICountryCca2>;
|
|
28
28
|
modalSearchInputPlaceholder?: string;
|
|
29
29
|
modalNotFoundCountryMessage?: string;
|
|
30
|
+
customCaret?: ReactNode;
|
|
30
31
|
}
|
|
31
32
|
|
|
32
33
|
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 {
|
|
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:
|
|
11
|
+
height: 48,
|
|
12
12
|
};
|
|
13
13
|
|
|
14
14
|
const flagContainerBase = {
|
|
15
15
|
justifyContent: 'center',
|
|
16
|
-
height: '
|
|
16
|
+
height: '100%',
|
|
17
17
|
paddingHorizontal: 20,
|
|
18
|
-
borderTopLeftRadius:
|
|
19
|
-
borderBottomLeftRadius:
|
|
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
|
-
|
|
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:
|
|
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',
|
package/lib/utils/getStyles.js
CHANGED
|
@@ -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
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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.
|
|
4
|
+
"version": "0.7.0",
|
|
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",
|