react-native-international-phone-number 0.5.2 → 0.5.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 +40 -0
- package/lib/index.js +30 -16
- package/lib/interfaces/modalStyle.ts +26 -0
- package/lib/interfaces/phoneInputProps.ts +3 -0
- package/lib/interfaces/phoneInputRef.ts +2 -0
- package/lib/utils/getStyles.js +44 -16
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -436,6 +436,45 @@ export default function App() {
|
|
|
436
436
|
fontWeight: 'bold',
|
|
437
437
|
color: '#F3F3F3',
|
|
438
438
|
}}
|
|
439
|
+
modalStyle={{
|
|
440
|
+
modal: {
|
|
441
|
+
backgroundColor: '#333333',
|
|
442
|
+
borderWidth: 1,
|
|
443
|
+
},
|
|
444
|
+
backdrop: {},
|
|
445
|
+
divider: {
|
|
446
|
+
backgroundColor: 'transparent',
|
|
447
|
+
},
|
|
448
|
+
countriesList: {},
|
|
449
|
+
searchInput: {
|
|
450
|
+
borderRadius: 8,
|
|
451
|
+
borderWidth: 1,
|
|
452
|
+
borderColor: '#F3F3F3',
|
|
453
|
+
color: '#F3F3F3',
|
|
454
|
+
backgroundColor: '#333333',
|
|
455
|
+
paddingHorizontal: 12,
|
|
456
|
+
height: 46,
|
|
457
|
+
},
|
|
458
|
+
countryButton: {
|
|
459
|
+
borderWidth: 1,
|
|
460
|
+
borderColor: '#F3F3F3',
|
|
461
|
+
backgroundColor: '#666666',
|
|
462
|
+
marginVertical: 4,
|
|
463
|
+
paddingVertical: 0,
|
|
464
|
+
},
|
|
465
|
+
noCountryText: {},
|
|
466
|
+
noCountryContainer: {},
|
|
467
|
+
flag: {
|
|
468
|
+
color: '#FFFFFF',
|
|
469
|
+
fontSize: 20,
|
|
470
|
+
},
|
|
471
|
+
callingCode: {
|
|
472
|
+
color: '#F3F3F3',
|
|
473
|
+
},
|
|
474
|
+
countryName: {
|
|
475
|
+
color: '#F3F3F3',
|
|
476
|
+
},
|
|
477
|
+
}}
|
|
439
478
|
/>
|
|
440
479
|
...
|
|
441
480
|
```
|
|
@@ -554,6 +593,7 @@ export default function App() {
|
|
|
554
593
|
- `flagContainerStyle?:` [StyleProp](https://reactnative.dev/docs/style)<[ViewStyle](https://reactnative.dev/docs/view-style-props)>;
|
|
555
594
|
- `flagTextStyle?:` [StyleProp](https://reactnative.dev/docs/style)<[TextStyle](https://reactnative.dev/docs/text-style-props)>;
|
|
556
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);
|
|
557
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)>
|
|
558
598
|
|
|
559
599
|
<br>
|
package/lib/index.js
CHANGED
|
@@ -44,6 +44,7 @@ const PhoneInput = forwardRef(
|
|
|
44
44
|
flagContainerStyle,
|
|
45
45
|
flagTextStyle,
|
|
46
46
|
inputStyle,
|
|
47
|
+
modalStyle,
|
|
47
48
|
disabled,
|
|
48
49
|
modalDisabled,
|
|
49
50
|
modalHeight,
|
|
@@ -70,6 +71,9 @@ const PhoneInput = forwardRef(
|
|
|
70
71
|
focus: textInputRef.current?.focus,
|
|
71
72
|
getValue: () => inputValue,
|
|
72
73
|
value: inputValue,
|
|
74
|
+
getFullPhoneNumber: () =>
|
|
75
|
+
`${countryValue?.callingCode} ${inputValue}`,
|
|
76
|
+
fullPhoneNumber: `${countryValue?.callingCode} ${inputValue}`,
|
|
73
77
|
getSelectedCountry: () => countryValue,
|
|
74
78
|
selectedCountry: countryValue,
|
|
75
79
|
props: {
|
|
@@ -82,6 +86,7 @@ const PhoneInput = forwardRef(
|
|
|
82
86
|
flagContainerStyle,
|
|
83
87
|
flagTextStyle,
|
|
84
88
|
inputStyle,
|
|
89
|
+
modalStyle,
|
|
85
90
|
disabled,
|
|
86
91
|
modalDisabled,
|
|
87
92
|
modalHeight,
|
|
@@ -101,6 +106,9 @@ const PhoneInput = forwardRef(
|
|
|
101
106
|
...refBase,
|
|
102
107
|
getValue: () => phoneNumber,
|
|
103
108
|
value: phoneNumber,
|
|
109
|
+
getFullPhoneNumber: () =>
|
|
110
|
+
`${country?.callingCode} ${phoneNumber}`,
|
|
111
|
+
fullPhoneNumber: `${country?.callingCode} ${phoneNumber}`,
|
|
104
112
|
getSelectedCountry: () => country,
|
|
105
113
|
selectedCountry: country,
|
|
106
114
|
props: {
|
|
@@ -154,6 +162,23 @@ const PhoneInput = forwardRef(
|
|
|
154
162
|
}
|
|
155
163
|
}
|
|
156
164
|
|
|
165
|
+
useEffect(() => {
|
|
166
|
+
if (!countryValue && !defaultCountry) {
|
|
167
|
+
const defaultCountry = getCountryByCca2('BR');
|
|
168
|
+
|
|
169
|
+
if (ref) {
|
|
170
|
+
setCountryValue(defaultCountry);
|
|
171
|
+
updateRef('', defaultCountry);
|
|
172
|
+
} else {
|
|
173
|
+
onChangeSelectedCountry(defaultCountry);
|
|
174
|
+
}
|
|
175
|
+
} else {
|
|
176
|
+
if (ref) {
|
|
177
|
+
updateRef('', countryValue);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}, []);
|
|
181
|
+
|
|
157
182
|
useEffect(() => {
|
|
158
183
|
if (defaultCountry) {
|
|
159
184
|
if (ref) {
|
|
@@ -200,21 +225,6 @@ const PhoneInput = forwardRef(
|
|
|
200
225
|
"The default number provided (defaultValue) don't match with anyone country. Please, correct it to be shown in the input. For more information: https://github.com/AstrOOnauta/react-native-international-phone-number#intermediate-usage---typescript--default-phone-number-value"
|
|
201
226
|
);
|
|
202
227
|
}
|
|
203
|
-
} else {
|
|
204
|
-
if (!countryValue && !defaultCountry) {
|
|
205
|
-
const defaultCountry = getCountryByCca2('BR');
|
|
206
|
-
|
|
207
|
-
if (ref) {
|
|
208
|
-
setCountryValue(defaultCountry);
|
|
209
|
-
updateRef('', defaultCountry);
|
|
210
|
-
} else {
|
|
211
|
-
onChangeSelectedCountry(defaultCountry);
|
|
212
|
-
}
|
|
213
|
-
} else {
|
|
214
|
-
if (ref) {
|
|
215
|
-
updateRef('', countryValue);
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
228
|
}
|
|
219
229
|
}, [defaultValue]);
|
|
220
230
|
|
|
@@ -335,7 +345,11 @@ const PhoneInput = forwardRef(
|
|
|
335
345
|
language || 'en'
|
|
336
346
|
)}
|
|
337
347
|
enableModalAvoiding
|
|
338
|
-
style={getCountryPickerStyle(
|
|
348
|
+
style={getCountryPickerStyle(
|
|
349
|
+
theme,
|
|
350
|
+
modalHeight,
|
|
351
|
+
modalStyle
|
|
352
|
+
)}
|
|
339
353
|
pickerButtonOnPress={onSelect}
|
|
340
354
|
onBackdropPress={() => setShow(false)}
|
|
341
355
|
/>
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { StyleProp, TextStyle, ViewStyle } from 'react-native';
|
|
2
|
+
|
|
3
|
+
export interface IModalStyle {
|
|
4
|
+
// Styles for whole modal [View]
|
|
5
|
+
modal?: StyleProp<ViewStyle>;
|
|
6
|
+
// Styles for modal backdrop [View]
|
|
7
|
+
backdrop?: StyleProp<ViewStyle>;
|
|
8
|
+
// Styles for search input [TextInput]
|
|
9
|
+
searchInput?: StyleProp<TextStyle>;
|
|
10
|
+
// Styles for the divider between the input and the countries list [View]
|
|
11
|
+
divider?: StyleProp<ViewStyle>;
|
|
12
|
+
// Styles for countries list [FlatList]
|
|
13
|
+
countriesList?: StyleProp<ViewStyle>;
|
|
14
|
+
// Styles for country button [TouchableOpacity]
|
|
15
|
+
countryButton?: StyleProp<ViewStyle>;
|
|
16
|
+
// Styles for country not found message container [View]
|
|
17
|
+
noCountryContainer?: StyleProp<ViewStyle>;
|
|
18
|
+
// Styles for country not found message [Text]
|
|
19
|
+
noCountryText?: StyleProp<TextStyle>;
|
|
20
|
+
// Flag styles [Text]
|
|
21
|
+
flag?: StyleProp<TextStyle>;
|
|
22
|
+
// Calling/Dial code styles [Text]
|
|
23
|
+
callingCode?: StyleProp<TextStyle>;
|
|
24
|
+
// Country name styles [Text]
|
|
25
|
+
countryName?: StyleProp<TextStyle>;
|
|
26
|
+
}
|
|
@@ -10,6 +10,7 @@ import { ICountry } from './country';
|
|
|
10
10
|
import { ICountryCca2 } from './countryCca2';
|
|
11
11
|
import { ILanguage } from './language';
|
|
12
12
|
import { ITheme } from './theme';
|
|
13
|
+
import { IModalStyle } from './modalStyle';
|
|
13
14
|
import { IPhoneInputRef } from './phoneInputRef';
|
|
14
15
|
|
|
15
16
|
interface IPhoneInputPropsWithoutRef extends TextInputProps {
|
|
@@ -21,6 +22,7 @@ interface IPhoneInputPropsWithoutRef extends TextInputProps {
|
|
|
21
22
|
flagContainerStyle?: StyleProp<ViewStyle>;
|
|
22
23
|
flagTextStyle?: StyleProp<TextStyle>;
|
|
23
24
|
inputStyle?: StyleProp<TextStyle>;
|
|
25
|
+
modalStyle?: IModalStyle;
|
|
24
26
|
theme?: ITheme;
|
|
25
27
|
disabled?: boolean;
|
|
26
28
|
modalDisabled?: boolean;
|
|
@@ -44,6 +46,7 @@ interface IPhoneInputPropsWithRef extends TextInputProps {
|
|
|
44
46
|
flagContainerStyle?: StyleProp<ViewStyle>;
|
|
45
47
|
flagTextStyle?: StyleProp<TextStyle>;
|
|
46
48
|
inputStyle?: StyleProp<TextStyle>;
|
|
49
|
+
modalStyle?: IModalStyle;
|
|
47
50
|
theme?: ITheme;
|
|
48
51
|
disabled?: boolean;
|
|
49
52
|
modalDisabled?: boolean;
|
package/lib/utils/getStyles.js
CHANGED
|
@@ -40,20 +40,48 @@ export function getInputStyle(theme, inputStyle) {
|
|
|
40
40
|
];
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
export function getCountryPickerStyle(theme, height) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
43
|
+
export function getCountryPickerStyle(theme, height, modalStyle) {
|
|
44
|
+
const themeStyle =
|
|
45
|
+
theme === 'dark'
|
|
46
|
+
? styles.darkCountryPicker
|
|
47
|
+
: styles.lightCountryPicker;
|
|
48
|
+
|
|
49
|
+
const countryPickerStyle = {
|
|
50
|
+
...themeStyle,
|
|
51
|
+
modal: {
|
|
52
|
+
...themeStyle.modal,
|
|
53
|
+
height: height || '50%',
|
|
54
|
+
...modalStyle?.modal,
|
|
55
|
+
},
|
|
56
|
+
backdrop: { ...themeStyle.backdrop, ...modalStyle?.backdrop },
|
|
57
|
+
textInput: {
|
|
58
|
+
...themeStyle.textInput,
|
|
59
|
+
...modalStyle?.searchInput,
|
|
60
|
+
},
|
|
61
|
+
line: { ...themeStyle.line, ...modalStyle?.divider },
|
|
62
|
+
itemsList: {
|
|
63
|
+
...themeStyle.itemsList,
|
|
64
|
+
...modalStyle?.countriesList,
|
|
65
|
+
},
|
|
66
|
+
countryButtonStyles: {
|
|
67
|
+
...themeStyle.countryButtonStyles,
|
|
68
|
+
...modalStyle?.countryButton,
|
|
69
|
+
},
|
|
70
|
+
countryMessageContainer: {
|
|
71
|
+
...themeStyle.countryMessageContainer,
|
|
72
|
+
...modalStyle?.noCountryContainer,
|
|
73
|
+
},
|
|
74
|
+
searchMessageText: {
|
|
75
|
+
...themeStyle.searchMessageText,
|
|
76
|
+
...modalStyle?.noCountryText,
|
|
77
|
+
},
|
|
78
|
+
flag: { ...themeStyle.flag, ...modalStyle?.flag },
|
|
79
|
+
dialCode: { ...themeStyle.dialCode, ...modalStyle?.callingCode },
|
|
80
|
+
countryName: {
|
|
81
|
+
...themeStyle.countryName,
|
|
82
|
+
...modalStyle?.countryName,
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
return countryPickerStyle;
|
|
59
87
|
}
|
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.
|
|
4
|
+
"version": "0.5.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",
|