Skip to content

Commit f49800e

Browse files
committed
Bug Fixes
1 parent 0873987 commit f49800e

File tree

2 files changed

+22
-24
lines changed

2 files changed

+22
-24
lines changed

README.md

Whitespace-only changes.

index.tsx

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
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';
33
import { countries, _getFlag } from './_inc/_lib/enhanced';
44

55

@@ -79,6 +79,7 @@ const CountryCodeSelectList: React.FC<CountryCodeProps> = ({
7979
const [_selected, _setSelected] = React.useState(false);
8080
const [_search, _setSearch] = React.useState('');
8181
const [_countries, _setCountries] = React.useState(countries);
82+
8283
const slideAnim = React.useRef(new Animated.Value(0)).current;
8384

8485

@@ -115,10 +116,11 @@ const CountryCodeSelectList: React.FC<CountryCodeProps> = ({
115116

116117

117118
const RenderBtn = () => {
119+
118120
if(!_selected){
119121
return(
120122
<View style={[styles.row]}>
121-
<TouchableOpacity style={{ flexDirection: 'row' }} onPress={ () => slideDown() }>
123+
<TouchableOpacity style={{ flexDirection: 'row' }} onPress={ () => {_setCountries(countries); slideDown()} }>
122124
<View style={[styles.selectedContainer, countryCodeContainerStyles]}>
123125
<Text style={{color: '#000', marginRight: 5}}>{_getFlag(selected)}</Text>
124126
<Text style={[countryCodeTextStyles]}>{selected}</Text>
@@ -162,40 +164,36 @@ const CountryCodeSelectList: React.FC<CountryCodeProps> = ({
162164
)
163165
}
164166
}
165-
166-
React.useEffect(() => {
167167

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+
169178

170179
return(
171180
<View style={styles.container}>
172-
<RenderBtn />
181+
{ RenderBtn() }
182+
173183
{
174184
(_selected)
175185
?
176186
<Animated.View
177187
style={{ maxHeight: slideAnim }}
178188
>
179-
<ScrollView
189+
<FlatList
190+
data={_countries}
180191
style={[styles.valuesContainer, dropdownStyles]}
181192
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+
/>
199197
</Animated.View>
200198
:
201199
<></>

0 commit comments

Comments
 (0)