forked from xcarpentier/react-native-country-picker-modal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
151 lines (147 loc) · 4.08 KB
/
App.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import React, { useState } from 'react'
import {
View,
Text,
StyleSheet,
PixelRatio,
Switch,
Button,
ScrollView
} from 'react-native'
import CountryPicker from './src/'
import { CountryCode, Country } from './src/types'
import { Row } from './src/Row'
const styles = StyleSheet.create({
container: {
paddingVertical: 15,
justifyContent: 'center',
alignItems: 'center'
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10
},
instructions: {
fontSize: 12,
textAlign: 'center',
color: '#888',
marginBottom: 5
},
data: {
padding: 10,
marginTop: 7,
backgroundColor: '#ddd',
borderColor: '#888',
borderWidth: 1 / PixelRatio.get(),
color: '#777'
}
})
interface OptionProps {
title: string
value: boolean
onValueChange(value: boolean): void
}
const Option = ({ value, onValueChange, title }: OptionProps) => (
<Row fullWidth>
<Text style={styles.instructions}>{title}</Text>
<Switch {...{ value, onValueChange }} />
</Row>
)
export default function App() {
const [countryCode, setCountryCode] = useState<CountryCode>('FR')
const [country, setCountry] = useState<Country>(null)
const [withCountryNameButton, setWithCountryNameButton] = useState<boolean>(
false
)
const [withCurrencyButton, setWithCurrencyButton] = useState<boolean>(false)
const [withCallingCodeButton, setWithCallingCodeButton] = useState<boolean>(
false
)
const [withFlag, setWithFlag] = useState<boolean>(true)
const [withEmoji, setWithEmoji] = useState<boolean>(true)
const [withFilter, setWithFilter] = useState<boolean>(true)
const [withAlphaFilter, setWithAlphaFilter] = useState<boolean>(false)
const [withCallingCode, setWithCallingCode] = useState<boolean>(false)
const [withCurrency, setWithCurrency] = useState<boolean>(false)
const [visible, setVisible] = useState<boolean>(false)
const onSelect = (country: Country) => {
setCountryCode(country.cca2)
setCountry(country)
}
const switchVisible = () => setVisible(!visible)
return (
<ScrollView contentContainerStyle={styles.container}>
<Text style={styles.welcome}>Welcome to Country Picker !</Text>
<Option
title="With country name on button"
value={withCountryNameButton}
onValueChange={setWithCountryNameButton}
/>
<Option
title="With currency on button"
value={withCurrencyButton}
onValueChange={setWithCurrencyButton}
/>
<Option
title="With calling code on button"
value={withCallingCodeButton}
onValueChange={setWithCallingCodeButton}
/>
<Option title="With flag" value={withFlag} onValueChange={setWithFlag} />
<Option
title="With emoji"
value={withEmoji}
onValueChange={setWithEmoji}
/>
<Option
title="With filter"
value={withFilter}
onValueChange={setWithFilter}
/>
<Option
title="With calling code"
value={withCallingCode}
onValueChange={setWithCallingCode}
/>
<Option
title="With currency"
value={withCurrency}
onValueChange={setWithCurrency}
/>
<Option
title="With alpha filter code"
value={withAlphaFilter}
onValueChange={setWithAlphaFilter}
/>
<CountryPicker
{...{
countryCode,
withFilter,
withFlag,
withCurrencyButton,
withCallingCodeButton,
withCountryNameButton,
withAlphaFilter,
withCallingCode,
withCurrency,
withEmoji,
onSelect,
modalProps: {
visible
},
onClose: () => setVisible(false),
onOpen: () => setVisible(true)
}}
/>
<Text style={styles.instructions}>Press on the flag to open modal</Text>
<Button
title={'Open modal from outside using visible props'}
onPress={() => switchVisible()}
/>
{country !== null && (
<Text style={styles.data}>{JSON.stringify(country, null, 0)}</Text>
)}
</ScrollView>
)
}