react-native-international-phone-number 0.4.13 → 0.4.14
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 +3 -1
- package/lib/index.d.ts +1 -6
- package/lib/index.js +82 -70
- package/lib/interfaces/phoneInputProps.ts +25 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -394,6 +394,8 @@ export default function App() {
|
|
|
394
394
|
}
|
|
395
395
|
```
|
|
396
396
|
|
|
397
|
+
> 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).
|
|
398
|
+
|
|
397
399
|
## Advanced Usage
|
|
398
400
|
|
|
399
401
|
- ### React-Hook-Form + Typescript + Default Phone Number Value
|
|
@@ -560,7 +562,7 @@ export default function App() {
|
|
|
560
562
|
- `containerStyle?:` StyleProp<[ViewStyle](https://reactnative.dev/docs/view-style-props)>;
|
|
561
563
|
- `flagContainerStyle?:` StyleProp<[ViewStyle](https://reactnative.dev/docs/view-style-props)>;
|
|
562
564
|
- `inputStyle?:` StyleProp<[TextStyle](https://reactnative.dev/docs/text-style-props)>;
|
|
563
|
-
- `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/
|
|
565
|
+
- `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)>
|
|
564
566
|
|
|
565
567
|
<br>
|
|
566
568
|
|
package/lib/index.d.ts
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
1
|
-
import { Ref } from 'react';
|
|
2
|
-
|
|
3
1
|
import { ICountry } from './interfaces/country';
|
|
4
2
|
import { IPhoneInputRef } from './interfaces/phoneInputRef';
|
|
5
3
|
import { PhoneInputProps } from './interfaces/phoneInputProps';
|
|
6
4
|
|
|
7
|
-
declare function PhoneInput
|
|
8
|
-
props: PhoneInputProps,
|
|
9
|
-
ref?: Ref<IPhoneInputRef>
|
|
10
|
-
): JSX.Element;
|
|
5
|
+
declare function PhoneInput(props: PhoneInputProps): JSX.Element;
|
|
11
6
|
|
|
12
7
|
declare function getAllCountries(): ICountry[];
|
|
13
8
|
|
package/lib/index.js
CHANGED
|
@@ -245,79 +245,91 @@ const PhoneInput = forwardRef(
|
|
|
245
245
|
}
|
|
246
246
|
}, [selectedCountry]);
|
|
247
247
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
? '#E3E3E3'
|
|
262
|
-
: styles.lightContainer.backgroundColor,
|
|
263
|
-
},
|
|
264
|
-
containerStyle ? containerStyle : {},
|
|
265
|
-
]}
|
|
266
|
-
onLayout={(e) =>
|
|
267
|
-
setContainerWidth(e.nativeEvent.layout.width)
|
|
268
|
-
}
|
|
269
|
-
>
|
|
270
|
-
<CountryPicker
|
|
271
|
-
containerButtonStyle={[
|
|
272
|
-
flagContainerBase,
|
|
273
|
-
countryValue?.cca2 === 'VA' ? { width: 140 } : {},
|
|
274
|
-
flagContainerStyle ? flagContainerStyle : {},
|
|
275
|
-
]}
|
|
276
|
-
onSelect={onSelect}
|
|
277
|
-
withFilter
|
|
278
|
-
withAlphaFilter
|
|
279
|
-
withCallingCode
|
|
280
|
-
withCallingCodeButton={countryValue || defaultCca2}
|
|
281
|
-
theme={withDarkTheme ? DARK_THEME : DEFAULT_THEME}
|
|
282
|
-
countryCode={
|
|
283
|
-
countryValue ? countryValue?.cca2 : defaultCca2
|
|
284
|
-
}
|
|
285
|
-
modalProps={
|
|
286
|
-
disabled || modalDisabled ? { visible: false } : {}
|
|
287
|
-
}
|
|
288
|
-
/>
|
|
289
|
-
<TextInput
|
|
248
|
+
if (
|
|
249
|
+
ref &&
|
|
250
|
+
(rest.value ||
|
|
251
|
+
onChangePhoneNumber ||
|
|
252
|
+
selectedCountry ||
|
|
253
|
+
onChangeSelectedCountry)
|
|
254
|
+
) {
|
|
255
|
+
throw new Error(
|
|
256
|
+
"Error: 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)."
|
|
257
|
+
);
|
|
258
|
+
} else {
|
|
259
|
+
return (
|
|
260
|
+
<View
|
|
290
261
|
style={[
|
|
291
|
-
withDarkTheme
|
|
292
|
-
|
|
293
|
-
|
|
262
|
+
withDarkTheme
|
|
263
|
+
? {
|
|
264
|
+
...styles.darkContainer,
|
|
265
|
+
backgroundColor: disabled
|
|
266
|
+
? '#858585'
|
|
267
|
+
: styles.darkContainer.backgroundColor,
|
|
268
|
+
}
|
|
269
|
+
: {
|
|
270
|
+
...styles.lightContainer,
|
|
271
|
+
backgroundColor: disabled
|
|
272
|
+
? '#E3E3E3'
|
|
273
|
+
: styles.lightContainer.backgroundColor,
|
|
274
|
+
},
|
|
275
|
+
containerStyle ? containerStyle : {},
|
|
294
276
|
]}
|
|
295
|
-
|
|
296
|
-
|
|
277
|
+
onLayout={(e) =>
|
|
278
|
+
setContainerWidth(e.nativeEvent.layout.width)
|
|
297
279
|
}
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
:
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
280
|
+
>
|
|
281
|
+
<CountryPicker
|
|
282
|
+
containerButtonStyle={[
|
|
283
|
+
flagContainerBase,
|
|
284
|
+
countryValue?.cca2 === 'VA' ? { width: 140 } : {},
|
|
285
|
+
flagContainerStyle ? flagContainerStyle : {},
|
|
286
|
+
]}
|
|
287
|
+
onSelect={onSelect}
|
|
288
|
+
withFilter
|
|
289
|
+
withAlphaFilter
|
|
290
|
+
withCallingCode
|
|
291
|
+
withCallingCodeButton={countryValue || defaultCca2}
|
|
292
|
+
theme={withDarkTheme ? DARK_THEME : DEFAULT_THEME}
|
|
293
|
+
countryCode={
|
|
294
|
+
countryValue ? countryValue?.cca2 : defaultCca2
|
|
295
|
+
}
|
|
296
|
+
modalProps={
|
|
297
|
+
disabled || modalDisabled ? { visible: false } : {}
|
|
298
|
+
}
|
|
299
|
+
/>
|
|
300
|
+
<TextInput
|
|
301
|
+
style={[
|
|
302
|
+
withDarkTheme ? styles.darkInput : styles.lightInput,
|
|
303
|
+
{ width: containerWidth - 100 },
|
|
304
|
+
inputStyle ? inputStyle : {},
|
|
305
|
+
]}
|
|
306
|
+
placeholder={
|
|
307
|
+
placeholder ? placeholder : 'Insert your phone number'
|
|
308
|
+
}
|
|
309
|
+
placeholderTextColor={
|
|
310
|
+
placeholderTextColor
|
|
311
|
+
? placeholderTextColor
|
|
312
|
+
: withDarkTheme
|
|
313
|
+
? '#CCCCCC'
|
|
314
|
+
: '#DDDDDD'
|
|
315
|
+
}
|
|
316
|
+
selectionColor={
|
|
317
|
+
selectionColor
|
|
318
|
+
? selectionColor
|
|
319
|
+
: withDarkTheme
|
|
320
|
+
? 'rgba(255,255,255, .4)'
|
|
321
|
+
: 'rgba(0 ,0 ,0 , .4)'
|
|
322
|
+
}
|
|
323
|
+
editable={!disabled}
|
|
324
|
+
value={inputValue}
|
|
325
|
+
onChangeText={onChangeText}
|
|
326
|
+
keyboardType="numeric"
|
|
327
|
+
ref={textInputRef}
|
|
328
|
+
{...rest}
|
|
329
|
+
/>
|
|
330
|
+
</View>
|
|
331
|
+
);
|
|
332
|
+
}
|
|
321
333
|
}
|
|
322
334
|
);
|
|
323
335
|
|
|
@@ -6,8 +6,10 @@ import {
|
|
|
6
6
|
} from 'react-native';
|
|
7
7
|
|
|
8
8
|
import { ICountry } from './country';
|
|
9
|
+
import { Ref } from 'react';
|
|
10
|
+
import { IPhoneInputRef } from './phoneInputRef';
|
|
9
11
|
|
|
10
|
-
|
|
12
|
+
interface IPhoneInputPropsWithoutRef extends TextInputProps {
|
|
11
13
|
placeholder?: string;
|
|
12
14
|
placeholderTextColor?: string;
|
|
13
15
|
containerStyle?: StyleProp<ViewStyle>;
|
|
@@ -21,4 +23,26 @@ export interface PhoneInputProps extends TextInputProps {
|
|
|
21
23
|
onChangePhoneNumber: (phoneNumber: string) => void;
|
|
22
24
|
selectedCountry: undefined | ICountry;
|
|
23
25
|
onChangeSelectedCountry: (country: ICountry) => void;
|
|
26
|
+
ref?: never;
|
|
24
27
|
}
|
|
28
|
+
|
|
29
|
+
interface IPhoneInputPropsWithRef extends TextInputProps {
|
|
30
|
+
placeholder?: string;
|
|
31
|
+
placeholderTextColor?: string;
|
|
32
|
+
containerStyle?: StyleProp<ViewStyle>;
|
|
33
|
+
flagContainerStyle?: StyleProp<ViewStyle>;
|
|
34
|
+
inputStyle?: StyleProp<TextStyle>;
|
|
35
|
+
withDarkTheme?: boolean;
|
|
36
|
+
disabled?: boolean;
|
|
37
|
+
modalDisabled?: boolean;
|
|
38
|
+
defaultValue?: string;
|
|
39
|
+
value?: never;
|
|
40
|
+
onChangePhoneNumber?: never;
|
|
41
|
+
selectedCountry?: never;
|
|
42
|
+
onChangeSelectedCountry?: never;
|
|
43
|
+
ref: Ref<IPhoneInputRef>;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export type PhoneInputProps =
|
|
47
|
+
| IPhoneInputPropsWithRef
|
|
48
|
+
| IPhoneInputPropsWithoutRef;
|
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.4.
|
|
4
|
+
"version": "0.4.14",
|
|
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",
|