|
1 | 1 | import React,{JSXElementConstructor} from 'react';
|
2 |
| -import { View, Text, StyleSheet,ScrollView, TouchableOpacity, Animated, TextInput, Image, ViewStyle } from 'react-native'; |
| 2 | +import { View, Text, StyleSheet,FlatList, TouchableOpacity, Animated, TextInput, Image, ViewStyle } from 'react-native'; |
3 | 3 | import { countries, _getFlag } from './_inc/_lib/enhanced';
|
4 | 4 |
|
5 | 5 |
|
@@ -79,6 +79,7 @@ const CountryCodeSelectList: React.FC<CountryCodeProps> = ({
|
79 | 79 | const [_selected, _setSelected] = React.useState(false);
|
80 | 80 | const [_search, _setSearch] = React.useState('');
|
81 | 81 | const [_countries, _setCountries] = React.useState(countries);
|
| 82 | + |
82 | 83 | const slideAnim = React.useRef(new Animated.Value(0)).current;
|
83 | 84 |
|
84 | 85 |
|
@@ -115,10 +116,11 @@ const CountryCodeSelectList: React.FC<CountryCodeProps> = ({
|
115 | 116 |
|
116 | 117 |
|
117 | 118 | const RenderBtn = () => {
|
| 119 | + |
118 | 120 | if(!_selected){
|
119 | 121 | return(
|
120 | 122 | <View style={[styles.row]}>
|
121 |
| - <TouchableOpacity style={{ flexDirection: 'row' }} onPress={ () => slideDown() }> |
| 123 | + <TouchableOpacity style={{ flexDirection: 'row' }} onPress={ () => {_setCountries(countries); slideDown()} }> |
122 | 124 | <View style={[styles.selectedContainer, countryCodeContainerStyles]}>
|
123 | 125 | <Text style={{color: '#000', marginRight: 5}}>{_getFlag(selected)}</Text>
|
124 | 126 | <Text style={[countryCodeTextStyles]}>{selected}</Text>
|
@@ -162,40 +164,36 @@ const CountryCodeSelectList: React.FC<CountryCodeProps> = ({
|
162 | 164 | )
|
163 | 165 | }
|
164 | 166 | }
|
165 |
| - |
166 |
| - React.useEffect(() => { |
167 | 167 |
|
168 |
| - }, []) |
| 168 | + |
| 169 | + const renderCountryItem = ({item}) => { |
| 170 | + return( |
| 171 | + <TouchableOpacity style={ styles.countryContainer } key={item.code} onPress={ () => {setSelected(item.dial_code); setCountryDetails(item); slideUp();} }> |
| 172 | + <Text style={styles.countryFlag}>{ item?.flag }</Text> |
| 173 | + <Text style={ [styles.countryText, dropdownTextStyles] } >{ item?.name }</Text> |
| 174 | + </TouchableOpacity> |
| 175 | + ) |
| 176 | + } |
| 177 | + |
169 | 178 |
|
170 | 179 | return(
|
171 | 180 | <View style={styles.container}>
|
172 |
| - <RenderBtn /> |
| 181 | + { RenderBtn() } |
| 182 | + |
173 | 183 | {
|
174 | 184 | (_selected)
|
175 | 185 | ?
|
176 | 186 | <Animated.View
|
177 | 187 | style={{ maxHeight: slideAnim }}
|
178 | 188 | >
|
179 |
| - <ScrollView |
| 189 | + <FlatList |
| 190 | + data={_countries} |
180 | 191 | style={[styles.valuesContainer, dropdownStyles]}
|
181 | 192 | showsVerticalScrollIndicator={false}
|
182 |
| - > |
183 |
| - { |
184 |
| - (_countries?.length > 0) |
185 |
| - ? |
186 |
| - _countries?.map((country, index) => { |
187 |
| - return( |
188 |
| - <TouchableOpacity style={ styles.countryContainer } key={index} onPress={ () => {setSelected(country.dial_code); setCountryDetails(country); slideUp();} }> |
189 |
| - <Text style={styles.countryFlag}>{ country?.flag }</Text> |
190 |
| - <Text style={ [styles.countryText, dropdownTextStyles] } >{ country?.name }</Text> |
191 |
| - </TouchableOpacity> |
192 |
| - ) |
193 |
| - }) |
194 |
| - : |
195 |
| - <Text style={{padding: 15, textAlign: 'center'}}>No Result Found</Text> |
196 |
| - } |
197 |
| - |
198 |
| - </ScrollView> |
| 193 | + renderItem={renderCountryItem} |
| 194 | + keyExtractor={(item) => item.code} |
| 195 | + ListEmptyComponent={ <Text style={{padding: 15, textAlign: 'center'}}>No Result Found</Text> } |
| 196 | + /> |
199 | 197 | </Animated.View>
|
200 | 198 | :
|
201 | 199 | <></>
|
|
0 commit comments