import { ComponentType, FC, useEffect, useMemo, useRef, useState } from "react" // eslint-disable-next-line no-restricted-imports import { TextInput, TextStyle, ViewStyle } from "react-native" import { Button } from "@/components/Button" import { PressableIcon } from "@/components/Icon" import { Screen } from "@/components/Screen" import { Text } from "@/components/Text" import { TextField, type TextFieldAccessoryProps } from "@/components/TextField" import { useAuth } from "@/context/AuthContext" import type { AppStackScreenProps } from "@/navigators/navigationTypes" import type { ThemedStyle } from "@/theme/types" import { useAppTheme } from "@/theme/context" interface LoginScreenProps extends AppStackScreenProps<"Login"> {} export const LoginScreen: FC = () => { const authPasswordInput = useRef(null) const [authPassword, setAuthPassword] = useState("") const [isAuthPasswordHidden, setIsAuthPasswordHidden] = useState(true) const [isSubmitted, setIsSubmitted] = useState(false) const [attemptsCount, setAttemptsCount] = useState(0) const { authEmail, setAuthEmail, setAuthToken, validationError } = useAuth() const { themed, theme: { colors }, } = useAppTheme() useEffect(() => { // Here is where you could fetch credentials from keychain or storage // and pre-fill the form fields. setAuthEmail("ignite@infinite.red") setAuthPassword("ign1teIsAwes0m3") }, [setAuthEmail]) const error = isSubmitted ? validationError : "" function login() { setIsSubmitted(true) setAttemptsCount(attemptsCount + 1) if (validationError) return // Make a request to your server to get an authentication token. // If successful, reset the fields and set the token. setIsSubmitted(false) setAuthPassword("") setAuthEmail("") // We'll mock this with a fake token. setAuthToken(String(Date.now())) } const PasswordRightAccessory: ComponentType = useMemo( () => function PasswordRightAccessory(props: TextFieldAccessoryProps) { return ( setIsAuthPasswordHidden(!isAuthPasswordHidden)} /> ) }, [isAuthPasswordHidden, colors.palette.neutral800], ) return ( {attemptsCount > 2 && ( )} authPasswordInput.current?.focus()} />