import React, { JSXElementConstructor } from "react"; import { View, Text, StyleSheet, FlatList, TouchableOpacity, Animated, TextInput, Image, ViewStyle, TextStyle, ScrollView, } from "react-native"; import { countries, _getFlag } from "./_inc/_lib/enhanced"; interface CountryCodeProps { /** * Selected Country Dial Code */ selected: string; /** * Function to set the country */ setSelected: React.Dispatch>; /** * Function to set the country */ setCountryDetails?: React.Dispatch>; /** * State variable for storing the phone number */ phone?: string; /** * Function to set the phone number state variable */ setPhone?: React.Dispatch>; /** * Style the Country Code Container */ countryCodeContainerStyles?: ViewStyle; /** * Style the text inside Country Code */ countryCodeTextStyles?: TextStyle; /** * Phone Text Input Styles */ phoneStyles?: ViewStyle; /** * URL for the search Icon */ searchIcon?: string; /** * URL for the close Icon */ closeIcon?: string; /** * Search Input Container Styles */ searchStyles?: ViewStyle; /** * Search Input Text Styles */ searchTextStyles?: TextStyle; /** /** * Search Dropdown Container Styles */ dropdownStyles?: ViewStyle; /** * Search Dropdown Text Styles */ dropdownTextStyles?: TextStyle; } const CountryCodeDropdownPicker: React.FC = ({ selected, setSelected, setCountryDetails = () => {}, phone, setPhone, countryCodeContainerStyles = {}, countryCodeTextStyles = {}, phoneStyles = {}, searchIcon, closeIcon, searchStyles = {}, searchTextStyles = {}, dropdownStyles = {}, dropdownTextStyles = {}, }) => { const [_selected, _setSelected] = React.useState(false); const [_search, _setSearch] = React.useState(""); const [_countries, _setCountries] = React.useState(countries); const slideAnim = React.useRef(new Animated.Value(0)).current; const _static = { search: searchIcon ?? require("./_inc/images/search.png"), close: closeIcon ?? require("./_inc/images/close.png"), }; const slideDown = () => { _setSelected(true); Animated.timing(slideAnim, { toValue: 235, duration: 400, useNativeDriver: false, }).start(); }; const slideUp = () => { Animated.timing(slideAnim, { toValue: 0, duration: 300, useNativeDriver: false, }).start(() => _setSelected(false)); }; function _searchCountry(country) { _setSearch(country); let c = countries.filter((item) => { return item.name.includes(country); }); _setCountries(c); } const RenderBtn = () => { if (!_selected) { return ( { _setCountries(countries); slideDown(); }} > {_getFlag(selected)} {selected} {phone != undefined && setPhone != undefined ? ( ) : ( <> )} ); } else { return ( slideUp()} style={{ marginHorizontal: 10 }} > ); } }; const renderCountryItem = ({ item }) => { return ( { setSelected(item.dial_code); setCountryDetails(item); slideUp(); }} > {item?.flag} {item?.name} ); }; return ( {RenderBtn()} {_selected ? ( item.code} ListEmptyComponent={ No Result Found } /> ) : ( <> )} ); }; export default CountryCodeDropdownPicker; const styles = StyleSheet.create({ row: { flexDirection: "row", alignItems: "center", color: "black", }, container: { width: "100%", color: "black", }, selectedContainer: { padding: 10, flexDirection: "row", minWidth: "20%", alignItems: "center", justifyContent: "space-between", borderWidth: 1, borderColor: "#dddddd", borderRadius: 8, backgroundColor: "white", color: "black", }, valuesContainer: { borderWidth: 1, borderColor: "#dddddd", borderRadius: 8, maxHeight: 235, backgroundColor: "white", marginTop: 8, color: "black", }, countryContainer: { flexDirection: "row", paddingHorizontal: 15, paddingVertical: 13, borderBottomWidth: 1, borderColor: "#dedede", alignItems: "center", color: "black", }, countryFlag: { marginRight: 8, color: "black", }, countryText: { fontWeight: "bold", color: "black", }, inputBoxContainer: { width: "100%", borderWidth: 1, borderColor: "#dddddd", borderRadius: 8, flexDirection: "row", justifyContent: "space-between", alignItems: "center", color: "black", }, icon: { width: 10, height: 10, }, });