A calm two-step password reset: a padlock rocks inside breathing rings above one floating-label email field that shakes with an inline error on a bad address, and the button spins before the content slides over to "Check your inbox". The padlock morphs into an envelope whose tick draws itself, with a masked address, a live resend countdown that turns into a tappable link, and a way back to change the email.

Details
1import { useEffect, useRef, useState, type ComponentRef, type ReactNode, type Ref } from 'react';2import {3 KeyboardAvoidingView,4 Platform,5 Pressable,6 ScrollView,7 StyleSheet,8 Text,9 TextInput,10 View,11 useColorScheme,12 type TextInputProps,13} from 'react-native';14import Animated, {15 Easing,16 Extrapolation,17 FadeIn,18 FadeInDown,19 interpolate,20 interpolateColor,21 useAnimatedProps,22 useAnimatedStyle,23 useSharedValue,24 withDelay,25 withRepeat,26 withSequence,27 withSpring,28 withTiming,29 ZoomIn,30} from 'react-native-reanimated';31import { LinearGradient } from 'expo-linear-gradient';32import { useSafeAreaInsets } from 'react-native-safe-area-context';33import Svg, { Circle, Defs, Path, RadialGradient, Rect, Stop } from 'react-native-svg';34import { ArrowLeft, ArrowRight, ArrowUpRight, Check, ChevronLeft, ChevronRight, LifeBuoy, RotateCw } from 'lucide-react-native';3536// ─── Brand ──────────────────────────────────────────────────────────────────37// The screen's accent. Every accent colour below derives from these, so changing them rebrands the screen.3839const ACCENT = '#1064FF';40const ACCENT_DARK = '#5B97FF'; // the accent on dark backgrounds41const ON_ACCENT = '#FFFFFF'; // text and icons on an accent fill4243/** `hex` at `alpha` opacity, as rgba(). */44function tint(hex: string, alpha: number) {45 const n = parseInt(hex.slice(1), 16);46 return `rgba(${(n >> 16) & 255}, ${(n >> 8) & 255}, ${n & 255}, ${alpha})`;47}4849/** `hex` mixed toward black (amount > 0) or white (amount < 0); amount from -1 to 1. */50function spin(hex: string, deg: number, light = 0, sat = 0) {51 const n = parseInt(hex.slice(1), 16);52 const r = ((n >> 16) & 255) / 255;53 const g = ((n >> 8) & 255) / 255;54 const b = (n & 255) / 255;55 const max = Math.max(r, g, b);56 const min = Math.min(r, g, b);57 const d = max - min;58 const s = Math.min(1, Math.max(0, (d === 0 ? 0 : d / (1 - Math.abs(max + min - 1))) + sat));59 const l = Math.min(1, Math.max(0, (max + min) / 2 + light));60 const h0 = d === 0 ? 0 : max === r ? ((g - b) / d + 6) % 6 : max === g ? (b - r) / d + 2 : (r - g) / d + 4;61 const h = (((h0 * 60 + deg) % 360) + 360) % 360;62 const a = s * Math.min(l, 1 - l);63 const f = (m: number) => {64 const k = (m + h / 30) % 12;65 return Math.round(255 * (l - a * Math.max(-1, Math.min(k - 3, 9 - k, 1)))).toString(16).padStart(2, '0');66 };67 return `#${f(0)}${f(8)}${f(4)}`.toUpperCase();68}6970/** `hex` with its hue turned by `deg` and saturation moved by `sat`, at an exact HSL `lightness` (0 to 1). */71function tone(hex: string, deg: number, lightness: number, sat = 0) {72 const n = parseInt(hex.slice(1), 16);73 const r = (n >> 16) & 255; const g = (n >> 8) & 255; const b = n & 255;74 return spin(hex, deg, lightness - (Math.max(r, g, b) + Math.min(r, g, b)) / 510, sat);75}7677// ─── Sample data ────────────────────────────────────────────────────────────7879// The preview opens with the address already typed, as it would arriving from sign-in.80const ACCOUNT_EMAIL = 'maya.patel@example.com';81const RESEND_SECONDS = 30; // wait before the link can be sent again82const LINK_MINUTES = 30; // how long your backend keeps a reset link alive83const SEND_MS = 1300; // stands in for the network call8485/** maya.patel@example.com becomes m•••@example.com, enough to recognise without showing it in full. */86function maskEmail(email: string) {87 const [name, domain] = email.trim().split('@');88 return `${name.slice(0, 1)}•••@${domain}`;89}90const clock = (s: number) => `${Math.floor(s / 60)}:${String(s % 60).padStart(2, '0')}`;9192// ─── Palette ────────────────────────────────────────────────────────────────9394const SUCCESS = '#16A34A';95const SPRING = { damping: 16, stiffness: 200, mass: 0.7 };96const EMAIL_RE = /^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/;97const TABULAR = { fontVariant: ['tabular-nums' as const] };9899function usePalette() {100 const dark = useColorScheme() === 'dark';101 return {102 dark,103 bg: dark ? '#000000' : '#FAFAFA',104 fg: dark ? '#FAFAFA' : '#0A0A0A',105 muted: dark ? '#8E8E93' : '#71717A',106 faint: dark ? '#5A5A60' : '#A1A1AA',107 field: dark ? '#141416' : '#FFFFFF',108 border: dark ? '#2A2A2E' : '#E4E4E7',109 error: dark ? '#FF6B6B' : '#E5484D',110 link: dark ? ACCENT_DARK : ACCENT,111 ok: dark ? '#34D399' : '#047857',112 off: dark ? '#17191F' : '#E3E8F1',113 offText: dark ? '#626B7C' : '#98A2B6',114 // Illustration115 disc: dark ? tone(ACCENT, 2, 0.143, -0.274) : tone(ACCENT, 2, 0.931),116 ring: dark ? ACCENT_DARK : ACCENT,117 shackle: dark ? tone(ACCENT, 1.5, 0.831) : tone(ACCENT, 3.5, 0.284, -0.248),118 glow: dark ? 0.36 : 0.14,119 ripple: dark ? ACCENT_DARK : SUCCESS,120 };121}122123// ─── Small pieces ───────────────────────────────────────────────────────────124125/** Left, right, settle: the "not yet" gesture. */126function useShake() {127 const x = useSharedValue(0);128 const style = useAnimatedStyle(() => ({ transform: [{ translateX: x.value }] }));129 const shake = () => {130 x.value = withSequence(131 withTiming(-8, { duration: 50 }),132 withTiming(8, { duration: 60 }),133 withTiming(-5, { duration: 60 }),134 withTiming(5, { duration: 60 }),135 withTiming(0, { duration: 50 })136 );137 };138 return { style, shake };139}140141function Tap({ label, onPress, children, to = 0.96 }: { label: string; onPress?: () => void; children: ReactNode; to?: number }) {142 const scale = useSharedValue(1);143 const style = useAnimatedStyle(() => ({ transform: [{ scale: scale.value }] }));144 return (145 <Pressable146 role="button"147 aria-label={label}148 onPress={onPress}149 hitSlop={6}150 onPressIn={() => (scale.value = withSpring(to, SPRING))}151 onPressOut={() => (scale.value = withSpring(1, SPRING))}152 >153 <Animated.View style={style}>{children}</Animated.View>154 </Pressable>155 );156}157158// ─── Illustration: a padlock that becomes a sealed, ticked envelope ─────────159160const AnimatedPath = Animated.createAnimatedComponent(Path);161162const STAGE = 168;163const LOCK = { w: 66, h: 54, r: 17 };164const MAIL = { w: 94, h: 66, r: 15 };165const LOCK_DROP = 13; // the lock body sits low so body plus shackle are centred together166const TICK_LEN = 14;167const GLOW = 360;168const DISC = 136;169170/** A ring that breathes slowly, each one a little out of step with the next. */171function Halo({ size, delay, opacity }: { size: number; delay: number; opacity: number }) {172 const c = usePalette();173 const t = useSharedValue(0);174 useEffect(() => {175 t.value = withDelay(delay, withRepeat(withTiming(1, { duration: 2400, easing: Easing.inOut(Easing.sin) }), -1, true));176 }, [delay, t]);177 const style = useAnimatedStyle(() => ({178 opacity: interpolate(t.value, [0, 1], [opacity, opacity * 0.35]),179 transform: [{ scale: interpolate(t.value, [0, 1], [1, 1.07]) }],180 }));181 const offset = (STAGE - size) / 2;182 return (183 <Animated.View184 style={[styles.halo, { left: offset, top: offset, width: size, height: size, borderRadius: size / 2, borderColor: c.ring }, style]}185 />186 );187}188189function Illustration({ sent, pulse }: { sent: boolean; pulse: number }) {190 const c = usePalette();191 const rock = useSharedValue(-1);192 const open = useSharedValue(0); // the shackle pops up193 const morph = useSharedValue(0); // lock body widens into the envelope194 const badge = useSharedValue(0);195 const tick = useSharedValue(0);196 const ripple = useSharedValue(0);197198 useEffect(() => {199 rock.value = withRepeat(withTiming(1, { duration: 1900, easing: Easing.inOut(Easing.sin) }), -1, true);200 }, [rock]);201202 useEffect(() => {203 if (sent) {204 open.value = withTiming(1, { duration: 200, easing: Easing.out(Easing.back(2.5)) });205 morph.value = withDelay(170, withTiming(1, { duration: 460, easing: Easing.inOut(Easing.cubic) }));206 badge.value = withDelay(540, withTiming(1, { duration: 320, easing: Easing.out(Easing.back(2.2)) }));207 tick.value = withDelay(740, withTiming(1, { duration: 300, easing: Easing.out(Easing.cubic) }));208 ripple.value = 0;209 ripple.value = withDelay(480, withTiming(1, { duration: 900, easing: Easing.out(Easing.cubic) }));210 } else {211 // Back the way it came: tick and badge go first, then the envelope folds back and the shackle clicks shut.212 tick.value = withTiming(0, { duration: 120 });213 badge.value = withTiming(0, { duration: 160 });214 morph.value = withDelay(80, withTiming(0, { duration: 380, easing: Easing.inOut(Easing.cubic) }));215 open.value = withDelay(400, withTiming(0, { duration: 220, easing: Easing.out(Easing.back(2)) }));216 }217 }, [sent, open, morph, badge, tick, ripple]);218219 // A resend replays the confirmation: the badge dips, the tick redraws, a ring goes out.220 useEffect(() => {221 if (!pulse) return;222 badge.value = withSequence(withTiming(0.8, { duration: 110 }), withTiming(1, { duration: 300, easing: Easing.out(Easing.back(3)) }));223 tick.value = 0;224 tick.value = withDelay(140, withTiming(1, { duration: 300, easing: Easing.out(Easing.cubic) }));225 ripple.value = 0;226 ripple.value = withTiming(1, { duration: 900, easing: Easing.out(Easing.cubic) });227 }, [pulse, badge, tick, ripple]);228229 // The lock rocks on its shackle; the envelope only floats.230 const sway = useAnimatedStyle(() => ({231 transform: [{ translateY: rock.value * 2.5 * morph.value }, { rotate: `${rock.value * 4 * (1 - morph.value)}deg` }],232 }));233 const body = useAnimatedStyle(() => ({234 width: interpolate(morph.value, [0, 1], [LOCK.w, MAIL.w]),235 height: interpolate(morph.value, [0, 1], [LOCK.h, MAIL.h]),236 borderRadius: interpolate(morph.value, [0, 1], [LOCK.r, MAIL.r]),237 transform: [{ translateY: interpolate(morph.value, [0, 1], [LOCK_DROP, 0]) }],238 }));239 const face = useAnimatedStyle(() => ({ borderRadius: interpolate(morph.value, [0, 1], [LOCK.r, MAIL.r]) }));240 const shackle = useAnimatedStyle(() => ({241 opacity: interpolate(morph.value, [0.35, 0.75], [1, 0], Extrapolation.CLAMP),242 transform: [{ translateY: -7 * open.value + 40 * morph.value }],243 }));244 const keyhole = useAnimatedStyle(() => ({245 opacity: interpolate(morph.value, [0, 0.4], [1, 0], Extrapolation.CLAMP),246 transform: [{ scale: interpolate(morph.value, [0, 0.4], [1, 0.6], Extrapolation.CLAMP) }],247 }));248 const flap = useAnimatedStyle(() => ({249 opacity: interpolate(morph.value, [0.55, 1], [0, 1], Extrapolation.CLAMP),250 transform: [{ translateY: interpolate(morph.value, [0.55, 1], [-6, 0], Extrapolation.CLAMP) }],251 }));252 const badgeStyle = useAnimatedStyle(() => ({253 opacity: interpolate(badge.value, [0, 0.3], [0, 1], Extrapolation.CLAMP),254 transform: [{ scale: badge.value }],255 }));256 const tickProps = useAnimatedProps(() => ({ strokeDashoffset: TICK_LEN * (1 - tick.value) }));257 const rippleStyle = useAnimatedStyle(() => ({258 opacity: interpolate(ripple.value, [0, 0.15, 1], [0, 0.55, 0]),259 transform: [{ scale: interpolate(ripple.value, [0, 1], [0.8, 1.55]) }],260 }));261262 return (263 <View264 role="img"265 aria-label={sent ? 'An envelope with a tick: the reset link is on its way' : 'A closed padlock'}266 style={styles.stage}267 >268 {/* A wash of the accent behind everything, fading into the page */}269 <View style={styles.glow}>270 <Svg width={GLOW} height={GLOW}>271 <Defs>272 <RadialGradient id="forgot-glow" cx="50%" cy="50%" r="50%">273 <Stop offset="0" stopColor={ACCENT} stopOpacity={c.glow} />274 <Stop offset="1" stopColor={ACCENT} stopOpacity={0} />275 </RadialGradient>276 </Defs>277 <Rect width={GLOW} height={GLOW} fill="url(#forgot-glow)" />278 </Svg>279 </View>280281 <Halo size={204} delay={500} opacity={c.dark ? 0.2 : 0.16} />282 <Halo size={170} delay={0} opacity={c.dark ? 0.38 : 0.32} />283 <Animated.View style={[styles.disc, styles.ripple, { borderColor: c.ripple }, rippleStyle]} />284 <View style={[styles.disc, { backgroundColor: c.disc }]} />285286 <Animated.View style={[StyleSheet.absoluteFill, styles.center, sway]}>287 {/* Shackle: drawn first so its legs disappear into the body */}288 <Animated.View style={[styles.shackle, shackle]}>289 <Svg width={46} height={40}>290 <Path d="M9 40 V21 a14 14 0 0 1 28 0 V40" stroke={c.shackle} strokeWidth={8.5} strokeLinecap="round" fill="none" />291 </Svg>292 </Animated.View>293294 <Animated.View style={[c.dark ? styles.bodyDark : styles.bodyLight, body]}>295 <Animated.View style={[StyleSheet.absoluteFill, styles.face, face]}>296 <LinearGradient colors={[spin(ACCENT, -2.5, 0.147), ACCENT, spin(ACCENT, 1.5, -0.1, -0.091)]} start={{ x: 0.1, y: 0 }} end={{ x: 0.9, y: 1 }} style={StyleSheet.absoluteFill} />297 <Animated.View style={[StyleSheet.absoluteFill, styles.center, keyhole]}>298 <View style={styles.keyholeTop} />299 <View style={styles.keyholeSlot} />300 </Animated.View>301 <Animated.View style={[StyleSheet.absoluteFill, styles.center, flap]}>302 <Svg width={MAIL.w} height={MAIL.h}>303 <Path d="M7 59 L34 38 M87 59 L60 38" stroke={ON_ACCENT} strokeOpacity={0.4} strokeWidth={2.5} strokeLinecap="round" fill="none" />304 <Path d="M6 11 L42 38 Q47 41.5 52 38 L88 11" stroke={ON_ACCENT} strokeOpacity={0.95} strokeWidth={3} strokeLinecap="round" strokeLinejoin="round" fill="none" />305 </Svg>306 </Animated.View>307 </Animated.View>308 </Animated.View>309310 {/* The badge cuts into the envelope's corner with a ring of the disc colour */}311 <Animated.View style={[styles.badge, { borderColor: c.disc }, badgeStyle]}>312 <Svg width={18} height={18} viewBox="0 0 16 16">313 <AnimatedPath314 d="M3.4 8.4 6.6 11.5 12.6 4.9"315 stroke="#FFFFFF"316 strokeWidth={2.2}317 strokeLinecap="round"318 strokeLinejoin="round"319 strokeDasharray={`${TICK_LEN} ${TICK_LEN * 2}`}320 animatedProps={tickProps}321 fill="none"322 />323 </Svg>324 </Animated.View>325 </Animated.View>326 </View>327 );328}329330// ─── A field whose label floats up on focus ─────────────────────────────────331332type FieldProps = {333 label: string;334 value: string;335 onChangeText: (v: string) => void;336 error?: string | null;337 /** Bump to shake the field again while its error is already showing. */338 nudge?: number;339 valid?: boolean;340 inputRef?: Ref<ComponentRef<typeof TextInput>>;341 onFocusChange?: (focused: boolean) => void;342} & Omit<TextInputProps, 'value' | 'onChangeText' | 'onFocus' | 'onBlur'>;343344function Field({ label, value, onChangeText, error, nudge = 0, valid, inputRef, onFocusChange, ...input }: FieldProps) {345 const c = usePalette();346 const [focused, setFocused] = useState(false);347 const lift = useSharedValue(value ? 1 : 0);348 const ring = useSharedValue(0);349 const { style: shakeStyle, shake } = useShake();350351 useEffect(() => {352 lift.value = withTiming(focused || value ? 1 : 0, { duration: 180, easing: Easing.out(Easing.cubic) });353 ring.value = withTiming(focused ? 1 : 0, { duration: 180 });354 }, [focused, value, lift, ring]);355356 useEffect(() => {357 if (error) shake();358 // eslint-disable-next-line react-hooks/exhaustive-deps359 }, [error, nudge]);360361 const labelStyle = useAnimatedStyle(() => ({362 transform: [{ translateY: interpolate(lift.value, [0, 1], [0, -11]) }, { scale: interpolate(lift.value, [0, 1], [1, 0.8]) }],363 }));364 const boxStyle = useAnimatedStyle(() => ({365 borderColor: error ? c.error : interpolateColor(ring.value, [0, 1], [c.border, ACCENT]),366 shadowOpacity: ring.value * 0.18,367 }));368369 const setFocus = (next: boolean) => {370 setFocused(next);371 onFocusChange?.(next);372 };373374 return (375 <Animated.View style={shakeStyle}>376 <Animated.View style={[styles.field, { backgroundColor: c.field }, boxStyle]}>377 <View style={styles.fieldBody}>378 <Animated.Text style={[styles.fieldLabel, { color: error ? c.error : focused ? c.link : c.muted }, labelStyle]}>379 {label}380 </Animated.Text>381 <TextInput382 ref={inputRef}383 {...input}384 value={value}385 onChangeText={onChangeText}386 onFocus={() => setFocus(true)}387 onBlur={() => setFocus(false)}388 aria-label={label}389 aria-invalid={!!error}390 placeholderTextColor={c.faint}391 selectionColor={ACCENT}392 style={[styles.fieldInput, { color: c.fg }, Platform.OS === 'web' ? ({ outlineStyle: 'none' } as object) : null]}393 />394 </View>395 {valid && (396 <Animated.View entering={ZoomIn.duration(220)} style={styles.validTick}>397 <Check size={13} color={ON_ACCENT} strokeWidth={3} />398 </Animated.View>399 )}400 </Animated.View>401 {error ? (402 <Animated.Text entering={FadeInDown.duration(180)} role="alert" style={[styles.fieldError, { color: c.error }]}>403 {error}404 </Animated.Text>405 ) : null}406 </Animated.View>407 );408}409410// ─── Primary button: locked, ready, spinning ────────────────────────────────411412function Spinner() {413 const r = useSharedValue(0);414 useEffect(() => {415 r.value = withRepeat(withTiming(360, { duration: 800, easing: Easing.linear }), -1);416 }, [r]);417 const style = useAnimatedStyle(() => ({ transform: [{ rotate: `${r.value}deg` }] }));418 return <Animated.View style={[styles.spinner, style]} />;419}420421function PrimaryButton({ label, icon, busy = false, ready = true, onPress }: { label: string; icon: ReactNode; busy?: boolean; ready?: boolean; onPress?: () => void }) {422 const c = usePalette();423 const on = useSharedValue(ready ? 1 : 0);424 const scale = useSharedValue(1);425 const first = useRef(true);426427 useEffect(() => {428 on.value = withTiming(ready ? 1 : 0, { duration: 320, easing: Easing.out(Easing.cubic) });429 if (first.current) {430 first.current = false;431 return;432 }433 // A small swell tells the eye the button just woke up.434 if (ready) scale.value = withSequence(withTiming(1.035, { duration: 150, easing: Easing.out(Easing.quad) }), withTiming(1, { duration: 280, easing: Easing.out(Easing.back(2)) }));435 }, [ready, on, scale]);436437 // The highlight on the button's top edge, faded in with the fill.438 const edge = [tint(ON_ACCENT, 0), tint(ON_ACCENT, 0.28)];439 const box = useAnimatedStyle(() => ({440 backgroundColor: interpolateColor(on.value, [0, 1], [c.off, ACCENT]),441 borderTopColor: interpolateColor(on.value, [0, 1], edge),442 shadowOpacity: 0.35 * on.value,443 transform: [{ scale: scale.value }],444 }));445 const text = useAnimatedStyle(() => ({ color: interpolateColor(on.value, [0, 1], [c.offText, ON_ACCENT]) }));446 // The arrow slides out from behind the label as the button unlocks.447 const arrow = useAnimatedStyle(() => ({ width: on.value * 26, opacity: on.value }));448449 return (450 <Pressable451 role="button"452 aria-label={label}453 aria-busy={busy}454 disabled={busy}455 onPress={onPress}456 onPressIn={() => ready && (scale.value = withSpring(0.97, SPRING))}457 onPressOut={() => ready && (scale.value = withSpring(1, SPRING))}458 >459 <Animated.View style={[styles.primary, box]}>460 {busy ? (461 <Spinner />462 ) : (463 <Animated.View entering={FadeIn.duration(150)} style={styles.primaryContent}>464 <Animated.Text style={[styles.primaryLabel, text]}>{label}</Animated.Text>465 <Animated.View style={[styles.primaryArrow, arrow]}>{icon}</Animated.View>466 </Animated.View>467 )}468 </Animated.View>469 </Pressable>470 );471}472473// ─── Resend: a draining ring, then a link, then a short "Sent again" ────────474475const AnimatedCircle = Animated.createAnimatedComponent(Circle);476const DIAL = 18;477const DIAL_R = 7;478const DIAL_LEN = 2 * Math.PI * DIAL_R;479480function Dial({ left }: { left: number }) {481 const c = usePalette();482 // Picks up from wherever the countdown is, so it can mount part way through.483 const t = useSharedValue(left / RESEND_SECONDS);484 useEffect(() => {485 t.value = withTiming(0, { duration: left * 1000, easing: Easing.linear });486 // eslint-disable-next-line react-hooks/exhaustive-deps487 }, []);488 const arc = useAnimatedProps(() => ({ strokeDashoffset: DIAL_LEN * (1 - t.value) }));489 return (490 <Svg width={DIAL} height={DIAL} style={styles.dial}>491 <Circle cx={DIAL / 2} cy={DIAL / 2} r={DIAL_R} stroke={c.border} strokeWidth={2} fill="none" />492 <AnimatedCircle cx={DIAL / 2} cy={DIAL / 2} r={DIAL_R} stroke={c.link} strokeWidth={2} strokeLinecap="round" strokeDasharray={`${DIAL_LEN} ${DIAL_LEN * 2}`} animatedProps={arc} fill="none" />493 </Svg>494 );495}496497function ResendRow({ left, again, onResend }: { left: number; again: boolean; onResend: () => void }) {498 const c = usePalette();499 return (500 <View aria-live="polite" style={styles.resend}>501 {again ? (502 <Animated.View key="again" entering={FadeIn.duration(200)} style={styles.resendRow}>503 <Animated.View entering={ZoomIn.duration(260)} style={styles.resendTick}>504 <Check size={11} color="#FFFFFF" strokeWidth={3.5} />505 </Animated.View>506 <Text style={[styles.resendAction, { color: c.ok }]}>Sent again</Text>507 </Animated.View>508 ) : left > 0 ? (509 <Animated.View key="wait" entering={FadeIn.duration(200)} style={styles.resendRow}>510 <Dial left={left} />511 <Text style={[styles.resendWait, { color: c.muted }]}>512 Resend in <Text style={[styles.strong, { color: c.fg }, TABULAR]}>{clock(left)}</Text>513 </Text>514 </Animated.View>515 ) : (516 <Animated.View key="ready" entering={FadeIn.duration(200)}>517 <Tap label="Resend link" onPress={onResend}>518 <View style={[styles.resendRow, styles.resendButton]}>519 <RotateCw size={15} color={c.link} strokeWidth={2.4} />520 <Text style={[styles.resendAction, { color: c.link }]}>Resend link</Text>521 </View>522 </Tap>523 </Animated.View>524 )}525 </View>526 );527}528529// ─── Screen ─────────────────────────────────────────────────────────────────530531type Step = 'request' | 'sent';532533export default function ForgotPasswordScreen() {534 const c = usePalette();535 const insets = useSafeAreaInsets();536 const [email, setEmail] = useState(ACCOUNT_EMAIL);537 const [error, setError] = useState<string | null>(null);538 const [nudge, setNudge] = useState(0);539 const [busy, setBusy] = useState(false);540 // `art` flips at once so the illustration starts moving; `step` follows once the old content has faded out.541 const [art, setArt] = useState<Step>('request');542 const [step, setStep] = useState<Step>('request');543 const [left, setLeft] = useState(RESEND_SECONDS);544 const [again, setAgain] = useState(false);545 const [pulse, setPulse] = useState(0);546 const inputRef = useRef<ComponentRef<typeof TextInput>>(null);547 const timers = useRef<ReturnType<typeof setTimeout>[]>([]);548 const fade = useSharedValue(1);549 const shift = useSharedValue(0);550 const swap = useAnimatedStyle(() => ({ opacity: fade.value, transform: [{ translateX: shift.value }] }));551552 const later = (fn: () => void, ms: number) => timers.current.push(setTimeout(fn, ms));553 useEffect(() => () => timers.current.forEach(clearTimeout), []);554555 // One tick a second while the sent step is showing.556 useEffect(() => {557 if (step !== 'sent' || left <= 0) return;558 const id = setTimeout(() => setLeft((l) => l - 1), 1000);559 return () => clearTimeout(id);560 }, [step, left]);561562 const emailValid = EMAIL_RE.test(email.trim());563564 /** Old content slides out one way, new content arrives from the other. */565 const go = (next: Step) => {566 const dir = next === 'sent' ? 1 : -1;567 setArt(next);568 fade.value = withTiming(0, { duration: 160 });569 shift.value = withTiming(-18 * dir, { duration: 160, easing: Easing.in(Easing.quad) });570 later(() => {571 setStep(next);572 setBusy(false);573 setAgain(false);574 setLeft(RESEND_SECONDS);575 shift.value = 18 * dir;576 shift.value = withTiming(0, { duration: 360, easing: Easing.out(Easing.cubic) });577 fade.value = withTiming(1, { duration: 300 });578 if (next === 'request') later(() => inputRef.current?.focus(), 380);579 }, 170);580 };581582 const submit = () => {583 if (!emailValid) {584 setError(email.trim() ? 'Enter a valid email, like name@example.com.' : 'Enter your email address.');585 setNudge((n) => n + 1);586 return;587 }588 setError(null);589 setBusy(true);590 inputRef.current?.blur();591 // Replace with your password-reset call, then move on whether or not the address has an account.592 later(() => go('sent'), SEND_MS);593 };594595 const resend = () => {596 // Replace with the same call as above.597 setLeft(RESEND_SECONDS);598 setAgain(true);599 setPulse((p) => p + 1);600 later(() => setAgain(false), 2200);601 };602603 const enter = (i: number) => FadeInDown.delay(40 + i * 60).duration(420);604605 return (606 <KeyboardAvoidingView behavior={Platform.OS === 'ios' ? 'padding' : undefined} style={[styles.screen, { backgroundColor: c.bg }]}>607 <ScrollView608 keyboardShouldPersistTaps="handled"609 showsVerticalScrollIndicator={false}610 contentContainerStyle={[styles.content, { paddingTop: insets.top + 8, paddingBottom: insets.bottom + 8 }]}611 >612 {/* The illustration comes first in the tree so its glow sits under the back button */}613 <Animated.View entering={FadeIn.duration(420)} style={styles.art}>614 <Illustration sent={art === 'sent'} pulse={pulse} />615 </Animated.View>616617 <Animated.View entering={enter(0)} style={[styles.backSlot, { top: insets.top + 8 }]}>618 <Tap label="Back" to={0.9}>619 <View style={[styles.back, { backgroundColor: c.field, borderColor: c.border }]}>620 <ChevronLeft size={22} color={c.fg} strokeWidth={2.2} style={styles.backIcon} />621 </View>622 </Tap>623 </Animated.View>624625 {/* Everything under the illustration swaps in place between the two steps */}626 <Animated.View entering={enter(1)} style={styles.body}>627 <Animated.View style={swap}>628 {step === 'request' ? (629 <View>630 <Text role="heading" style={[styles.title, { color: c.fg }]}>631 Forgot your password?632 </Text>633 <Text style={[styles.subtitle, { color: c.muted }]}>Enter your email and we'll send a reset link.</Text>634635 <View style={styles.fieldSlot}>636 <Field637 inputRef={inputRef}638 label="Email"639 value={email}640 onChangeText={(v) => {641 setEmail(v);642 if (error) setError(null);643 }}644 // Checked when the field is left, never while the address is still being typed.645 onFocusChange={(focused) => !focused && !busy && setError(email.trim() && !emailValid ? 'Enter a valid email, like name@example.com.' : null)}646 valid={emailValid}647 error={error}648 nudge={nudge}649 keyboardType="email-address"650 autoCapitalize="none"651 autoCorrect={false}652 autoComplete="email"653 textContentType="emailAddress"654 returnKeyType="send"655 onSubmitEditing={submit}656 />657 </View>658659 <View style={styles.sendSlot}>660 <PrimaryButton label="Send reset link" icon={<ArrowRight size={18} color={ON_ACCENT} strokeWidth={2.4} />} busy={busy} ready={emailValid} onPress={submit} />661 </View>662 </View>663 ) : (664 <View>665 <Text role="heading" style={[styles.title, { color: c.fg }]}>666 Check your inbox667 </Text>668 <Text style={[styles.subtitle, { color: c.muted }]}>669 We sent a link to <Text style={[styles.strong, { color: c.fg }]}>{maskEmail(email)}</Text>670 {`\nIt works for the next ${LINK_MINUTES} minutes.`}671 </Text>672673 <View style={styles.openSlot}>674 {/* Placeholder: open the mail client with Linking.openURL, or your own deep link */}675 <PrimaryButton label="Open mail app" icon={<ArrowUpRight size={18} color={ON_ACCENT} strokeWidth={2.4} />} />676 </View>677678 <View style={styles.resendSlot}>679 <ResendRow left={left} again={again} onResend={resend} />680 </View>681 <Pressable role="button" aria-label="Use a different email" onPress={() => go('request')} hitSlop={4} style={styles.differentEmail}>682 <Text style={[styles.resendAction, { color: c.fg }]}>Use a different email</Text>683 </Pressable>684 </View>685 )}686 </Animated.View>687 </Animated.View>688689 <View style={styles.spacer} />690691 {/* Quiet exits, the same in both steps */}692 <Animated.View entering={enter(2)}>693 <Tap label="Contact support" to={0.98}>694 <View style={[styles.support, { borderColor: c.border, backgroundColor: c.field }]}>695 <View style={[styles.supportIcon, { backgroundColor: c.disc }]}>696 <LifeBuoy size={17} color={c.link} strokeWidth={2.2} />697 </View>698 <Text style={[styles.supportHint, { color: c.muted }]}>Still stuck?</Text>699 <Text style={[styles.resendAction, { color: c.fg }]}>Contact support</Text>700 <ChevronRight size={16} color={c.faint} strokeWidth={2.4} style={styles.supportChevron} />701 </View>702 </Tap>703 <Pressable role="link" aria-label="Back to sign in" hitSlop={4} style={styles.signIn}>704 <ArrowLeft size={16} color={c.fg} strokeWidth={2.4} />705 <Text style={[styles.signInLabel, { color: c.fg }]}>Back to sign in</Text>706 </Pressable>707 </Animated.View>708 </ScrollView>709 </KeyboardAvoidingView>710 );711}712713// ─── Styles ─────────────────────────────────────────────────────────────────714715const styles = StyleSheet.create({716 screen: { flex: 1 },717 content: { flexGrow: 1, paddingHorizontal: 24 },718 art: { marginTop: 44 + 38 },719 backSlot: { position: 'absolute', left: 24, height: 44, justifyContent: 'center' },720 back: { width: 40, height: 40, borderRadius: 20, borderWidth: 1, alignItems: 'center', justifyContent: 'center' },721 backIcon: { marginLeft: -2 },722 body: { marginTop: 36 },723 title: { fontSize: 28, lineHeight: 34, fontWeight: '700', letterSpacing: -0.7, textAlign: 'center' },724 subtitle: { marginTop: 8, fontSize: 15.5, lineHeight: 22, textAlign: 'center' },725 strong: { fontWeight: '600' },726 fieldSlot: { marginTop: 28 },727 sendSlot: { marginTop: 14 },728 openSlot: { marginTop: 26 },729 resendSlot: { marginTop: 12 },730 differentEmail: { alignSelf: 'center', height: 40, paddingHorizontal: 10, justifyContent: 'center' },731 spacer: { flex: 1, minHeight: 24 },732733 // Illustration734 stage: { width: STAGE, height: STAGE, alignSelf: 'center' },735 glow: { position: 'absolute', left: (STAGE - GLOW) / 2, top: (STAGE - GLOW) / 2, pointerEvents: 'none' },736 halo: { position: 'absolute', borderWidth: 1.5 },737 disc: { position: 'absolute', left: (STAGE - DISC) / 2, top: (STAGE - DISC) / 2, width: DISC, height: DISC, borderRadius: DISC / 2 },738 ripple: { borderWidth: 2 },739 center: { alignItems: 'center', justifyContent: 'center' },740 shackle: { position: 'absolute', left: (STAGE - 46) / 2, top: 41 },741 // The lock body's shadow is stronger on the dark page; one entry per theme keeps the shadow in one object.742 bodyLight: { backgroundColor: ACCENT, shadowColor: ACCENT, shadowOpacity: 0.38, shadowRadius: 18, shadowOffset: { width: 0, height: 10 } },743 bodyDark: { backgroundColor: ACCENT, shadowColor: ACCENT, shadowOpacity: 0.55, shadowRadius: 18, shadowOffset: { width: 0, height: 10 } },744 face: { overflow: 'hidden', borderTopWidth: 1, borderTopColor: tint(ON_ACCENT, 0.4) },745 keyholeTop: { width: 13, height: 13, borderRadius: 6.5, backgroundColor: ON_ACCENT },746 keyholeSlot: { width: 5, height: 11, borderRadius: 2.5, backgroundColor: ON_ACCENT, marginTop: -3 },747 badge: { position: 'absolute', left: 107, top: 93, width: 38, height: 38, borderRadius: 19, backgroundColor: SUCCESS, borderWidth: 3.5, alignItems: 'center', justifyContent: 'center' },748749 // Field750 field: { height: 58, borderRadius: 16, borderWidth: 1.5, paddingHorizontal: 16, flexDirection: 'row', alignItems: 'center', shadowColor: ACCENT, shadowRadius: 10, shadowOffset: { width: 0, height: 0 } },751 fieldBody: { flex: 1, height: '100%', justifyContent: 'center' },752 fieldLabel: { position: 'absolute', left: 0, fontSize: 16, transformOrigin: 'left center', pointerEvents: 'none' },753 fieldInput: { paddingTop: 18, height: '100%', fontSize: 16 },754 validTick: { width: 22, height: 22, borderRadius: 11, backgroundColor: ACCENT, alignItems: 'center', justifyContent: 'center' },755 fieldError: { fontSize: 13, marginTop: 6, marginLeft: 4 },756757 // Primary button758 spinner: { width: 20, height: 20, borderRadius: 10, borderWidth: 2.5, borderColor: tint(ON_ACCENT, 0.35), borderTopColor: ON_ACCENT },759 primary: { height: 56, borderRadius: 16, alignItems: 'center', justifyContent: 'center', flexDirection: 'row', shadowColor: ACCENT, shadowRadius: 16, shadowOffset: { width: 0, height: 8 }, borderTopWidth: 1 },760 primaryContent: { flexDirection: 'row', alignItems: 'center' },761 primaryLabel: { fontSize: 16, fontWeight: '600' },762 primaryArrow: { height: 18, overflow: 'hidden', alignItems: 'flex-end' },763764 // Resend765 dial: { transform: [{ rotate: '-90deg' }] },766 resend: { height: 40, alignItems: 'center', justifyContent: 'center' },767 resendRow: { flexDirection: 'row', alignItems: 'center', gap: 8 },768 resendButton: { height: 40, paddingHorizontal: 10 },769 resendTick: { width: 18, height: 18, borderRadius: 9, backgroundColor: SUCCESS, alignItems: 'center', justifyContent: 'center' },770 resendAction: { fontSize: 15, fontWeight: '600' },771 resendWait: { fontSize: 15 },772773 // Quiet exits774 support: { height: 54, borderRadius: 16, borderWidth: 1, flexDirection: 'row', alignItems: 'center', paddingLeft: 12, paddingRight: 14, gap: 12 },775 supportIcon: { width: 32, height: 32, borderRadius: 16, alignItems: 'center', justifyContent: 'center' },776 supportHint: { flex: 1, fontSize: 15 },777 supportChevron: { marginLeft: -6 },778 signIn: { alignSelf: 'center', marginTop: 6, height: 44, paddingHorizontal: 10, flexDirection: 'row', alignItems: 'center', gap: 7 },779 signInLabel: { fontSize: 15, fontWeight: '700' },780});