Skip to content

Commit d3206c7

Browse files
authored
Update README.md
1 parent 9bec5ff commit d3206c7

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

README.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,68 @@ export default function App() {
6666
}
6767
```
6868

69+
### Modal with list header
70+
```JS
71+
import {CountryPicker} from "react-native-country-codes-picker";
72+
73+
function ListHeaderComponent({countries, locale}) {
74+
return (
75+
<View
76+
style={{
77+
paddingBottom: 20,
78+
}}
79+
>
80+
<Text>
81+
Popular countries
82+
</Text>
83+
{countries?.map((country, index) => {
84+
return (
85+
<CountryButton key={index} item={country} name={country?.name?.[locale || 'en']}/>
86+
)
87+
})}
88+
</View>
89+
)
90+
}
91+
92+
export default function App() {
93+
const [show, setShow] = useState(false);
94+
const [countryCode, setCountryCode] = useState('');
95+
96+
return (
97+
<View style={styles.container}>
98+
<TouchableOpacity
99+
onPress={() => setShow(true)}
100+
style={{
101+
width: '80%',
102+
height: 60,
103+
backgroundColor: 'black',
104+
padding: 10,
105+
}}
106+
>
107+
<Text style={{
108+
color: 'white',
109+
fontSize: 20
110+
}}>
111+
{countryCode}
112+
</Text>
113+
</TouchableOpacity>
114+
115+
// For showing picker just put show state to show prop
116+
<CountryPicker
117+
show={show}
118+
// when picker button press you will get the country object with dial code
119+
pickerButtonOnPress={(item) => {
120+
setCountryCode(item.dial_code);
121+
setShow(false);
122+
}}
123+
ListHeaderComponent={ListHeaderComponent}
124+
popularCountries={['en', 'ua', 'pl']}
125+
/>
126+
</View>
127+
);
128+
}
129+
```
130+
69131
### List
70132
71133
```js
@@ -123,6 +185,9 @@ Below are the props you can pass to the React Component.
123185
| onBackdropPress | function | null | onBackdropPress={() => setShow(false)} | If you want to close modal when user taps on the modal background. |
124186
| initialState | string | | initialState={'+380'} | Sometimes you need to pre-select country for example by user current location so you may use this prop. |
125187
| excludedCountries | array | | excludedCountries={['RU', 'BY']} | In this prop you can define list of countries which you want to remove by adding their codes. |
188+
| showOnly | array | | showOnly={['UA', 'EN']} | This prop allow you to configure which countries you want to show. |
189+
| popularCountries | array | | popularCountries={['UA', 'EN']} | This prop allow you to send popular countries array to yout ListHeaderComponent. |
190+
| ListHeaderComponent | JSX.Element | | ListHeaderComponent={ListHeaderComponent} | This prop allow you to create header component to show popular countries on top of list! Check example section with ListHeaderComponent |
126191
127192
:grey_exclamation: Also you can use all other FlatList and TextInput props if you need. :grey_exclamation:
128193

0 commit comments

Comments
 (0)