The moment after paying: a check that draws itself inside a disc with an expanding ring and a confetti burst (tap it to replay), an order number you can copy, a delivery tracker whose line fills to a pulsing current step, and an item row that expands in place into the full receipt above sticky track and continue buttons.

Details
1import { useEffect, useRef, useState, type ComponentRef, type ReactNode } from 'react';2import { Image, Platform, Pressable, StyleSheet, Text, View, useColorScheme, useWindowDimensions } from 'react-native';3import Animated, {4 cancelAnimation,5 Easing,6 FadeInDown,7 ZoomIn,8 interpolate,9 useAnimatedProps,10 useAnimatedScrollHandler,11 useAnimatedStyle,12 useSharedValue,13 withDelay,14 withRepeat,15 withSequence,16 withSpring,17 withTiming,18 type SharedValue,19} from 'react-native-reanimated';20import { LinearGradient } from 'expo-linear-gradient';21import { useSafeAreaInsets } from 'react-native-safe-area-context';22import Svg, { Circle, Path, Rect } from 'react-native-svg';23import { Check, ChevronDown, Copy, LifeBuoy, Mail, PackageSearch, Truck, Undo2, X, type LucideIcon } from 'lucide-react-native';2425// ─── Brand ──────────────────────────────────────────────────────────────────26// The store's accent. Every accent colour below derives from these, so changing them rebrands the screen.2728const ACCENT = '#17705A';29const ACCENT_DARK = '#5AD1A6'; // the accent on dark backgrounds30const ON_ACCENT = '#FFFFFF'; // text and icons on an accent fill3132/** `hex` at `alpha` opacity, as rgba(). */33function tint(hex: string, alpha: number) {34 const n = parseInt(hex.slice(1), 16);35 return `rgba(${(n >> 16) & 255}, ${(n >> 8) & 255}, ${n & 255}, ${alpha})`;36}3738/** `hex` mixed toward black (amount > 0) or white (amount < 0); amount from -1 to 1. */39function shade(hex: string, amount: number) {40 const n = parseInt(hex.slice(1), 16);41 const target = amount < 0 ? 255 : 0;42 const p = Math.abs(amount);43 const c = (v: number) => Math.round(v + (target - v) * p).toString(16).padStart(2, '0');44 return `#${c((n >> 16) & 255)}${c((n >> 8) & 255)}${c(n & 255)}`.toUpperCase();45}4647// ─── Sample data ────────────────────────────────────────────────────────────4849const photo = (id: string, w = 300) => `https://images.unsplash.com/photo-${id}?w=${w}&q=80&fit=crop`;5051const CUSTOMER = { firstName: 'Maya', email: 'maya.patel@example.com' };52const ORDER_NUMBER = 'HC-48213';53const PLACED = 'Placed Fri, Nov 27';5455// `aspect` is the photo's height / width; `focus` and `zoom` crop it to the product inside a square tile.56const ITEMS = [57 { id: 'derby', name: 'Weekend Derby', variant: 'Sage · EU 42', qty: 1, price: 159, image: photo('1560343090-f0409e92791a'), aspect: 1.25, zoom: 1.2, focus: { x: 0.53, y: 0.62 } },58 { id: 'pack', name: 'Canvas Pack', variant: 'Midnight · 18 L', qty: 1, price: 89, image: photo('1553062407-98eeb64c6a62'), aspect: 1.5, zoom: 1.75, focus: { x: 0.38, y: 0.39 } },59 { id: 'watch', name: 'Field Watch', variant: 'Chalk · 40 mm', qty: 2, price: 148, image: photo('1523275335684-37898b6baf30'), aspect: 0.727, zoom: 1.1, focus: { x: 0.48, y: 0.48 } },60];61type Item = (typeof ITEMS)[number];6263const ADDRESS = { tag: 'Home', name: 'Maya Patel', line1: '1428 Larkin St, Apt 3B', line2: 'San Francisco, CA 94109' };64const DELIVERY = { label: 'Express', arrives: 'Mon, Nov 30', price: 12, status: 'Express delivery · being packed now' };65const PAYMENT = { label: 'Card ending 4242', detail: 'Charged today at 9:41 AM' };66const TAX_RATE = 0.0825;6768const STEPS = ['Confirmed', 'Packed', 'Shipped', 'Delivered'];69const CURRENT_STEP = 1; // Confirmed is done, packing is under way.7071const NEXT_STEPS: { icon: LucideIcon; title: string; body: string }[] = [72 { icon: Mail, title: 'Receipt by email', body: `On its way to ${CUSTOMER.email}` },73 { icon: PackageSearch, title: 'Tracking link when it ships', body: 'We will email and text it the moment your parcel leaves.' },74 { icon: Undo2, title: 'Free returns for 30 days', body: 'Send anything back by Dec 30, on us.' },75];7677const SUBTOTAL = ITEMS.reduce((s, i) => s + i.price * i.qty, 0);78const UNITS = ITEMS.reduce((s, i) => s + i.qty, 0);79const TAX = Math.round(SUBTOTAL * TAX_RATE * 100) / 100;80const TOTAL = SUBTOTAL + DELIVERY.price + TAX;8182// ─── Formatting ─────────────────────────────────────────────────────────────8384const money = (n: number) => `$${n.toFixed(2).replace(/\B(?=(\d{3})+(?!\d))/g, ',')}`;8586// ─── Palette ────────────────────────────────────────────────────────────────8788const PRESS = { damping: 16, stiffness: 300, mass: 0.6 };89const TABULAR = { fontVariant: ['tabular-nums' as const] };90const HEADER_H = 52;91const HERO_TOP = 16;92const HALO = 112;93const DISC = 80;94const BAR_BUTTON = 54;95// The payment card is drawn in the store's colour.96const CARD_ART = [shade(ACCENT, 0.47), shade(ACCENT, -0.08)] as const;9798function usePalette() {99 const dark = useColorScheme() === 'dark';100 return {101 dark,102 bg: dark ? '#0A0A0A' : '#FAFAF9',103 card: dark ? '#161616' : '#FFFFFF',104 field: dark ? '#0E0E0E' : '#FAFAF9',105 fg: dark ? '#FAFAFA' : '#0A0A0A',106 inverse: dark ? '#0A0A0A' : '#FAFAFA',107 muted: dark ? '#A1A1AA' : '#71717A',108 ring: dark ? '#4A4A50' : '#C9C9CF',109 track: dark ? '#2A2A2E' : '#E7E5E1',110 hairline: dark ? 'rgba(255,255,255,0.1)' : 'rgba(0,0,0,0.08)',111 skeleton: dark ? '#1C1C1E' : '#EFEEEC',112 shine: dark ? '#2A2A2E' : '#E2E0DC',113 accent: dark ? ACCENT_DARK : ACCENT,114 onAccent: dark ? shade(ACCENT, 0.64) : ON_ACCENT,115 tint: dark ? tint(ACCENT_DARK, 0.11) : tint(ACCENT, 0.07),116 confetti: dark ? [ACCENT_DARK, '#F5C456', '#F58D78', '#7DB5F5'] : [ACCENT, '#E9A91F', '#EC6F57', '#4C93E6'],117 mapLand: dark ? '#1B1E1D' : '#E8ECE2',118 mapRoad: dark ? '#2F3432' : '#FFFFFF',119 mapPark: dark ? '#1D3A2F' : '#D3E6D0',120 mapWater: dark ? '#16303F' : '#CDE2F1',121 };122}123type Palette = ReturnType<typeof usePalette>;124125// ─── Small pieces ───────────────────────────────────────────────────────────126127function Tap({ children, label, onPress, to = 0.92, expanded }: { children: ReactNode; label: string; onPress?: () => void; to?: number; expanded?: boolean }) {128 const scale = useSharedValue(1);129 const style = useAnimatedStyle(() => ({ transform: [{ scale: scale.value }] }));130 return (131 <Pressable132 role="button"133 aria-label={label}134 aria-expanded={expanded}135 onPress={onPress}136 hitSlop={8}137 onPressIn={() => (scale.value = withSpring(to, PRESS))}138 onPressOut={() => (scale.value = withSpring(1, PRESS))}139 >140 <Animated.View style={style}>{children}</Animated.View>141 </Pressable>142 );143}144145/** A square product photo that pulses as a placeholder, then fades in once it has loaded. */146function Photo({ item, size, radius, pal }: { item: Item; size: number; radius: number; pal: Palette }) {147 const shown = useSharedValue(0);148 const pulse = useSharedValue(0.4);149 useEffect(() => {150 pulse.value = withRepeat(withSequence(withTiming(1, { duration: 700 }), withTiming(0.4, { duration: 700 })), -1);151 return () => cancelAnimation(pulse);152 }, [pulse]);153 const image = useAnimatedStyle(() => ({ opacity: shown.value }));154 const placeholder = useAnimatedStyle(() => ({ opacity: (1 - shown.value) * pulse.value }));155 // Lay the photo out larger than the tile and slide it so the focus point sits in the middle.156 const w = size * Math.max(1, 1 / item.aspect) * item.zoom;157 const h = w * item.aspect;158 const left = Math.min(0, Math.max(size - w, size / 2 - item.focus.x * w));159 const top = Math.min(0, Math.max(size - h, size / 2 - item.focus.y * h));160 return (161 <View style={[styles.photo, { width: size, height: size, borderRadius: radius, backgroundColor: pal.skeleton }]}>162 <Animated.View style={[StyleSheet.absoluteFill, { backgroundColor: pal.shine }, placeholder]} />163 <Animated.View style={[styles.photoFrame, { left, top, width: w, height: h }, image]}>164 <Image165 source={{ uri: item.image }}166 alt={item.name}167 resizeMode="cover"168 style={styles.photoImage}169 onLoad={() => {170 cancelAnimation(pulse);171 shown.value = withTiming(1, { duration: 320 });172 }}173 />174 </Animated.View>175 </View>176 );177}178179function QtyBadge({ qty, pal }: { qty: number; pal: Palette }) {180 return (181 <View style={[styles.qty, { backgroundColor: pal.fg, borderColor: pal.card }]}>182 <Text style={[styles.qtyLabel, { color: pal.inverse }, TABULAR]}>{qty}</Text>183 </View>184 );185}186187function Card({ children, pal, padded = true }: { children: ReactNode; pal: Palette; padded?: boolean }) {188 return <View style={[styles.card, { borderColor: pal.hairline, backgroundColor: pal.card, padding: padded ? 14 : 0 }]}>{children}</View>;189}190191// ─── Celebration: one clock drives the disc, the check, the ring and the confetti ───192193const CELEBRATION_MS = 1100;194const CHECK_PATH = 'M11.5 20.5 L17.5 26.5 L29 13.5';195const CHECK_LENGTH = 26;196const CHECK_STROKE = 3.4;197198/** Where `t` sits inside a slice of the timeline, from 0 to 1. */199function slice(t: number, from: number, to: number) {200 'worklet';201 return Math.min(1, Math.max(0, (t - from) / (to - from)));202}203function easeOut(x: number) {204 'worklet';205 return 1 - Math.pow(1 - x, 3);206}207function overshoot(x: number) {208 'worklet';209 const c = 1.9;210 return 1 + (c + 1) * Math.pow(x - 1, 3) + c * Math.pow(x - 1, 2);211}212213const AnimatedPath = Animated.createAnimatedComponent(Path);214215function SuccessMark({ clock, onReplay, pal }: { clock: SharedValue<number>; onReplay: () => void; pal: Palette }) {216 const press = useSharedValue(1);217 const halo = useAnimatedStyle(() => {218 const p = easeOut(slice(clock.value, 0.08, 0.42));219 return { opacity: p, transform: [{ scale: 0.7 + 0.3 * p }] };220 });221 const disc = useAnimatedStyle(() => ({ transform: [{ scale: overshoot(slice(clock.value, 0, 0.36)) * press.value }] }));222 const ring = useAnimatedStyle(() => {223 const p = slice(clock.value, 0.27, 0.92);224 return { opacity: p > 0 ? 0.6 * (1 - p) : 0, transform: [{ scale: 1 + 0.8 * easeOut(p) }] };225 });226 // The check draws itself: the dash slides along the path until it covers it.227 const check = useAnimatedProps(() => ({228 strokeDashoffset: (CHECK_LENGTH + CHECK_STROKE) * (1 - easeOut(slice(clock.value, 0.24, 0.62))),229 }));230 return (231 <Pressable232 role="button"233 aria-label="Replay celebration"234 onPress={onReplay}235 onPressIn={() => (press.value = withSpring(0.93, PRESS))}236 onPressOut={() => (press.value = withSpring(1, PRESS))}237 style={styles.mark}238 >239 <Animated.View style={[styles.markHalo, { backgroundColor: pal.tint }, halo]} />240 <Animated.View style={[styles.markRing, { borderColor: pal.accent }, ring]} />241 <Animated.View style={[styles.markDisc, { backgroundColor: pal.accent }, disc]}>242 <Svg width={46} height={46} viewBox="0 0 40 40">243 <AnimatedPath244 d={CHECK_PATH}245 stroke={pal.onAccent}246 strokeWidth={CHECK_STROKE}247 strokeLinecap="round"248 strokeLinejoin="round"249 strokeDasharray={`${CHECK_LENGTH} ${CHECK_LENGTH * 2}`}250 animatedProps={check}251 fill="none"252 />253 </Svg>254 </Animated.View>255 </Pressable>256 );257}258259// Fourteen pieces fanned around the disc; the offsets keep them from looking evenly spaced.260const CONFETTI = Array.from({ length: 14 }, (_, i) => ({261 angle: (i / 14) * Math.PI * 2 - Math.PI / 2 + (i % 2 ? 0.2 : -0.14),262 reach: 62 + ((i * 37) % 5) * 15,263 size: 7 + (i % 3) * 2,264 tone: i % 4,265 dot: i % 3 === 0,266 spin: (i % 2 ? 1 : -1) * (200 + (i % 4) * 70),267 lag: (i % 3) * 0.035,268}));269270function ConfettiPiece({ piece, clock, pal }: { piece: (typeof CONFETTI)[number]; clock: SharedValue<number>; pal: Palette }) {271 const style = useAnimatedStyle(() => {272 const p = slice(clock.value, 0.25 + piece.lag, 1);273 const out = DISC / 2 - 8 + piece.reach * easeOut(p);274 return {275 opacity: Math.min(1, p * 14) * (1 - slice(p, 0.55, 1)),276 transform: [277 { translateX: Math.cos(piece.angle) * out },278 // A little gravity bends the path downward as the piece slows.279 { translateY: Math.sin(piece.angle) * out + 46 * p * p },280 { rotate: `${piece.spin * p}deg` },281 { scale: 0.4 + 0.6 * Math.min(1, p * 5) },282 ],283 };284 });285 const w = piece.dot ? piece.size * 0.8 : piece.size;286 const h = piece.dot ? piece.size * 0.8 : piece.size * 0.46;287 return <Animated.View style={[styles.confetti, { left: -w / 2, top: -h / 2, width: w, height: h, borderRadius: piece.dot ? w / 2 : 1.5, backgroundColor: pal.confetti[piece.tone] }, style]} />;288}289290/** Sits above the header so pieces are never clipped, and follows the mark as the page scrolls. */291function ConfettiBurst({ clock, scrollY, pal }: { clock: SharedValue<number>; scrollY: SharedValue<number>; pal: Palette }) {292 const insets = useSafeAreaInsets();293 const { width } = useWindowDimensions();294 const follow = useAnimatedStyle(() => ({ transform: [{ translateY: -scrollY.value }] }));295 return (296 <Animated.View297 aria-hidden298 style={[styles.burst, { left: width / 2, top: insets.top + HEADER_H + HERO_TOP + HALO / 2 }, follow]}299 >300 {CONFETTI.map((piece, i) => (301 <ConfettiPiece key={i} piece={piece} clock={clock} pal={pal} />302 ))}303 </Animated.View>304 );305}306307// ─── Order number: copy swaps to a tick for a moment ────────────────────────308309function OrderChip({ pal }: { pal: Palette }) {310 const [copied, setCopied] = useState(false);311 const timer = useRef<ReturnType<typeof setTimeout> | null>(null);312 useEffect(() => () => void (timer.current && clearTimeout(timer.current)), []);313314 const copy = () => {315 // Web clipboard. On a device, call your clipboard module here instead.316 if (Platform.OS === 'web') {317 const nav = (globalThis as { navigator?: { clipboard?: { writeText?: (text: string) => Promise<void> } } }).navigator;318 nav?.clipboard?.writeText?.(`#${ORDER_NUMBER}`)?.catch(() => {});319 }320 setCopied(true);321 if (timer.current) clearTimeout(timer.current);322 timer.current = setTimeout(() => setCopied(false), 1800);323 };324325 return (326 <View style={[styles.chip, { borderColor: pal.hairline, backgroundColor: pal.card }]}>327 <Text style={[styles.chipLabel, { color: pal.muted }]}>Order</Text>328 <Text style={[styles.chipNumber, { color: pal.fg }, TABULAR]}>#{ORDER_NUMBER}</Text>329 <Tap label={copied ? 'Order number copied' : 'Copy order number'} onPress={copy}>330 {/* A fixed width keeps the chip from shifting when the label changes. */}331 <View style={[styles.copy, { backgroundColor: pal.tint }]}>332 <Animated.View key={copied ? 'done' : 'copy'} entering={ZoomIn.duration(200)}>333 {copied ? <Check size={14} color={pal.accent} strokeWidth={3} /> : <Copy size={13.5} color={pal.accent} strokeWidth={2.4} />}334 </Animated.View>335 <Text style={[styles.copyLabel, { color: pal.accent }]}>{copied ? 'Copied' : 'Copy'}</Text>336 </View>337 </Tap>338 </View>339 );340}341342// ─── Delivery: the line fills to the current step, which then pulses ────────343344const DOT = 22;345346function Tracker({ pal }: { pal: Palette }) {347 const fill = useSharedValue(0);348 const pulse = useSharedValue(0);349 useEffect(() => {350 fill.value = withDelay(460, withTiming(1, { duration: 620, easing: Easing.out(Easing.cubic) }));351 pulse.value = withDelay(1100, withRepeat(withTiming(1, { duration: 1800, easing: Easing.out(Easing.quad) }), -1));352 return () => {353 cancelAnimation(fill);354 cancelAnimation(pulse);355 };356 }, [fill, pulse]);357358 const edge = 100 / (STEPS.length * 2); // the line runs between the first and last dot centres359 const lineStyle = useAnimatedStyle(() => ({ width: `${fill.value * (CURRENT_STEP / (STEPS.length - 1)) * 100}%` }));360 // The current dot lights up as the line reaches it.361 const arrive = useAnimatedStyle(() => {362 const p = slice(fill.value, 0.82, 1);363 return { opacity: p, transform: [{ scale: 0.5 + 0.5 * p }] };364 });365 const haloStyle = useAnimatedStyle(() => ({ opacity: 0.38 * (1 - pulse.value) * slice(fill.value, 0.9, 1), transform: [{ scale: 1 + 1.15 * pulse.value }] }));366367 return (368 <View aria-label={`Order progress: ${STEPS[CURRENT_STEP]} is step ${CURRENT_STEP + 1} of ${STEPS.length}`}>369 <View style={[styles.trackLine, { left: `${edge}%`, right: `${edge}%`, backgroundColor: pal.track }]}>370 <Animated.View style={[styles.trackFill, { backgroundColor: pal.accent }, lineStyle]} />371 </View>372 <View style={styles.steps}>373 {STEPS.map((step, i) => {374 const done = i < CURRENT_STEP;375 const current = i === CURRENT_STEP;376 return (377 <View key={step} style={styles.step}>378 <View style={styles.dotSlot}>379 {current ? <Animated.View style={[styles.dotHalo, { backgroundColor: pal.accent }, haloStyle]} /> : null}380 <View style={[styles.dot, { backgroundColor: done ? pal.accent : pal.card, borderWidth: done ? 0 : 2, borderColor: pal.ring }]}>381 {done ? <Check size={13} color={pal.onAccent} strokeWidth={3.2} /> : null}382 </View>383 {current ? (384 <Animated.View385 style={[styles.dotCurrent, { backgroundColor: pal.card, borderColor: pal.accent }, arrive]}386 >387 <View style={[styles.dotCore, { backgroundColor: pal.accent }]} />388 </Animated.View>389 ) : null}390 </View>391 <Text numberOfLines={1} style={[styles.stepLabel, { color: done || current ? pal.fg : pal.muted, fontWeight: done || current ? '600' : '500' }]}>392 {step}393 </Text>394 </View>395 );396 })}397 </View>398 </View>399 );400}401402/** A drawn street map with a pin on the delivery address. */403function MapThumb({ pal }: { pal: Palette }) {404 const size = 56;405 const land = pal.mapLand;406 const road = pal.mapRoad;407 const park = pal.mapPark;408 const water = pal.mapWater;409 return (410 <View style={[styles.map, { width: size, height: size, backgroundColor: land }]} aria-label="Map of the delivery address">411 <Svg width={size} height={size} viewBox="22 28 72 72">412 <Rect x={0} y={0} width={180} height={180} fill={land} />413 <Path d="M118,0 C126,22 150,32 180,36 L180,0 Z" fill={water} />414 <Rect x={16} y={96} width={44} height={32} rx={7} fill={park} />415 <Rect x={92} y={18} width={22} height={18} rx={5} fill={park} />416 <Path d="M-5,42 L185,48 M-5,134 L185,140 M30,-5 L38,185 M124,-5 L132,185 M-5,12 L100,16" stroke={road} strokeWidth={4} strokeLinecap="round" fill="none" />417 <Path d="M-5,84 L185,92 M76,-5 L86,185 M-5,172 L172,-5" stroke={road} strokeWidth={7.5} strokeLinecap="round" fill="none" />418 </Svg>419 <View style={[styles.pin, { left: size / 2 - 10, top: size / 2 - 23 }]}>420 <Svg width={20} height={25} viewBox="0 0 24 30">421 <Path d="M12 29C12 29 22.5 19 22.5 11.5A10.5 10.5 0 1 0 1.5 11.5C1.5 19 12 29 12 29Z" fill={pal.accent} stroke={pal.card} strokeWidth={1.5} />422 <Circle cx={12} cy={11.5} r={3.8} fill={pal.onAccent} />423 </Svg>424 </View>425 </View>426 );427}428429function DeliveryCard({ pal }: { pal: Palette }) {430 return (431 <Card pal={pal}>432 <View style={styles.cardRow}>433 <View style={styles.fill}>434 <Text style={[styles.arrives, { color: pal.fg }]}>Arriving {DELIVERY.arrives}</Text>435 <Text numberOfLines={1} style={[styles.status, { color: pal.muted }]}>436 {DELIVERY.status}437 </Text>438 </View>439 <View style={[styles.truck, { backgroundColor: pal.tint }]}>440 <Truck size={19} color={pal.accent} strokeWidth={2} />441 </View>442 </View>443444 <View style={styles.tracker}>445 <Tracker pal={pal} />446 </View>447448 <View style={[styles.deliveryRule, { backgroundColor: pal.hairline }]} />449450 <View style={styles.cardRow}>451 <MapThumb pal={pal} />452 <View style={styles.fill}>453 <View style={styles.addressHead}>454 <Text style={[styles.rowTitle, { color: pal.fg }]}>{ADDRESS.name}</Text>455 <View style={[styles.addressTag, { backgroundColor: pal.tint }]}>456 <Text style={[styles.addressTagLabel, { color: pal.accent }]}>{ADDRESS.tag}</Text>457 </View>458 </View>459 <Text numberOfLines={1} style={[styles.addressFirst, { color: pal.muted }]}>460 {ADDRESS.line1}461 </Text>462 <Text numberOfLines={1} style={[styles.addressLine, { color: pal.muted }]}>463 {ADDRESS.line2}464 </Text>465 </View>466 </View>467 </Card>468 );469}470471// ─── Items: a row of thumbnails that opens, in place, into the full receipt ──472473const THUMB = 46;474const ITEMS_ROW = 74;475476function CardMark() {477 return (478 <LinearGradient colors={CARD_ART} start={{ x: 0, y: 0 }} end={{ x: 1, y: 1 }} style={styles.cardMark}>479 <View style={styles.cardMarkGloss} />480 <View style={styles.cardMarkChip} />481 <View style={styles.cardMarkDigits}>482 {[0, 1, 2, 3].map((i) => (483 <View key={i} style={[styles.cardMarkDigit, i === 3 ? styles.cardMarkDigitLast : null]} />484 ))}485 </View>486 </LinearGradient>487 );488}489490function LineItem({ item, pal }: { item: Item; pal: Palette }) {491 return (492 <View style={styles.line} aria-label={`${item.qty} × ${item.name}, ${item.variant}, ${money(item.price * item.qty)}`}>493 <Photo item={item} size={52} radius={13} pal={pal} />494 <View style={styles.fill}>495 <Text numberOfLines={1} style={[styles.rowTitle, { color: pal.fg }]}>496 {item.name}497 </Text>498 <Text numberOfLines={1} style={[styles.rowSub, { color: pal.muted }]}>499 {item.variant} · Qty {item.qty}500 </Text>501 </View>502 <View style={styles.lineEnd}>503 <Text style={[styles.linePrice, { color: pal.fg }, TABULAR]}>{money(item.price * item.qty)}</Text>504 {item.qty > 1 ? <Text style={[styles.lineEach, { color: pal.muted }, TABULAR]}>{money(item.price)} each</Text> : null}505 </View>506 </View>507 );508}509510function SummaryRow({ label, value, pal }: { label: string; value: string; pal: Palette }) {511 return (512 <View style={styles.sumRow}>513 <Text style={[styles.sumLabel, { color: pal.muted }]}>{label}</Text>514 <Text style={[styles.sumValue, { color: pal.fg }, TABULAR]}>{value}</Text>515 </View>516 );517}518519function ItemsCard({ onOpen, pal }: { onOpen: (card: ComponentRef<typeof View> | null, openHeight: number) => void; pal: Palette }) {520 const [open, setOpen] = useState(false);521 const cardRef = useRef<ComponentRef<typeof View>>(null);522 const measured = useRef(0);523 const t = useSharedValue(0);524 const bodyHeight = useSharedValue(0);525 useEffect(() => {526 t.value = withTiming(open ? 1 : 0, { duration: 360, easing: Easing.out(Easing.cubic) });527 }, [open, t]);528529 const bodyStyle = useAnimatedStyle(() => ({ height: bodyHeight.value * t.value, opacity: interpolate(t.value, [0, 0.5, 1], [0, 0.6, 1]) }));530 const chevronStyle = useAnimatedStyle(() => ({ transform: [{ rotate: `${t.value * 180}deg` }] }));531 // The thumbnails hand over to a title as their photos reappear in the list below.532 const thumbsStyle = useAnimatedStyle(() => ({ opacity: 1 - slice(t.value, 0, 0.6), transform: [{ translateY: 10 * t.value }] }));533 const titleStyle = useAnimatedStyle(() => ({ opacity: slice(t.value, 0.4, 1), transform: [{ translateY: -8 * (1 - t.value) }] }));534535 return (536 <View ref={cardRef}>537 <Card pal={pal} padded={false}>538 <Pressable539 role="button"540 aria-label={open ? 'Hide order details' : 'Show order details'}541 aria-expanded={open}542 onPress={() => {543 if (!open) onOpen(cardRef.current, ITEMS_ROW + measured.current);544 setOpen(!open);545 }}546 style={styles.itemsHead}547 >548 <View style={styles.itemsLead}>549 <Animated.View style={[styles.thumbs, thumbsStyle]}>550 {ITEMS.map((item) => (551 <View key={item.id}>552 <Photo item={item} size={THUMB} radius={12} pal={pal} />553 {item.qty > 1 ? <QtyBadge qty={item.qty} pal={pal} /> : null}554 </View>555 ))}556 </Animated.View>557 <Animated.View style={[styles.itemsTitle, titleStyle]}>558 <Text style={[styles.itemsTitleText, { color: pal.fg }]}>Order summary</Text>559 <Text style={[styles.rowSub, { color: pal.muted }]}>{PLACED}</Text>560 </Animated.View>561 </View>562 <View style={styles.itemsEnd}>563 <Text numberOfLines={1} style={[styles.itemsCount, { color: pal.fg }, TABULAR]}>564 {UNITS} items · {money(SUBTOTAL)}565 </Text>566 <Text style={[styles.itemsToggle, { color: pal.muted }]}>{open ? 'Hide details' : 'View details'}</Text>567 </View>568 <Animated.View style={chevronStyle}>569 <ChevronDown size={19} color={pal.muted} strokeWidth={2.2} />570 </Animated.View>571 </Pressable>572573 <Animated.View style={[styles.itemsBody, { pointerEvents: open ? 'auto' : 'none' }, bodyStyle]} aria-hidden={!open}>574 {/* Out of flow, so it keeps its natural height for the container to animate to. */}575 <View style={styles.itemsBodyInner} onLayout={(e) => {576 measured.current = e.nativeEvent.layout.height;577 bodyHeight.value = measured.current;578 }}579 >580 <View style={[styles.ruleTop, { backgroundColor: pal.hairline }]} />581 {ITEMS.map((item) => (582 <LineItem key={item.id} item={item} pal={pal} />583 ))}584 <View style={[styles.ruleMid, { backgroundColor: pal.hairline }]} />585 <SummaryRow label="Subtotal" value={money(SUBTOTAL)} pal={pal} />586 <SummaryRow label={`Delivery · ${DELIVERY.label}`} value={money(DELIVERY.price)} pal={pal} />587 <SummaryRow label={`Tax · ${(TAX_RATE * 100).toFixed(2)}%`} value={money(TAX)} pal={pal} />588 <View style={[styles.ruleBottom, { backgroundColor: pal.hairline }]} />589 <View style={styles.totalRow}>590 <Text style={[styles.totalLabel, { color: pal.fg }]}>Total paid</Text>591 <Text style={[styles.totalValue, { color: pal.fg }, TABULAR]}>{money(TOTAL)}</Text>592 </View>593 <View style={[styles.payment, { backgroundColor: pal.field, borderColor: pal.hairline }]}>594 <CardMark />595 <View style={styles.fill}>596 <Text numberOfLines={1} style={[styles.paymentLabel, { color: pal.fg }]}>597 {PAYMENT.label}598 </Text>599 <Text numberOfLines={1} style={[styles.paymentDetail, { color: pal.muted }]}>600 {PAYMENT.detail}601 </Text>602 </View>603 <View style={[styles.paid, { backgroundColor: pal.tint }]}>604 <Check size={12} color={pal.accent} strokeWidth={3} />605 <Text style={[styles.paidLabel, { color: pal.accent }]}>Paid</Text>606 </View>607 </View>608 </View>609 </Animated.View>610 </Card>611 </View>612 );613}614615// ─── What happens next ──────────────────────────────────────────────────────616617function NextSteps({ pal }: { pal: Palette }) {618 return (619 <Card pal={pal} padded={false}>620 {NEXT_STEPS.map((step, i) => {621 const Icon = step.icon;622 return (623 <View key={step.title} style={[styles.next, { borderTopWidth: i ? 1 : 0, borderTopColor: pal.hairline }]}>624 <View style={[styles.nextIcon, { backgroundColor: pal.tint }]}>625 <Icon size={18} color={pal.accent} strokeWidth={2} />626 </View>627 <View style={styles.fill}>628 <Text style={[styles.rowTitle, { color: pal.fg }]}>{step.title}</Text>629 <Text style={[styles.nextBody, { color: pal.muted }]}>{step.body}</Text>630 </View>631 </View>632 );633 })}634 </Card>635 );636}637638// ─── Header and bottom bar ──────────────────────────────────────────────────639640function Header({ scrollY, pal }: { scrollY: SharedValue<number>; pal: Palette }) {641 const insets = useSafeAreaInsets();642 // The hairline appears once content scrolls under the bar; the title once the headline has gone.643 const hairline = useAnimatedStyle(() => ({ opacity: interpolate(scrollY.value, [0, 20], [0, 1], 'clamp') }));644 const title = useAnimatedStyle(() => ({645 opacity: interpolate(scrollY.value, [128, 164], [0, 1], 'clamp'),646 transform: [{ translateY: interpolate(scrollY.value, [128, 164], [6, 0], 'clamp') }],647 }));648 return (649 <View style={[styles.header, { paddingTop: insets.top, backgroundColor: pal.bg }]}>650 <View style={styles.headerBar}>651 <View style={styles.headerStart}>652 <Tap label="Close">653 <View style={[styles.close, { backgroundColor: pal.card, borderColor: pal.hairline }]}>654 <X size={19} color={pal.fg} strokeWidth={2.2} />655 </View>656 </Tap>657 </View>658 <Animated.Text numberOfLines={1} style={[styles.headerTitle, { color: pal.fg }, title]}>659 Order confirmed660 </Animated.Text>661 <View style={styles.headerEnd}>662 <Tap label="Get help with this order">663 <View style={[styles.help, { backgroundColor: pal.tint }]}>664 <LifeBuoy size={13} color={pal.accent} strokeWidth={2.4} />665 <Text style={[styles.copyLabel, { color: pal.accent }]}>Help</Text>666 </View>667 </Tap>668 </View>669 </View>670 <Animated.View style={[styles.hairline, { backgroundColor: pal.hairline }, hairline]} />671 </View>672 );673}674675function BarButton({ label, primary, icon: Icon, onPress, pal }: { label: string; primary?: boolean; icon?: LucideIcon; onPress?: () => void; pal: Palette }) {676 const scale = useSharedValue(1);677 const style = useAnimatedStyle(() => ({ transform: [{ scale: scale.value }] }));678 const ink = primary ? pal.inverse : pal.fg;679 return (680 <Pressable681 role="button"682 aria-label={label}683 onPress={onPress}684 onPressIn={() => (scale.value = withSpring(0.96, PRESS))}685 onPressOut={() => (scale.value = withSpring(1, PRESS))}686 style={styles.fill}687 >688 <Animated.View style={[styles.barButton, { backgroundColor: primary ? pal.fg : pal.card, borderWidth: primary ? 0 : 1, borderColor: pal.hairline }, style]}>689 {Icon ? <Icon size={17} color={ink} strokeWidth={2.2} /> : null}690 <Text numberOfLines={1} style={[styles.barLabel, { color: ink }]}>691 {label}692 </Text>693 </Animated.View>694 </Pressable>695 );696}697698function BottomBar({ pal }: { pal: Palette }) {699 const insets = useSafeAreaInsets();700 return (701 <View style={[styles.bottomBar, { paddingBottom: Math.max(insets.bottom, 14), backgroundColor: pal.bg, borderTopColor: pal.hairline }]}>702 {/* Point these at your store home and your tracking screen. */}703 <BarButton label="Continue shopping" pal={pal} />704 <BarButton label="Track order" primary icon={Truck} pal={pal} />705 </View>706 );707}708709// ─── Screen ─────────────────────────────────────────────────────────────────710711export default function OrderSuccessScreen() {712 const pal = usePalette();713 const insets = useSafeAreaInsets();714 const { height } = useWindowDimensions();715 const barHeight = 12 + BAR_BUTTON + Math.max(insets.bottom, 14);716717 const scrollRef = useRef<Animated.ScrollView>(null);718 const scrollY = useSharedValue(0);719 const onScroll = useAnimatedScrollHandler((e) => {720 scrollY.value = e.contentOffset.y;721 });722723 // One clock, 0 to 1, that every part of the celebration reads from.724 const clock = useSharedValue(0);725 const celebrate = () => {726 clock.value = 0;727 clock.value = withTiming(1, { duration: CELEBRATION_MS, easing: Easing.linear });728 };729 useEffect(() => {730 clock.value = withTiming(1, { duration: CELEBRATION_MS, easing: Easing.linear });731 return () => cancelAnimation(clock);732 }, [clock]);733734 // Bring the opening receipt into view: only as far as needed, and never up under the header.735 const revealTimer = useRef<ReturnType<typeof setTimeout> | null>(null);736 useEffect(() => () => void (revealTimer.current && clearTimeout(revealTimer.current)), []);737 const revealItems = (card: ComponentRef<typeof View> | null, openHeight: number) => {738 card?.measureInWindow((_x: number, y: number) => {739 const by = Math.min(y + openHeight + 16 - (height - barHeight), y - (insets.top + HEADER_H + 12));740 // A short wait lets the card grow first, so there is room to scroll into.741 if (by > 0) revealTimer.current = setTimeout(() => scrollRef.current?.scrollTo({ y: scrollY.value + by, animated: true }), 120);742 });743 };744745 const rise = (i: number) => FadeInDown.delay(200 + i * 70).duration(420);746747 return (748 <View style={[styles.screen, { backgroundColor: pal.bg }]}>749 <Animated.ScrollView750 ref={scrollRef}751 onScroll={onScroll}752 scrollEventThrottle={16}753 showsVerticalScrollIndicator={false}754 contentContainerStyle={[styles.content, { paddingTop: insets.top + HEADER_H + HERO_TOP, paddingBottom: barHeight + 28 }]}755 >756 <View style={styles.hero}>757 <SuccessMark clock={clock} onReplay={celebrate} pal={pal} />758 <Animated.View entering={rise(0)} style={styles.heading}>759 <Text role="heading" style={[styles.title, { color: pal.fg }]}>760 Order confirmed761 </Text>762 <Text style={[styles.subtitle, { color: pal.muted }]}>763 Thanks, {CUSTOMER.firstName}. A receipt is on its way to <Text style={[styles.email, { color: pal.fg }]}>{CUSTOMER.email}</Text>764 </Text>765 </Animated.View>766 <Animated.View entering={rise(1)} style={styles.chipSlot}>767 <OrderChip pal={pal} />768 </Animated.View>769 </View>770771 <Animated.View entering={rise(2)} style={styles.deliverySlot}>772 <DeliveryCard pal={pal} />773 </Animated.View>774775 <Animated.View entering={rise(3)} style={styles.itemsSlot}>776 <ItemsCard onOpen={revealItems} pal={pal} />777 </Animated.View>778779 <Animated.View entering={rise(4)} style={styles.nextSlot}>780 <Text style={[styles.sectionTitle, { color: pal.fg }]}>What happens next</Text>781 <NextSteps pal={pal} />782 </Animated.View>783 </Animated.ScrollView>784785 <Header scrollY={scrollY} pal={pal} />786 <BottomBar pal={pal} />787 <ConfettiBurst clock={clock} scrollY={scrollY} pal={pal} />788 </View>789 );790}791792// ─── Styles ─────────────────────────────────────────────────────────────────793794const styles = StyleSheet.create({795 screen: { flex: 1 },796 content: { paddingHorizontal: 20 },797 fill: { flex: 1 },798799 // Hero800 hero: { alignItems: 'center' },801 heading: { marginTop: 16, alignItems: 'center' },802 title: { fontSize: 27, fontWeight: '700', letterSpacing: -0.7, textAlign: 'center' },803 subtitle: { marginTop: 6, maxWidth: 310, fontSize: 15, lineHeight: 21, textAlign: 'center' },804 email: { fontWeight: '500' },805 chipSlot: { marginTop: 14 },806 deliverySlot: { marginTop: 24 },807 itemsSlot: { marginTop: 12 },808 nextSlot: { marginTop: 26 },809 sectionTitle: { marginBottom: 10, fontSize: 16, fontWeight: '600', letterSpacing: -0.2 },810811 // Celebration812 mark: { width: HALO, height: HALO, alignItems: 'center', justifyContent: 'center' },813 markHalo: { position: 'absolute', width: HALO, height: HALO, borderRadius: HALO / 2 },814 markRing: { position: 'absolute', width: DISC, height: DISC, borderRadius: DISC / 2, borderWidth: 2 },815 markDisc: { width: DISC, height: DISC, borderRadius: DISC / 2, alignItems: 'center', justifyContent: 'center' },816 burst: { position: 'absolute', width: 0, height: 0, pointerEvents: 'none' },817 confetti: { position: 'absolute' },818819 // Order chip820 chip: { height: 40, paddingLeft: 15, paddingRight: 5, borderRadius: 20, borderWidth: 1, flexDirection: 'row', alignItems: 'center', gap: 6 },821 chipLabel: { fontSize: 14 },822 chipNumber: { fontSize: 14.5, fontWeight: '600', letterSpacing: 0.2, marginRight: 6 },823 copy: { width: 86, height: 30, borderRadius: 15, flexDirection: 'row', alignItems: 'center', justifyContent: 'center', gap: 5 },824 copyLabel: { fontSize: 13, fontWeight: '600' },825826 // Cards and photos827 card: { borderRadius: 22, borderWidth: 1, overflow: 'hidden' },828 photo: { overflow: 'hidden' },829 photoFrame: { position: 'absolute' },830 photoImage: { width: '100%', height: '100%' },831 qty: {832 position: 'absolute',833 top: -6,834 right: -6,835 minWidth: 21,836 height: 21,837 borderRadius: 11,838 paddingHorizontal: 4,839 borderWidth: 2,840 alignItems: 'center',841 justifyContent: 'center',842 },843 qtyLabel: { fontSize: 10.5, fontWeight: '700' },844 rowTitle: { fontSize: 15, fontWeight: '600', letterSpacing: -0.2 },845 rowSub: { marginTop: 2, fontSize: 13 },846847 // Delivery848 cardRow: { flexDirection: 'row', alignItems: 'center', gap: 12 },849 arrives: { fontSize: 19, fontWeight: '700', letterSpacing: -0.4 },850 status: { marginTop: 2, fontSize: 13.5 },851 truck: { width: 40, height: 40, borderRadius: 13, alignItems: 'center', justifyContent: 'center' },852 tracker: { marginTop: 18 },853 deliveryRule: { height: 1, marginTop: 14, marginBottom: 12 },854 addressHead: { flexDirection: 'row', alignItems: 'center', gap: 8 },855 addressTag: { height: 19, paddingHorizontal: 7, borderRadius: 10, justifyContent: 'center' },856 addressTagLabel: { fontSize: 11, fontWeight: '700' },857 addressFirst: { marginTop: 3, fontSize: 13.5, lineHeight: 19 },858 addressLine: { fontSize: 13.5, lineHeight: 19 },859 map: { borderRadius: 14, overflow: 'hidden' },860 pin: { position: 'absolute', pointerEvents: 'none' },861862 // Tracker863 trackLine: { position: 'absolute', top: DOT / 2 - 1.5, height: 3, borderRadius: 1.5 },864 trackFill: { height: 3, borderRadius: 1.5 },865 steps: { flexDirection: 'row' },866 step: { flex: 1, alignItems: 'center' },867 dotSlot: { width: DOT, height: DOT, alignItems: 'center', justifyContent: 'center' },868 dotHalo: { position: 'absolute', width: DOT, height: DOT, borderRadius: DOT / 2 },869 dot: { width: DOT, height: DOT, borderRadius: DOT / 2, alignItems: 'center', justifyContent: 'center' },870 dotCurrent: { position: 'absolute', width: DOT, height: DOT, borderRadius: DOT / 2, borderWidth: 2, alignItems: 'center', justifyContent: 'center' },871 dotCore: { width: 9, height: 9, borderRadius: 4.5 },872 stepLabel: { marginTop: 8, fontSize: 12.5 },873874 // Items875 itemsHead: { height: ITEMS_ROW, paddingHorizontal: 14, flexDirection: 'row', alignItems: 'center' },876 itemsLead: { flex: 1, height: THUMB, justifyContent: 'center' },877 thumbs: { flexDirection: 'row', gap: 9 },878 itemsTitle: { position: 'absolute', left: 0 },879 itemsTitleText: { fontSize: 16, fontWeight: '600', letterSpacing: -0.2 },880 itemsEnd: { alignItems: 'flex-end', marginRight: 8 },881 itemsCount: { fontSize: 14.5, fontWeight: '600', letterSpacing: -0.1 },882 itemsToggle: { marginTop: 2, fontSize: 12.5 },883 itemsBody: { overflow: 'hidden' },884 itemsBodyInner: { position: 'absolute', top: 0, left: 0, right: 0, paddingHorizontal: 14, paddingBottom: 14 },885 ruleTop: { height: 1, marginBottom: 6 },886 ruleMid: { height: 1, marginTop: 6, marginBottom: 8 },887 ruleBottom: { height: 1, marginTop: 8, marginBottom: 12 },888 line: { flexDirection: 'row', alignItems: 'center', gap: 12, paddingVertical: 8 },889 lineEnd: { alignItems: 'flex-end' },890 linePrice: { fontSize: 15, fontWeight: '600' },891 lineEach: { marginTop: 2, fontSize: 12 },892 sumRow: { height: 28, flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between' },893 sumLabel: { fontSize: 14.5 },894 sumValue: { fontSize: 14.5, fontWeight: '500' },895 totalRow: { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between' },896 totalLabel: { fontSize: 16, fontWeight: '600' },897 totalValue: { fontSize: 20, fontWeight: '700', letterSpacing: -0.5 },898 payment: { marginTop: 14, padding: 10, borderRadius: 16, borderWidth: 1, flexDirection: 'row', alignItems: 'center', gap: 12 },899 paymentLabel: { fontSize: 14.5, fontWeight: '600', letterSpacing: -0.1 },900 paymentDetail: { marginTop: 1, fontSize: 12.5 },901 paid: { height: 24, paddingHorizontal: 9, borderRadius: 12, flexDirection: 'row', alignItems: 'center', gap: 4 },902 paidLabel: { fontSize: 12, fontWeight: '700' },903 cardMark: { width: 46, height: 31, borderRadius: 7, overflow: 'hidden', padding: 5, justifyContent: 'space-between' },904 cardMarkGloss: { position: 'absolute', right: -16, top: -26, width: 52, height: 52, borderRadius: 26, backgroundColor: 'rgba(255,255,255,0.1)' },905 cardMarkChip: { width: 9, height: 7, borderRadius: 2, backgroundColor: '#E6C777' },906 cardMarkDigits: { flexDirection: 'row', gap: 2.5 },907 cardMarkDigit: { width: 6, height: 2.5, borderRadius: 1.25, backgroundColor: 'rgba(255,255,255,0.5)' },908 cardMarkDigitLast: { backgroundColor: '#FFFFFF' },909910 // What happens next911 next: { flexDirection: 'row', alignItems: 'center', gap: 12, paddingHorizontal: 14, paddingVertical: 13 },912 nextIcon: { width: 38, height: 38, borderRadius: 12, alignItems: 'center', justifyContent: 'center' },913 nextBody: { marginTop: 2, fontSize: 13, lineHeight: 18 },914915 // Header and bottom bar916 header: { position: 'absolute', top: 0, left: 0, right: 0 },917 headerBar: { height: HEADER_H, flexDirection: 'row', alignItems: 'center', paddingHorizontal: 16 },918 headerStart: { width: 84, alignItems: 'flex-start' },919 headerEnd: { width: 84, alignItems: 'flex-end' },920 headerTitle: { flex: 1, textAlign: 'center', fontSize: 17, fontWeight: '600', letterSpacing: -0.3 },921 close: { width: 40, height: 40, borderRadius: 20, borderWidth: 1, alignItems: 'center', justifyContent: 'center' },922 help: { height: 30, paddingHorizontal: 11, borderRadius: 15, flexDirection: 'row', alignItems: 'center', gap: 5 },923 hairline: { height: 1 },924 bottomBar: { position: 'absolute', left: 0, right: 0, bottom: 0, flexDirection: 'row', gap: 10, paddingTop: 12, paddingHorizontal: 20, borderTopWidth: 1 },925 barButton: { height: BAR_BUTTON, borderRadius: BAR_BUTTON / 2, flexDirection: 'row', alignItems: 'center', justifyContent: 'center', gap: 8 },926 barLabel: { fontSize: 15.5, fontWeight: '600', letterSpacing: -0.2 },927});