import React, { forwardRef, useState } from 'react'; import { TextInput, TextInputProps, View, TouchableOpacity } from 'react-native'; import { useTheme } from '~/features/theme/ThemeProvider'; import { Icon } from './Icon'; import colors from 'tailwindcss/colors'; interface InputProps extends Omit { value: string; onChangeText: (text: string) => void; placeholder?: string; secureTextEntry?: boolean; multiline?: boolean; numberOfLines?: number; textArea?: boolean; // Neue Eigenschaft für größere Texteingabefelder minHeight?: number; // Optionale benutzerdefinierte Mindesthöhe showPasswordToggle?: boolean; // Neue Eigenschaft für Passwort-Toggle textContentType?: TextInputProps['textContentType']; // iOS autofill support autoComplete?: TextInputProps['autoComplete']; // Android autofill support } // Keine StyleSheet-Styles mehr, wir verwenden NativeWind und direkte Style-Objekte const Input = forwardRef((props, ref) => { const { value, onChangeText, placeholder = '', secureTextEntry = false, showPasswordToggle = false, style, ...restProps } = props; const [isPasswordVisible, setIsPasswordVisible] = useState(false); const { isDark, themeVariant } = useTheme(); // Holen der Theme-Farben basierend auf der aktuellen Variante const themeColors = (colors as any).theme?.extend?.colors as Record; // Textfarbe basierend auf dem Theme const textColor = isDark ? themeColors?.dark?.[themeVariant]?.text || '#FFFFFF' : themeColors?.[themeVariant]?.text || '#000000'; // Rahmenfarbe basierend auf dem Theme const borderColor = isDark ? themeColors?.dark?.[themeVariant]?.border || '#424242' : themeColors?.[themeVariant]?.border || '#e6e6e6'; // Hintergrundfarbe basierend auf dem Theme const bgColor = isDark ? themeColors?.dark?.[themeVariant]?.contentBackground || '#1E1E1E' : themeColors?.[themeVariant]?.contentBackground || '#FFFFFF'; // Platzhalterfarbe const placeholderColor = isDark ? 'rgba(255, 255, 255, 0.5)' : 'rgba(0, 0, 0, 0.5)'; // Extrahiere multiline und textArea aus den Props const { multiline = false, textArea = false, numberOfLines = 5 } = props; // Berechne die Mindesthöhe basierend auf den Props const calculatedMinHeight = props.minHeight || (textArea ? 150 : multiline ? 100 : undefined); // Bestimme ob das Passwort verborgen werden soll const shouldHidePassword = secureTextEntry && !isPasswordVisible; // Basis-Styles für alle Inputs const baseStyles = { height: multiline || textArea ? undefined : 48, minHeight: calculatedMinHeight, borderRadius: 12, paddingHorizontal: 16, paddingRight: secureTextEntry && showPasswordToggle ? 50 : 16, paddingVertical: multiline || textArea ? 12 : undefined, fontSize: 16, lineHeight: multiline || textArea ? 24 : undefined, // Erhöhter Zeilenabstand für mehrzeilige Eingaben width: '100%' as const, // TypeScript-Typ-Annotation borderWidth: 1, borderColor, color: textColor, backgroundColor: bgColor, textAlignVertical: multiline || textArea ? ('top' as const) : undefined, }; if (secureTextEntry && showPasswordToggle) { return ( setIsPasswordVisible(!isPasswordVisible)} activeOpacity={0.7} > ); } return ( ); }); Input.displayName = 'Input'; export default Input;