react-native-international-phone-number 0.5.3 → 0.6.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 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)
@@ -76,6 +77,7 @@
76
77
  ## Old Versions
77
78
 
78
79
  - [Version 0.4.x](https://github.com/AstrOOnauta/react-native-international-phone-number/tree/v0.4.x)
80
+ - [Version 0.5.x](https://github.com/AstrOOnauta/react-native-international-phone-number/tree/v0.5.x)
79
81
 
80
82
  <br>
81
83
 
@@ -91,18 +93,42 @@ OR
91
93
  $ yarn add react-native-international-phone-number
92
94
  ```
93
95
 
94
- AND
96
+ ## Additional config to `Web`
95
97
 
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
- > ```
98
+ - Using React Native CLI:
99
+
100
+ create a `react-native.config.js` file at the root of your react-native project with:
101
+
102
+ ```bash
103
+ module.exports = {
104
+ project: {
105
+ ios: {},
106
+ android: {},
107
+ },
108
+ assets: [
109
+ './node_modules/react-native-international-phone-number/assets/fonts',
110
+ ],
111
+ };
112
+ ```
113
+
114
+ - Using Expo:
115
+
116
+ 1. Install [expo-fonts](https://docs.expo.dev/versions/latest/sdk/font/): `npx expo install expo-font`;
117
+ 2. Initialize the `expo-font`:
118
+
119
+ ```bash
120
+ import { useFonts } from 'expo-font';
121
+
122
+ ...
123
+
124
+ useFonts({
125
+ 'TwemojiMozilla': require('./node_modules/react-native-international-phone-number/assets/fonts/TwemojiMozilla.ttf'),
126
+ });
127
+
128
+ ...
129
+ ```
130
+
131
+ > Observation: _you need to recompile your project after adding new fonts._
106
132
 
107
133
  <br>
108
134
 
@@ -395,6 +421,8 @@ export default function App() {
395
421
 
396
422
  ## Customizing lib
397
423
 
424
+ <img src="lib/assets/images/custom-styles.png" alt="Custom lib styles">
425
+
398
426
  - ### Dark Mode:
399
427
 
400
428
  ```jsx
@@ -408,35 +436,34 @@ export default function App() {
408
436
 
409
437
  - ### Custom Lib Styles:
410
438
 
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
439
  ```jsx
416
440
  ...
417
441
  <PhoneInput
418
442
  ...
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={{
443
+ phoneInputStyles={{
444
+ container: {
445
+ backgroundColor: '#575757',
446
+ borderWidth: 1,
447
+ borderStyle: 'solid',
448
+ borderColor: '#F3F3F3',
449
+ },
450
+ flagContainer: {
451
+ borderTopLeftRadius: 7,
452
+ borderBottomLeftRadius: 7,
453
+ backgroundColor: '#808080',
454
+ justifyContent: 'center',
455
+ },
456
+ flag: {}
457
+ callingCode: {
435
458
  fontSize: 16,
436
459
  fontWeight: 'bold',
437
460
  color: '#F3F3F3',
461
+ },
462
+ input: {
463
+ color: '#F3F3F3',
464
+ },
438
465
  }}
439
- modalStyle={{
466
+ modalStyles={{
440
467
  modal: {
441
468
  backgroundColor: '#333333',
442
469
  borderWidth: 1,
@@ -576,35 +603,32 @@ export default function App() {
576
603
 
577
604
  </br>
578
605
 
579
- ## Component Props ([PhoneInputProps](https://github.com/AstrOOnauta/react-native-international-phone-number/blob/master/lib/interfaces/phoneInputProps.ts))
606
+ ## Component Props ([PhoneInputProps](lib/interfaces/phoneInputProps.ts))
580
607
 
581
- - `language?:` [ILanguage](https://github.com/AstrOOnauta/react-native-international-phone-number/blob/master/lib/interfaces/language.ts);
608
+ - `language?:` [ILanguage](lib/interfaces/language.ts);
582
609
  - `customMask?:` string[];
583
610
  - `defaultValue?:` string;
584
611
  - `value?:` string;
585
612
  - `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;
613
+ - `selectedCountry?:` [ICountry](lib/interfaces/country.ts);
614
+ - `onChangeSelectedCountry?:` (country: [ICountry](lib/interfaces/country.ts)) => void;
588
615
  - `disabled?:` boolean;
589
616
  - `modalDisabled?:` boolean;
590
617
  - `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)>
618
+ - `theme?:` [ITheme](lib/interfaces/theme.ts);
619
+ - `modalStyles?:` [IPhoneInputStyles](lib/interfaces/phoneInputStyles.ts);
620
+ - `modalStyles?:` [IModalStyles](lib/interfaces/modalStyles.ts);
621
+ - `ref?:` [Ref](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/663f439d11d78b65f1dfd38d120f3728ea2cc207/types/react/index.d.ts#L100)<[IPhoneInputRef](lib/interfaces/phoneInputRef.ts)>
598
622
 
599
623
  <br>
600
624
 
601
625
  ## Functions
602
626
 
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;
627
+ - `getAllCountries:` () => [ICountry](lib/interfaces/country.ts)[];
628
+ - `getCountriesByCallingCode:` (callingCode: string) => [ICountry](lib/interfaces/country.ts)[] | undefined;
629
+ - `getCountryByCca2:` (cca2: string) => [ICountry](lib/interfaces/country.ts) | undefined;
630
+ - `getCountriesByName:` (name: string, language: [ILanguage](lib/interfaces/language.ts)) => [ICountry](lib/interfaces/country.ts)[] | undefined;
631
+ - `getCountryByPhoneNumber:` (phoneNumber: string) => [ICountry](lib/interfaces/country.ts) | undefined;
608
632
 
609
633
  </br>
610
634
 
@@ -651,7 +675,7 @@ export default function App() {
651
675
 
652
676
  ## License
653
677
 
654
- [ISC](https://github.com/AstrOOnauta/react-native-international-phone-number/blob/master/LICENSE.md)
678
+ [ISC](LICENSE.md)
655
679
 
656
680
  <br>
657
681
 
Binary file
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,
@@ -82,10 +79,7 @@ const PhoneInput = forwardRef(
82
79
  placeholder,
83
80
  placeholderTextColor,
84
81
  selectionColor,
85
- containerStyle,
86
- flagContainerStyle,
87
- flagTextStyle,
88
- inputStyle,
82
+ phoneInputStyle,
89
83
  modalStyle,
90
84
  disabled,
91
85
  modalDisabled,
@@ -296,22 +290,36 @@ const PhoneInput = forwardRef(
296
290
  return (
297
291
  <>
298
292
  <View
299
- style={getContainerStyle(theme, containerStyle, disabled)}
293
+ style={getContainerStyle(
294
+ theme,
295
+ phoneInputStyle?.container,
296
+ disabled
297
+ )}
300
298
  >
301
299
  <TouchableOpacity
302
300
  activeOpacity={disabled || modalDisabled ? 1 : 0.6}
303
301
  onPress={() =>
304
302
  disabled || modalDisabled ? null : setShow(true)
305
303
  }
306
- style={getFlagContainerStyle(theme, flagContainerStyle)}
304
+ style={getFlagContainerStyle(
305
+ theme,
306
+ phoneInputStyle?.flagContainer
307
+ )}
307
308
  >
308
- <Text style={styles.flag}>{countryValue?.flag}</Text>
309
- <Text style={getFlagTextStyle(theme, flagTextStyle)}>
309
+ <Text style={getFlagStyle(phoneInputStyle?.flag)}>
310
+ {countryValue?.flag}
311
+ </Text>
312
+ <Text
313
+ style={getFlagTextStyle(
314
+ theme,
315
+ phoneInputStyle?.callingCode
316
+ )}
317
+ >
310
318
  {countryValue?.callingCode}
311
319
  </Text>
312
320
  </TouchableOpacity>
313
321
  <TextInput
314
- style={getInputStyle(theme, inputStyle)}
322
+ style={getInputStyle(theme, phoneInputStyle?.input)}
315
323
  placeholder={
316
324
  placeholder ||
317
325
  getPhoneNumberInputPlaceholder(language || 'en')
@@ -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;
@@ -42,11 +35,8 @@ interface IPhoneInputPropsWithRef extends TextInputProps {
42
35
  placeholder?: string;
43
36
  placeholderTextColor?: string;
44
37
  selectionColor?: string;
45
- containerStyle?: StyleProp<ViewStyle>;
46
- flagContainerStyle?: StyleProp<ViewStyle>;
47
- flagTextStyle?: StyleProp<TextStyle>;
48
- inputStyle?: StyleProp<TextStyle>;
49
- modalStyle?: IModalStyle;
38
+ phoneInputStyle?: IPhoneInputStyles;
39
+ modalStyle?: IModalStyles;
50
40
  theme?: ITheme;
51
41
  disabled?: boolean;
52
42
  modalDisabled?: boolean;
@@ -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',
@@ -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.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",
Binary file
Binary file