import { useRef, useState } from "react"; import { Platform, NativeSyntheticEvent, TextInputSubmitEditingEventData, } from "react-native"; import { TextInput, TextInputProps } from "react-native-paper"; interface PasswordInputProps { label: string; value: string; onChangeText: (text: string) => void; onBlur?: () => void; disabled?: boolean; style?: any; onSubmitEditing?: ( e?: NativeSyntheticEvent ) => void; returnKeyType?: any; submitBehavior?: TextInputProps["submitBehavior"]; } export const PasswordInput = ({ label, value, onChangeText, onBlur, disabled = false, style = {}, onSubmitEditing, returnKeyType, submitBehavior, }: PasswordInputProps) => { const [secureTextEntry, setSecureTextEntry] = useState(true); const submitGuardRef = useRef(false); const triggerSubmitOnce = () => { if (submitGuardRef.current) return; submitGuardRef.current = true; try { onSubmitEditing?.(); } finally { // release guard on next tick to allow future submissions setTimeout(() => { submitGuardRef.current = false; }, 0); } }; return ( triggerSubmitOnce()} returnKeyType={returnKeyType} submitBehavior={submitBehavior ?? "submit"} onKeyPress={(e) => { if (Platform.OS === "web" && e?.nativeEvent?.key === "Enter") { triggerSubmitOnce(); } }} left={} right={ setSecureTextEntry(!secureTextEntry)} /> } theme={{ colors: { primary: "#6750a4" } }} disabled={disabled} placeholderTextColor="#d9d9d9" /> ); };