import { BottomSheetTextInput } from '@gorhom/bottom-sheet'; import React, { useState } from 'react'; import { StyleProp, StyleSheet, Text, TextInput as RNTextInput, TextInputProps, TextStyle, View, ViewStyle } from 'react-native'; import Touchable from 'react-native-platform-touchable'; import { useTheme } from '../../theme'; import sharedStyles from '../../views/Styles'; import ActivityIndicator from '../ActivityIndicator'; import { CustomIcon, TIconsName } from '../CustomIcon'; import { TextInput } from './TextInput'; const styles = StyleSheet.create({ error: { ...sharedStyles.textAlignCenter, paddingTop: 5 }, inputContainer: { marginBottom: 10 }, label: { marginBottom: 10, fontSize: 14, ...sharedStyles.textSemibold }, input: { ...sharedStyles.textRegular, height: 48, fontSize: 16, paddingHorizontal: 16, paddingVertical: 10, borderWidth: 2, borderRadius: 2 }, inputIconLeft: { paddingLeft: 45 }, inputIconRight: { paddingRight: 45 }, wrap: { position: 'relative', justifyContent: 'center' }, iconContainer: { position: 'absolute' }, iconLeft: { left: 12 }, iconRight: { right: 12 } }); export interface IRCTextInputProps extends TextInputProps { label?: string; error?: any; loading?: boolean; containerStyle?: StyleProp; inputStyle?: StyleProp; inputRef?: React.Ref; iconLeft?: TIconsName; iconRight?: TIconsName; left?: JSX.Element; bottomSheet?: boolean; onClearInput?: () => void; } export const FormTextInput = ({ label, error, loading, containerStyle, inputStyle, inputRef, iconLeft, iconRight, onClearInput, value, left, testID, secureTextEntry, bottomSheet, placeholder, ...inputProps }: IRCTextInputProps): React.ReactElement => { const { colors } = useTheme(); const [showPassword, setShowPassword] = useState(false); const showClearInput = onClearInput && value && value.length > 0; const Input = bottomSheet ? BottomSheetTextInput : TextInput; return ( {label ? ( {label} ) : null} {iconLeft ? ( ) : null} {showClearInput ? ( ) : null} {iconRight && !showClearInput ? ( ) : null} {secureTextEntry ? ( setShowPassword(!showPassword)} style={[styles.iconContainer, styles.iconRight]}> ) : null} {loading ? ( ) : null} {left} {error && error.reason ? {error.reason} : null} ); };