import {
FlatList,
Image,
ImageStyle,
Modal,
Pressable,
ReturnKeyTypeOptions,
Text,
TextInput,
TextStyle,
TouchableOpacity,
View,
ViewStyle,
} from "react-native";
import styles from "./index.styles";
import React, { useMemo, useState } from "react";
import { countryCodesData } from "./countrycode";
import ModalCloseButton from "./modalCloseButton";
interface Props {
value: string;
onBlur?: () => void;
placeHolder: string;
countryCode: string;
inputStyle?: TextStyle;
searchStyle?: TextStyle;
listItemStyle?: ViewStyle;
flagImgStyle?: ImageStyle;
containerStyle?: ViewStyle;
downArrowStyle?: ImageStyle;
placeholderTextColor?: string;
isListDialCodeHide?: boolean;
listDialCodeStyle?: TextStyle;
listContainerStyle?: ViewStyle;
countryNameTextStyle?: TextStyle;
countryCodeTextStyle?: TextStyle;
setSelCountry: (val: any) => void;
updatePhoneVal: (val: any) => void;
listItemSeparatorStyle?: ViewStyle;
modalInnerContainerStyle?: ViewStyle;
keyboardReturnKeyType?: ReturnKeyTypeOptions;
}
function PhoneNumberCountryCodeInput(
{
value,
onBlur,
inputStyle,
searchStyle,
placeHolder,
countryCode,
flagImgStyle,
listItemStyle,
setSelCountry,
updatePhoneVal,
containerStyle,
downArrowStyle,
listDialCodeStyle,
listContainerStyle,
placeholderTextColor,
countryNameTextStyle,
isListDialCodeHide = false,
countryCodeTextStyle,
keyboardReturnKeyType = "next",
listItemSeparatorStyle,
modalInnerContainerStyle,
}: Props,
ref: any
) {
const [open, setOpen] = useState(false);
const [search, setSearch] = useState("");
const toggleModal = () => {
setSearch("");
setOpen((val) => !val);
};
const getCountryCodesData = useMemo(() => {
return countryCodesData.filter((item) => {
return item.name.toLowerCase().includes(search.toLowerCase());
});
}, [countryCodesData, search]);
const renderCountryCodeModal = () => {
return (
renderCountryCode(item)}
contentContainerStyle={[styles.listContainer, listContainerStyle]}
/>
);
};
const renderCountryCode = (item: any) => {
return (
{
setSelCountry(item.dial_code);
toggleModal();
}}
>
{!isListDialCodeHide && (
{item.dial_code}
)}
{item.name}
);
};
const rednerRightArrow = () => {
return (
);
};
return (
{countryCode}
{rednerRightArrow()}
{
if (/^[0-9]*$/.test(val)) {
updatePhoneVal(val);
} else if (val.length === 0) {
updatePhoneVal(val);
}
}}
style={[
styles.inputStyle,
{ fontWeight: value?.length ? "500" : "400" },
inputStyle,
]}
/>
{renderCountryCodeModal()}
);
}
export default React.forwardRef(PhoneNumberCountryCodeInput);