import { StyleConstants } from '@utils/styles/constants' import { useTheme } from '@utils/styles/ThemeManager' import React, { ForwardedRef, forwardRef } from 'react' import { Platform, TextInput, TextInputProps, View } from 'react-native' import Animated, { useAnimatedStyle, withTiming } from 'react-native-reanimated' import { EmojisState } from './Emojis/Context' import CustomText from './Text' export type Props = { title?: string multiline?: boolean invalid?: boolean } & Pick, 'value'> & Pick, 'isFocused' | 'selection'> & Omit< TextInputProps, | 'style' | 'onChangeText' | 'onSelectionChange' | 'keyboardAppearance' | 'textAlignVertical' | 'multiline' | 'selection' | 'value' > const ComponentInput = forwardRef( ( { title, multiline = false, invalid = false, value: [value, setValue], selection, isFocused, ...props }: Props, ref: ForwardedRef ) => { const { colors, mode } = useTheme() const animateTitle = useAnimatedStyle(() => { if (value) { return { fontSize: withTiming(StyleConstants.Font.Size.S), paddingHorizontal: withTiming(StyleConstants.Spacing.XS), left: withTiming(StyleConstants.Spacing.S), top: withTiming(-(StyleConstants.Font.Size.S / 2) - 2), backgroundColor: colors.backgroundDefault } } else { return { fontSize: withTiming(StyleConstants.Font.Size.M), paddingHorizontal: withTiming(0), left: withTiming(StyleConstants.Spacing.S), top: withTiming(StyleConstants.Spacing.S + 1), backgroundColor: withTiming(colors.backgroundDefaultTransparent) } } }, [mode, value]) return ( (isFocused.current = true), onBlur: () => (isFocused.current = false) })} {...(selection !== undefined && { onSelectionChange: ({ nativeEvent }) => selection[1](nativeEvent.selection) })} {...(multiline && { multiline, numberOfLines: Platform.OS === 'android' ? 5 : undefined })} textAlignVertical='top' {...props} /> {title ? ( {title} ) : null} {props?.maxLength && value?.length ? ( {value?.length} / {props.maxLength} ) : null} ) } ) export default ComponentInput