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 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/phoneInputeRef.ts)>
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<IPhoneInputRef, PhoneInputProps>(
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
- return (
249
- <View
250
- style={[
251
- withDarkTheme
252
- ? {
253
- ...styles.darkContainer,
254
- backgroundColor: disabled
255
- ? '#858585'
256
- : styles.darkContainer.backgroundColor,
257
- }
258
- : {
259
- ...styles.lightContainer,
260
- backgroundColor: disabled
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 ? styles.darkInput : styles.lightInput,
292
- { width: containerWidth - 100 },
293
- inputStyle ? inputStyle : {},
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
- placeholder={
296
- placeholder ? placeholder : 'Insert your phone number'
277
+ onLayout={(e) =>
278
+ setContainerWidth(e.nativeEvent.layout.width)
297
279
  }
298
- placeholderTextColor={
299
- placeholderTextColor
300
- ? placeholderTextColor
301
- : withDarkTheme
302
- ? '#CCCCCC'
303
- : '#DDDDDD'
304
- }
305
- selectionColor={
306
- selectionColor
307
- ? selectionColor
308
- : withDarkTheme
309
- ? 'rgba(255,255,255, .4)'
310
- : 'rgba(0 ,0 ,0 , .4)'
311
- }
312
- editable={!disabled}
313
- value={inputValue}
314
- onChangeText={onChangeText}
315
- keyboardType="numeric"
316
- ref={textInputRef}
317
- {...rest}
318
- />
319
- </View>
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
- export interface PhoneInputProps extends TextInputProps {
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.13",
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",