import InputPhone from '@sesamsolutions/phone-input' import React, { FC, useCallback, useEffect, useRef, useState } from 'react' import { Platform, View } from 'react-native' import Input from '../input/Input' import s from './/styles' import { IOnChangePhoneNumberPayload, IPhoneInputProps } from './types' const PhoneInput: FC = ({ phoneNumber, onChangePhoneNumber, onBlur, styles, error, texts, country = 'US', }) => { const [localValue, setLocalValue] = useState('') const isUserInitiatedRef = useRef(false) useEffect(() => { if (!isUserInitiatedRef.current) { setLocalValue(phoneNumber) } isUserInitiatedRef.current = false }, [phoneNumber]) const handleOnChangeInputPhone = useCallback( (payload: IOnChangePhoneNumberPayload) => { isUserInitiatedRef.current = true setLocalValue(payload.input) onChangePhoneNumber(payload) }, [onChangePhoneNumber] ) return ( { isUserInitiatedRef.current = true setLocalValue(text) }} onBlur={onBlur} label={texts?.label || 'Phone number'} keyboardType="phone-pad" value={localValue} styles={{ container: s.phoneInputContainer, ...styles?.input, color: error ? styles?.input?.errorColor : styles?.input?.baseColor, }} labelOffset={{ x1: -32 }} renderLeftAccessory={() => ( )} error={error} /> ) } export default PhoneInput