react-native-international-phone-number 0.2.10 → 0.3.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 +14 -3
- package/images/custom-styles.png +0 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +24 -7
- package/lib/utils/countries.js +1416 -0
- package/lib/utils/inputMask.js +26 -3
- package/package.json +1 -1
- package/lib/utils/countriesPhoneCode.js +0 -260
package/README.md
CHANGED
|
@@ -157,7 +157,7 @@ interface FormProps extends FieldValues {
|
|
|
157
157
|
export default function App() {
|
|
158
158
|
const [selectedCountry, setSelectedCountry] = useState<undefined | Country>(undefined);
|
|
159
159
|
|
|
160
|
-
const { control, handleSubmit, resetField } = useForm();
|
|
160
|
+
const { control, handleSubmit, resetField } = useForm<FormProps>();
|
|
161
161
|
|
|
162
162
|
function onSubmit(form: FormProps) {
|
|
163
163
|
Alert.alert(
|
|
@@ -215,7 +215,11 @@ export default function App() {
|
|
|
215
215
|
/>
|
|
216
216
|
```
|
|
217
217
|
|
|
218
|
-
###
|
|
218
|
+
### Custom Lib Styles:
|
|
219
|
+
|
|
220
|
+
<div>
|
|
221
|
+
<img src="https://github.com/AstrOOnauta/react-native-international-phone-number/blob/master/images/custom-styles.png">
|
|
222
|
+
</div>
|
|
219
223
|
|
|
220
224
|
```jsx
|
|
221
225
|
<PhoneInput
|
|
@@ -230,6 +234,12 @@ export default function App() {
|
|
|
230
234
|
borderColor: '#F3F3F3',
|
|
231
235
|
marginVertical: 16,
|
|
232
236
|
}}
|
|
237
|
+
flagContainerStyle={{
|
|
238
|
+
borderTopLeftRadius: 7,
|
|
239
|
+
borderBottomLeftRadius: 7,
|
|
240
|
+
backgroundColor: '#808080',
|
|
241
|
+
justifyContent: 'center',
|
|
242
|
+
}}
|
|
233
243
|
/>
|
|
234
244
|
```
|
|
235
245
|
|
|
@@ -238,7 +248,8 @@ export default function App() {
|
|
|
238
248
|
- `value?`: string
|
|
239
249
|
- `onChangeText?`: (text: string) => void
|
|
240
250
|
- `containerStyle?`: StyleProp<ViewStyle>
|
|
241
|
-
- `
|
|
251
|
+
- `flagContainerStyle?`: StyleProp<ViewStyle>
|
|
252
|
+
- `inputStyle?`: StyleProp<InputStyle>
|
|
242
253
|
- `withDarkTheme?`: boolean
|
|
243
254
|
- `disabled?`: boolean
|
|
244
255
|
- `placeholder?`: string
|
|
Binary file
|
package/lib/index.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ interface PhoneInputProps extends TextInputProps {
|
|
|
11
11
|
placeholder?: string;
|
|
12
12
|
placeholderTextColor?: string;
|
|
13
13
|
containerStyle?: StyleProp<ViewStyle>;
|
|
14
|
+
flagContainerStyle?: StyleProp<ViewStyle>;
|
|
14
15
|
inputStyle?: StyleProp<TextStyle>;
|
|
15
16
|
withDarkTheme?: boolean;
|
|
16
17
|
disabled?: boolean;
|
package/lib/index.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import React, { useEffect } from 'react';
|
|
1
|
+
import React, { useEffect, useState } from 'react';
|
|
2
2
|
import {
|
|
3
3
|
StyleSheet,
|
|
4
4
|
Dimensions,
|
|
5
|
-
Platform,
|
|
6
5
|
View,
|
|
7
6
|
TextInput,
|
|
8
7
|
} from 'react-native';
|
|
@@ -18,6 +17,7 @@ function PhoneInput({
|
|
|
18
17
|
placeholderTextColor,
|
|
19
18
|
selectionColor,
|
|
20
19
|
containerStyle,
|
|
20
|
+
flagContainerStyle,
|
|
21
21
|
inputStyle,
|
|
22
22
|
withDarkTheme,
|
|
23
23
|
disabled,
|
|
@@ -25,6 +25,10 @@ function PhoneInput({
|
|
|
25
25
|
setSelectedCountry,
|
|
26
26
|
...rest
|
|
27
27
|
}) {
|
|
28
|
+
const [containerWidth, setContainerWidth] = useState(
|
|
29
|
+
Dimensions.get('window').width
|
|
30
|
+
);
|
|
31
|
+
|
|
28
32
|
const onSelect = (country) => {
|
|
29
33
|
if (setSelectedCountry) {
|
|
30
34
|
setSelectedCountry({
|
|
@@ -52,11 +56,13 @@ function PhoneInput({
|
|
|
52
56
|
withDarkTheme ? styles.darkContainer : styles.lightContainer,
|
|
53
57
|
containerStyle ? containerStyle : {},
|
|
54
58
|
]}
|
|
59
|
+
onLayout={(e) => setContainerWidth(e.nativeEvent.layout.width)}
|
|
55
60
|
>
|
|
56
61
|
<CountryPicker
|
|
57
|
-
containerButtonStyle={
|
|
58
|
-
|
|
59
|
-
|
|
62
|
+
containerButtonStyle={[
|
|
63
|
+
flagContainerBase,
|
|
64
|
+
flagContainerStyle ? flagContainerStyle : {},
|
|
65
|
+
]}
|
|
60
66
|
onSelect={onSelect}
|
|
61
67
|
withFilter
|
|
62
68
|
withAlphaFilter
|
|
@@ -68,6 +74,7 @@ function PhoneInput({
|
|
|
68
74
|
<TextInput
|
|
69
75
|
style={[
|
|
70
76
|
withDarkTheme ? styles.darkInput : styles.lightInput,
|
|
77
|
+
{ width: containerWidth - 100 },
|
|
71
78
|
inputStyle ? inputStyle : {},
|
|
72
79
|
]}
|
|
73
80
|
placeholder={
|
|
@@ -98,14 +105,24 @@ function PhoneInput({
|
|
|
98
105
|
const containerBase = {
|
|
99
106
|
flexDirection: 'row',
|
|
100
107
|
alignItems: 'center',
|
|
108
|
+
justifyContent: 'space-between',
|
|
101
109
|
borderWidth: 1,
|
|
102
110
|
borderStyle: 'solid',
|
|
103
111
|
borderRadius: 8,
|
|
112
|
+
width: '100%',
|
|
113
|
+
height: 45,
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
const flagContainerBase = {
|
|
117
|
+
width: 100,
|
|
118
|
+
height: '99%',
|
|
119
|
+
alignItems: 'center',
|
|
120
|
+
justifyContent: 'center',
|
|
104
121
|
};
|
|
105
122
|
|
|
106
123
|
const inputBase = {
|
|
107
|
-
width: Dimensions.get('window').width -
|
|
108
|
-
paddingVertical:
|
|
124
|
+
width: Dimensions.get('window').width - 140,
|
|
125
|
+
paddingVertical: 8,
|
|
109
126
|
paddingHorizontal: 16,
|
|
110
127
|
fontSize: 16,
|
|
111
128
|
};
|