Add card

Add a payment card with a live preview: digits pop onto the card as you type, the gradient and a drawn network mark change with the first digit, the card flips to its back while the CVV is focused, a simulated camera scan fills the form, invalid fields shake with inline errors, and Save morphs to a check before the card slides into a wallet.

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

Details

File
components/patterns/add-card.tsx
Lines
1105
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/add-card.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 LayoutChangeEvent,
14 type TextInputProps,
15} from 'react-native';
16import Animated, {
17 cancelAnimation,
18 Easing,
19 FadeIn,
20 FadeInDown,
21 interpolate,
22 interpolateColor,
23 useAnimatedStyle,
24 useSharedValue,
25 withDelay,
26 withRepeat,
27 withSequence,
28 withSpring,
29 withTiming,
30 ZoomIn,
31 type SharedValue,
32} from 'react-native-reanimated';
33import { LinearGradient } from 'expo-linear-gradient';
34import { useSafeAreaInsets } from 'react-native-safe-area-context';
35import Svg, { Circle, Path } from 'react-native-svg';
36import { Check, ChevronLeft, Lock, Nfc, ScanLine, X } from 'lucide-react-native';
37
38// ─── Brand ──────────────────────────────────────────────────────────────────
39// The wallet's accent and name. Every accent colour below derives from these, so changing them rebrands the screen. The card networks' own colours are not the wallet's brand.
40
41const ACCENT = '#FF5A1F';
42const ON_ACCENT = '#140A05'; // text and icons on an accent fill
43const APP_NAME = 'Ember';
44
45/** `hex` at `alpha` opacity, as rgba(). */
46function tint(hex: string, alpha: number) {
47 const n = parseInt(hex.slice(1), 16);
48 return `rgba(${(n >> 16) & 255}, ${(n >> 8) & 255}, ${n & 255}, ${alpha})`;
49}
50
51/** `hex` mixed toward black (amount > 0) or white (amount < 0); amount from -1 to 1. */
52function shade(hex: string, amount: number) {
53 const n = parseInt(hex.slice(1), 16);
54 const target = amount < 0 ? 255 : 0;
55 const p = Math.abs(amount);
56 const c = (v: number) => Math.round(v + (target - v) * p).toString(16).padStart(2, '0');
57 return `#${c((n >> 16) & 255)}${c((n >> 8) & 255)}${c(n & 255)}`.toUpperCase();
58}
59
60/** `hex` with its hue turned by `deg` degrees and its HSL lightness and saturation moved by `light` / `sat` (-1 to 1). */
61function spin(hex: string, deg: number, light = 0, sat = 0) {
62 const n = parseInt(hex.slice(1), 16);
63 const r = ((n >> 16) & 255) / 255;
64 const g = ((n >> 8) & 255) / 255;
65 const b = (n & 255) / 255;
66 const max = Math.max(r, g, b);
67 const min = Math.min(r, g, b);
68 const d = max - min;
69 const s = Math.min(1, Math.max(0, (d === 0 ? 0 : d / (1 - Math.abs(max + min - 1))) + sat));
70 const l = Math.min(1, Math.max(0, (max + min) / 2 + light));
71 const h0 = d === 0 ? 0 : max === r ? ((g - b) / d + 6) % 6 : max === g ? (b - r) / d + 2 : (r - g) / d + 4;
72 const h = (((h0 * 60 + deg) % 360) + 360) % 360;
73 const a = s * Math.min(l, 1 - l);
74 const f = (m: number) => {
75 const k = (m + h / 30) % 12;
76 return Math.round(255 * (l - a * Math.max(-1, Math.min(k - 3, 9 - k, 1)))).toString(16).padStart(2, '0');
77 };
78 return `#${f(0)}${f(8)}${f(4)}`.toUpperCase();
79}
80
81// ─── Sample data ────────────────────────────────────────────────────────────
82
83// The form opens part filled so the preview is populated. Start from empty strings in your app.
84const PREFILL = { number: '4286 1953 0724 1039', name: 'Maya Chen', expiry: '08/29' };
85// What the simulated scan "reads". A test number that passes the Luhn check.
86const SCANNED = { number: '5418036271951039', name: 'Maya Chen', expiry: '11/30' };
87
88type NetworkId = 'none' | 'kite' | 'orbit' | 'tern';
89
90// Invented networks, picked from the first digit. Each has its own card colours and CVV length.
91const NETWORKS: Record<NetworkId, { name: string; colors: readonly [string, string]; ink: string; cvv: number }> = {
92 none: { name: 'Card', colors: ['#45454C', '#17171A'], ink: '#FFFFFF', cvv: 3 },
93 // Kite is the network the sample number shows, so its card wears the app's accent; the others keep their own art.
94 kite: { name: 'Kite', colors: [spin(ACCENT, 9.5, 0.14), ACCENT], ink: ON_ACCENT, cvv: 3 },
95 orbit: { name: 'Orbit', colors: ['#14806F', '#073B36'], ink: '#FFFFFF', cvv: 3 },
96 tern: { name: 'Tern', colors: ['#E6EEDF', '#A9C4A0'], ink: '#10170D', cvv: 4 },
97};
98const NETWORK_IDS: NetworkId[] = ['none', 'kite', 'orbit', 'tern'];
99const ACCEPTED: NetworkId[] = ['kite', 'orbit', 'tern'];
100
101// ─── Palette ────────────────────────────────────────────────────────────────
102
103// Printed ink on the card's signature strip.
104const INK = '#140A05';
105const SUCCESS = '#16A34A';
106const POP = { damping: 12, stiffness: 280, mass: 0.6 };
107const PRESS = { damping: 16, stiffness: 320, mass: 0.6 };
108const CARD_H = 204;
109const BUTTON_H = 58;
110const NO_OUTLINE = Platform.OS === 'web' ? ({ outlineStyle: 'none' } as object) : null;
111
112function usePalette() {
113 const dark = useColorScheme() === 'dark';
114 return {
115 dark,
116 bg: dark ? '#000000' : '#F5F5F5',
117 surface: dark ? '#171717' : '#FFFFFF',
118 field: dark ? '#141416' : '#FFFFFF',
119 fg: dark ? '#FAFAFA' : '#0A0A0A',
120 muted: dark ? '#8A8A8F' : '#7A7A80',
121 faint: dark ? '#48484D' : '#C2C2C8',
122 border: dark ? '#2A2A2E' : '#E4E4E7',
123 track: dark ? '#303036' : '#DEDEE2',
124 accentText: dark ? shade(ACCENT, -0.29) : shade(ACCENT, 0.15),
125 accentTint: dark ? tint(ACCENT, 0.16) : tint(ACCENT, 0.1),
126 error: dark ? '#FF6B6B' : '#E5484D',
127 cardEdge: dark ? 'rgba(255,255,255,0.16)' : 'rgba(255,255,255,0.45)',
128 backdrop: dark ? 'rgba(0,0,0,0.72)' : 'rgba(10,10,10,0.45)',
129 };
130}
131type Palette = ReturnType<typeof usePalette>;
132
133// ─── Card rules ─────────────────────────────────────────────────────────────
134
135const digitsOf = (v: string) => v.replace(/\D/g, '');
136const formatNumber = (v: string) => digitsOf(v).slice(0, 16).replace(/(\d{4})(?=\d)/g, '$1 ');
137const detect = (digits: string): NetworkId => (digits[0] === '4' ? 'kite' : digits[0] === '5' ? 'orbit' : digits[0] === '3' ? 'tern' : 'none');
138
139/** Luhn checksum: double every second digit from the right, the sum must end in 0. */
140function luhn(digits: string) {
141 let sum = 0;
142 for (let i = 0; i < digits.length; i++) {
143 let d = Number(digits[digits.length - 1 - i]);
144 if (i % 2 === 1) d = d * 2 > 9 ? d * 2 - 9 : d * 2;
145 sum += d;
146 }
147 return digits.length === 16 && sum % 10 === 0;
148}
149
150/** "0829" becomes "08/29". The slash arrives after the month while typing and leaves when deleting. */
151function formatExpiry(next: string, prev: string) {
152 let d = digitsOf(next).slice(0, 4);
153 if (d.length === 1 && Number(d) > 1) d = `0${d}`;
154 if (d.length >= 3) return `${d.slice(0, 2)}/${d.slice(2)}`;
155 return d.length === 2 && next.length > prev.length ? `${d}/` : d;
156}
157
158type FieldKey = 'number' | 'name' | 'expiry' | 'cvv' | 'zip';
159type Values = Record<FieldKey, string>;
160
161function check(key: FieldKey, v: Values): string | null {
162 if (key === 'number') {
163 const d = digitsOf(v.number);
164 return d.length < 16 ? 'Enter all 16 digits.' : luhn(d) ? null : 'That card number is not valid. Check the digits.';
165 }
166 if (key === 'name') return v.name.trim().length < 2 ? 'Enter the name printed on the card.' : null;
167 if (key === 'expiry') {
168 if (!/^\d\d\/\d\d$/.test(v.expiry)) return 'Use MM/YY';
169 const month = Number(v.expiry.slice(0, 2));
170 const year = 2000 + Number(v.expiry.slice(3));
171 if (month < 1 || month > 12) return 'Invalid month';
172 const now = new Date();
173 return year < now.getFullYear() || (year === now.getFullYear() && month < now.getMonth() + 1) ? 'Card expired' : null;
174 }
175 if (key === 'cvv') {
176 const n = NETWORKS[detect(digitsOf(v.number))].cvv;
177 return v.cvv.length === n ? null : `${n} digits`;
178 }
179 return /^\d{5}$/.test(v.zip) ? null : '5 digits';
180}
181
182// ─── Network marks, drawn: double chevron, two circles, a diamond ───────────
183
184function NetworkMark({ id, color, width = 44 }: { id: NetworkId; color: string; width?: number }) {
185 if (id === 'none') return null;
186 return (
187 <Svg width={width} height={width * 0.625} viewBox="0 0 40 25" aria-label={`${NETWORKS[id].name} network`}>
188 {id === 'kite' && <Path d="M8 4.5l9 8-9 8M21 4.5l9 8-9 8" stroke={color} strokeWidth={3.6} strokeLinecap="round" strokeLinejoin="round" fill="none" />}
189 {id === 'orbit' && (
190 <>
191 <Circle cx={14} cy={12.5} r={8.2} stroke={color} strokeWidth={2.8} fill="none" />
192 <Circle cx={26} cy={12.5} r={8.2} stroke={color} strokeWidth={2.8} fill="none" opacity={0.55} />
193 </>
194 )}
195 {id === 'tern' && (
196 <>
197 <Path d="M20 2.5l10 10-10 10-10-10z" stroke={color} strokeWidth={2.6} strokeLinejoin="round" fill="none" />
198 <Path d="M20 8l4.5 4.5L20 17l-4.5-4.5z" fill={color} />
199 </>
200 )}
201 </Svg>
202 );
203}
204
205// ─── Card preview ───────────────────────────────────────────────────────────
206
207/** One gradient per network, stacked. The active one fades in over the others. */
208function Tint({ id, active }: { id: NetworkId; active: boolean }) {
209 const o = useSharedValue(active ? 1 : 0);
210 useEffect(() => {
211 o.value = withTiming(active ? 1 : 0, { duration: 380, easing: Easing.out(Easing.cubic) });
212 }, [active, o]);
213 const style = useAnimatedStyle(() => ({ opacity: o.value }));
214 return (
215 <Animated.View pointerEvents="none" style={[StyleSheet.absoluteFill, style]}>
216 <LinearGradient colors={NETWORKS[id].colors} start={{ x: 0, y: 0 }} end={{ x: 1, y: 1 }} style={StyleSheet.absoluteFill} />
217 </Animated.View>
218 );
219}
220
221function CardFace({ network, sheen, children }: { network: NetworkId; sheen?: SharedValue<number>; children: ReactNode }) {
222 const c = usePalette();
223 return (
224 <View style={[styles.cardClip, { borderColor: c.cardEdge }]}>
225 {NETWORK_IDS.map((id) => (
226 <Tint key={id} id={id} active={id === network} />
227 ))}
228 <View pointerEvents="none" style={styles.cardGlow} />
229 {sheen && <Sheen t={sheen} />}
230 {children}
231 </View>
232 );
233}
234
235function Sheen({ t }: { t: SharedValue<number> }) {
236 const style = useAnimatedStyle(() => ({
237 opacity: t.value > 0 && t.value < 1 ? 1 : 0,
238 transform: [{ translateX: -180 + t.value * 640 }, { rotate: '20deg' }],
239 }));
240 return (
241 <Animated.View pointerEvents="none" style={[styles.sheen, style]}>
242 <LinearGradient colors={['rgba(255,255,255,0)', 'rgba(255,255,255,0.34)', 'rgba(255,255,255,0)']} start={{ x: 0, y: 0.5 }} end={{ x: 1, y: 0.5 }} style={StyleSheet.absoluteFill} />
243 </Animated.View>
244 );
245}
246
247function Chip() {
248 return (
249 <View style={styles.chip}>
250 <LinearGradient colors={['#F7E7B4', '#C9A455']} start={{ x: 0, y: 0 }} end={{ x: 1, y: 1 }} style={StyleSheet.absoluteFill} />
251 <Svg width={44} height={32} viewBox="0 0 44 32" style={StyleSheet.absoluteFill}>
252 <Path d="M0 11h13M0 21h13M31 11h13M31 21h13M13 0v32M31 0v32M13 16h18" stroke="rgba(70,48,8,0.8)" strokeWidth={1.2} fill="none" />
253 </Svg>
254 </View>
255 );
256}
257
258/** One slot of the card number: a dot until its digit is typed, then the digit pops in. */
259function Digit({ ch, index, ink }: { ch: string; index: number; ink: string }) {
260 const pop = useSharedValue(ch ? 0 : 1);
261 const booted = useRef(false);
262 useEffect(() => {
263 if (ch) {
264 pop.value = 0;
265 pop.value = withDelay(booted.current ? 0 : 320 + index * 26, withSpring(1, POP));
266 } else {
267 pop.value = 1;
268 }
269 booted.current = true;
270 }, [ch, index, pop]);
271 const style = useAnimatedStyle(() => ({
272 opacity: Math.min(1, pop.value * 1.6),
273 transform: [{ translateY: (1 - pop.value) * 9 }, { scale: 0.4 + pop.value * 0.6 }],
274 }));
275 return (
276 <Animated.Text style={[styles.cardDigit, { color: ink, opacity: ch ? 1 : 0.45 }, style, !ch && styles.cardDot]}>{ch || '•'}</Animated.Text>
277 );
278}
279
280type PreviewProps = { values: Values; network: NetworkId; flipped: boolean; width: number; bump: SharedValue<number> };
281
282function CardPreview({ values, network, flipped, width, bump }: PreviewProps) {
283 const ink = NETWORKS[network].ink;
284 const digits = digitsOf(values.number);
285 const flip = useSharedValue(0);
286 const sheen = useSharedValue(1);
287 const booted = useRef(false);
288
289 useEffect(() => {
290 flip.value = withTiming(flipped ? 1 : 0, { duration: 520, easing: Easing.inOut(Easing.cubic) });
291 }, [flipped, flip]);
292 // A light sweep crosses the card whenever the network changes.
293 useEffect(() => {
294 sheen.value = 0;
295 sheen.value = withDelay(booted.current ? 60 : 700, withTiming(1, { duration: 900, easing: Easing.inOut(Easing.cubic) }));
296 booted.current = true;
297 }, [network, sheen]);
298
299 const lift = useAnimatedStyle(() => ({
300 transform: [{ perspective: 900 }, { scale: 1 + bump.value * 0.045 }, { rotateX: `${bump.value * 10}deg` }],
301 }));
302 const front = useAnimatedStyle(() => ({
303 opacity: flip.value < 0.5 ? 1 : 0,
304 transform: [{ perspective: 1000 }, { rotateY: `${flip.value * 180}deg` }],
305 }));
306 const back = useAnimatedStyle(() => ({
307 opacity: flip.value < 0.5 ? 0 : 1,
308 transform: [{ perspective: 1000 }, { rotateY: `${flip.value * 180 - 180}deg` }],
309 }));
310
311 const cvvLength = NETWORKS[network].cvv;
312 const name = values.name.trim().toUpperCase();
313 return (
314 <Animated.View
315 aria-label={`Card preview, ${flipped ? 'back' : 'front'}${network === 'none' ? '' : `, ${NETWORKS[network].name}`}`}
316 style={[styles.cardWrap, { width }, lift]}
317 >
318 <Animated.View style={[styles.cardFace, front]}>
319 <CardFace network={network} sheen={sheen}>
320 <View style={styles.cardBody}>
321 <View style={styles.cardRow}>
322 <Text style={[styles.cardBrand, { color: ink }]}>{APP_NAME}</Text>
323 <Nfc size={24} color={ink} strokeWidth={1.8} />
324 </View>
325 <Chip />
326 <View style={styles.cardNumber} aria-label="Card number preview">
327 {Array.from({ length: 16 }, (_, i) => (
328 <View key={i} style={i % 4 === 3 && i < 15 ? styles.cardGroupEnd : null}>
329 <Digit ch={digits[i] ?? ''} index={i} ink={ink} />
330 </View>
331 ))}
332 </View>
333 <View style={styles.cardRow}>
334 <View style={styles.cardHolder}>
335 <Text style={[styles.cardCaption, { color: ink }]}>Card holder</Text>
336 <Text numberOfLines={1} style={[styles.cardValue, { color: ink, opacity: name ? 1 : 0.45 }]}>
337 {name || 'YOUR NAME'}
338 </Text>
339 </View>
340 <View style={styles.cardExpiry}>
341 <Text style={[styles.cardCaption, { color: ink }]}>Expires</Text>
342 <Text style={[styles.cardValue, styles.tabular, { color: ink, opacity: values.expiry ? 1 : 0.45 }]}>{values.expiry || 'MM/YY'}</Text>
343 </View>
344 <View style={styles.cardMark}>
345 {network !== 'none' && (
346 <Animated.View key={network} entering={ZoomIn.springify().damping(11).stiffness(220)}>
347 <NetworkMark id={network} color={ink} />
348 </Animated.View>
349 )}
350 </View>
351 </View>
352 </View>
353 </CardFace>
354 </Animated.View>
355
356 <Animated.View pointerEvents="none" style={[styles.cardFace, StyleSheet.absoluteFill, back]}>
357 <CardFace network={network}>
358 <View style={styles.magStripe} />
359 <View style={styles.backRow}>
360 <View style={styles.signature}>
361 <Svg width={120} height={26} viewBox="0 0 120 26">
362 <Path d="M6 18c8-12 12-14 14-8s-6 12-2 10 10-16 16-12-2 10 4 8 8-8 14-6 4 6 12 4 14-6 22-4 14 2 26-2" stroke="#3B3B44" strokeWidth={1.6} strokeLinecap="round" fill="none" />
363 </Svg>
364 </View>
365 <View style={styles.cvvBox} aria-label="CVV preview">
366 <Text style={[styles.cvvText, styles.tabular, { opacity: values.cvv ? 1 : 0.35 }]}>{values.cvv || '•'.repeat(cvvLength)}</Text>
367 </View>
368 </View>
369 <Text style={[styles.cvvCaption, { color: ink }]}>Security code</Text>
370 <View style={styles.backFoot}>
371 <Text style={[styles.backPrint, { color: ink }]}>
372 Issued by {APP_NAME} Financial. Use of this card is subject to the cardholder agreement.
373 </Text>
374 <NetworkMark id={network} color={ink} width={36} />
375 </View>
376 </CardFace>
377 </Animated.View>
378 </Animated.View>
379 );
380}
381
382// ─── A field whose label floats up on focus ─────────────────────────────────
383
384type FieldProps = {
385 label: string;
386 value: string;
387 onChangeText: (v: string) => void;
388 error?: string | null;
389 valid?: boolean;
390 trailing?: ReactNode;
391 onFocusChange?: (focused: boolean) => void;
392 inputRef?: Ref<ComponentRef<typeof TextInput>>;
393} & Omit<TextInputProps, 'value' | 'onChangeText'>;
394
395function Field({ label, value, onChangeText, error, valid, trailing, onFocusChange, inputRef, ...input }: FieldProps) {
396 const c = usePalette();
397 const [focused, setFocused] = useState(false);
398 const lift = useSharedValue(value ? 1 : 0);
399 const ring = useSharedValue(0);
400
401 useEffect(() => {
402 lift.value = withTiming(focused || value ? 1 : 0, { duration: 180, easing: Easing.out(Easing.cubic) });
403 ring.value = withTiming(focused ? 1 : 0, { duration: 180 });
404 }, [focused, value, lift, ring]);
405
406 const labelStyle = useAnimatedStyle(() => ({
407 transform: [{ translateY: interpolate(lift.value, [0, 1], [0, -11]) }, { scale: interpolate(lift.value, [0, 1], [1, 0.8]) }],
408 }));
409 const boxStyle = useAnimatedStyle(() => ({
410 borderColor: error ? c.error : interpolateColor(ring.value, [0, 1], [c.border, ACCENT]),
411 shadowOpacity: ring.value * 0.18,
412 }));
413 const focus = (on: boolean) => {
414 setFocused(on);
415 onFocusChange?.(on);
416 };
417
418 return (
419 <View style={styles.fieldSlot}>
420 <Animated.View style={[styles.field, { backgroundColor: c.field }, boxStyle]}>
421 <View style={styles.fieldBody}>
422 <Animated.Text pointerEvents="none" numberOfLines={1} style={[styles.fieldLabel, { color: error ? c.error : focused ? c.accentText : c.muted }, labelStyle]}>
423 {label}
424 </Animated.Text>
425 <TextInput
426 ref={inputRef}
427 {...input}
428 value={value}
429 onChangeText={onChangeText}
430 onFocus={() => focus(true)}
431 onBlur={() => focus(false)}
432 aria-label={label}
433 aria-invalid={!!error}
434 placeholderTextColor={c.faint}
435 selectionColor={ACCENT}
436 style={[styles.fieldInput, styles.tabular, { color: c.fg }, NO_OUTLINE]}
437 />
438 </View>
439 {trailing}
440 {valid && (
441 <Animated.View entering={ZoomIn.springify().damping(14)} style={styles.validTick} aria-label={`${label} is valid`}>
442 <Check size={13} color="#fff" strokeWidth={3} />
443 </Animated.View>
444 )}
445 </Animated.View>
446 {error ? (
447 <Animated.Text entering={FadeInDown.duration(180)} role="alert" style={[styles.fieldError, { color: c.error }]}>
448 {error}
449 </Animated.Text>
450 ) : null}
451 </View>
452 );
453}
454
455// ─── Small controls ─────────────────────────────────────────────────────────
456
457function PressableScale({ children, onPress, label, to = 0.96 }: { children: ReactNode; onPress?: () => void; label: string; to?: number }) {
458 const scale = useSharedValue(1);
459 const style = useAnimatedStyle(() => ({ transform: [{ scale: scale.value }] }));
460 return (
461 <Pressable role="button" aria-label={label} onPress={onPress} onPressIn={() => (scale.value = withSpring(to, PRESS))} onPressOut={() => (scale.value = withSpring(1, PRESS))}>
462 <Animated.View style={style}>{children}</Animated.View>
463 </Pressable>
464 );
465}
466
467function Toggle({ on, pal }: { on: boolean; pal: Palette }) {
468 const t = useSharedValue(on ? 1 : 0);
469 useEffect(() => {
470 t.value = withSpring(on ? 1 : 0, { damping: 18, stiffness: 300, mass: 0.6 });
471 }, [on, t]);
472 const track = useAnimatedStyle(() => ({ backgroundColor: interpolateColor(t.value, [0, 1], [pal.track, ACCENT]) }));
473 const thumb = useAnimatedStyle(() => ({ transform: [{ translateX: t.value * 20 }] }));
474 return (
475 <Animated.View style={[styles.toggle, track]}>
476 <Animated.View style={[styles.toggleThumb, thumb]} />
477 </Animated.View>
478 );
479}
480
481function Spinner() {
482 const r = useSharedValue(0);
483 useEffect(() => {
484 r.value = withRepeat(withTiming(360, { duration: 750, easing: Easing.linear }), -1);
485 return () => cancelAnimation(r);
486 }, [r]);
487 const style = useAnimatedStyle(() => ({ transform: [{ rotate: `${r.value}deg` }] }));
488 return <Animated.View style={[styles.spinner, style]} />;
489}
490
491// ─── Save button: the pill closes to a circle, spins, then turns to a check ─
492
493type Status = 'idle' | 'loading' | 'done';
494
495function SaveButton({ status, onPress }: { status: Status; onPress: () => void }) {
496 const [width, setWidth] = useState(0);
497 const morph = useSharedValue(0);
498 const scale = useSharedValue(1);
499 useEffect(() => {
500 morph.value = withTiming(status === 'idle' ? 0 : 1, { duration: 340, easing: Easing.inOut(Easing.cubic) });
501 }, [status, morph]);
502 const pill = useAnimatedStyle(() => ({
503 ...(width > 0 ? { width: interpolate(morph.value, [0, 1], [width, BUTTON_H]), alignSelf: 'center' as const } : null),
504 transform: [{ scale: scale.value }],
505 }));
506 return (
507 <Pressable
508 role="button"
509 aria-label="Save card"
510 aria-busy={status === 'loading'}
511 disabled={status !== 'idle'}
512 onPress={onPress}
513 onPressIn={() => (scale.value = withSpring(0.97, PRESS))}
514 onPressOut={() => (scale.value = withSpring(1, PRESS))}
515 onLayout={(e: LayoutChangeEvent) => setWidth(e.nativeEvent.layout.width)}
516 style={styles.saveSlot}
517 >
518 <Animated.View style={[styles.save, status === 'done' ? styles.saveDone : styles.saveIdle, pill]}>
519 {status === 'idle' && (
520 <Animated.Text entering={FadeIn.duration(160)} numberOfLines={1} style={styles.saveLabel}>
521 Save card
522 </Animated.Text>
523 )}
524 {status === 'loading' && <Spinner />}
525 {status === 'done' && (
526 <Animated.View entering={ZoomIn.springify().damping(11)}>
527 <Check size={26} color="#fff" strokeWidth={3} />
528 </Animated.View>
529 )}
530 </Animated.View>
531 </Pressable>
532 );
533}
534
535// ─── Scan sheet: a simulated camera frame with brackets and a scanning line ─
536
537const FRAME_W = 268;
538const FRAME_H = 170;
539const CORNERS = ['cornerTL', 'cornerTR', 'cornerBL', 'cornerBR'] as const;
540
541function ScanSheet({ open, onClose, onFound, pal, bottom }: { open: boolean; onClose: () => void; onFound: () => void; pal: Palette; bottom: number }) {
542 const [mounted, setMounted] = useState(false);
543 const [found, setFound] = useState(false);
544 const t = useSharedValue(0);
545 const line = useSharedValue(0);
546 const pulse = useSharedValue(0);
547 const done = useRef(onFound);
548 done.current = onFound;
549
550 useEffect(() => {
551 if (!open) {
552 t.value = withTiming(0, { duration: 240, easing: Easing.in(Easing.cubic) });
553 const id = setTimeout(() => setMounted(false), 260);
554 return () => clearTimeout(id);
555 }
556 setMounted(true);
557 setFound(false);
558 t.value = withTiming(1, { duration: 340, easing: Easing.out(Easing.cubic) });
559 line.value = 0;
560 line.value = withRepeat(withTiming(1, { duration: 1000, easing: Easing.inOut(Easing.quad) }), -1, true);
561 pulse.value = 0;
562 pulse.value = withRepeat(withTiming(1, { duration: 700, easing: Easing.inOut(Easing.quad) }), -1, true);
563 // There is no camera here: after two seconds the scan "finds" the sample card.
564 const a = setTimeout(() => {
565 setFound(true);
566 cancelAnimation(pulse);
567 pulse.value = withSpring(-1.4, POP);
568 }, 2000);
569 const b = setTimeout(() => done.current(), 2650);
570 return () => {
571 clearTimeout(a);
572 clearTimeout(b);
573 };
574 }, [open, t, line, pulse]);
575
576 const backdrop = useAnimatedStyle(() => ({ opacity: t.value }));
577 const sheet = useAnimatedStyle(() => ({ transform: [{ translateY: (1 - t.value) * 520 }] }));
578 const frame = useAnimatedStyle(() => ({ transform: [{ scale: 1 + pulse.value * 0.028 }] }));
579 const beam = useAnimatedStyle(() => ({ transform: [{ translateY: line.value * (FRAME_H - 44) }] }));
580
581 if (!mounted) return null;
582 return (
583 <View style={StyleSheet.absoluteFill} pointerEvents={open ? 'auto' : 'none'}>
584 <Animated.View style={[StyleSheet.absoluteFill, { backgroundColor: pal.backdrop }, backdrop]}>
585 <Pressable aria-label="Close scanner" onPress={onClose} style={styles.fill} />
586 </Animated.View>
587 <Animated.View role="dialog" aria-label="Scan card" style={[styles.sheet, { backgroundColor: pal.surface, paddingBottom: bottom + 12 }, sheet]}>
588 <View style={[styles.grabber, { backgroundColor: pal.track }]} />
589 <View style={styles.sheetHead}>
590 <View style={styles.sheetTitles}>
591 <Text style={[styles.sheetTitle, { color: pal.fg }]}>Scan card</Text>
592 <Text style={[styles.sheetSub, { color: found ? pal.fg : pal.muted }]}>{found ? 'Card found. Filling in the details.' : 'Hold the front of your card inside the frame.'}</Text>
593 </View>
594 <PressableScale label="Close" onPress={onClose} to={0.9}>
595 <View style={[styles.round, { backgroundColor: pal.bg }]}>
596 <X size={18} color={pal.fg} strokeWidth={2.2} />
597 </View>
598 </PressableScale>
599 </View>
600
601 <View style={styles.camera}>
602 <LinearGradient colors={['#26262B', '#0B0B0D']} start={{ x: 0.2, y: 0 }} end={{ x: 0.8, y: 1 }} style={StyleSheet.absoluteFill} />
603 {/* What the "camera" sees: a card lying on a table, slightly off axis. */}
604 <View style={styles.ghost}>
605 <View style={styles.ghostChip} />
606 <View style={styles.ghostNumber}>
607 {[0, 1, 2, 3].map((i) => (
608 <View key={i} style={styles.ghostGroup} />
609 ))}
610 </View>
611 <View style={styles.ghostName} />
612 </View>
613 <Animated.View style={[styles.frame, frame]}>
614 {CORNERS.map((k) => (
615 <View key={k} style={[styles.corner, styles[k], found ? styles.cornerFound : styles.cornerIdle]} />
616 ))}
617 {!found && (
618 <Animated.View style={[styles.beam, beam]}>
619 <LinearGradient colors={[tint(ACCENT, 0), tint(ACCENT, 0.28)]} style={styles.beamTrail} />
620 <View style={styles.beamLine} />
621 </Animated.View>
622 )}
623 </Animated.View>
624 {found && (
625 <Animated.View entering={ZoomIn.springify().damping(11)} style={styles.foundBadge}>
626 <Check size={26} color="#fff" strokeWidth={3} />
627 </Animated.View>
628 )}
629 </View>
630
631 <Pressable role="button" aria-label="Enter details manually" onPress={onClose} style={({ pressed }) => [styles.manual, { opacity: pressed ? 0.55 : 1 }]}>
632 <Text style={[styles.manualLabel, { color: pal.accentText }]}>Enter details manually</Text>
633 </Pressable>
634 </Animated.View>
635 </View>
636 );
637}
638
639// ─── Success: the new card drops into the wallet behind the others ──────────
640
641function MiniCard({ network, last4, style }: { network: NetworkId; last4: string; style?: object }) {
642 const ink = NETWORKS[network].ink;
643 return (
644 <Animated.View style={[styles.mini, style]}>
645 <LinearGradient colors={NETWORKS[network].colors} start={{ x: 0, y: 0 }} end={{ x: 1, y: 1 }} style={StyleSheet.absoluteFill} />
646 {last4 ? (
647 <View style={styles.miniRow}>
648 <Text style={[styles.miniNumber, styles.tabular, { color: ink }]}>•••• {last4}</Text>
649 <NetworkMark id={network} color={ink} width={30} />
650 </View>
651 ) : null}
652 </Animated.View>
653 );
654}
655
656function Success({ network, last4, isDefault, onDone, pal, top, bottom }: { network: NetworkId; last4: string; isDefault: boolean; onDone: () => void; pal: Palette; top: number; bottom: number }) {
657 const t = useSharedValue(0);
658 useEffect(() => {
659 t.value = withDelay(260, withSpring(1, { damping: 15, stiffness: 110, mass: 0.9 }));
660 }, [t]);
661 const drop = useAnimatedStyle(() => ({
662 opacity: Math.min(1, t.value * 3),
663 transform: [{ translateY: (1 - t.value) * -190 }, { rotate: `${(1 - t.value) * -12}deg` }, { scale: 1 + (1 - t.value) * 0.12 }],
664 }));
665 return (
666 <Animated.View entering={FadeIn.duration(260)} role="alert" style={[StyleSheet.absoluteFill, styles.success, { backgroundColor: pal.bg, paddingTop: top, paddingBottom: bottom + 8 }]}>
667 <View style={styles.successBody}>
668 <View style={styles.wallet}>
669 <MiniCard network="none" last4="" style={styles.miniBack} />
670 <MiniCard network={network === 'tern' ? 'kite' : 'tern'} last4="" style={styles.miniMid} />
671 <MiniCard network={network} last4={last4} style={[styles.miniNew, drop]} />
672 <View style={[styles.pocket, { backgroundColor: pal.surface, borderColor: pal.border }]}>
673 <View style={[styles.stitch, { borderColor: pal.faint }]} />
674 <View style={styles.pocketTag}>
675 <Text style={styles.pocketTagLabel}>{APP_NAME}</Text>
676 </View>
677 </View>
678 <Animated.View entering={ZoomIn.delay(820).springify().damping(11)} style={[styles.successBadge, { borderColor: pal.bg }]}>
679 <Check size={20} color="#fff" strokeWidth={3.2} />
680 </Animated.View>
681 </View>
682 <Animated.Text entering={FadeInDown.delay(420).duration(380)} style={[styles.successTitle, { color: pal.fg }]}>
683 Card added
684 </Animated.Text>
685 <Animated.Text entering={FadeInDown.delay(500).duration(380)} style={[styles.successSub, { color: pal.muted }]}>
686 Your {NETWORKS[network].name} card ending in {last4} is in your wallet{isDefault ? ' and set as your default payment method.' : '.'}
687 </Animated.Text>
688 </View>
689 <Animated.View entering={FadeInDown.delay(620).duration(380)} style={styles.successActions}>
690 <PressableScale label="Done" onPress={onDone} to={0.97}>
691 <View style={[styles.save, styles.saveIdle]}>
692 <Text style={styles.saveLabel}>Done</Text>
693 </View>
694 </PressableScale>
695 <Pressable role="button" aria-label="Add another card" onPress={onDone} style={({ pressed }) => [styles.manual, { opacity: pressed ? 0.55 : 1 }]}>
696 <Text style={[styles.manualLabel, { color: pal.fg }]}>Add another card</Text>
697 </Pressable>
698 </Animated.View>
699 </Animated.View>
700 );
701}
702
703// ─── Screen ─────────────────────────────────────────────────────────────────
704
705const EMPTY: Values = { number: '', name: '', expiry: '', cvv: '', zip: '' };
706
707export default function AddCardScreen() {
708 const c = usePalette();
709 const insets = useSafeAreaInsets();
710 const { width } = useWindowDimensions();
711 const [values, setValues] = useState<Values>({ ...EMPTY, ...PREFILL });
712 const [errors, setErrors] = useState<Partial<Record<FieldKey, string>>>({});
713 const [flipped, setFlipped] = useState(false);
714 const [isDefault, setIsDefault] = useState(true);
715 const [scanning, setScanning] = useState(false);
716 const [status, setStatus] = useState<Status>('idle');
717 const [added, setAdded] = useState(false);
718 const timers = useRef<ReturnType<typeof setTimeout>[]>([]);
719 const refs = {
720 name: useRef<ComponentRef<typeof TextInput>>(null),
721 expiry: useRef<ComponentRef<typeof TextInput>>(null),
722 cvv: useRef<ComponentRef<typeof TextInput>>(null),
723 zip: useRef<ComponentRef<typeof TextInput>>(null),
724 };
725 const shake = useSharedValue(0);
726 const bump = useSharedValue(0);
727 const shakeStyle = useAnimatedStyle(() => ({ transform: [{ translateX: shake.value }] }));
728
729 useEffect(() => () => timers.current.forEach(clearTimeout), []);
730
731 const digits = digitsOf(values.number);
732 const network = detect(digits);
733 const cvvLength = NETWORKS[network].cvv;
734 const later = (fn: () => void, ms: number) => timers.current.push(setTimeout(fn, ms));
735
736 const set = (key: FieldKey, v: string) => {
737 setValues((s) => ({ ...s, [key]: v }));
738 if (errors[key]) setErrors((e) => ({ ...e, [key]: undefined }));
739 };
740 // Leaving a field that has something in it checks just that field.
741 const blur = (key: FieldKey) => (focused: boolean) => {
742 if (key === 'cvv') setFlipped(focused);
743 if (focused || !values[key]) return;
744 const message = check(key, values);
745 if (message) setErrors((e) => ({ ...e, [key]: message }));
746 };
747
748 const submit = () => {
749 const found: Partial<Record<FieldKey, string>> = {};
750 (Object.keys(EMPTY) as FieldKey[]).forEach((key) => {
751 const message = check(key, values);
752 if (message) found[key] = message;
753 });
754 setErrors(found);
755 if (Object.keys(found).length) {
756 shake.value = withSequence(
757 withTiming(-9, { duration: 50 }),
758 withTiming(9, { duration: 60 }),
759 withTiming(-6, { duration: 60 }),
760 withTiming(6, { duration: 60 }),
761 withTiming(0, { duration: 50 })
762 );
763 return;
764 }
765 setStatus('loading');
766 // Replace with the call to your payment provider.
767 later(() => setStatus('done'), 1400);
768 later(() => setAdded(true), 2150);
769 };
770
771 // The scan result types itself in, so every digit pops onto the card in turn.
772 const fillFromScan = () => {
773 setScanning(false);
774 setErrors({});
775 setValues((s) => ({ ...EMPTY, zip: s.zip }));
776 for (let i = 1; i <= 16; i++) {
777 later(() => setValues((s) => ({ ...s, number: formatNumber(SCANNED.number.slice(0, i)) })), 300 + i * 42);
778 }
779 later(() => setValues((s) => ({ ...s, name: SCANNED.name, expiry: SCANNED.expiry })), 300 + 17 * 42);
780 bump.value = withDelay(280, withSequence(withTiming(1, { duration: 240, easing: Easing.out(Easing.cubic) }), withTiming(0, { duration: 620, easing: Easing.out(Easing.back(2.4)) })));
781 };
782
783 const reset = () => {
784 setValues(EMPTY);
785 setErrors({});
786 setStatus('idle');
787 setAdded(false);
788 };
789
790 const enter = (i: number) => FadeInDown.delay(60 + i * 60).duration(440);
791
792 return (
793 <KeyboardAvoidingView behavior={Platform.OS === 'ios' ? 'padding' : undefined} style={[styles.screen, { backgroundColor: c.bg }]}>
794 <View style={[styles.header, { marginTop: insets.top }]}>
795 <PressableScale label="Back" to={0.9}>
796 <View style={[styles.round, { backgroundColor: c.surface }]}>
797 <ChevronLeft size={22} color={c.fg} strokeWidth={2.2} />
798 </View>
799 </PressableScale>
800 <Text style={[styles.title, { color: c.fg }]}>Add card</Text>
801 <View style={styles.headerSpacer} />
802 </View>
803
804 <ScrollView keyboardShouldPersistTaps="handled" showsVerticalScrollIndicator={false} contentContainerStyle={styles.content}>
805 <Animated.View entering={enter(0)}>
806 <CardPreview values={values} network={network} flipped={flipped} width={width - 40} bump={bump} />
807 </Animated.View>
808
809 <Animated.View entering={enter(1)} style={styles.scanSlot}>
810 <PressableScale label="Scan card" onPress={() => setScanning(true)} to={0.97}>
811 <View style={[styles.scan, { backgroundColor: c.accentTint }]}>
812 <ScanLine size={18} color={c.accentText} strokeWidth={2.2} />
813 <Text style={[styles.scanLabel, { color: c.accentText }]}>Scan card</Text>
814 </View>
815 </PressableScale>
816 </Animated.View>
817
818 <Animated.View entering={enter(2)}>
819 <Animated.View style={[styles.form, shakeStyle]}>
820 <Field
821 label="Card number"
822 value={values.number}
823 onChangeText={(v) => set('number', formatNumber(v))}
824 onFocusChange={blur('number')}
825 error={errors.number}
826 valid={luhn(digits)}
827 trailing={
828 network !== 'none' ? (
829 <Animated.View key={network} entering={ZoomIn.springify().damping(13)} style={[styles.fieldMark, { borderColor: c.border }]}>
830 <NetworkMark id={network} color={c.fg} width={26} />
831 </Animated.View>
832 ) : null
833 }
834 keyboardType="number-pad"
835 inputMode="numeric"
836 autoComplete="cc-number"
837 maxLength={19}
838 returnKeyType="next"
839 onSubmitEditing={() => refs.name.current?.focus()}
840 />
841 <Field
842 inputRef={refs.name}
843 label="Name on card"
844 value={values.name}
845 onChangeText={(v) => set('name', v.replace(/[^\p{L} .'-]/gu, '').slice(0, 26))}
846 onFocusChange={blur('name')}
847 error={errors.name}
848 autoCapitalize="words"
849 autoComplete="cc-name"
850 returnKeyType="next"
851 onSubmitEditing={() => refs.expiry.current?.focus()}
852 />
853 <View style={styles.formRow}>
854 <Field
855 inputRef={refs.expiry}
856 label="Expiry"
857 value={values.expiry}
858 onChangeText={(v) => set('expiry', formatExpiry(v, values.expiry))}
859 onFocusChange={blur('expiry')}
860 error={errors.expiry}
861 keyboardType="number-pad"
862 inputMode="numeric"
863 autoComplete="cc-exp"
864 maxLength={5}
865 />
866 <Field
867 inputRef={refs.cvv}
868 label="CVV"
869 value={values.cvv}
870 onChangeText={(v) => set('cvv', digitsOf(v).slice(0, cvvLength))}
871 onFocusChange={blur('cvv')}
872 error={errors.cvv}
873 keyboardType="number-pad"
874 inputMode="numeric"
875 autoComplete="cc-csc"
876 maxLength={cvvLength}
877 />
878 <Field
879 inputRef={refs.zip}
880 label="ZIP"
881 value={values.zip}
882 onChangeText={(v) => set('zip', digitsOf(v).slice(0, 5))}
883 onFocusChange={blur('zip')}
884 error={errors.zip}
885 keyboardType="number-pad"
886 inputMode="numeric"
887 autoComplete="postal-code"
888 maxLength={5}
889 returnKeyType="done"
890 />
891 </View>
892 </Animated.View>
893 </Animated.View>
894
895 <Animated.View entering={enter(3)}>
896 <Pressable
897 role="switch"
898 aria-checked={isDefault}
899 aria-label="Set as default payment method"
900 onPress={() => setIsDefault((v) => !v)}
901 style={[styles.defaultRow, { backgroundColor: c.surface }]}
902 >
903 <View style={styles.defaultText}>
904 <Text style={[styles.defaultTitle, { color: c.fg }]}>Set as default payment method</Text>
905 <Text style={[styles.defaultSub, { color: c.muted }]}>Used first for payments and top ups</Text>
906 </View>
907 <Toggle on={isDefault} pal={c} />
908 </Pressable>
909 </Animated.View>
910
911 <Animated.View entering={enter(4)} style={styles.secure}>
912 <Lock size={14} color={c.muted} strokeWidth={2.2} />
913 <Text style={[styles.secureText, { color: c.muted }]}>Your card details are encrypted</Text>
914 <View style={styles.accepted} aria-label="Accepted networks">
915 {ACCEPTED.map((id) => (
916 <View key={id} style={[styles.acceptedMark, { borderColor: c.border, backgroundColor: c.surface }]}>
917 <NetworkMark id={id} color={c.muted} width={22} />
918 </View>
919 ))}
920 </View>
921 </Animated.View>
922 </ScrollView>
923
924 {/* Opaque bar, so the form never shows through it */}
925 <View style={[styles.bar, { backgroundColor: c.bg, borderTopColor: c.border, paddingBottom: insets.bottom + 8 }]}>
926 <SaveButton status={status} onPress={submit} />
927 </View>
928
929 <ScanSheet open={scanning} onClose={() => setScanning(false)} onFound={fillFromScan} pal={c} bottom={insets.bottom} />
930 {added && <Success network={network} last4={digits.slice(-4)} isDefault={isDefault} onDone={reset} pal={c} top={insets.top} bottom={insets.bottom} />}
931 </KeyboardAvoidingView>
932 );
933}
934
935// ─── Styles ─────────────────────────────────────────────────────────────────
936
937const styles = StyleSheet.create({
938 screen: { flex: 1, overflow: 'hidden' },
939 fill: { flex: 1 },
940 tabular: { fontVariant: ['tabular-nums'] },
941 content: { paddingHorizontal: 20, paddingTop: 4, paddingBottom: 16 },
942
943 // Header
944 header: { height: 48, flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', paddingHorizontal: 16 },
945 round: { width: 40, height: 40, borderRadius: 20, alignItems: 'center', justifyContent: 'center' },
946 title: { fontSize: 17, fontWeight: '600', letterSpacing: -0.2 },
947 headerSpacer: { width: 40 },
948
949 // Card preview
950 cardWrap: { height: CARD_H },
951 cardFace: {
952 height: CARD_H,
953 borderRadius: 24,
954 shadowColor: '#000',
955 shadowOpacity: 0.22,
956 shadowRadius: 22,
957 shadowOffset: { width: 0, height: 14 },
958 },
959 cardClip: { flex: 1, borderRadius: 24, overflow: 'hidden', borderTopWidth: 1 },
960 cardGlow: { position: 'absolute', top: -120, right: -80, width: 280, height: 280, borderRadius: 140, backgroundColor: 'rgba(255,255,255,0.10)' },
961 sheen: { position: 'absolute', top: -80, bottom: -80, left: 0, width: 120 },
962 cardBody: { flex: 1, padding: 22, justifyContent: 'space-between' },
963 cardRow: { flexDirection: 'row', alignItems: 'flex-end', justifyContent: 'space-between' },
964 cardBrand: { fontSize: 18, fontWeight: '700', letterSpacing: -0.4 },
965 chip: { width: 44, height: 32, borderRadius: 7, overflow: 'hidden' },
966 cardNumber: { flexDirection: 'row', alignItems: 'center', height: 28 },
967 cardGroupEnd: { marginRight: 16 },
968 cardDigit: { width: 14.5, textAlign: 'center', fontSize: 22, lineHeight: 28, fontWeight: '600', fontVariant: ['tabular-nums'] },
969 cardDot: { fontSize: 20 },
970 cardHolder: { flex: 1, paddingRight: 12 },
971 cardExpiry: { width: 76 },
972 cardCaption: { fontSize: 10, fontWeight: '600', letterSpacing: 1.2, textTransform: 'uppercase', opacity: 0.6 },
973 cardValue: { marginTop: 3, fontSize: 14.5, fontWeight: '600', letterSpacing: 0.6 },
974 cardMark: { width: 44, height: 28, alignItems: 'flex-end', justifyContent: 'flex-end' },
975
976 // Card back
977 magStripe: { marginTop: 26, height: 42, backgroundColor: 'rgba(10,10,12,0.88)' },
978 backRow: { marginTop: 20, marginHorizontal: 22, flexDirection: 'row', height: 40 },
979 signature: { flex: 1, backgroundColor: '#EFEBE2', borderTopLeftRadius: 6, borderBottomLeftRadius: 6, justifyContent: 'center', paddingLeft: 8 },
980 cvvBox: { width: 76, backgroundColor: '#FFFFFF', borderTopRightRadius: 6, borderBottomRightRadius: 6, alignItems: 'center', justifyContent: 'center' },
981 cvvText: { color: INK, fontSize: 17, fontWeight: '700', letterSpacing: 3, fontStyle: 'italic' },
982 cvvCaption: { marginTop: 6, marginRight: 22, textAlign: 'right', fontSize: 10, fontWeight: '600', letterSpacing: 1.2, textTransform: 'uppercase', opacity: 0.6 },
983 backFoot: { position: 'absolute', left: 22, right: 22, bottom: 20, flexDirection: 'row', alignItems: 'flex-end', justifyContent: 'space-between', gap: 24 },
984 backPrint: { flex: 1, fontSize: 9.5, lineHeight: 13, opacity: 0.55 },
985
986 // Scan button
987 scanSlot: { marginTop: 14 },
988 scan: { height: 46, borderRadius: 16, flexDirection: 'row', alignItems: 'center', justifyContent: 'center', gap: 8 },
989 scanLabel: { fontSize: 15, fontWeight: '600' },
990
991 // Form
992 form: { marginTop: 14, gap: 12 },
993 formRow: { flexDirection: 'row', gap: 10, alignItems: 'flex-start' },
994 fieldSlot: { flex: 1, minWidth: 0 },
995 field: {
996 height: 60,
997 borderRadius: 16,
998 borderWidth: 1.5,
999 paddingHorizontal: 14,
1000 flexDirection: 'row',
1001 alignItems: 'center',
1002 gap: 8,
1003 shadowColor: ACCENT,
1004 shadowRadius: 10,
1005 shadowOffset: { width: 0, height: 0 },
1006 },
1007 fieldBody: { flex: 1, minWidth: 0, height: '100%', justifyContent: 'center' },
1008 fieldLabel: { position: 'absolute', left: 0, fontSize: 16, transformOrigin: 'left center' },
1009 fieldInput: { paddingTop: 18, height: '100%', width: '100%', fontSize: 16, minWidth: 0 },
1010 fieldError: { fontSize: 12.5, marginTop: 6, marginLeft: 4 },
1011 fieldMark: { width: 38, height: 26, borderRadius: 7, borderWidth: 1, alignItems: 'center', justifyContent: 'center' },
1012 validTick: { width: 22, height: 22, borderRadius: 11, backgroundColor: SUCCESS, alignItems: 'center', justifyContent: 'center' },
1013
1014 // Default switch
1015 defaultRow: { marginTop: 12, minHeight: 64, borderRadius: 16, paddingHorizontal: 14, flexDirection: 'row', alignItems: 'center', gap: 12 },
1016 defaultText: { flex: 1 },
1017 defaultTitle: { fontSize: 15, fontWeight: '600', letterSpacing: -0.1 },
1018 defaultSub: { marginTop: 2, fontSize: 13 },
1019 toggle: { width: 50, height: 30, borderRadius: 15, padding: 3 },
1020 toggleThumb: {
1021 width: 24,
1022 height: 24,
1023 borderRadius: 12,
1024 backgroundColor: '#FFFFFF',
1025 shadowColor: '#000',
1026 shadowOpacity: 0.2,
1027 shadowRadius: 3,
1028 shadowOffset: { width: 0, height: 1 },
1029 },
1030
1031 // Security footer
1032 secure: { marginTop: 16, flexDirection: 'row', alignItems: 'center', gap: 6, paddingHorizontal: 2 },
1033 secureText: { flex: 1, fontSize: 12.5 },
1034 accepted: { flexDirection: 'row', gap: 6 },
1035 acceptedMark: { width: 34, height: 22, borderRadius: 6, borderWidth: 1, alignItems: 'center', justifyContent: 'center' },
1036
1037 // Bottom bar and save button
1038 bar: { paddingHorizontal: 20, paddingTop: 12, borderTopWidth: StyleSheet.hairlineWidth },
1039 saveSlot: { alignItems: 'stretch' },
1040 save: { height: BUTTON_H, borderRadius: BUTTON_H / 2, alignSelf: 'stretch', minWidth: BUTTON_H, alignItems: 'center', justifyContent: 'center', borderTopWidth: 1, borderTopColor: 'rgba(255,255,255,0.3)' },
1041 // A shadow's props stay together in one style object: React Native Web builds the shadow per object.
1042 saveIdle: { backgroundColor: ACCENT, shadowColor: ACCENT, shadowOpacity: 0.32, shadowRadius: 16, shadowOffset: { width: 0, height: 8 } },
1043 saveDone: { backgroundColor: SUCCESS, shadowColor: SUCCESS, shadowOpacity: 0.32, shadowRadius: 16, shadowOffset: { width: 0, height: 8 } },
1044 saveLabel: { color: ON_ACCENT, fontSize: 17, fontWeight: '700', letterSpacing: -0.2 },
1045 spinner: { width: 22, height: 22, borderRadius: 11, borderWidth: 2.5, borderColor: tint(ON_ACCENT, 0.2), borderTopColor: ON_ACCENT },
1046
1047 // Scan sheet
1048 sheet: { position: 'absolute', left: 0, right: 0, bottom: 0, borderTopLeftRadius: 28, borderTopRightRadius: 28, paddingHorizontal: 20, paddingTop: 10 },
1049 grabber: { alignSelf: 'center', width: 40, height: 5, borderRadius: 3 },
1050 sheetHead: { marginTop: 14, flexDirection: 'row', alignItems: 'flex-start', gap: 12 },
1051 sheetTitles: { flex: 1 },
1052 sheetTitle: { fontSize: 22, fontWeight: '700', letterSpacing: -0.5 },
1053 sheetSub: { marginTop: 4, fontSize: 14.5, lineHeight: 20 },
1054 camera: { marginTop: 18, height: 236, borderRadius: 22, overflow: 'hidden', alignItems: 'center', justifyContent: 'center' },
1055 ghost: {
1056 position: 'absolute',
1057 width: 236,
1058 height: 148,
1059 borderRadius: 14,
1060 padding: 16,
1061 justifyContent: 'space-between',
1062 backgroundColor: 'rgba(255,255,255,0.09)',
1063 borderWidth: 1,
1064 borderColor: 'rgba(255,255,255,0.14)',
1065 transform: [{ rotate: '-3deg' }],
1066 },
1067 ghostChip: { marginTop: 22, width: 32, height: 24, borderRadius: 5, backgroundColor: 'rgba(255,255,255,0.2)' },
1068 ghostNumber: { flexDirection: 'row', gap: 10 },
1069 ghostGroup: { width: 40, height: 9, borderRadius: 4.5, backgroundColor: 'rgba(255,255,255,0.24)' },
1070 ghostName: { width: 92, height: 7, borderRadius: 3.5, backgroundColor: 'rgba(255,255,255,0.16)' },
1071 frame: { width: FRAME_W, height: FRAME_H },
1072 corner: { position: 'absolute', width: 30, height: 30 },
1073 cornerIdle: { borderColor: '#FFFFFF' },
1074 cornerFound: { borderColor: '#4ADE80' },
1075 cornerTL: { top: 0, left: 0, borderTopWidth: 3.5, borderLeftWidth: 3.5, borderTopLeftRadius: 14 },
1076 cornerTR: { top: 0, right: 0, borderTopWidth: 3.5, borderRightWidth: 3.5, borderTopRightRadius: 14 },
1077 cornerBL: { bottom: 0, left: 0, borderBottomWidth: 3.5, borderLeftWidth: 3.5, borderBottomLeftRadius: 14 },
1078 cornerBR: { bottom: 0, right: 0, borderBottomWidth: 3.5, borderRightWidth: 3.5, borderBottomRightRadius: 14 },
1079 beam: { position: 'absolute', left: 12, right: 12, top: 0, height: 44, justifyContent: 'flex-end' },
1080 beamTrail: { height: 42 },
1081 beamLine: { height: 2.5, borderRadius: 2, backgroundColor: ACCENT, shadowColor: ACCENT, shadowOpacity: 0.9, shadowRadius: 8, shadowOffset: { width: 0, height: 0 } },
1082 foundBadge: { position: 'absolute', width: 56, height: 56, borderRadius: 28, backgroundColor: SUCCESS, alignItems: 'center', justifyContent: 'center' },
1083 manual: { marginTop: 6, height: 48, alignItems: 'center', justifyContent: 'center' },
1084 manualLabel: { fontSize: 15, fontWeight: '600' },
1085
1086 // Success
1087 success: { paddingHorizontal: 20 },
1088 successBody: { flex: 1, alignItems: 'center', justifyContent: 'center' },
1089 wallet: { width: 260, height: 214, transform: [{ scale: 1.12 }] },
1090 mini: { position: 'absolute', left: 30, width: 200, height: 126, borderRadius: 16, overflow: 'hidden' },
1091 miniBack: { top: 24, transform: [{ scale: 0.88 }] },
1092 miniMid: { top: 42, transform: [{ scale: 0.94 }] },
1093 miniNew: { top: 60 },
1094 miniRow: { padding: 14, flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between' },
1095 miniNumber: { fontSize: 14, fontWeight: '600', letterSpacing: 1 },
1096 pocket: { position: 'absolute', left: 12, right: 12, top: 110, bottom: 0, borderRadius: 26, borderWidth: 1, alignItems: 'center', justifyContent: 'center' },
1097 stitch: { position: 'absolute', top: 8, left: 8, right: 8, bottom: 8, borderRadius: 19, borderWidth: 1.5, borderStyle: 'dashed' },
1098 pocketTag: { height: 26, paddingHorizontal: 12, borderRadius: 13, backgroundColor: ACCENT, justifyContent: 'center' },
1099 pocketTagLabel: { color: ON_ACCENT, fontSize: 12.5, fontWeight: '700', letterSpacing: -0.1 },
1100 successBadge: { position: 'absolute', right: 0, top: 92, width: 42, height: 42, borderRadius: 21, borderWidth: 3, backgroundColor: SUCCESS, alignItems: 'center', justifyContent: 'center' },
1101 successTitle: { marginTop: 44, fontSize: 30, fontWeight: '700', letterSpacing: -0.8 },
1102 successSub: { marginTop: 8, fontSize: 16, lineHeight: 23, textAlign: 'center', maxWidth: 300 },
1103 successActions: { gap: 2 },
1104});

More screens like this.

All Finance