import React, { useEffect } from 'react'; import { View, Animated, StyleSheet, StyleProp, ViewStyle } from 'react-native'; import TextFieldBase, { TextFieldBaseProps } from './TextFieldBase'; import { Text } from 'native-base'; import { Warning2 } from 'iconsax-react-native'; interface TextFormFieldProps extends TextFieldBaseProps { style?: StyleProp; error: string | null; } const ERROR_HEIGHT = 20; const ERROR_PADDING_TOP = 8; const TextFormField: React.FC = ({ error, style, ...textFieldBaseProps }) => { const fadeAnim = React.useRef(new Animated.Value(0)).current; const heightAnim = React.useRef(new Animated.Value(0)).current; const paddingTopAnim = React.useRef(new Animated.Value(0)).current; useEffect(() => { Animated.parallel([ Animated.timing(fadeAnim, { toValue: error ? 1 : 0, duration: 150, useNativeDriver: false, }), Animated.timing(heightAnim, { toValue: error ? ERROR_HEIGHT : 0, duration: 250, useNativeDriver: false, }), Animated.timing(paddingTopAnim, { toValue: error ? ERROR_PADDING_TOP : 0, duration: 250, useNativeDriver: false, }), ]).start(); }, [error]); return ( {error} ); }; const styles = StyleSheet.create({ wrapper: { width: '100%', }, errorContainer: { flexDirection: 'row', alignItems: 'center', paddingLeft: 12, }, errorText: { color: '#f7253d', fontSize: 12, marginLeft: 8, }, }); export default TextFormField;