react-native-international-phone-number 0.4.15 → 0.5.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,5 +1,7 @@
1
+ <br>
2
+
1
3
  <div align = "center">
2
- <img src="https://github.com/AstrOOnauta/react-native-international-phone-number/blob/master/gif/preview.gif">
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">
3
5
  </div>
4
6
 
5
7
  <br>
@@ -41,15 +43,13 @@
41
43
 
42
44
  ## List of Contents
43
45
 
46
+ - [Old Versions](#old-versions)
44
47
  - [Installation](#installation)
45
48
  - [Features](#features)
46
49
  - [Basic Usage](#basic-usage)
47
50
  - [With Class Component](#class-component)
48
51
  - [With Function Component](#function-component)
49
- - [Custom Default Flag](#custom-default-flag)
50
- - [Default Phone Number Value](#default-phone-number-value)
51
- - [Custom Phone Mask](#custom-phone-mask)
52
- - [Typescript](#typescript)
52
+ - [With Typescript](#typescript)
53
53
  - [Intermediate Usage](#intermediate-usage)
54
54
  - [Typescript + useRef](#typescript--useref)
55
55
  - [Advanced Usage](#advanced-usage)
@@ -57,16 +57,28 @@
57
57
  - [Customizing Lib](#customizing-lib)
58
58
  - [Dark Mode](#dark-mode)
59
59
  - [Custom Lib Styles](#custom-lib-styles)
60
- - [Phone Input Disabled Mode](#phone-input-disabled-mode)
60
+ - [Custom Modal Height](#custom-modal-height)
61
61
  - [Country Modal Disabled Mode](#country-modal-disabled-mode)
62
+ - [Phone Input Disabled Mode](#phone-input-disabled-mode)
62
63
  - [Custom Disabled Mode Style](#custom-disabled-mode-style)
64
+ - [Change Default Language](#change-default-language)
65
+ - [Custom Phone Mask](#custom-phone-mask)
66
+ - [Custom Default Flag/Country](#custom-default-flagcountry)
67
+ - [Default Phone Number Value](#default-phone-number-value)
63
68
  - [Lib Props](#component-props-phoneinputprops)
64
69
  - [Lib Functions](#functions)
70
+ - [Supported languages](#🎌-supported-languages-🎌)
65
71
  - [Contributing](#contributing)
66
72
  - [License](#license)
67
73
 
68
74
  <br>
69
75
 
76
+ ## Old Versions
77
+
78
+ - [Version 0.4.x](https://github.com/AstrOOnauta/react-native-international-phone-number/tree/v0.4.x)
79
+
80
+ <br>
81
+
70
82
  ## Installation
71
83
 
72
84
  ```bash
@@ -98,8 +110,9 @@ AND
98
110
 
99
111
  - 📱 Works with iOS, Android (Cross-platform) and Expo;
100
112
  - 🎨 Lib with UI customizable;
101
- - 🌎 Phone Input Mask according to the selected country;
102
- - 👨‍💻 Functional and class component support.
113
+ - 🌎 Phone Input Mask according with the selected country;
114
+ - 👨‍💻 Functional and class component support;
115
+ - 🈶 18 languages supported.
103
116
 
104
117
  <br>
105
118
 
@@ -110,13 +123,13 @@ AND
110
123
  ```jsx
111
124
  import React from 'react';
112
125
  import { View, Text } from 'react-native';
113
- import { PhoneInput } from 'react-native-international-phone-number';
126
+ import PhoneInput from 'react-native-international-phone-number';
114
127
 
115
128
  export class App extends React.Component {
116
129
  constructor(props) {
117
130
  super(props)
118
131
  this.state = {
119
- selectedCountry: undefined,
132
+ selectedCountry: null,
120
133
  inputValue: ''
121
134
  }
122
135
  }
@@ -145,7 +158,7 @@ export class App extends React.Component {
145
158
  <View style={{ marginTop: 10 }}>
146
159
  <Text>
147
160
  Country:{' '}
148
- {`${this.state.selectedCountry?.name} (${this.state.selectedCountry?.cca2})`}
161
+ {`${this.state.selectedCountry?.name?.en} (${this.state.selectedCountry?.cca2})`}
149
162
  </Text>
150
163
  <Text>
151
164
  Phone Number: {`${this.state.selectedCountry?.callingCode} ${this.state.inputValue}`}
@@ -162,147 +175,10 @@ export class App extends React.Component {
162
175
  ```jsx
163
176
  import React, { useState } from 'react';
164
177
  import { View, Text } from 'react-native';
165
- import { PhoneInput } from 'react-native-international-phone-number';
166
-
167
- export default function App() {
168
- const [selectedCountry, setSelectedCountry] = useState(undefined);
169
- const [inputValue, setInputValue] = useState('');
170
-
171
- function handleInputValue(phoneNumber) {
172
- setInputValue(phoneNumber);
173
- }
174
-
175
- function handleSelectedCountry(country) {
176
- setSelectedCountry(country);
177
- }
178
-
179
- return (
180
- <View style={{ width: '100%', flex: 1, padding: 24 }}>
181
- <PhoneInput
182
- value={inputValue}
183
- onChangePhoneNumber={handleInputValue}
184
- selectedCountry={selectedCountry}
185
- onChangeSelectedCountry={handleSelectedCountry}
186
- />
187
- <View style={{ marginTop: 10 }}>
188
- <Text>
189
- Country:{' '}
190
- {`${selectedCountry?.name} (${selectedCountry?.cca2})`}
191
- </Text>
192
- <Text>
193
- Phone Number:{' '}
194
- {`${selectedCountry?.callingCode} ${inputValue}`}
195
- </Text>
196
- </View>
197
- </View>
198
- );
199
- }
200
- ```
201
-
202
- - ### Custom Default Flag:
203
-
204
- ```jsx
205
- import React, { useState } from 'react';
206
- import { View, Text } from 'react-native';
207
- import {
208
- PhoneInput,
209
- getCountryByCca2,
210
- } from 'react-native-international-phone-number';
211
-
212
- export default function App() {
213
- const [selectedCountry, setSelectedCountry] = useState(
214
- getCountryByCca2('CA') // <--- In this exemple, returns the CANADA Country and PhoneInput CANADA Flag
215
- );
216
- const [inputValue, setInputValue] = useState('');
217
-
218
- function handleInputValue(phoneNumber) {
219
- setInputValue(phoneNumber);
220
- }
221
-
222
- function handleSelectedCountry(country) {
223
- setSelectedCountry(country);
224
- }
225
-
226
- return (
227
- <View style={{ width: '100%', flex: 1, padding: 24 }}>
228
- <PhoneInput
229
- value={inputValue}
230
- onChangePhoneNumber={handleInputValue}
231
- selectedCountry={selectedCountry}
232
- onChangeSelectedCountry={handleSelectedCountry}
233
- />
234
- <View style={{ marginTop: 10 }}>
235
- <Text>
236
- Country:{' '}
237
- {`${selectedCountry?.name} (${selectedCountry?.cca2})`}
238
- </Text>
239
- <Text>
240
- Phone Number:{' '}
241
- {`${selectedCountry?.callingCode} ${inputValue}`}
242
- </Text>
243
- </View>
244
- </View>
245
- );
246
- }
247
- ```
248
-
249
- - ### Default Phone Number Value
250
-
251
- ```tsx
252
- import React, { useState } from 'react';
253
- import { View, Text } from 'react-native';
254
- import { PhoneInput } from 'react-native-international-phone-number';
255
-
256
- export default function App() {
257
- const [selectedCountry, setSelectedCountry] = useState(undefined);
258
- const [inputValue, setInputValue] = useState('');
259
-
260
- function handleInputValue(phoneNumber) {
261
- setInputValue(phoneNumber);
262
- }
263
-
264
- function handleSelectedCountry(country) {
265
- setSelectedCountry(country);
266
- }
267
-
268
- return (
269
- <View style={{ width: '100%', flex: 1, padding: 24 }}>
270
- <PhoneInput
271
- defaultValue="+12505550199"
272
- value={inputValue}
273
- onChangePhoneNumber={handleInputValue}
274
- selectedCountry={selectedCountry}
275
- onChangeSelectedCountry={handleSelectedCountry}
276
- />
277
- <View style={{ marginTop: 10 }}>
278
- <Text>
279
- Country:{' '}
280
- {`${selectedCountry?.name} (${selectedCountry?.cca2})`}
281
- </Text>
282
- <Text>
283
- Phone Number:{' '}
284
- {`${selectedCountry?.callingCode} ${inputValue}`}
285
- </Text>
286
- </View>
287
- </View>
288
- );
289
- }
290
- ```
291
-
292
- > Observations:
293
- >
294
- > 1. You need to use a default value with the following format: `+(country callling code)(area code)(number phone)`
295
- > 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).
296
-
297
- - ### Custom Phone Mask
298
-
299
- ```tsx
300
- import React, { useState } from 'react';
301
- import { View, Text } from 'react-native';
302
- import { PhoneInput } from 'react-native-international-phone-number';
178
+ import PhoneInput from 'react-native-international-phone-number';
303
179
 
304
180
  export default function App() {
305
- const [selectedCountry, setSelectedCountry] = useState(undefined);
181
+ const [selectedCountry, setSelectedCountry] = useState(null);
306
182
  const [inputValue, setInputValue] = useState('');
307
183
 
308
184
  function handleInputValue(phoneNumber) {
@@ -316,7 +192,6 @@ export default function App() {
316
192
  return (
317
193
  <View style={{ width: '100%', flex: 1, padding: 24 }}>
318
194
  <PhoneInput
319
- customMask={['#### ####', '##### ####']}
320
195
  value={inputValue}
321
196
  onChangePhoneNumber={handleInputValue}
322
197
  selectedCountry={selectedCountry}
@@ -325,7 +200,7 @@ export default function App() {
325
200
  <View style={{ marginTop: 10 }}>
326
201
  <Text>
327
202
  Country:{' '}
328
- {`${selectedCountry?.name} (${selectedCountry?.cca2})`}
203
+ {`${selectedCountry?.name?.en} (${selectedCountry?.cca2})`}
329
204
  </Text>
330
205
  <Text>
331
206
  Phone Number:{' '}
@@ -342,15 +217,13 @@ export default function App() {
342
217
  ```tsx
343
218
  import React, { useState } from 'react';
344
219
  import { View, Text } from 'react-native';
345
- import {
346
- PhoneInput,
220
+ import PhoneInput, {
347
221
  ICountry,
348
222
  } from 'react-native-international-phone-number';
349
223
 
350
224
  export default function App() {
351
- const [selectedCountry, setSelectedCountry] = useState<
352
- undefined | ICountry
353
- >(undefined);
225
+ const [selectedCountry, setSelectedCountry] =
226
+ useState<null | ICountry>(null);
354
227
  const [inputValue, setInputValue] = useState<string>('');
355
228
 
356
229
  function handleInputValue(phoneNumber: string) {
@@ -372,7 +245,7 @@ export default function App() {
372
245
  <View style={{ marginTop: 10 }}>
373
246
  <Text>
374
247
  Country:{' '}
375
- {`${selectedCountry?.name} (${selectedCountry?.cca2})`}
248
+ {`${selectedCountry?.name?.en} (${selectedCountry?.cca2})`}
376
249
  </Text>
377
250
  <Text>
378
251
  Phone Number:{' '}
@@ -391,10 +264,9 @@ export default function App() {
391
264
  - ### Typescript + useRef
392
265
 
393
266
  ```tsx
394
- import React, { useState, useRef } from 'react';
267
+ import React, { useRef } from 'react';
395
268
  import { View, Text } from 'react-native';
396
- import {
397
- PhoneInput,
269
+ import PhoneInput, {
398
270
  ICountry,
399
271
  IPhoneInputRef,
400
272
  } from 'react-native-international-phone-number';
@@ -440,6 +312,8 @@ export default function App() {
440
312
 
441
313
  > Observation: Don't use the useRef hook combined with the useState hook to manage the phoneNumber and selectedCountry values. Instead, choose to use just one of them (useRef or useState).
442
314
 
315
+ <br>
316
+
443
317
  ## Advanced Usage
444
318
 
445
319
  - ### React-Hook-Form + Typescript + Default Phone Number Value
@@ -447,8 +321,7 @@ export default function App() {
447
321
  ```tsx
448
322
  import React, { useState, useEffect } from 'react';
449
323
  import { View, Text, TouchableOpacity, Alert } from 'react-native';
450
- import {
451
- PhoneInput,
324
+ import PhoneInput, {
452
325
  ICountry,
453
326
  } from 'react-native-international-phone-number';
454
327
  import { Controller, FieldValues } from 'react-hook-form';
@@ -525,19 +398,22 @@ export default function App() {
525
398
  - ### Dark Mode:
526
399
 
527
400
  ```jsx
401
+ ...
528
402
  <PhoneInput
529
403
  ...
530
- withDarkTheme
404
+ theme="dark"
531
405
  />
406
+ ...
532
407
  ```
533
408
 
534
409
  - ### Custom Lib Styles:
535
410
 
536
411
  <div>
537
- <img src="https://github.com/AstrOOnauta/react-native-international-phone-number/blob/master/images/custom-styles.png">
412
+ <img src="https://github.com/AstrOOnauta/react-native-international-phone-number/blob/master/images/custom-styles.png" alt="Lib with custom styles">
538
413
  </div>
539
414
 
540
415
  ```jsx
416
+ ...
541
417
  <PhoneInput
542
418
  ...
543
419
  inputStyle={{
@@ -548,7 +424,6 @@ export default function App() {
548
424
  borderWidth: 1,
549
425
  borderStyle: 'solid',
550
426
  borderColor: '#F3F3F3',
551
- marginVertical: 16,
552
427
  }}
553
428
  flagContainerStyle={{
554
429
  borderTopLeftRadius: 7,
@@ -556,31 +431,51 @@ export default function App() {
556
431
  backgroundColor: '#808080',
557
432
  justifyContent: 'center',
558
433
  }}
434
+ flagTextStyle={{
435
+ fontSize: 16,
436
+ fontWeight: 'bold',
437
+ color: '#F3F3F3',
438
+ }}
559
439
  />
440
+ ...
560
441
  ```
561
442
 
562
- - ### Phone Input Disabled Mode:
443
+ - ### Custom Modal Height:
563
444
 
564
445
  ```jsx
446
+ ...
565
447
  <PhoneInput
566
448
  ...
567
- disabled
449
+ modalHeight="80%"
568
450
  />
451
+ ...
569
452
  ```
570
453
 
571
454
  - ### Country Modal Disabled Mode:
572
455
 
573
456
  ```jsx
457
+ ...
574
458
  <PhoneInput
575
459
  ...
576
460
  modalDisabled
577
461
  />
462
+ ...
578
463
  ```
579
464
 
580
- - ### Custom Disabled Mode Style:
465
+ - ### Phone Input Disabled Mode:
581
466
 
582
467
  ```jsx
583
468
  ...
469
+ <PhoneInput
470
+ ...
471
+ disabled
472
+ />
473
+ ...
474
+ ```
475
+
476
+ - ### Custom Disabled Mode Style:
477
+
478
+ ```jsx
584
479
  const [isDisabled, setIsDisabled] = useState<boolean>(true)
585
480
  ...
586
481
  <PhoneInput
@@ -591,22 +486,74 @@ export default function App() {
591
486
  ...
592
487
  ```
593
488
 
489
+ - ### Change Default Language:
490
+
491
+ ```jsx
492
+ ...
493
+ <PhoneInput
494
+ ...
495
+ language="pt"
496
+ />
497
+ ...
498
+ ```
499
+
500
+ - ### Custom Phone Mask:
501
+
502
+ ```jsx
503
+ ...
504
+ <PhoneInput
505
+ ...
506
+ customMask={['#### ####', '##### ####']}
507
+ />
508
+ ...
509
+ ```
510
+
511
+ - ### Custom Default Flag/Country:
512
+
513
+ ```jsx
514
+ ...
515
+ <PhoneInput
516
+ ...
517
+ defaultCountry="CA"
518
+ />
519
+ ...
520
+ ```
521
+
522
+ - ### Default Phone Number Value:
523
+
524
+ ```jsx
525
+ ...
526
+ <PhoneInput
527
+ ...
528
+ defaultValue="+12505550199"
529
+ />
530
+ ...
531
+ ```
532
+
533
+ > Observations:
534
+ >
535
+ > 1. You need to use a default value with the following format: `+(country callling code)(area code)(number phone)`
536
+ > 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).
537
+
594
538
  </br>
595
539
 
596
540
  ## Component Props ([PhoneInputProps](https://github.com/AstrOOnauta/react-native-international-phone-number/blob/master/lib/interfaces/phoneInputProps.ts))
597
541
 
542
+ - `language?:` [ILanguage](https://github.com/AstrOOnauta/react-native-international-phone-number/blob/master/lib/interfaces/language.ts);
598
543
  - `customMask?:` string[];
599
544
  - `defaultValue?:` string;
600
545
  - `value?:` string;
601
546
  - `onChangePhoneNumber?:` (phoneNumber: string) => void;
602
- - `selectedCountry?:` undefined | [ICountry](https://github.com/AstrOOnauta/react-native-international-phone-number/blob/master/lib/interfaces/country.ts);
547
+ - `selectedCountry?:` [ICountry](https://github.com/AstrOOnauta/react-native-international-phone-number/blob/master/lib/interfaces/country.ts);
603
548
  - `onChangeSelectedCountry?:` (country: [ICountry](https://github.com/AstrOOnauta/react-native-international-phone-number/blob/master/lib/interfaces/country.ts)) => void;
604
549
  - `disabled?:` boolean;
605
550
  - `modalDisabled?:` boolean;
606
- - `withDarkTheme?:` boolean;
607
- - `containerStyle?:` StyleProp<[ViewStyle](https://reactnative.dev/docs/view-style-props)>;
608
- - `flagContainerStyle?:` StyleProp<[ViewStyle](https://reactnative.dev/docs/view-style-props)>;
609
- - `inputStyle?:` StyleProp<[TextStyle](https://reactnative.dev/docs/text-style-props)>;
551
+ - `modalHeight?:` number | string;
552
+ - `theme?:` [ITheme](https://github.com/AstrOOnauta/react-native-international-phone-number/blob/master/lib/interfaces/theme.ts);
553
+ - `containerStyle?:` [StyleProp](https://reactnative.dev/docs/style)<[ViewStyle](https://reactnative.dev/docs/view-style-props)>;
554
+ - `flagContainerStyle?:` [StyleProp](https://reactnative.dev/docs/style)<[ViewStyle](https://reactnative.dev/docs/view-style-props)>;
555
+ - `flagTextStyle?:` [StyleProp](https://reactnative.dev/docs/style)<[TextStyle](https://reactnative.dev/docs/text-style-props)>;
556
+ - `inputStyle?:` [StyleProp](https://reactnative.dev/docs/style)<[TextStyle](https://reactnative.dev/docs/text-style-props)>;
610
557
  - `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)>
611
558
 
612
559
  <br>
@@ -614,13 +561,40 @@ export default function App() {
614
561
  ## Functions
615
562
 
616
563
  - `getAllCountries:` () => [ICountry](https://github.com/AstrOOnauta/react-native-international-phone-number/blob/master/lib/interfaces/country.ts)[];
564
+ - `getCountriesByCallingCode:` (callingCode: string) => [ICountry](https://github.com/AstrOOnauta/react-native-international-phone-number/blob/master/lib/interfaces/country.ts)[] | undefined;
565
+ - `getCountryByCca2:` (cca2: string) => [ICountry](https://github.com/AstrOOnauta/react-native-international-phone-number/blob/master/lib/interfaces/country.ts) | undefined;
566
+ - `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;
617
567
  - `getCountryByPhoneNumber:` (phoneNumber: string) => [ICountry](https://github.com/AstrOOnauta/react-native-international-phone-number/blob/master/lib/interfaces/country.ts) | undefined;
618
- - `getCountryByCca2:` (phoneNumber: string) => [ICountry](https://github.com/AstrOOnauta/react-native-international-phone-number/blob/master/lib/interfaces/country.ts) | undefined;
619
- - `getCountriesByCallingCode:` (phoneNumber: string) => [ICountry](https://github.com/AstrOOnauta/react-native-international-phone-number/blob/master/lib/interfaces/country.ts)[] | undefined;
620
- - `getCountriesByName:` (phoneNumber: string) => [ICountry](https://github.com/AstrOOnauta/react-native-international-phone-number/blob/master/lib/interfaces/country.ts)[] | undefined;
621
568
 
622
569
  </br>
623
570
 
571
+ ## 🎌 Supported languages 🎌
572
+
573
+ ```js
574
+ "name": {
575
+ "en": "English",
576
+ "ru": "Russian",
577
+ "pl": "Polish",
578
+ "ua": "Ukrainian",
579
+ "cz": "Czech",
580
+ "by": "Belarusian",
581
+ "pt": "Portuguese",
582
+ "es": "Espanol",
583
+ "ro": "Romanian",
584
+ "bg": "Bulgarian",
585
+ "de": "German",
586
+ "fr": "French",
587
+ "nl": "Dutch",
588
+ "it": "Italian",
589
+ "cn": "Chinese",
590
+ "ee": "Estonian",
591
+ "jp": "Japanese",
592
+ "he": "Hebrew"
593
+ },
594
+ ```
595
+
596
+ <br>
597
+
624
598
  ## Contributing
625
599
 
626
600
  - Fork or clone this repository
Binary file