Sign in

A sign-in screen with motion: soft light blooms drift behind the brand mark, labels float up as fields focus, the email ticks when valid, a wrong entry shakes the form with an inline error, and the button spins, then confirms. Apple, Google and passkey options.

authloginformsocial loginanimationreanimated
Paste into Claude Code Cursor Codex Lovable RapidNative
Live preview · follows the site themeOpen full screen

Details

File
components/patterns/sign-in.tsx
Lines
513
Stack
React Native, StyleSheet
Packages
lucide-react-native, react-native-reanimated, react-native-safe-area-context, react-native-svg, react-native-worklets
Platforms
iOS, Android, Web

Using gluestack-ui?

Optional. The screen is plain React Native; these components can stand in for its primitives.

components/patterns/sign-in.tsx
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 FadeIn,
17 FadeInDown,
18 interpolate,
19 interpolateColor,
20 useAnimatedStyle,
21 useSharedValue,
22 withRepeat,
23 withSequence,
24 withSpring,
25 withTiming,
26 ZoomIn,
27} from 'react-native-reanimated';
28import { useSafeAreaInsets } from 'react-native-safe-area-context';
29import Svg, { Defs, Path, RadialGradient, Rect, Stop } from 'react-native-svg';
30import { ArrowRight, Check, Eye, EyeOff, KeyRound } from 'lucide-react-native';
31
32// ─── Brand ──────────────────────────────────────────────────────────────────
33// The screen's accent. Every accent colour below derives from these, so changing them rebrands the screen.
34
35const ACCENT = '#1064FF';
36const ON_ACCENT = '#FFFFFF'; // text and icons on an accent fill
37
38/** `hex` at `alpha` opacity, as rgba(). */
39function tint(hex: string, alpha: number) {
40 const n = parseInt(hex.slice(1), 16);
41 return `rgba(${(n >> 16) & 255}, ${(n >> 8) & 255}, ${n & 255}, ${alpha})`;
42}
43
44/** `hex` with its hue turned by `deg` degrees and its HSL lightness and saturation moved by `light` / `sat` (-1 to 1). */
45function spin(hex: string, deg: number, light = 0, sat = 0) {
46 const n = parseInt(hex.slice(1), 16);
47 const r = ((n >> 16) & 255) / 255;
48 const g = ((n >> 8) & 255) / 255;
49 const b = (n & 255) / 255;
50 const max = Math.max(r, g, b);
51 const min = Math.min(r, g, b);
52 const d = max - min;
53 const s = Math.min(1, Math.max(0, (d === 0 ? 0 : d / (1 - Math.abs(max + min - 1))) + sat));
54 const l = Math.min(1, Math.max(0, (max + min) / 2 + light));
55 const h0 = d === 0 ? 0 : max === r ? ((g - b) / d + 6) % 6 : max === g ? (b - r) / d + 2 : (r - g) / d + 4;
56 const h = (((h0 * 60 + deg) % 360) + 360) % 360;
57 const a = s * Math.min(l, 1 - l);
58 const f = (m: number) => {
59 const k = (m + h / 30) % 12;
60 return Math.round(255 * (l - a * Math.max(-1, Math.min(k - 3, 9 - k, 1)))).toString(16).padStart(2, '0');
61 };
62 return `#${f(0)}${f(8)}${f(4)}`.toUpperCase();
63}
64
65// ─── Palette ────────────────────────────────────────────────────────────────
66
67const SUCCESS = '#16A34A';
68const SPRING = { damping: 16, stiffness: 200, mass: 0.7 };
69const EMAIL_RE = /^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/;
70
71function usePalette() {
72 const dark = useColorScheme() === 'dark';
73 return {
74 dark,
75 bg: dark ? '#000000' : '#FAFAFA',
76 fg: dark ? '#FAFAFA' : '#0A0A0A',
77 sub: dark ? '#A3A3A3' : '#737373',
78 muted: dark ? '#8E8E93' : '#71717A',
79 faint: dark ? '#5A5A60' : '#A1A1AA',
80 field: dark ? '#141416' : '#FFFFFF',
81 border: dark ? '#2A2A2E' : '#E4E4E7',
82 error: dark ? '#FF6B6B' : '#E5484D',
83 };
84}
85
86// ─── Background: two soft blooms drifting behind the brand mark ─────────────
87
88function Bloom({ color, size, from, to, duration }: { color: string; size: number; from: [number, number]; to: [number, number]; duration: number }) {
89 const t = useSharedValue(0);
90 useEffect(() => {
91 t.value = withRepeat(withTiming(1, { duration, easing: Easing.inOut(Easing.sin) }), -1, true);
92 }, [duration, t]);
93 const style = useAnimatedStyle(() => ({
94 transform: [
95 { translateX: interpolate(t.value, [0, 1], [from[0], to[0]]) },
96 { translateY: interpolate(t.value, [0, 1], [from[1], to[1]]) },
97 { scale: interpolate(t.value, [0, 1], [1, 1.15]) },
98 ],
99 }));
100 const id = `bloom-${color.slice(1)}`;
101 return (
102 <Animated.View pointerEvents="none" style={[styles.bloom, { width: size, height: size }, style]}>
103 <Svg width={size} height={size}>
104 <Defs>
105 <RadialGradient id={id} cx="50%" cy="50%" r="50%">
106 <Stop offset="0" stopColor={color} stopOpacity={0.55} />
107 <Stop offset="1" stopColor={color} stopOpacity={0} />
108 </RadialGradient>
109 </Defs>
110 <Rect width={size} height={size} fill={`url(#${id})`} />
111 </Svg>
112 </Animated.View>
113 );
114}
115
116// ─── Brand logos ────────────────────────────────────────────────────────────
117
118function AppleLogo({ color }: { color: string }) {
119 return (
120 <Svg width={17} height={17} viewBox="0 0 24 24">
121 <Path
122 fill={color}
123 d="M16.37 12.73c-.03-2.67 2.18-3.95 2.28-4.02-1.24-1.82-3.18-2.07-3.87-2.1-1.65-.17-3.21.97-4.05.97-.84 0-2.12-.95-3.49-.92-1.8.03-3.45 1.04-4.38 2.65-1.87 3.24-.48 8.03 1.34 10.66.89 1.29 1.95 2.73 3.34 2.68 1.34-.05 1.85-.87 3.47-.87 1.62 0 2.08.87 3.49.84 1.44-.02 2.35-1.31 3.23-2.6 1.02-1.49 1.44-2.94 1.46-3.01-.03-.01-2.8-1.08-2.82-4.28ZM13.71 4.89c.74-.9 1.24-2.14 1.1-3.39-1.07.04-2.36.71-3.12 1.6-.69.79-1.29 2.06-1.13 3.28 1.19.09 2.41-.6 3.15-1.49Z"
124 />
125 </Svg>
126 );
127}
128
129function GoogleLogo() {
130 return (
131 <Svg width={17} height={17} viewBox="0 0 24 24">
132 <Path fill="#4285F4" d="M23.52 12.27c0-.85-.08-1.67-.22-2.45H12v4.64h6.46a5.52 5.52 0 0 1-2.4 3.62v3h3.88c2.27-2.09 3.58-5.17 3.58-8.81Z" />
133 <Path fill="#34A853" d="M12 24c3.24 0 5.96-1.07 7.94-2.91l-3.88-3.01c-1.08.72-2.45 1.15-4.06 1.15-3.12 0-5.77-2.11-6.71-4.95H1.28v3.11A12 12 0 0 0 12 24Z" />
134 <Path fill="#FBBC05" d="M5.29 14.28A7.2 7.2 0 0 1 4.91 12c0-.79.14-1.56.38-2.28V6.61H1.28a12 12 0 0 0 0 10.78l4.01-3.11Z" />
135 <Path fill="#EA4335" d="M12 4.77c1.76 0 3.34.61 4.59 1.8l3.44-3.44C17.95 1.19 15.24 0 12 0A12 12 0 0 0 1.28 6.61l4.01 3.11C6.23 6.88 8.88 4.77 12 4.77Z" />
136 </Svg>
137 );
138}
139
140// ─── A field whose label floats up on focus ─────────────────────────────────
141
142type FieldProps = {
143 label: string;
144 value: string;
145 onChangeText: (v: string) => void;
146 error?: string | null;
147 valid?: boolean;
148 trailing?: ReactNode;
149 inputRef?: Ref<ComponentRef<typeof TextInput>>;
150} & Omit<TextInputProps, 'value' | 'onChangeText'>;
151
152function Field({ label, value, onChangeText, error, valid, trailing, inputRef, ...input }: FieldProps) {
153 const c = usePalette();
154 const [focused, setFocused] = useState(false);
155 const lift = useSharedValue(value ? 1 : 0);
156 const ring = useSharedValue(0);
157
158 useEffect(() => {
159 lift.value = withTiming(focused || value ? 1 : 0, { duration: 180, easing: Easing.out(Easing.cubic) });
160 ring.value = withTiming(focused ? 1 : 0, { duration: 180 });
161 }, [focused, value, lift, ring]);
162
163 const labelStyle = useAnimatedStyle(() => ({
164 transform: [{ translateY: interpolate(lift.value, [0, 1], [0, -11]) }, { scale: interpolate(lift.value, [0, 1], [1, 0.8]) }],
165 }));
166 const boxStyle = useAnimatedStyle(() => ({
167 borderColor: error ? c.error : interpolateColor(ring.value, [0, 1], [c.border, ACCENT]),
168 shadowOpacity: ring.value * 0.18,
169 }));
170
171 return (
172 <View>
173 <Animated.View style={[styles.field, { backgroundColor: c.field }, boxStyle]}>
174 <View style={styles.fieldBody}>
175 <Animated.Text pointerEvents="none" style={[styles.fieldLabel, { color: focused ? ACCENT : c.muted }, labelStyle]}>
176 {label}
177 </Animated.Text>
178 <TextInput
179 ref={inputRef}
180 {...input}
181 value={value}
182 onChangeText={onChangeText}
183 onFocus={() => setFocused(true)}
184 onBlur={() => setFocused(false)}
185 aria-label={label}
186 placeholderTextColor={c.faint}
187 selectionColor={ACCENT}
188 style={[styles.fieldInput, { color: c.fg }, Platform.OS === 'web' ? ({ outlineStyle: 'none' } as object) : null]}
189 />
190 </View>
191 {valid && !trailing && (
192 <Animated.View entering={ZoomIn.springify().damping(14)} style={styles.validTick}>
193 <Check size={13} color={ON_ACCENT} strokeWidth={3} />
194 </Animated.View>
195 )}
196 {trailing}
197 </Animated.View>
198 {error ? (
199 <Animated.Text entering={FadeInDown.duration(180)} style={[styles.fieldError, { color: c.error }]}>
200 {error}
201 </Animated.Text>
202 ) : null}
203 </View>
204 );
205}
206
207// ─── Primary button: press, spin, tick ──────────────────────────────────────
208
209type Status = 'idle' | 'loading' | 'done';
210
211function Spinner() {
212 const r = useSharedValue(0);
213 useEffect(() => {
214 r.value = withRepeat(withTiming(360, { duration: 800, easing: Easing.linear }), -1);
215 }, [r]);
216 const style = useAnimatedStyle(() => ({ transform: [{ rotate: `${r.value}deg` }] }));
217 return <Animated.View style={[styles.spinner, style]} />;
218}
219
220function SubmitButton({ status, onPress }: { status: Status; onPress: () => void }) {
221 const scale = useSharedValue(1);
222 const style = useAnimatedStyle(() => ({ transform: [{ scale: scale.value }] }));
223 return (
224 <Pressable
225 role="button"
226 aria-label="Sign in"
227 aria-busy={status === 'loading'}
228 disabled={status !== 'idle'}
229 onPress={onPress}
230 onPressIn={() => (scale.value = withSpring(0.97, SPRING))}
231 onPressOut={() => (scale.value = withSpring(1, SPRING))}
232 >
233 <Animated.View style={[styles.submit, status === 'done' ? styles.submitDone : styles.submitIdle, style]}>
234 {status === 'idle' && (
235 <Animated.View entering={FadeIn.duration(150)} style={styles.submitContent}>
236 <Text style={[styles.submitLabel, { color: ON_ACCENT }]}>Sign in</Text>
237 <ArrowRight size={18} color={ON_ACCENT} strokeWidth={2.4} />
238 </Animated.View>
239 )}
240 {status === 'loading' && <Spinner />}
241 {status === 'done' && (
242 <Animated.View entering={ZoomIn.springify().damping(12)} style={styles.submitContent}>
243 <Check size={20} color="#fff" strokeWidth={3} />
244 <Text style={styles.submitLabel}>Signed in</Text>
245 </Animated.View>
246 )}
247 </Animated.View>
248 </Pressable>
249 );
250}
251
252function SocialButton({ label, children, onPress }: { label: string; children: ReactNode; onPress?: () => void }) {
253 const c = usePalette();
254 const scale = useSharedValue(1);
255 const style = useAnimatedStyle(() => ({ transform: [{ scale: scale.value }] }));
256 return (
257 <Pressable
258 role="button"
259 aria-label={label}
260 onPress={onPress}
261 onPressIn={() => (scale.value = withSpring(0.96, SPRING))}
262 onPressOut={() => (scale.value = withSpring(1, SPRING))}
263 style={styles.socialSlot}
264 >
265 <Animated.View style={[styles.social, { borderColor: c.border, backgroundColor: c.field }, style]}>
266 {children}
267 </Animated.View>
268 </Pressable>
269 );
270}
271
272// ─── Screen ─────────────────────────────────────────────────────────────────
273
274export default function SignInScreen() {
275 const c = usePalette();
276 const insets = useSafeAreaInsets();
277 const [email, setEmail] = useState('');
278 const [password, setPassword] = useState('');
279 const [show, setShow] = useState(false);
280 const [error, setError] = useState<{ field: 'email' | 'password'; message: string } | null>(null);
281 const [status, setStatus] = useState<Status>('idle');
282 const passwordRef = useRef<ComponentRef<typeof TextInput>>(null);
283 const shake = useSharedValue(0);
284 const shakeStyle = useAnimatedStyle(() => ({ transform: [{ translateX: shake.value }] }));
285 const emailValid = EMAIL_RE.test(email.trim());
286
287 const submit = () => {
288 if (!emailValid || password.length < 6) {
289 setError(!emailValid ? { field: 'email', message: 'Enter a valid email address.' } : { field: 'password', message: 'Your password has at least 6 characters.' });
290 shake.value = withSequence(
291 withTiming(-9, { duration: 50 }),
292 withTiming(9, { duration: 60 }),
293 withTiming(-6, { duration: 60 }),
294 withTiming(6, { duration: 60 }),
295 withTiming(0, { duration: 50 })
296 );
297 return;
298 }
299 setError(null);
300 setStatus('loading');
301 // Replace with your auth call.
302 setTimeout(() => setStatus('done'), 1300);
303 };
304
305 const enter = (i: number) => FadeInDown.delay(80 + i * 60).duration(500).easing(Easing.out(Easing.cubic));
306
307 return (
308 <KeyboardAvoidingView behavior={Platform.OS === 'ios' ? 'padding' : undefined} style={[styles.screen, { backgroundColor: c.bg }]}>
309 {/* Blooms run edge to edge, under the status bar */}
310 <View pointerEvents="none" style={styles.blooms}>
311 <Bloom color={ACCENT} size={360} from={[-120, -140]} to={[-60, -90]} duration={7000} />
312 <Bloom color={c.dark ? spin(ACCENT, -27.5, -0.167, -0.087) : spin(ACCENT, -31, 0.002, -0.143)} size={320} from={[170, -120]} to={[120, -60]} duration={9000} />
313 </View>
314
315 <ScrollView
316 keyboardShouldPersistTaps="handled"
317 contentContainerStyle={[styles.content, { paddingTop: insets.top + 56, paddingBottom: insets.bottom + 24 }]}
318 >
319 {/* Brand */}
320 <Animated.View entering={enter(0)} style={styles.brandRow}>
321 <View style={styles.brand}>
322 <Svg width={26} height={26} viewBox="0 0 24 24">
323 <Path fill={ON_ACCENT} d="M4 4h7v7H4zM13 4h7v7h-4l-3-3zM4 13h3l4 4v3H4zM13 13h7v7h-7z" />
324 </Svg>
325 </View>
326 </Animated.View>
327
328 <Animated.View entering={enter(1)} style={styles.heading}>
329 <Text style={[styles.title, { color: c.fg }]}>Welcome back</Text>
330 <Text style={[styles.subtitle, { color: c.sub }]}>
331 Sign in to pick up right where you left off.
332 </Text>
333 </Animated.View>
334
335 {/* Form */}
336 <Animated.View entering={enter(2)} style={[styles.form, shakeStyle]}>
337 <Field
338 label="Email"
339 value={email}
340 onChangeText={(v) => {
341 setEmail(v);
342 if (error) setError(null);
343 }}
344 valid={emailValid}
345 error={error?.field === 'email' ? error.message : null}
346 keyboardType="email-address"
347 autoCapitalize="none"
348 autoComplete="email"
349 textContentType="emailAddress"
350 returnKeyType="next"
351 onSubmitEditing={() => passwordRef.current?.focus()}
352 />
353 <Field
354 inputRef={passwordRef}
355 label="Password"
356 value={password}
357 onChangeText={(v) => {
358 setPassword(v);
359 if (error) setError(null);
360 }}
361 error={error?.field === 'password' ? error.message : null}
362 secureTextEntry={!show}
363 autoComplete="password"
364 textContentType="password"
365 returnKeyType="go"
366 onSubmitEditing={submit}
367 trailing={
368 <Pressable role="button" aria-label={show ? 'Hide password' : 'Show password'} onPress={() => setShow((s) => !s)} hitSlop={10}>
369 <Animated.View key={show ? 'on' : 'off'} entering={ZoomIn.duration(160)}>
370 {show ? <EyeOff size={20} color={c.muted} /> : <Eye size={20} color={c.muted} />}
371 </Animated.View>
372 </Pressable>
373 }
374 />
375 <Pressable role="link" aria-label="Forgot password" style={styles.forgot}>
376 <Text style={styles.forgotLabel}>Forgot password?</Text>
377 </Pressable>
378 </Animated.View>
379
380 <Animated.View entering={enter(3)} style={styles.submitSlot}>
381 <SubmitButton status={status} onPress={submit} />
382 </Animated.View>
383
384 {/* Alternatives */}
385 <Animated.View entering={enter(4)} style={styles.dividerRow}>
386 <View style={[styles.rule, { backgroundColor: c.border }]} />
387 <Text style={[styles.dividerLabel, { color: c.muted }]}>or continue with</Text>
388 <View style={[styles.rule, { backgroundColor: c.border }]} />
389 </Animated.View>
390
391 <Animated.View entering={enter(5)} style={styles.socialRow}>
392 <SocialButton label="Continue with Apple">
393 <AppleLogo color={c.fg} />
394 <Text style={[styles.altLabel, { color: c.fg }]}>Apple</Text>
395 </SocialButton>
396 <SocialButton label="Continue with Google">
397 <GoogleLogo />
398 <Text style={[styles.altLabel, { color: c.fg }]}>Google</Text>
399 </SocialButton>
400 </Animated.View>
401
402 <Animated.View entering={enter(6)}>
403 <Pressable
404 role="button"
405 aria-label="Sign in with a passkey"
406 style={styles.passkey}
407 >
408 <KeyRound size={17} color={c.fg} />
409 <Text style={[styles.altLabel, { color: c.fg }]}>Use a passkey</Text>
410 </Pressable>
411 </Animated.View>
412
413 <View style={styles.spacer} />
414
415 <Animated.View entering={enter(7)} style={styles.footer}>
416 <Text style={[styles.footerText, { color: c.muted }]}>New here?</Text>
417 <Pressable role="link" aria-label="Create an account">
418 <Text style={[styles.footerLink, { color: c.fg }]}>Create an account</Text>
419 </Pressable>
420 </Animated.View>
421 </ScrollView>
422 </KeyboardAvoidingView>
423 );
424}
425
426// ─── Styles ─────────────────────────────────────────────────────────────────
427
428const styles = StyleSheet.create({
429 screen: { flex: 1 },
430 blooms: { position: 'absolute', top: 0, left: 0, right: 0, height: 420, overflow: 'hidden' },
431 bloom: { position: 'absolute' },
432 content: { flexGrow: 1, paddingHorizontal: 24 },
433
434 brandRow: { alignItems: 'flex-start' },
435 brand: {
436 width: 56,
437 height: 56,
438 borderRadius: 18,
439 backgroundColor: ACCENT,
440 alignItems: 'center',
441 justifyContent: 'center',
442 shadowColor: ACCENT,
443 shadowOpacity: 0.45,
444 shadowRadius: 20,
445 shadowOffset: { width: 0, height: 10 },
446 borderTopWidth: 1,
447 borderTopColor: tint(ON_ACCENT, 0.35),
448 },
449 heading: { marginTop: 28 },
450 title: { fontSize: 34, fontWeight: '700', letterSpacing: -1 },
451 subtitle: { marginTop: 8, fontSize: 16, lineHeight: 23 },
452
453 form: { marginTop: 32, gap: 14 },
454 field: {
455 height: 60,
456 borderRadius: 16,
457 borderWidth: 1.5,
458 paddingHorizontal: 16,
459 flexDirection: 'row',
460 alignItems: 'center',
461 shadowColor: ACCENT,
462 shadowRadius: 10,
463 shadowOffset: { width: 0, height: 0 },
464 },
465 fieldBody: { flex: 1, height: '100%', justifyContent: 'center' },
466 fieldLabel: { position: 'absolute', left: 0, fontSize: 16, transformOrigin: 'left center' },
467 fieldInput: { paddingTop: 18, height: '100%', fontSize: 16 },
468 fieldError: { fontSize: 13, marginTop: 6, marginLeft: 4 },
469 validTick: { width: 22, height: 22, borderRadius: 11, backgroundColor: ACCENT, alignItems: 'center', justifyContent: 'center' },
470 forgot: { alignSelf: 'flex-end', paddingVertical: 2 },
471 forgotLabel: { color: ACCENT, fontSize: 14, fontWeight: '600' },
472
473 submitSlot: { marginTop: 22 },
474 submit: {
475 height: 58,
476 borderRadius: 16,
477 alignItems: 'center',
478 justifyContent: 'center',
479 flexDirection: 'row',
480 gap: 8,
481 borderTopWidth: 1,
482 borderTopColor: tint(ON_ACCENT, 0.28),
483 },
484 // A shadow's props stay together in one style object: React Native Web builds the shadow per object.
485 submitIdle: { backgroundColor: ACCENT, shadowColor: ACCENT, shadowOpacity: 0.35, shadowRadius: 16, shadowOffset: { width: 0, height: 8 } },
486 submitDone: { backgroundColor: SUCCESS, shadowColor: SUCCESS, shadowOpacity: 0.35, shadowRadius: 16, shadowOffset: { width: 0, height: 8 } },
487 submitContent: { flexDirection: 'row', alignItems: 'center', gap: 8 },
488 submitLabel: { color: '#fff', fontSize: 16, fontWeight: '600' },
489 spinner: { width: 20, height: 20, borderRadius: 10, borderWidth: 2.5, borderColor: tint(ON_ACCENT, 0.35), borderTopColor: ON_ACCENT },
490
491 dividerRow: { marginTop: 28, flexDirection: 'row', alignItems: 'center', gap: 12 },
492 rule: { flex: 1, height: 1 },
493 dividerLabel: { fontSize: 13 },
494 socialRow: { marginTop: 20, flexDirection: 'row', gap: 12 },
495 socialSlot: { flex: 1 },
496 social: {
497 height: 54,
498 borderRadius: 16,
499 borderWidth: 1.5,
500 flexDirection: 'row',
501 alignItems: 'center',
502 justifyContent: 'center',
503 gap: 9,
504 },
505 altLabel: { fontSize: 15, fontWeight: '600' },
506 passkey: { marginTop: 12, height: 50, borderRadius: 16, flexDirection: 'row', alignItems: 'center', justifyContent: 'center', gap: 8 },
507
508 spacer: { flex: 1, minHeight: 24 },
509 footer: { flexDirection: 'row', justifyContent: 'center', gap: 5 },
510 footerText: { fontSize: 15 },
511 footerLink: { fontSize: 15, fontWeight: '700' },
512});

More screens like this.

All Authentication