react-native-international-phone-number 0.7.0 → 0.7.2

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
@@ -70,6 +70,7 @@
70
70
  - [Default Phone Number Value](#default-phone-number-value)
71
71
  - [Show Only Some Countries Inside Modal](#show-only-some-countries)
72
72
  - [Exclude some countries Inside Modal](#exclude-some-countries)
73
+ - [Show Popular Countries at the Top of the Countries List Inside Modal](#show-popular-countries-at-the-top-of-the-countries-list-inside-modal)
73
74
  - [Lib Props](#component-props-phoneinputprops)
74
75
  - [Lib Functions](#functions)
75
76
  - [Supported languages](#🎌-supported-languages-🎌)
@@ -665,6 +666,17 @@ export default function App() {
665
666
  ...
666
667
  ```
667
668
 
669
+ - ### Show Popular Countries at the Top of the Countries List Inside Modal:
670
+
671
+ ```jsx
672
+ ...
673
+ <PhoneInput
674
+ ...
675
+ popularCountriess={['BR', 'PT', 'CA', 'US']}
676
+ />
677
+ ...
678
+ ```
679
+
668
680
  </br>
669
681
 
670
682
  ## Component Props ([PhoneInputProps](lib/interfaces/phoneInputProps.ts))
@@ -679,6 +691,7 @@ export default function App() {
679
691
  - `onChangeSelectedCountry?:` (country: [ICountry](lib/interfaces/country.ts)) => void;
680
692
  - `showOnly?:` [ICountryCca2[]](lib/interfaces/countryCca2.ts);
681
693
  - `excludedCountries?:` [ICountryCca2[]](lib/interfaces/countryCca2.ts);
694
+ - `popularCountries?:` [ICountryCca2[]](lib/interfaces/countryCca2.ts);
682
695
  - `disabled?:` boolean;
683
696
  - `modalDisabled?:` boolean;
684
697
  - `modalHeight?:` number | string;
package/lib/index.js CHANGED
@@ -10,7 +10,10 @@ import {
10
10
  TouchableOpacity,
11
11
  TextInput,
12
12
  } from 'react-native';
13
- import { CountryPicker } from 'react-native-country-codes-picker';
13
+ import {
14
+ CountryPicker,
15
+ CountryButton,
16
+ } from 'react-native-country-codes-picker';
14
17
 
15
18
  import getInputMask from './utils/getInputMask';
16
19
  import getAllCountries from './utils/getAllCountries';
@@ -55,6 +58,7 @@ const PhoneInput = forwardRef(
55
58
  customMask,
56
59
  showOnly,
57
60
  excludedCountries,
61
+ popularCountries,
58
62
  modalSearchInputPlaceholder,
59
63
  modalNotFoundCountryMessage,
60
64
  customCaret,
@@ -99,6 +103,7 @@ const PhoneInput = forwardRef(
99
103
  customMask,
100
104
  showOnly,
101
105
  excludedCountries,
106
+ popularCountries,
102
107
  modalSearchInputPlaceholder,
103
108
  modalNotFoundCountryMessage,
104
109
  customCaret,
@@ -311,12 +316,22 @@ const PhoneInput = forwardRef(
311
316
  {countryValue?.flag}
312
317
  </Text>
313
318
  {customCaret || (
314
- <View
315
- style={getCaretStyle(
316
- theme,
317
- phoneInputStyles?.caret
318
- )}
319
- />
319
+ <View style={phoneInputStyles?.caret}>
320
+ <View
321
+ style={{
322
+ flexDirection: 'row',
323
+ justifyContent: 'center',
324
+ paddingTop: 4,
325
+ }}
326
+ >
327
+ <View
328
+ style={getCaretStyle(
329
+ theme,
330
+ phoneInputStyles?.caret
331
+ )}
332
+ />
333
+ </View>
334
+ </View>
320
335
  )}
321
336
  <View
322
337
  style={getDividerStyle(
@@ -380,6 +395,24 @@ const PhoneInput = forwardRef(
380
395
  onBackdropPress={() => setShow(false)}
381
396
  showOnly={showOnly}
382
397
  excludedCountries={excludedCountries}
398
+ popularCountries={popularCountries}
399
+ ListHeaderComponent={({ countries, lang, onPress }) => {
400
+ return countries.map((country, index) => {
401
+ return (
402
+ <CountryButton
403
+ key={index}
404
+ item={country}
405
+ name={country?.name?.[lang || 'en']}
406
+ onPress={() => onPress(country)}
407
+ style={getCountryPickerStyle(
408
+ theme,
409
+ modalHeight,
410
+ modalStyles
411
+ )}
412
+ />
413
+ );
414
+ });
415
+ }}
383
416
  />
384
417
  ) : null}
385
418
  </>
@@ -25,6 +25,7 @@ interface BasePhoneInput extends TextInputProps {
25
25
  customMask?: Array<string>;
26
26
  showOnly?: Array<ICountryCca2>;
27
27
  excludedCountries?: Array<ICountryCca2>;
28
+ popularCountries?: Array<ICountryCca2>;
28
29
  modalSearchInputPlaceholder?: string;
29
30
  modalNotFoundCountryMessage?: string;
30
31
  customCaret?: ReactNode;
package/lib/styles.js CHANGED
@@ -24,7 +24,6 @@ const flagContainerBase = {
24
24
  const caretBase = {
25
25
  width: 0,
26
26
  height: 0,
27
- marginTop: 4,
28
27
  borderWidth: 7,
29
28
  borderBottomWidth: 0,
30
29
  borderLeftColor: 'transparent',
@@ -74,7 +73,10 @@ const styles = StyleSheet.create({
74
73
  color: '#FFFFFF',
75
74
  fontSize: 20,
76
75
  marginRight: 6,
77
- fontFamily: Platform.OS === 'web' ? 'TwemojiMozilla' : 'System',
76
+ fontFamily:
77
+ Platform.OS === 'web' && navigator.userAgent.includes('Win')
78
+ ? 'TwemojiMozilla'
79
+ : 'System',
78
80
  },
79
81
  lightCaret: {
80
82
  ...caretBase,
@@ -137,7 +139,10 @@ const styles = StyleSheet.create({
137
139
  flag: {
138
140
  color: '#FFFFFF',
139
141
  fontSize: 20,
140
- fontFamily: Platform.OS === 'web' ? 'TwemojiMozilla' : 'System',
142
+ fontFamily:
143
+ Platform.OS === 'web' && navigator.userAgent.includes('Win')
144
+ ? 'TwemojiMozilla'
145
+ : 'System',
141
146
  },
142
147
  dialCode: {},
143
148
  countryName: {},
@@ -173,7 +178,10 @@ const styles = StyleSheet.create({
173
178
  flag: {
174
179
  color: '#FFFFFF',
175
180
  fontSize: 20,
176
- fontFamily: Platform.OS === 'web' ? 'TwemojiMozilla' : 'System',
181
+ fontFamily:
182
+ Platform.OS === 'web' && navigator.userAgent.includes('Win')
183
+ ? 'TwemojiMozilla'
184
+ : 'System',
177
185
  },
178
186
  dialCode: {
179
187
  color: '#F3F3F3',
@@ -35,20 +35,17 @@ export function getFlagStyle(flagStyle) {
35
35
  export function getCaretStyle(theme, caretStyle) {
36
36
  return [
37
37
  theme === 'dark' ? styles.darkCaret : styles.lightCaret,
38
- caretStyle
38
+ caretStyle?.color !== undefined
39
39
  ? {
40
- borderTopColor: caretStyle?.color
41
- ? caretStyle?.color
42
- : theme === 'dark'
43
- ? styles.darkCaret.borderTopColor
44
- : styles.lightCaret.borderTopColor,
45
- borderWidth: caretStyle?.fontSize
46
- ? caretStyle?.fontSize * 0.45
47
- : theme === 'dark'
48
- ? styles.darkCaret.borderWidth
49
- : styles.lightCaret.borderWidth,
40
+ borderTopColor: caretStyle?.color,
50
41
  }
51
42
  : {},
43
+ caretStyle?.fontSize !== undefined
44
+ ? { borderWidth: caretStyle?.fontSize * 0.45 }
45
+ : {},
46
+ caretStyle && caretStyle?.display === 'none'
47
+ ? { display: 'none', borderWidth: 0 }
48
+ : {},
52
49
  ];
53
50
  }
54
51
 
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.7.0",
4
+ "version": "0.7.2",
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",