Sign up

A one-screen sign-up with motion: labels float as fields focus, a four-segment strength meter fills and shifts from red to green while its one-word verdict cross-fades, each password rule pops from a dot to a tick, the terms checkbox draws its check, and the button wakes up, spins, then confirms. Inline email validation with a shake, plus Apple and Google options.

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

Details

File
components/patterns/sign-up.tsx
Lines
829
Stack
React Native, StyleSheet
Packages
expo-linear-gradient, 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-up.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 useWindowDimensions,
13 type TextInputProps,
14} from 'react-native';
15import Animated, {
16 Easing,
17 Extrapolation,
18 FadeIn,
19 FadeInDown,
20 interpolate,
21 interpolateColor,
22 useAnimatedStyle,
23 useSharedValue,
24 withDelay,
25 withRepeat,
26 withSequence,
27 withSpring,
28 withTiming,
29 ZoomIn,
30 type SharedValue,
31} from 'react-native-reanimated';
32import { LinearGradient } from 'expo-linear-gradient';
33import { useSafeAreaInsets } from 'react-native-safe-area-context';
34import Svg, { Circle, Path } from 'react-native-svg';
35import { ArrowRight, Check, ChevronLeft, Eye, EyeOff } from 'lucide-react-native';
36
37// ─── Brand ──────────────────────────────────────────────────────────────────
38// The screen's accent. Every accent colour below derives from these, so changing them rebrands the screen.
39
40const ACCENT = '#1064FF';
41const ACCENT_DARK = '#5B97FF'; // the accent on dark backgrounds
42const ON_ACCENT = '#FFFFFF'; // text and icons on an accent fill
43
44/** `hex` at `alpha` opacity, as rgba(). */
45function tint(hex: string, alpha: number) {
46 const n = parseInt(hex.slice(1), 16);
47 return `rgba(${(n >> 16) & 255}, ${(n >> 8) & 255}, ${n & 255}, ${alpha})`;
48}
49
50/** `hex` mixed toward black (amount > 0) or white (amount < 0); amount from -1 to 1. */
51function shade(hex: string, amount: number) {
52 const n = parseInt(hex.slice(1), 16);
53 const target = amount < 0 ? 255 : 0;
54 const p = Math.abs(amount);
55 const c = (v: number) => Math.round(v + (target - v) * p).toString(16).padStart(2, '0');
56 return `#${c((n >> 16) & 255)}${c((n >> 8) & 255)}${c(n & 255)}`.toUpperCase();
57}
58
59// ─── Sample data ────────────────────────────────────────────────────────────
60
61// The preview opens part way through: name and email filled in, a password one rule short of strong.
62const PREFILL = { name: 'Maya Patel', email: 'maya.patel@example.com', password: 'Sunset2026', agreed: true };
63
64// Keep these in step with the password policy your backend enforces.
65const RULES: { key: string; label: string; test: (p: string) => boolean }[] = [
66 { key: 'length', label: '8+ characters', test: (p) => p.length >= 8 },
67 { key: 'number', label: 'A number', test: (p) => /\d/.test(p) },
68 { key: 'symbol', label: 'A symbol', test: (p) => /[^A-Za-z0-9]/.test(p) },
69 { key: 'case', label: 'Upper and lower case', test: (p) => /[a-z]/.test(p) && /[A-Z]/.test(p) },
70];
71
72// One level per meter segment. `ink` is the label colour on a light background.
73const LEVELS = [
74 { label: 'Weak', bar: '#EF4444', ink: '#DC2626' },
75 { label: 'Fair', bar: '#F59E0B', ink: '#B45309' },
76 { label: 'Good', bar: '#84CC16', ink: '#4D7C0F' },
77 { label: 'Strong', bar: '#10B981', ink: '#047857' },
78];
79const BARS = LEVELS.map((l) => l.bar);
80const STRONG_ENOUGH = 3; // rules met before the button unlocks
81
82function strengthOf(password: string) {
83 const met = RULES.map((r) => r.test(password));
84 const score = met.filter(Boolean).length;
85 // Anything typed fills at least the first segment.
86 return { met, score, level: password ? Math.max(1, score) : 0 };
87}
88
89// ─── Palette ────────────────────────────────────────────────────────────────
90
91const SUCCESS = '#16A34A';
92const SPRING = { damping: 16, stiffness: 200, mass: 0.7 };
93const EMAIL_RE = /^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/;
94
95function usePalette() {
96 const dark = useColorScheme() === 'dark';
97 return {
98 dark,
99 bg: dark ? '#000000' : '#FAFAFA',
100 fg: dark ? '#FAFAFA' : '#0A0A0A',
101 muted: dark ? '#8E8E93' : '#71717A',
102 faint: dark ? '#5A5A60' : '#A1A1AA',
103 field: dark ? '#141416' : '#FFFFFF',
104 border: dark ? '#2A2A2E' : '#E4E4E7',
105 outline: dark ? '#55555D' : '#C4C4CC',
106 track: dark ? '#26262A' : '#E4E4E7',
107 error: dark ? '#FF6B6B' : '#E5484D',
108 link: dark ? ACCENT_DARK : ACCENT,
109 ok: dark ? '#34D399' : '#10B981',
110 off: dark ? '#17191F' : '#E3E8F1',
111 offText: dark ? '#626B7C' : '#98A2B6',
112 onOk: dark ? '#04130D' : '#FFFFFF',
113 ring: dark ? ACCENT_DARK : ACCENT,
114 ringOpacity: dark ? 0.22 : 0.16,
115 band: dark ? ([shade(ACCENT, 0.65), shade(ACCENT, 0.84), '#000000'] as const) : ([shade(ACCENT, -0.83), shade(ACCENT, -0.91), '#FAFAFA'] as const),
116 veil: dark ? (['rgba(0,0,0,0)', '#000000'] as const) : (['rgba(250,250,250,0)', '#FAFAFA'] as const),
117 };
118}
119
120// ─── Background: a soft band of the accent, with rings spreading from the brand mark ───
121
122const BAND = 250;
123
124function HeaderBand({ width, top }: { width: number; top: number }) {
125 const c = usePalette();
126 const height = top + BAND;
127 const cx = width - 42;
128 const cy = top + 30;
129 return (
130 <View style={[styles.band, { height }]}>
131 <LinearGradient colors={c.band} locations={[0, 0.5, 1]} style={styles.bandFill} />
132 <View style={styles.rings}>
133 <Svg width={width} height={height}>
134 {[52, 96, 146, 202, 264].map((r, i) => (
135 <Circle key={r} cx={cx} cy={cy} r={r} fill="none" stroke={c.ring} strokeWidth={1} strokeOpacity={c.ringOpacity - i * 0.03} />
136 ))}
137 </Svg>
138 </View>
139 {/* The rings dissolve into the page before the band ends */}
140 <LinearGradient colors={c.veil} style={styles.veil} />
141 </View>
142 );
143}
144
145// ─── Brand logos ────────────────────────────────────────────────────────────
146
147function AppleLogo({ color }: { color: string }) {
148 return (
149 <Svg width={17} height={17} viewBox="0 0 24 24">
150 <Path
151 fill={color}
152 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"
153 />
154 </Svg>
155 );
156}
157
158function GoogleLogo() {
159 return (
160 <Svg width={17} height={17} viewBox="0 0 24 24">
161 <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" />
162 <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" />
163 <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" />
164 <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" />
165 </Svg>
166 );
167}
168
169// ─── Small pieces ───────────────────────────────────────────────────────────
170
171/** Left, right, settle: the "not yet" gesture shared by fields and the terms row. */
172function useShake() {
173 const x = useSharedValue(0);
174 const style = useAnimatedStyle(() => ({ transform: [{ translateX: x.value }] }));
175 const shake = () => {
176 x.value = withSequence(
177 withTiming(-8, { duration: 50 }),
178 withTiming(8, { duration: 60 }),
179 withTiming(-5, { duration: 60 }),
180 withTiming(5, { duration: 60 }),
181 withTiming(0, { duration: 50 })
182 );
183 };
184 return { style, shake };
185}
186
187function Tap({ label, onPress, children, to = 0.96, flex }: { label: string; onPress?: () => void; children: ReactNode; to?: number; flex?: boolean }) {
188 const scale = useSharedValue(1);
189 const style = useAnimatedStyle(() => ({ transform: [{ scale: scale.value }] }));
190 return (
191 <Pressable
192 role="button"
193 aria-label={label}
194 onPress={onPress}
195 hitSlop={6}
196 onPressIn={() => (scale.value = withSpring(to, SPRING))}
197 onPressOut={() => (scale.value = withSpring(1, SPRING))}
198 style={flex ? styles.fill : undefined}
199 >
200 <Animated.View style={style}>{children}</Animated.View>
201 </Pressable>
202 );
203}
204
205// ─── A field whose label floats up on focus ─────────────────────────────────
206
207type FieldProps = {
208 label: string;
209 value: string;
210 onChangeText: (v: string) => void;
211 error?: string | null;
212 /** Bump to shake the field again while its error is already showing. */
213 nudge?: number;
214 valid?: boolean;
215 trailing?: ReactNode;
216 inputRef?: Ref<ComponentRef<typeof TextInput>>;
217 onFocusChange?: (focused: boolean) => void;
218} & Omit<TextInputProps, 'value' | 'onChangeText' | 'onFocus' | 'onBlur'>;
219
220function Field({ label, value, onChangeText, error, nudge = 0, valid, trailing, inputRef, onFocusChange, ...input }: FieldProps) {
221 const c = usePalette();
222 const [focused, setFocused] = useState(false);
223 const lift = useSharedValue(value ? 1 : 0);
224 const ring = useSharedValue(0);
225 const { style: shakeStyle, shake } = useShake();
226
227 useEffect(() => {
228 lift.value = withTiming(focused || value ? 1 : 0, { duration: 180, easing: Easing.out(Easing.cubic) });
229 ring.value = withTiming(focused ? 1 : 0, { duration: 180 });
230 }, [focused, value, lift, ring]);
231
232 useEffect(() => {
233 if (error) shake();
234 // eslint-disable-next-line react-hooks/exhaustive-deps
235 }, [error, nudge]);
236
237 const labelStyle = useAnimatedStyle(() => ({
238 transform: [{ translateY: interpolate(lift.value, [0, 1], [0, -11]) }, { scale: interpolate(lift.value, [0, 1], [1, 0.8]) }],
239 }));
240 const boxStyle = useAnimatedStyle(() => ({
241 borderColor: error ? c.error : interpolateColor(ring.value, [0, 1], [c.border, ACCENT]),
242 shadowOpacity: ring.value * 0.18,
243 }));
244
245 const setFocus = (next: boolean) => {
246 setFocused(next);
247 onFocusChange?.(next);
248 };
249
250 return (
251 <Animated.View style={shakeStyle}>
252 <Animated.View style={[styles.field, { backgroundColor: c.field }, boxStyle]}>
253 <View style={styles.fieldBody}>
254 <Animated.Text style={[styles.fieldLabel, { color: error ? c.error : focused ? c.link : c.muted }, labelStyle]}>
255 {label}
256 </Animated.Text>
257 <TextInput
258 ref={inputRef}
259 {...input}
260 value={value}
261 onChangeText={onChangeText}
262 onFocus={() => setFocus(true)}
263 onBlur={() => setFocus(false)}
264 aria-label={label}
265 aria-invalid={!!error}
266 placeholderTextColor={c.faint}
267 selectionColor={ACCENT}
268 style={[styles.fieldInput, { color: c.fg }, Platform.OS === 'web' ? ({ outlineStyle: 'none' } as object) : null]}
269 />
270 </View>
271 {valid && !trailing && (
272 <Animated.View entering={ZoomIn.duration(220)} style={styles.validTick}>
273 <Check size={13} color={ON_ACCENT} strokeWidth={3} />
274 </Animated.View>
275 )}
276 {trailing}
277 </Animated.View>
278 {error ? (
279 <Animated.Text entering={FadeInDown.duration(180)} role="alert" style={[styles.fieldError, { color: c.error }]}>
280 {error}
281 </Animated.Text>
282 ) : null}
283 </Animated.View>
284 );
285}
286
287// ─── Password strength: four segments, one word, four rules ─────────────────
288
289function Segment({ index, filled, tone }: { index: number; filled: boolean; tone: SharedValue<number> }) {
290 const c = usePalette();
291 const fill = useSharedValue(0);
292 const first = useRef(true);
293 useEffect(() => {
294 // Fill left to right, drain right to left. The very first fill waits for the screen to arrive.
295 const delay = filled ? index * 45 + (first.current ? 380 : 0) : (LEVELS.length - 1 - index) * 30;
296 first.current = false;
297 fill.value = withDelay(delay, withTiming(filled ? 1 : 0, { duration: 280, easing: Easing.out(Easing.cubic) }));
298 // eslint-disable-next-line react-hooks/exhaustive-deps
299 }, [filled]);
300 const style = useAnimatedStyle(() => ({
301 width: `${fill.value * 100}%`,
302 backgroundColor: interpolateColor(tone.value, [1, 2, 3, 4], BARS),
303 }));
304 return (
305 <View style={[styles.segment, { backgroundColor: c.track }]}>
306 <Animated.View style={[styles.segmentFill, style]} />
307 </View>
308 );
309}
310
311/** All four words sit on top of each other; only the current one is opaque, so a change is a true cross-fade. */
312function Word({ text, color, active }: { text: string; color: string; active: boolean }) {
313 const on = useSharedValue(0);
314 useEffect(() => {
315 on.value = withTiming(active ? 1 : 0, { duration: active ? 240 : 150, easing: Easing.out(Easing.cubic) });
316 }, [active, on]);
317 const style = useAnimatedStyle(() => ({ opacity: on.value, transform: [{ translateY: interpolate(on.value, [0, 1], [5, 0]) }] }));
318 return (
319 <Animated.Text aria-hidden={!active} style={[styles.word, { color }, style]}>
320 {text}
321 </Animated.Text>
322 );
323}
324
325/** A dot that swells into a ticked disc, with a little overshoot, once its rule is met. */
326function Rule({ label, ok, index }: { label: string; ok: boolean; index: number }) {
327 const c = usePalette();
328 const t = useSharedValue(0);
329 const first = useRef(true);
330 useEffect(() => {
331 const delay = first.current && ok ? 460 + index * 70 : 0;
332 first.current = false;
333 t.value = withDelay(
334 delay,
335 withTiming(ok ? 1 : 0, ok ? { duration: 340, easing: Easing.out(Easing.back(2.8)) } : { duration: 170, easing: Easing.out(Easing.quad) })
336 );
337 // eslint-disable-next-line react-hooks/exhaustive-deps
338 }, [ok]);
339 const disc = useAnimatedStyle(() => ({
340 backgroundColor: interpolateColor(t.value, [0, 1], [c.faint, c.ok]),
341 transform: [{ scale: interpolate(t.value, [0, 1], [0.34, 1]) }],
342 }));
343 const tick = useAnimatedStyle(() => ({ opacity: interpolate(t.value, [0.35, 0.9], [0, 1], Extrapolation.CLAMP) }));
344 return (
345 <View aria-label={`${label}: ${ok ? 'met' : 'not met yet'}`} style={styles.rule}>
346 <Animated.View style={[styles.ruleDisc, disc]}>
347 <Animated.View style={tick}>
348 <Check size={10} color={c.onOk} strokeWidth={4} />
349 </Animated.View>
350 </Animated.View>
351 <Text numberOfLines={1} style={[styles.ruleLabel, { color: ok ? c.fg : c.muted }]}>
352 {label}
353 </Text>
354 </View>
355 );
356}
357
358const RULES_H = 60; // 12 gap + two 20pt rows + 8 between them
359
360function StrengthMeter({ password, open }: { password: string; open: boolean }) {
361 const c = usePalette();
362 const { met, level } = strengthOf(password);
363 const tone = useSharedValue(level || 1);
364 const reveal = useSharedValue(open ? 1 : 0);
365 useEffect(() => {
366 if (level) tone.value = withTiming(level, { duration: 300 });
367 }, [level, tone]);
368 useEffect(() => {
369 reveal.value = withTiming(open ? 1 : 0, { duration: 260, easing: Easing.out(Easing.cubic) });
370 }, [open, reveal]);
371 const rules = useAnimatedStyle(() => ({ height: reveal.value * RULES_H, opacity: reveal.value }));
372
373 return (
374 <View style={styles.meter}>
375 <View
376 role="progressbar"
377 aria-label="Password strength"
378 aria-valuemin={0}
379 aria-valuemax={LEVELS.length}
380 aria-valuenow={level}
381 aria-valuetext={level ? LEVELS[level - 1].label : 'Empty'}
382 style={styles.meterRow}
383 >
384 <View style={styles.segments}>
385 {LEVELS.map((l, i) => (
386 <Segment key={l.label} index={i} filled={i < level} tone={tone} />
387 ))}
388 </View>
389 <View style={styles.words}>
390 {LEVELS.map((l, i) => (
391 <Word key={l.label} text={l.label} color={c.dark ? l.bar : l.ink} active={level === i + 1} />
392 ))}
393 </View>
394 </View>
395 <Animated.View style={[styles.rulesClip, rules]}>
396 <View style={styles.rules}>
397 {RULES.map((r, i) => (
398 <Rule key={r.key} label={r.label} ok={met[i]} index={i} />
399 ))}
400 </View>
401 </Animated.View>
402 </View>
403 );
404}
405
406// ─── Terms: a box that fills, then the tick draws itself in ─────────────────
407
408function Checkbox({ checked, onToggle, label }: { checked: boolean; onToggle: () => void; label: string }) {
409 const c = usePalette();
410 const t = useSharedValue(checked ? 1 : 0);
411 const pop = useSharedValue(1);
412 const first = useRef(true);
413 useEffect(() => {
414 t.value = withTiming(checked ? 1 : 0, { duration: checked ? 300 : 150, easing: Easing.out(Easing.cubic) });
415 if (first.current) {
416 first.current = false;
417 return;
418 }
419 pop.value = withSequence(withTiming(0.84, { duration: 80 }), withTiming(1, { duration: 260, easing: Easing.out(Easing.back(3)) }));
420 }, [checked, t, pop]);
421 const box = useAnimatedStyle(() => ({
422 backgroundColor: interpolateColor(t.value, [0, 0.5], [c.field, ACCENT]),
423 borderColor: interpolateColor(t.value, [0, 0.5], [c.outline, ACCENT]),
424 transform: [{ scale: pop.value }],
425 }));
426 // The tick is revealed left to right behind a growing clip, which reads as a pen stroke.
427 const clip = useAnimatedStyle(() => ({ width: interpolate(t.value, [0.3, 1], [0, 14], Extrapolation.CLAMP) }));
428 return (
429 <Pressable role="checkbox" aria-checked={checked} aria-label={label} onPress={onToggle} hitSlop={12}>
430 <Animated.View style={[styles.checkbox, box]}>
431 <Animated.View style={[styles.checkClip, clip]}>
432 <Svg width={14} height={14} viewBox="0 0 14 14">
433 <Path d="M2.4 7.5 5.6 10.6 11.6 3.9" stroke={ON_ACCENT} strokeWidth={2.2} strokeLinecap="round" strokeLinejoin="round" fill="none" />
434 </Svg>
435 </Animated.View>
436 </Animated.View>
437 </Pressable>
438 );
439}
440
441// ─── Primary button: locked, ready, spinning, done ──────────────────────────
442
443type Status = 'idle' | 'loading' | 'done';
444
445// The highlight along the button's top edge, off while locked and on once it unlocks.
446const SUBMIT_EDGE = [tint(ON_ACCENT, 0), tint(ON_ACCENT, 0.28)];
447
448function Spinner() {
449 const r = useSharedValue(0);
450 useEffect(() => {
451 r.value = withRepeat(withTiming(360, { duration: 800, easing: Easing.linear }), -1);
452 }, [r]);
453 const style = useAnimatedStyle(() => ({ transform: [{ rotate: `${r.value}deg` }] }));
454 return <Animated.View style={[styles.spinner, style]} />;
455}
456
457function SubmitButton({ status, ready, onPress }: { status: Status; ready: boolean; onPress: () => void }) {
458 const c = usePalette();
459 const on = useSharedValue(ready ? 1 : 0);
460 const scale = useSharedValue(1);
461 const first = useRef(true);
462 const done = status === 'done';
463
464 useEffect(() => {
465 on.value = withTiming(ready ? 1 : 0, { duration: 320, easing: Easing.out(Easing.cubic) });
466 if (first.current) {
467 first.current = false;
468 return;
469 }
470 // A small swell tells the eye the button just woke up.
471 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)) }));
472 }, [ready, on, scale]);
473
474 const box = useAnimatedStyle(() => ({
475 backgroundColor: done ? SUCCESS : interpolateColor(on.value, [0, 1], [c.off, ACCENT]),
476 borderTopColor: interpolateColor(on.value, [0, 1], SUBMIT_EDGE),
477 shadowOpacity: 0.35 * on.value,
478 transform: [{ scale: scale.value }],
479 }));
480 const text = useAnimatedStyle(() => ({ color: interpolateColor(on.value, [0, 1], [c.offText, ON_ACCENT]) }));
481 // The arrow slides out from behind the label as the button unlocks.
482 const arrow = useAnimatedStyle(() => ({ width: on.value * 26, opacity: on.value }));
483
484 return (
485 <Pressable
486 role="button"
487 aria-label="Create account"
488 aria-busy={status === 'loading'}
489 disabled={status !== 'idle'}
490 onPress={onPress}
491 onPressIn={() => ready && (scale.value = withSpring(0.97, SPRING))}
492 onPressOut={() => ready && (scale.value = withSpring(1, SPRING))}
493 >
494 <Animated.View style={[styles.submit, done ? styles.submitDone : styles.submitIdle, box]}>
495 {status === 'idle' && (
496 <Animated.View entering={FadeIn.duration(150)} style={styles.submitContent}>
497 <Animated.Text style={[styles.submitText, text]}>Create account</Animated.Text>
498 <Animated.View style={[styles.submitArrow, arrow]}>
499 <ArrowRight size={18} color={ON_ACCENT} strokeWidth={2.4} />
500 </Animated.View>
501 </Animated.View>
502 )}
503 {status === 'loading' && <Spinner />}
504 {done && (
505 <Animated.View entering={ZoomIn.duration(260)} style={styles.submitDoneContent}>
506 <Check size={20} color="#fff" strokeWidth={3} />
507 <Text style={styles.submitDoneLabel}>Account created</Text>
508 </Animated.View>
509 )}
510 </Animated.View>
511 </Pressable>
512 );
513}
514
515// ─── Screen ─────────────────────────────────────────────────────────────────
516
517type Errors = { name?: string; email?: string; password?: string };
518
519export default function SignUpScreen() {
520 const c = usePalette();
521 const insets = useSafeAreaInsets();
522 const { width } = useWindowDimensions();
523 const [name, setName] = useState(PREFILL.name);
524 const [email, setEmail] = useState(PREFILL.email);
525 const [password, setPassword] = useState(PREFILL.password);
526 const [show, setShow] = useState(false);
527 const [agreed, setAgreed] = useState(PREFILL.agreed);
528 const [errors, setErrors] = useState<Errors>({});
529 const [nudge, setNudge] = useState(0);
530 const [passwordFocused, setPasswordFocused] = useState(false);
531 const [status, setStatus] = useState<Status>('idle');
532 const emailRef = useRef<ComponentRef<typeof TextInput>>(null);
533 const passwordRef = useRef<ComponentRef<typeof TextInput>>(null);
534 const timers = useRef<ReturnType<typeof setTimeout>[]>([]);
535 const terms = useShake();
536
537 useEffect(() => () => timers.current.forEach(clearTimeout), []);
538
539 const nameValid = name.trim().length >= 2;
540 const emailValid = EMAIL_RE.test(email.trim());
541 const passwordValid = strengthOf(password).score >= STRONG_ENOUGH;
542 const ready = nameValid && emailValid && passwordValid && agreed;
543
544 const clear = (field: keyof Errors) => setErrors((e) => (e[field] ? { ...e, [field]: undefined } : e));
545 const flag = (field: keyof Errors, message: string | undefined) => setErrors((e) => ({ ...e, [field]: message }));
546
547 // The button looks locked but still takes a tap, which points at whatever is missing.
548 // For a hard lock instead, pass `disabled={!ready}` to the Pressable in SubmitButton.
549 const explain = () => {
550 const next: Errors = {
551 name: nameValid ? undefined : 'Enter your full name.',
552 email: emailValid ? undefined : 'Enter a valid email address.',
553 password: passwordValid ? undefined : 'Meet at least three of the rules below.',
554 };
555 setErrors(next);
556 setNudge((n) => n + 1);
557 if (!next.name && !next.email && !next.password && !agreed) terms.shake();
558 };
559
560 const submit = () => {
561 if (!ready) return explain();
562 setErrors({});
563 setStatus('loading');
564 // Replace with your sign-up call. The reset is only here so the preview can be replayed.
565 timers.current.push(setTimeout(() => setStatus('done'), 1300), setTimeout(() => setStatus('idle'), 3300));
566 };
567
568 const enter = (i: number) => FadeInDown.delay(40 + i * 55).duration(420);
569
570 return (
571 <KeyboardAvoidingView behavior={Platform.OS === 'ios' ? 'padding' : undefined} style={[styles.screen, { backgroundColor: c.bg }]}>
572 <HeaderBand width={width} top={insets.top} />
573
574 <ScrollView
575 keyboardShouldPersistTaps="handled"
576 showsVerticalScrollIndicator={false}
577 contentContainerStyle={[styles.content, { paddingTop: insets.top + 8, paddingBottom: insets.bottom + 16 }]}
578 >
579 {/* Top bar: back on the left, a compact brand mark on the right */}
580 <Animated.View entering={enter(0)} style={styles.topBar}>
581 <Tap label="Back" to={0.9}>
582 <View style={[styles.back, { backgroundColor: c.field, borderColor: c.border }]}>
583 <ChevronLeft size={22} color={c.fg} strokeWidth={2.2} style={styles.backGlyph} />
584 </View>
585 </Tap>
586 <View
587 role="img"
588 aria-label="App logo"
589 style={styles.brand}
590 >
591 <Svg width={17} height={17} viewBox="0 0 24 24">
592 <Path fill={ON_ACCENT} d="M4 4h7v7H4zM13 4h7v7h-4l-3-3zM4 13h3l4 4v3H4zM13 13h7v7h-7z" />
593 </Svg>
594 </View>
595 </Animated.View>
596
597 <Animated.View entering={enter(1)} style={styles.heading}>
598 <Text role="heading" style={[styles.title, { color: c.fg }]}>
599 Create your account
600 </Text>
601 <Text style={[styles.subtitle, { color: c.muted }]}>It takes less than a minute. No card needed.</Text>
602 </Animated.View>
603
604 {/* Form */}
605 <Animated.View entering={enter(2)} style={styles.form}>
606 <Field
607 label="Full name"
608 value={name}
609 onChangeText={(v) => {
610 setName(v);
611 clear('name');
612 }}
613 onFocusChange={(focused) => !focused && flag('name', nameValid ? undefined : 'Enter your full name.')}
614 valid={nameValid}
615 error={errors.name}
616 nudge={nudge}
617 autoCapitalize="words"
618 autoComplete="name"
619 textContentType="name"
620 returnKeyType="next"
621 onSubmitEditing={() => emailRef.current?.focus()}
622 />
623 <Field
624 inputRef={emailRef}
625 label="Email"
626 value={email}
627 onChangeText={(v) => {
628 setEmail(v);
629 clear('email');
630 }}
631 // Checked when the field is left, never while the address is still being typed.
632 onFocusChange={(focused) => !focused && flag('email', email.trim() && !emailValid ? 'Enter a valid email address.' : undefined)}
633 valid={emailValid}
634 error={errors.email}
635 nudge={nudge}
636 keyboardType="email-address"
637 autoCapitalize="none"
638 autoComplete="email"
639 textContentType="emailAddress"
640 returnKeyType="next"
641 onSubmitEditing={() => passwordRef.current?.focus()}
642 />
643 <View>
644 <Field
645 inputRef={passwordRef}
646 label="Password"
647 value={password}
648 onChangeText={(v) => {
649 setPassword(v);
650 clear('password');
651 }}
652 onFocusChange={setPasswordFocused}
653 error={errors.password}
654 nudge={nudge}
655 secureTextEntry={!show}
656 autoCapitalize="none"
657 autoComplete="new-password"
658 textContentType="newPassword"
659 returnKeyType="go"
660 onSubmitEditing={submit}
661 trailing={
662 <Pressable role="button" aria-label={show ? 'Hide password' : 'Show password'} onPress={() => setShow((s) => !s)} hitSlop={10}>
663 <Animated.View key={show ? 'on' : 'off'} entering={ZoomIn.duration(160)}>
664 {show ? <EyeOff size={20} color={c.muted} /> : <Eye size={20} color={c.muted} />}
665 </Animated.View>
666 </Pressable>
667 }
668 />
669 {/* The rules stay out of the way until the password is in play */}
670 <StrengthMeter password={password} open={passwordFocused || password.length > 0} />
671 </View>
672 </Animated.View>
673
674 {/* Terms */}
675 <Animated.View entering={enter(3)} style={[styles.terms, terms.style]}>
676 <Checkbox checked={agreed} onToggle={() => setAgreed((a) => !a)} label="Agree to the Terms and Privacy Policy" />
677 <Text onPress={() => setAgreed((a) => !a)} style={[styles.termsText, { color: c.muted }]}>
678 I agree to the{' '}
679 <Text role="link" aria-label="Terms" onPress={() => {}} style={[styles.termsLink, { color: c.link }]}>
680 Terms
681 </Text>{' '}
682 and{' '}
683 <Text role="link" aria-label="Privacy Policy" onPress={() => {}} style={[styles.termsLink, { color: c.link }]}>
684 Privacy Policy
685 </Text>
686 </Text>
687 </Animated.View>
688
689 <Animated.View entering={enter(4)} style={styles.submitSlot}>
690 <SubmitButton status={status} ready={ready} onPress={submit} />
691 </Animated.View>
692
693 {/* Alternatives */}
694 <Animated.View entering={enter(5)} style={styles.dividerRow}>
695 <View style={[styles.divider, { backgroundColor: c.border }]} />
696 <Text style={[styles.dividerLabel, { color: c.muted }]}>or</Text>
697 <View style={[styles.divider, { backgroundColor: c.border }]} />
698 </Animated.View>
699
700 <Animated.View entering={enter(6)} style={styles.socialRow}>
701 {[
702 { label: 'Apple', logo: <AppleLogo color={c.fg} /> },
703 { label: 'Google', logo: <GoogleLogo /> },
704 ].map((s) => (
705 <Tap key={s.label} label={`Sign up with ${s.label}`} flex>
706 <View style={[styles.social, { borderColor: c.border, backgroundColor: c.field }]}>
707 {s.logo}
708 <Text style={[styles.socialLabel, { color: c.fg }]}>{s.label}</Text>
709 </View>
710 </Tap>
711 ))}
712 </Animated.View>
713
714 <View style={styles.spacer} />
715
716 <Animated.View entering={enter(7)} style={styles.footer}>
717 <Text style={[styles.footerText, { color: c.muted }]}>Already have an account?</Text>
718 <Pressable role="link" aria-label="Sign in" hitSlop={8}>
719 <Text style={[styles.footerLink, { color: c.fg }]}>Sign in</Text>
720 </Pressable>
721 </Animated.View>
722 </ScrollView>
723 </KeyboardAvoidingView>
724 );
725}
726
727// ─── Styles ─────────────────────────────────────────────────────────────────
728
729const styles = StyleSheet.create({
730 screen: { flex: 1 },
731 content: { flexGrow: 1, paddingHorizontal: 24 },
732 fill: { flex: 1 },
733
734 // Background
735 band: { position: 'absolute', top: 0, left: 0, right: 0, overflow: 'hidden', pointerEvents: 'none' },
736 bandFill: { position: 'absolute', top: 0, left: 0, right: 0, bottom: 0 },
737 rings: { position: 'absolute', top: 0, left: 0 },
738 veil: { position: 'absolute', left: 0, right: 0, bottom: 0, height: 150 },
739
740 // Top bar and heading
741 topBar: { height: 44, flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between' },
742 back: { width: 40, height: 40, borderRadius: 20, borderWidth: 1, alignItems: 'center', justifyContent: 'center' },
743 backGlyph: { marginLeft: -2 },
744 brand: {
745 width: 36,
746 height: 36,
747 borderRadius: 12,
748 backgroundColor: ACCENT,
749 alignItems: 'center',
750 justifyContent: 'center',
751 shadowColor: ACCENT,
752 shadowOpacity: 0.4,
753 shadowRadius: 12,
754 shadowOffset: { width: 0, height: 6 },
755 borderTopWidth: 1,
756 borderTopColor: tint(ON_ACCENT, 0.35),
757 },
758 heading: { marginTop: 20 },
759 title: { fontSize: 30, lineHeight: 36, fontWeight: '700', letterSpacing: -0.8 },
760 subtitle: { marginTop: 6, fontSize: 15.5, lineHeight: 22 },
761
762 // Fields
763 form: { marginTop: 26, gap: 12 },
764 field: {
765 height: 58,
766 borderRadius: 16,
767 borderWidth: 1.5,
768 paddingHorizontal: 16,
769 flexDirection: 'row',
770 alignItems: 'center',
771 shadowColor: ACCENT,
772 shadowRadius: 10,
773 shadowOffset: { width: 0, height: 0 },
774 },
775 fieldBody: { flex: 1, height: '100%', justifyContent: 'center' },
776 fieldLabel: { position: 'absolute', left: 0, fontSize: 16, transformOrigin: 'left center', pointerEvents: 'none' },
777 fieldInput: { paddingTop: 18, height: '100%', fontSize: 16 },
778 fieldError: { fontSize: 13, marginTop: 6, marginLeft: 4 },
779 validTick: { width: 22, height: 22, borderRadius: 11, backgroundColor: ACCENT, alignItems: 'center', justifyContent: 'center' },
780
781 // Strength meter
782 meter: { marginTop: 12, paddingHorizontal: 4 },
783 meterRow: { flexDirection: 'row', alignItems: 'center', gap: 10 },
784 segments: { flex: 1, flexDirection: 'row', gap: 5 },
785 segment: { flex: 1, height: 5, borderRadius: 3, overflow: 'hidden' },
786 segmentFill: { height: '100%', borderRadius: 3 },
787 words: { width: 46, height: 16 },
788 word: { position: 'absolute', right: 0, fontSize: 13, lineHeight: 16, fontWeight: '700' },
789 rulesClip: { overflow: 'hidden' },
790 rules: { paddingTop: 12, flexDirection: 'row', flexWrap: 'wrap', rowGap: 8 },
791 rule: { width: '50%', height: 20, flexDirection: 'row', alignItems: 'center', gap: 8 },
792 ruleDisc: { width: 16, height: 16, borderRadius: 8, alignItems: 'center', justifyContent: 'center' },
793 ruleLabel: { flex: 1, fontSize: 13 },
794
795 // Terms
796 terms: { marginTop: 20, flexDirection: 'row', alignItems: 'center', gap: 11 },
797 termsText: { flex: 1, fontSize: 14, lineHeight: 20 },
798 termsLink: { fontWeight: '600' },
799 checkbox: { width: 22, height: 22, borderRadius: 7, borderWidth: 1.5, justifyContent: 'center', paddingLeft: 2.5 },
800 checkClip: { height: 14, overflow: 'hidden' },
801
802 // Submit
803 submitSlot: { marginTop: 20 },
804 submit: { height: 56, borderRadius: 16, alignItems: 'center', justifyContent: 'center', flexDirection: 'row', borderTopWidth: 1 },
805 // A shadow's props stay together in one style object: React Native Web builds the shadow per object.
806 // Its opacity follows the unlock animation, so it stays in the animated style.
807 submitIdle: { shadowColor: ACCENT, shadowRadius: 16, shadowOffset: { width: 0, height: 8 } },
808 submitDone: { shadowColor: SUCCESS, shadowRadius: 16, shadowOffset: { width: 0, height: 8 } },
809 submitContent: { flexDirection: 'row', alignItems: 'center' },
810 submitText: { fontSize: 16, fontWeight: '600' },
811 submitArrow: { height: 18, overflow: 'hidden', alignItems: 'flex-end' },
812 submitDoneContent: { flexDirection: 'row', alignItems: 'center', gap: 8 },
813 submitDoneLabel: { color: '#fff', fontSize: 16, fontWeight: '600' },
814 spinner: { width: 20, height: 20, borderRadius: 10, borderWidth: 2.5, borderColor: tint(ON_ACCENT, 0.35), borderTopColor: ON_ACCENT },
815
816 // Alternatives
817 dividerRow: { marginTop: 22, flexDirection: 'row', alignItems: 'center', gap: 12 },
818 divider: { flex: 1, height: 1 },
819 dividerLabel: { fontSize: 13 },
820 socialRow: { marginTop: 18, flexDirection: 'row', gap: 12 },
821 social: { height: 52, borderRadius: 16, borderWidth: 1.5, flexDirection: 'row', alignItems: 'center', justifyContent: 'center', gap: 9 },
822 socialLabel: { fontSize: 15, fontWeight: '600' },
823
824 spacer: { flex: 1, minHeight: 20 },
825 footer: { flexDirection: 'row', justifyContent: 'center', gap: 5 },
826 footerText: { fontSize: 15 },
827 footerLink: { fontSize: 15, fontWeight: '700' },
828});

More screens like this.

All Authentication