import { Ionicons } from "@expo/vector-icons"; import { useEffect, useState } from "react"; import { Modal, Pressable, StyleSheet, Text, TextInput, View, } from "react-native"; import { LogoMark } from "@/components/Logo"; import { Button } from "@/components/ui/Button"; import { fonts, spacing } from "@/constants/theme"; import { useAppLock } from "@/contexts/AppLockContext"; import { useAppTheme } from "@/contexts/ThemeContext"; export function AppLockOverlay() { const { colors } = useAppTheme(); const { enabled, isLocked, biometricEnabled, biometricAvailable, biometricLabel, unlockWithPin, unlockWithBiometric, } = useAppLock(); const [pin, setPin] = useState(""); const [error, setError] = useState(""); useEffect(() => { if (!isLocked) { setPin(""); setError(""); } }, [isLocked]); useEffect(() => { if (!enabled || !isLocked || !biometricEnabled || !biometricAvailable) { return; } void unlockWithBiometric().then((success) => { if (!success) return; setPin(""); setError(""); }); }, [enabled, isLocked, biometricEnabled, biometricAvailable, unlockWithBiometric]); if (!enabled || !isLocked) { return null; } async function submitPin() { const success = await unlockWithPin(pin); if (success) { setPin(""); setError(""); return; } setError("Incorrect PIN"); setPin(""); } async function tryBiometric() { const success = await unlockWithBiometric(); if (!success) { setError(`Could not unlock with ${biometricLabel}`); } } return ( beenvoice is locked Enter your PIN to continue { setError(""); setPin(value.replace(/\D/g, "").slice(0, 6)); }} keyboardType="number-pad" secureTextEntry maxLength={6} style={[ styles.pinInput, { color: colors.foreground, borderColor: colors.border, backgroundColor: colors.card, }, ]} placeholder="PIN" placeholderTextColor={colors.mutedForeground} onSubmitEditing={() => void submitPin()} /> {error ? {error} : null}