react-native-international-phone-number 0.8.1 β 0.8.3
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 +37 -29
- package/lib/constants/countries.js +4 -7
- package/lib/index.js +23 -20
- package/lib/utils/getInputMask.js +15 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -37,16 +37,32 @@
|
|
|
37
37
|
</a>
|
|
38
38
|
</div>
|
|
39
39
|
|
|
40
|
+
<br>
|
|
41
|
+
|
|
42
|
+
## Features
|
|
43
|
+
|
|
44
|
+
- π± Works with iOS, Android (Cross-platform), Expo and Web;
|
|
45
|
+
- π¨ Lib with UI customizable;
|
|
46
|
+
- π Phone Input Mask according with the selected country;
|
|
47
|
+
- π¨βπ» Functional and class component support;
|
|
48
|
+
- πΆ 22 languages supported.
|
|
49
|
+
|
|
50
|
+
<br>
|
|
51
|
+
|
|
40
52
|
## Try it out
|
|
41
53
|
|
|
42
54
|
- [Demo](https://snack.expo.dev/@astroonauta/react-native-international-phone-number)
|
|
43
55
|
|
|
56
|
+
<br>
|
|
57
|
+
|
|
44
58
|
## List of Contents
|
|
45
59
|
|
|
46
60
|
- [Old Versions](#old-versions)
|
|
47
61
|
- [Installation](#installation)
|
|
48
|
-
- [Additional Config
|
|
49
|
-
- [
|
|
62
|
+
- [Additional Config](#additional-config)
|
|
63
|
+
- [React Native CLI](#using-react-native-cli)
|
|
64
|
+
- [Expo](#using-expo)
|
|
65
|
+
- [Web](#using-web)
|
|
50
66
|
- [Basic Usage](#basic-usage)
|
|
51
67
|
- [With Class Component](#class-component)
|
|
52
68
|
- [With Function Component](#function-component)
|
|
@@ -102,11 +118,11 @@ OR
|
|
|
102
118
|
$ yarn add react-native-international-phone-number
|
|
103
119
|
```
|
|
104
120
|
|
|
105
|
-
## Additional config
|
|
121
|
+
## Additional config
|
|
106
122
|
|
|
107
|
-
- Using React Native CLI:
|
|
123
|
+
- ### Using React Native CLI:
|
|
108
124
|
|
|
109
|
-
|
|
125
|
+
Create a `react-native.config.js` file at the root of your react-native project with:
|
|
110
126
|
|
|
111
127
|
```bash
|
|
112
128
|
module.exports = {
|
|
@@ -126,23 +142,10 @@ Then link the font to your native projects with:
|
|
|
126
142
|
npx react-native-asset
|
|
127
143
|
```
|
|
128
144
|
|
|
129
|
-
- Using Expo:
|
|
145
|
+
- ### Using Expo:
|
|
130
146
|
|
|
131
|
-
1.
|
|
132
|
-
|
|
133
|
-
```bash
|
|
134
|
-
...
|
|
135
|
-
|
|
136
|
-
"web": {
|
|
137
|
-
...
|
|
138
|
-
"output": "single",
|
|
139
|
-
...
|
|
140
|
-
},
|
|
141
|
-
...
|
|
142
|
-
```
|
|
143
|
-
|
|
144
|
-
2. Install [expo-fonts](https://docs.expo.dev/versions/latest/sdk/font/): `npx expo install expo-font`;
|
|
145
|
-
3. Initialize the `expo-font`:
|
|
147
|
+
1. Install [expo-fonts](https://docs.expo.dev/versions/latest/sdk/font/): `npx expo install expo-font`;
|
|
148
|
+
2. Initialize the `expo-font`:
|
|
146
149
|
|
|
147
150
|
```bash
|
|
148
151
|
import { useFonts } from 'expo-font';
|
|
@@ -156,17 +159,22 @@ npx react-native-asset
|
|
|
156
159
|
...
|
|
157
160
|
```
|
|
158
161
|
|
|
159
|
-
> Observation:
|
|
162
|
+
> Observation: you need to recompile your project after adding new fonts.
|
|
160
163
|
|
|
161
|
-
|
|
164
|
+
- ### Using Web:
|
|
162
165
|
|
|
163
|
-
|
|
166
|
+
Change the `app.json` file to:
|
|
164
167
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
168
|
+
```bash
|
|
169
|
+
...
|
|
170
|
+
|
|
171
|
+
"web": {
|
|
172
|
+
...
|
|
173
|
+
"output": "single",
|
|
174
|
+
...
|
|
175
|
+
},
|
|
176
|
+
...
|
|
177
|
+
```
|
|
170
178
|
|
|
171
179
|
<br>
|
|
172
180
|
|
|
@@ -423,12 +423,7 @@ export const countries = [
|
|
|
423
423
|
zh: 'ζΎ³ε€§ε©δΊ',
|
|
424
424
|
tr: 'Avustralya',
|
|
425
425
|
},
|
|
426
|
-
phoneMasks: [
|
|
427
|
-
'2 #### ####',
|
|
428
|
-
'3 #### ####',
|
|
429
|
-
'4## ### ###',
|
|
430
|
-
'7 #### ####',
|
|
431
|
-
],
|
|
426
|
+
phoneMasks: ['### ### ###'],
|
|
432
427
|
},
|
|
433
428
|
{
|
|
434
429
|
callingCode: '+297',
|
|
@@ -5182,7 +5177,9 @@ export const countries = [
|
|
|
5182
5177
|
zh: 'ε·΄ζΏι¦¬',
|
|
5183
5178
|
tr: 'Panama',
|
|
5184
5179
|
},
|
|
5185
|
-
|
|
5180
|
+
// https://en.wikipedia.org/wiki/Telephone_numbers_in_Panama
|
|
5181
|
+
// Mobile numbers in Panama always start with 6 and are eight digits.
|
|
5182
|
+
phoneMasks: ['### ####', '6### ####'],
|
|
5186
5183
|
},
|
|
5187
5184
|
{
|
|
5188
5185
|
callingCode: '+51',
|
package/lib/index.js
CHANGED
|
@@ -198,7 +198,7 @@ const PhoneInput = forwardRef(
|
|
|
198
198
|
callingCode ? callingCode : countryValue?.callingCode,
|
|
199
199
|
countryValue?.cca2,
|
|
200
200
|
customMask ? customMask : null,
|
|
201
|
-
allowZeroAfterCallingCode
|
|
201
|
+
allowZeroAfterCallingCode === false ? false : true
|
|
202
202
|
);
|
|
203
203
|
|
|
204
204
|
if (ref) {
|
|
@@ -331,27 +331,30 @@ const PhoneInput = forwardRef(
|
|
|
331
331
|
} else {
|
|
332
332
|
// Create a separate constant for each part of the component
|
|
333
333
|
const touchableStart = (
|
|
334
|
-
|
|
335
|
-
{
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
<View style={phoneInputStyles?.caret}>
|
|
341
|
-
<View
|
|
342
|
-
style={{
|
|
343
|
-
flexDirection: 'row',
|
|
344
|
-
justifyContent: 'center',
|
|
345
|
-
paddingTop: 4,
|
|
346
|
-
}}
|
|
347
|
-
>
|
|
334
|
+
<>
|
|
335
|
+
<Text style={getFlagStyle(phoneInputStyles?.flag)}>
|
|
336
|
+
{countryValue?.flag}
|
|
337
|
+
</Text>
|
|
338
|
+
{customCaret || (
|
|
339
|
+
<View style={phoneInputStyles?.caret}>
|
|
348
340
|
<View
|
|
349
|
-
style={
|
|
350
|
-
|
|
341
|
+
style={{
|
|
342
|
+
flexDirection: 'row',
|
|
343
|
+
justifyContent: 'center',
|
|
344
|
+
paddingTop: 4,
|
|
345
|
+
}}
|
|
346
|
+
>
|
|
347
|
+
<View
|
|
348
|
+
style={getCaretStyle(
|
|
349
|
+
theme,
|
|
350
|
+
phoneInputStyles?.caret
|
|
351
|
+
)}
|
|
352
|
+
/>
|
|
353
|
+
</View>
|
|
351
354
|
</View>
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
+
)}
|
|
356
|
+
</>
|
|
357
|
+
);
|
|
355
358
|
|
|
356
359
|
const touchableMiddle = (
|
|
357
360
|
<View
|
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
import { countries } from '../constants/countries';
|
|
2
2
|
|
|
3
|
-
function
|
|
3
|
+
function startsWithZero(phoneNumber, callingCode) {
|
|
4
4
|
const newCode = callingCode.replace('+', '');
|
|
5
|
-
return
|
|
5
|
+
return (
|
|
6
|
+
phoneNumber.startsWith('0') ||
|
|
6
7
|
phoneNumber.startsWith(`${newCode}0`)
|
|
7
|
-
|
|
8
|
+
);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function eliminateZeroAfterCallingCode(phoneNumber, callingCode) {
|
|
12
|
+
return startsWithZero(phoneNumber, callingCode)
|
|
13
|
+
? phoneNumber.slice(1, phoneNumber.length)
|
|
8
14
|
: phoneNumber;
|
|
9
15
|
}
|
|
10
16
|
|
|
@@ -73,7 +79,12 @@ export default function getInputMask(
|
|
|
73
79
|
? value
|
|
74
80
|
: eliminateZeroAfterCallingCode(value, callingCode);
|
|
75
81
|
|
|
76
|
-
|
|
82
|
+
const newMatrix =
|
|
83
|
+
allowZeroAfterCallingCode && startsWithZero(value, callingCode)
|
|
84
|
+
? '#' + matrix
|
|
85
|
+
: matrix;
|
|
86
|
+
|
|
87
|
+
return newMatrix.replace(/(?!\+)./g, function (a) {
|
|
77
88
|
return /[#\d]/.test(a) && i < newValue.length
|
|
78
89
|
? newValue.charAt(i++)
|
|
79
90
|
: i >= newValue.length
|
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.8.
|
|
4
|
+
"version": "0.8.3",
|
|
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",
|