Commit 3483f1bc authored by Lorenzo Trujillo Rojas's avatar Lorenzo Trujillo Rojas
Browse files

Refactorización del text input para hacerlo más reutilizable

parent bb44e6e9
Loading
Loading
Loading
Loading
+6 −9
Original line number Diff line number Diff line
import { useEffect, useRef } from "react";
import { TextInput, Text, StyleSheet, View, Animated, TouchableOpacity } from "react-native";
import { TextInput, Text, StyleSheet, View, Animated, TouchableOpacity, TextInputProps } from "react-native";
import { LIGTHT_THEME } from "../../constants/theme";

interface TextInputProps {
interface CustomTextInputProps {
  isPassword?: boolean;
  label: string;
  onChangeText: (text: string) => void;
  value: string;
  onBlur?: () => void;
  errors?: string;
  type?: any;
  editable?: boolean;
  textInputProps?: TextInputProps;
}

export const CustomTextInput = (props: TextInputProps) => {
  const { isPassword, label, type, onBlur, errors, value, editable,...rest } = props;
export const CustomTextInput = ({ textInputProps, label, value, errors, onBlur, editable, isPassword }: CustomTextInputProps) => {
  const labelFocusAnimation = useRef(new Animated.Value(value.length > 0 ? 1 : 0)).current;
  const inputRef = useRef<TextInput>(null);

@@ -27,7 +25,7 @@ export const CustomTextInput = (props: TextInputProps) => {
  };

  const handleBlur = () => {
    if (!props.value || props.value === "") {
    if (!value || value === "") {
      Animated.timing(labelFocusAnimation, {
        toValue: 0,
        duration: 200,
@@ -52,11 +50,10 @@ export const CustomTextInput = (props: TextInputProps) => {
          {label}
        </Animated.Text>
        <TextInput
          {...rest}
          {...textInputProps}
          editable={editable}
          ref={inputRef}
          value={value}
          textContentType={type}
          onFocus={handleFocus}
          onBlur={handleBlur}
          style={styles.input}