import React from 'react'; import { StyleProp, StyleSheet, Text, TextInputProps, TextInput as RNTextInput, TextStyle, View, ViewStyle } from 'react-native'; import Touchable from 'react-native-platform-touchable'; import sharedStyles from '../../views/Styles'; import TextInput from './index'; import { themes } from '../../lib/constants'; import { CustomIcon, TIconsName } from '../CustomIcon'; import ActivityIndicator from '../ActivityIndicator'; import { TSupportedThemes } from '../../theme'; 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, padding: 14, borderWidth: StyleSheet.hairlineWidth, borderRadius: 2 }, inputIconLeft: { paddingLeft: 45 }, inputIconRight: { paddingRight: 45 }, wrap: { position: 'relative' }, iconContainer: { position: 'absolute', top: 14 }, iconLeft: { left: 15 }, iconRight: { right: 15 } }); export interface IRCTextInputProps extends TextInputProps { label?: string; error?: any; loading?: boolean; containerStyle?: StyleProp; inputStyle?: StyleProp; inputRef?: React.Ref; testID?: string; iconLeft?: TIconsName; iconRight?: TIconsName; left?: JSX.Element; onIconRightPress?(): void; theme: TSupportedThemes; } interface IRCTextInputState { showPassword: boolean; } export default class FormTextInput extends React.PureComponent { static defaultProps = { error: {}, theme: 'light' }; state = { showPassword: false }; get iconLeft() { const { testID, iconLeft, theme } = this.props; return iconLeft ? ( ) : null; } get iconRight() { const { iconRight, onIconRightPress, theme } = this.props; return iconRight ? ( ) : null; } get iconPassword() { const { showPassword } = this.state; const { testID, theme } = this.props; return ( ); } get loading() { const { theme } = this.props; return ; } tooglePassword = () => { this.setState(prevState => ({ showPassword: !prevState.showPassword })); }; render() { const { showPassword } = this.state; const { label, left, error, loading, secureTextEntry, containerStyle, inputRef, iconLeft, iconRight, inputStyle, testID, placeholder, theme, ...inputProps } = this.props; const { dangerColor } = themes[theme]; return ( {label ? ( {label} ) : null} {iconLeft ? this.iconLeft : null} {iconRight ? this.iconRight : null} {secureTextEntry ? this.iconPassword : null} {loading ? this.loading : null} {left} {error && error.reason ? {error.reason} : null} ); } }