Shopping cart

A store bag where everything responds: quantity steppers roll their digits and turn the minus into a bin at one, removed items slide out behind an Undo bar, and a free-shipping meter fills, turns green and pops when the threshold is crossed. A promo row opens into a field that shakes on a wrong code, totals count to their new values, and the sticky checkout button carries the live total down to a drawn empty-bag state.

cartecommercequantity stepperpromo codecheckoutfree shippingundoempty stateanimationreanimated
Paste into Claude Code Cursor Codex Lovable RapidNative
Live preview · follows the site themeOpen full screen

Details

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

Using gluestack-ui?

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

components/patterns/cart.tsx
1import { useEffect, useRef, useState, type ComponentRef, type ReactNode } from 'react';
2import {
3 Image,
4 KeyboardAvoidingView,
5 Platform,
6 Pressable,
7 StyleSheet,
8 Text,
9 TextInput,
10 View,
11 useColorScheme,
12 useWindowDimensions,
13 type LayoutChangeEvent,
14 type StyleProp,
15 type TextStyle,
16 type ViewStyle,
17} from 'react-native';
18import Animated, {
19 cancelAnimation,
20 Easing,
21 FadeIn,
22 FadeInDown,
23 FadeOut,
24 FadeOutLeft,
25 interpolate,
26 interpolateColor,
27 LinearTransition,
28 useAnimatedScrollHandler,
29 useAnimatedStyle,
30 useSharedValue,
31 withDelay,
32 withRepeat,
33 withSequence,
34 withSpring,
35 withTiming,
36 ZoomIn,
37 type SharedValue,
38} from 'react-native-reanimated';
39import { useSafeAreaInsets } from 'react-native-safe-area-context';
40import Svg, { Circle, Ellipse, Path } from 'react-native-svg';
41import { Check, ChevronLeft, Heart, Lock, Minus, Plus, RotateCcw, Tag, Trash2, Truck, Undo2, X } from 'lucide-react-native';
42
43// ─── Brand ──────────────────────────────────────────────────────────────────
44// The screen's accent. Every accent colour below derives from these, so changing them rebrands the screen.
45
46const ACCENT = '#E11D48';
47const ACCENT_DARK = '#FB5A7A';
48const ON_ACCENT = '#FFFFFF'; // text and icons on an accent fill
49
50/** `hex` at `alpha` opacity, as rgba(). */
51function tint(hex: string, alpha: number) {
52 const n = parseInt(hex.slice(1), 16);
53 return `rgba(${(n >> 16) & 255}, ${(n >> 8) & 255}, ${n & 255}, ${alpha})`;
54}
55
56/** `hex` mixed toward black (amount > 0) or white (amount < 0); amount from -1 to 1. */
57function shade(hex: string, amount: number) {
58 const n = parseInt(hex.slice(1), 16);
59 const target = amount < 0 ? 255 : 0;
60 const p = Math.abs(amount);
61 const c = (v: number) => Math.round(v + (target - v) * p).toString(16).padStart(2, '0');
62 return `#${c((n >> 16) & 255)}${c((n >> 8) & 255)}${c(n & 255)}`.toUpperCase();
63}
64
65// ─── Sample data ────────────────────────────────────────────────────────────
66
67const photo = (id: string, w = 400) => `https://images.unsplash.com/photo-${id}?w=${w}&q=80&fit=crop`;
68
69type Line = { id: string; name: string; variant: string; price: number; qty: number; image: string; alt: string };
70
71const BAG: Line[] = [
72 {
73 id: 'derby',
74 name: 'Weekend Derby',
75 variant: 'Sage suede · EU 42',
76 price: 159,
77 qty: 1,
78 image: photo('1560343090-f0409e92791a'),
79 alt: 'A sage green suede derby shoe with a crepe sole',
80 },
81 {
82 id: 'pack',
83 name: 'Transit Day Pack',
84 variant: 'Navy · 22 L',
85 price: 79,
86 qty: 1,
87 image: photo('1553062407-98eeb64c6a62'),
88 alt: 'A navy backpack standing on a tiled floor',
89 },
90 {
91 id: 'bottle',
92 name: 'Insulated Bottle',
93 variant: 'Forest · 500 ml',
94 price: 22,
95 qty: 2,
96 image: photo('1602143407151-7111542de6e8'),
97 alt: 'A matte forest green steel water bottle',
98 },
99];
100
101const FREE_SHIPPING_AT = 300;
102const SHIPPING_FEE = 8;
103const PROMO = { code: 'WELCOME10', rate: 0.1, label: '10% off' };
104const MAX_QTY = 9;
105const UNDO_MS = 4500;
106
107// ─── Palette ────────────────────────────────────────────────────────────────
108
109const SPRING = { damping: 16, stiffness: 240, mass: 0.7 };
110const MOVE = LinearTransition.duration(300);
111const TABULAR = { fontVariant: ['tabular-nums' as const] };
112const OUT = Easing.out(Easing.cubic);
113
114const money = (n: number) => `$${Math.max(0, n).toFixed(2).replace(/\B(?=(\d{3})+(?!\d))/g, ',')}`;
115
116function usePalette() {
117 const dark = useColorScheme() === 'dark';
118 return {
119 dark,
120 bg: dark ? '#0A0A0A' : '#FAFAF9',
121 card: dark ? '#161618' : '#FFFFFF',
122 fg: dark ? '#FAFAFA' : '#0A0A0A',
123 inverse: dark ? '#0A0A0A' : '#FAFAFA',
124 muted: dark ? '#A1A1AA' : '#71717A',
125 faint: dark ? '#63636B' : '#A8A29E',
126 line: dark ? '#26262A' : '#ECEAE6',
127 border: dark ? '#34343A' : '#DEDBD5',
128 chip: dark ? '#232326' : '#F4F2EE',
129 raised: dark ? '#3A3A41' : '#FFFFFF',
130 shine: dark ? '#2C2C31' : '#E7E4DE',
131 accent: dark ? ACCENT_DARK : ACCENT,
132 accentSoft: dark ? tint(ACCENT_DARK, 0.16) : shade(ACCENT, -0.905),
133 success: dark ? '#34D399' : '#059669',
134 successSoft: dark ? 'rgba(52,211,153,0.15)' : '#E3F6EC',
135 error: dark ? '#FF7B72' : '#DC2626',
136 toast: dark ? '#F4F4F5' : '#18181B',
137 toastFg: dark ? '#0A0A0A' : '#FAFAFA',
138 toastMuted: dark ? '#52525B' : '#A1A1AA',
139 toastAccent: dark ? ACCENT : shade(ACCENT_DARK, -0.12),
140 // the bag's face, a deep shade of its accent body
141 accentInk: dark ? shade(ACCENT_DARK, 0.85) : shade(ACCENT, 0.66),
142 };
143}
144type Palette = ReturnType<typeof usePalette>;
145
146// ─── Small pieces ───────────────────────────────────────────────────────────
147
148function Tap({ children, label, onPress, to = 0.94, disabled, style }: { children: ReactNode; label: string; onPress?: () => void; to?: number; disabled?: boolean; style?: StyleProp<ViewStyle> }) {
149 const scale = useSharedValue(1);
150 const pressed = useAnimatedStyle(() => ({ transform: [{ scale: scale.value }] }));
151 return (
152 <Pressable
153 role="button"
154 aria-label={label}
155 aria-disabled={disabled}
156 disabled={disabled}
157 onPress={onPress}
158 hitSlop={6}
159 onPressIn={() => (scale.value = withSpring(to, SPRING))}
160 onPressOut={() => (scale.value = withSpring(1, SPRING))}
161 style={style}
162 >
163 <Animated.View style={pressed}>{children}</Animated.View>
164 </Pressable>
165 );
166}
167
168/** A photo that pulses as a tinted placeholder, then fades in once it has loaded. */
169function Photo({ uri, alt, size, radius }: { uri: string; alt: string; size: number; radius: number }) {
170 const pal = usePalette();
171 const shown = useSharedValue(0);
172 const pulse = useSharedValue(0.4);
173 useEffect(() => {
174 pulse.value = withRepeat(withSequence(withTiming(1, { duration: 700 }), withTiming(0.4, { duration: 700 })), -1);
175 return () => cancelAnimation(pulse);
176 }, [pulse]);
177 const image = useAnimatedStyle(() => ({ opacity: shown.value }));
178 const placeholder = useAnimatedStyle(() => ({ opacity: (1 - shown.value) * pulse.value }));
179 return (
180 <View style={[styles.photo, { width: size, height: size, borderRadius: radius, backgroundColor: pal.chip }]}>
181 <Animated.View style={[StyleSheet.absoluteFill, { backgroundColor: pal.shine }, placeholder]} />
182 <Animated.View style={[styles.photoFill, image]}>
183 <Image
184 source={{ uri }}
185 alt={alt}
186 resizeMode="cover"
187 style={styles.photoImage}
188 onLoad={() => {
189 cancelAnimation(pulse);
190 shown.value = withTiming(1, { duration: 320 });
191 }}
192 />
193 </Animated.View>
194 </View>
195 );
196}
197
198/** Counts from the value on screen to the new one, easing out. Starts settled. */
199function useCountUp(target: number, ms = 420) {
200 const [value, setValue] = useState(target);
201 const from = useRef(target);
202 useEffect(() => {
203 const a = from.current;
204 if (a === target) return;
205 const start = Date.now();
206 let raf = 0;
207 const tick = () => {
208 const t = Math.min(1, (Date.now() - start) / ms);
209 const v = t === 1 ? target : a + (target - a) * (1 - Math.pow(1 - t, 3));
210 from.current = v;
211 setValue(v);
212 if (t < 1) raf = requestAnimationFrame(tick);
213 };
214 raf = requestAnimationFrame(tick);
215 return () => cancelAnimationFrame(raf);
216 }, [target, ms]);
217 return value;
218}
219
220function Money({ value, prefix = '', style }: { value: number; prefix?: string; style?: StyleProp<TextStyle> }) {
221 const shown = useCountUp(value);
222 return (
223 <Text style={[style, TABULAR]}>
224 {prefix}
225 {money(shown)}
226 </Text>
227 );
228}
229
230/** A number that rolls: the old digit leaves one way as the new one arrives from the other. */
231function Roll({ value, width, height, style }: { value: number; width: number; height: number; style: StyleProp<TextStyle> }) {
232 const [state, setState] = useState({ now: value, before: value, turn: 0 });
233 if (state.now !== value) setState({ now: value, before: state.now, turn: state.turn + 1 });
234 return (
235 <View style={[styles.roll, { width, height }]}>
236 <RollPair key={state.turn} from={state.before} to={state.now} animate={state.turn > 0} height={height} style={style} />
237 </View>
238 );
239}
240
241function RollPair({ from, to, animate, height, style }: { from: number; to: number; animate: boolean; height: number; style: StyleProp<TextStyle> }) {
242 const t = useSharedValue(animate ? 0 : 1);
243 useEffect(() => {
244 if (animate) t.value = withTiming(1, { duration: 240, easing: OUT });
245 }, [animate, t]);
246 const dir = to > from ? 1 : -1;
247 const leaving = useAnimatedStyle(() => ({ opacity: 1 - t.value, transform: [{ translateY: -dir * height * t.value }] }));
248 const arriving = useAnimatedStyle(() => ({ opacity: t.value, transform: [{ translateY: dir * height * (1 - t.value) }] }));
249 const digit: StyleProp<TextStyle> = [style, TABULAR, styles.digit, { height, lineHeight: height }];
250 return (
251 <>
252 <Animated.Text aria-hidden style={[digit, leaving]}>
253 {from}
254 </Animated.Text>
255 <Animated.Text style={[digit, arriving]}>{to}</Animated.Text>
256 </>
257 );
258}
259
260function AppleLogo({ color, size = 19 }: { color: string; size?: number }) {
261 return (
262 <Svg width={size} height={size} viewBox="0 0 24 24">
263 <Path
264 fill={color}
265 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"
266 />
267 </Svg>
268 );
269}
270
271// ─── Free shipping: the bar follows the subtotal, then celebrates ───────────
272
273function Spark({ angle, t, color }: { angle: number; t: SharedValue<number>; color: string }) {
274 const style = useAnimatedStyle(() => {
275 const reach = 16 + t.value * 24;
276 return {
277 opacity: t.value === 0 ? 0 : 1 - t.value * t.value * t.value,
278 transform: [{ translateX: Math.cos(angle) * reach }, { translateY: Math.sin(angle) * reach }, { scale: 1 - t.value * 0.5 }],
279 };
280 });
281 return <Animated.View style={[styles.spark, { backgroundColor: color }, style]} />;
282}
283
284function ShippingMeter({ subtotal }: { subtotal: number }) {
285 const pal = usePalette();
286 const reached = subtotal >= FREE_SHIPPING_AT;
287 const away = useCountUp(Math.max(0, FREE_SHIPPING_AT - subtotal));
288 const fill = useSharedValue(0);
289 const tone = useSharedValue(reached ? 1 : 0);
290 const pop = useSharedValue(1);
291 const burst = useSharedValue(0);
292 const settled = useRef(false);
293
294 useEffect(() => {
295 const first = !settled.current;
296 fill.value = withDelay(first ? 260 : 0, withTiming(Math.min(1, subtotal / FREE_SHIPPING_AT), { duration: first ? 700 : 420, easing: OUT }));
297 }, [subtotal, fill]);
298
299 useEffect(() => {
300 tone.value = withTiming(reached ? 1 : 0, { duration: 280 });
301 // Crossing the threshold pops the badge and throws a ring of sparks.
302 if (reached && settled.current) {
303 pop.value = withSequence(withTiming(1.3, { duration: 170, easing: Easing.out(Easing.back(3)) }), withTiming(1, { duration: 240, easing: OUT }));
304 burst.value = 0;
305 burst.value = withDelay(60, withTiming(1, { duration: 640, easing: OUT }));
306 }
307 settled.current = true;
308 }, [reached, tone, pop, burst]);
309
310 const bar = useAnimatedStyle(() => ({ width: `${fill.value * 100}%`, backgroundColor: interpolateColor(tone.value, [0, 1], [pal.accent, pal.success]) }));
311 const badge = useAnimatedStyle(() => ({
312 backgroundColor: interpolateColor(tone.value, [0, 1], [pal.accentSoft, pal.success]),
313 transform: [{ scale: pop.value }],
314 }));
315
316 return (
317 <View
318 aria-label={reached ? 'Free shipping unlocked' : `${money(FREE_SHIPPING_AT - subtotal)} away from free shipping`}
319 style={[styles.meter, { backgroundColor: pal.card, borderColor: pal.line }]}
320 >
321 <View style={styles.meterBadgeSlot}>
322 {[0, 1, 2, 3, 4, 5, 6, 7].map((i) => (
323 <Spark key={i} angle={(i * Math.PI) / 4 - 0.3} t={burst} color={i % 2 ? pal.success : '#F59E0B'} />
324 ))}
325 <Animated.View style={[styles.meterBadge, badge]}>
326 <Animated.View key={reached ? 'check' : 'truck'} entering={ZoomIn.duration(220)}>
327 {reached ? <Check size={20} color="#FFFFFF" strokeWidth={3} /> : <Truck size={20} color={pal.accent} strokeWidth={2.1} />}
328 </Animated.View>
329 </Animated.View>
330 </View>
331 <View style={styles.meterBody}>
332 <Animated.View key={reached ? 'unlocked' : 'away'} entering={FadeIn.duration(240)}>
333 {reached ? (
334 <Text numberOfLines={1} style={[styles.meterText, { color: pal.fg }]}>
335 You’ve unlocked <Text style={[styles.meterStrong, { color: pal.success }]}>free shipping</Text>
336 </Text>
337 ) : (
338 <Text numberOfLines={1} style={[styles.meterText, { color: pal.fg }]}>
339 You’re <Text style={[styles.meterAmount, TABULAR]}>${Math.ceil(away)}</Text> away from free shipping
340 </Text>
341 )}
342 </Animated.View>
343 <View style={[styles.meterTrack, { backgroundColor: pal.chip }]}>
344 <Animated.View style={[styles.meterFill, bar]} />
345 </View>
346 </View>
347 </View>
348 );
349}
350
351// ─── Line item: photo, variant, rolling stepper ─────────────────────────────
352
353function StepButton({ label, onPress, disabled, children }: { label: string; onPress: () => void; disabled?: boolean; children: ReactNode }) {
354 const pal = usePalette();
355 const scale = useSharedValue(1);
356 const pressed = useAnimatedStyle(() => ({ transform: [{ scale: scale.value }] }));
357 return (
358 <Pressable
359 role="button"
360 aria-label={label}
361 aria-disabled={disabled}
362 disabled={disabled}
363 onPress={onPress}
364 hitSlop={4}
365 onPressIn={() => (scale.value = withSpring(0.82, SPRING))}
366 onPressOut={() => (scale.value = withSpring(1, SPRING))}
367 >
368 <Animated.View
369 style={[
370 styles.step,
371 pal.dark ? styles.stepDark : styles.stepLight,
372 { backgroundColor: pal.raised, opacity: disabled ? 0.4 : 1 },
373 pressed,
374 ]}
375 >
376 {children}
377 </Animated.View>
378 </Pressable>
379 );
380}
381
382function Stepper({ name, qty, onChange, onRemove }: { name: string; qty: number; onChange: (by: number) => void; onRemove: () => void }) {
383 const pal = usePalette();
384 const last = qty === 1;
385 return (
386 <View style={[styles.stepper, { backgroundColor: pal.chip }]}>
387 {/* At one, the minus turns into a bin. */}
388 <StepButton label={last ? `Remove ${name}` : `Decrease quantity of ${name}`} onPress={last ? onRemove : () => onChange(-1)}>
389 <Animated.View key={last ? 'bin' : 'minus'} entering={ZoomIn.duration(180)}>
390 {last ? <Trash2 size={15} color={pal.accent} strokeWidth={2.2} /> : <Minus size={16} color={pal.fg} strokeWidth={2.4} />}
391 </Animated.View>
392 </StepButton>
393 <View aria-label={`Quantity of ${name}: ${qty}`}>
394 <Roll value={qty} width={30} height={32} style={[styles.stepperQty, { color: pal.fg }]} />
395 </View>
396 <StepButton label={`Increase quantity of ${name}`} onPress={() => onChange(1)} disabled={qty >= MAX_QTY}>
397 <Plus size={16} color={pal.fg} strokeWidth={2.4} />
398 </StepButton>
399 </View>
400 );
401}
402
403function LineItem({ line, saved, onChange, onRemove, onSave }: { line: Line; saved: boolean; onChange: (by: number) => void; onRemove: () => void; onSave: () => void }) {
404 const pal = usePalette();
405 const heart = useSharedValue(1);
406 const heartStyle = useAnimatedStyle(() => ({ transform: [{ scale: heart.value }] }));
407 const save = () => {
408 onSave();
409 heart.value = withSequence(withTiming(1.35, { duration: 140, easing: Easing.out(Easing.back(3)) }), withTiming(1, { duration: 200, easing: OUT }));
410 };
411 return (
412 <View style={[styles.line, { backgroundColor: pal.card, borderColor: pal.line }]}>
413 <Photo uri={line.image} alt={line.alt} size={92} radius={16} />
414 <View style={styles.lineBody}>
415 <View style={styles.lineTop}>
416 <View style={styles.lineTitles}>
417 <Text numberOfLines={1} style={[styles.lineName, { color: pal.fg }]}>
418 {line.name}
419 </Text>
420 <Text numberOfLines={1} style={[styles.lineVariant, { color: pal.muted }]}>
421 {line.variant}
422 </Text>
423 </View>
424 <Pressable role="button" aria-label={saved ? `Remove ${line.name} from saved` : `Save ${line.name} for later`} aria-pressed={saved} onPress={save} hitSlop={8} style={styles.lineSave}>
425 <Animated.View style={heartStyle}>
426 <Heart size={18} color={saved ? pal.accent : pal.faint} fill={saved ? pal.accent : 'transparent'} strokeWidth={2} />
427 </Animated.View>
428 </Pressable>
429 </View>
430 <View style={styles.lineBottom}>
431 <View style={styles.linePrices}>
432 {line.qty > 1 && (
433 <Animated.Text entering={FadeIn.duration(220)} style={[styles.lineEach, { color: pal.muted }, TABULAR]}>
434 ${line.price} each
435 </Animated.Text>
436 )}
437 <Money value={line.price * line.qty} style={[styles.lineTotal, { color: pal.fg }]} />
438 </View>
439 <Stepper name={line.name} qty={line.qty} onChange={onChange} onRemove={onRemove} />
440 </View>
441 </View>
442 </View>
443 );
444}
445
446// ─── Promo code: a row that opens into a field ──────────────────────────────
447
448function PromoCode({ applied, onApply, onRemove }: { applied: boolean; onApply: () => void; onRemove: () => void }) {
449 const pal = usePalette();
450 const input = useRef<ComponentRef<typeof TextInput>>(null);
451 const [open, setOpen] = useState(false);
452 const [code, setCode] = useState('');
453 const [error, setError] = useState(false);
454 const [focused, setFocused] = useState(false);
455 const [bodyHeight, setBodyHeight] = useState(0);
456 const show = open && !applied;
457 const height = useSharedValue(0);
458 const shake = useSharedValue(0);
459
460 useEffect(() => {
461 height.value = withTiming(show ? bodyHeight : 0, { duration: 260, easing: OUT });
462 }, [show, bodyHeight, height]);
463
464 const body = useAnimatedStyle(() => ({ height: height.value, opacity: bodyHeight ? height.value / bodyHeight : 0 }));
465 const plus = useAnimatedStyle(() => ({ transform: [{ rotate: `${bodyHeight ? (height.value / bodyHeight) * 45 : 0}deg` }] }));
466 const shakeStyle = useAnimatedStyle(() => ({ transform: [{ translateX: shake.value }] }));
467
468 const toggle = () => {
469 if (open) input.current?.blur();
470 else setTimeout(() => input.current?.focus(), 220);
471 setOpen((o) => !o);
472 };
473
474 const submit = () => {
475 const entered = code.trim().toUpperCase();
476 if (!entered) return;
477 // Replace with a call to your promotions API.
478 if (entered === PROMO.code) {
479 input.current?.blur();
480 setOpen(false);
481 setCode('');
482 setError(false);
483 onApply();
484 return;
485 }
486 setError(true);
487 shake.value = withSequence(
488 withTiming(-9, { duration: 50 }),
489 withTiming(9, { duration: 60 }),
490 withTiming(-6, { duration: 60 }),
491 withTiming(6, { duration: 60 }),
492 withTiming(0, { duration: 50 })
493 );
494 };
495
496 const ready = code.trim().length > 0;
497 const icon = (color: string, background: string) => (
498 <View style={[styles.promoIcon, { backgroundColor: background }]}>
499 <Tag size={17} color={color} strokeWidth={2.1} />
500 </View>
501 );
502
503 return (
504 <View style={[styles.promo, { backgroundColor: pal.card, borderColor: pal.line }]}>
505 {applied ? (
506 <Animated.View key="applied" entering={FadeIn.duration(220)} style={styles.promoApplied}>
507 {icon(pal.success, pal.successSoft)}
508 <Animated.View
509 entering={ZoomIn.duration(260)}
510 aria-label={`Promo code ${PROMO.code} applied`}
511 style={[styles.promoChip, { backgroundColor: pal.successSoft }]}
512 >
513 <Check size={14} color={pal.success} strokeWidth={3} />
514 <Text style={[styles.promoChipText, { color: pal.success }]}>{PROMO.code}</Text>
515 <Pressable role="button" aria-label={`Remove promo code ${PROMO.code}`} onPress={onRemove} hitSlop={8} style={styles.promoChipRemove}>
516 <X size={14} color={pal.success} strokeWidth={2.8} />
517 </Pressable>
518 </Animated.View>
519 <View style={styles.promoGap} />
520 <Text style={[styles.promoRate, { color: pal.success }]}>{PROMO.label}</Text>
521 </Animated.View>
522 ) : (
523 <Pressable key="add" role="button" aria-label="Add a promo code" aria-expanded={open} onPress={toggle} style={styles.promoAdd}>
524 {icon(pal.fg, pal.chip)}
525 <Text style={[styles.promoAddLabel, { color: pal.fg }]}>Add a promo code</Text>
526 <View style={styles.promoPlus}>
527 <Animated.View style={plus}>
528 <Plus size={20} color={pal.muted} strokeWidth={2.2} />
529 </Animated.View>
530 </View>
531 </Pressable>
532 )}
533
534 <Animated.View style={[styles.promoBody, { pointerEvents: show ? 'auto' : 'none' }, body]}>
535 <View onLayout={(e: LayoutChangeEvent) => setBodyHeight(e.nativeEvent.layout.height)} style={styles.promoBodyInner}>
536 <Animated.View style={[styles.promoForm, shakeStyle]}>
537 <View style={[styles.promoField, { borderColor: error ? pal.error : focused ? pal.fg : pal.border, backgroundColor: pal.bg }]}>
538 <TextInput
539 ref={input}
540 value={code}
541 onChangeText={(v) => {
542 setCode(v.toUpperCase());
543 if (error) setError(false);
544 }}
545 onFocus={() => setFocused(true)}
546 onBlur={() => setFocused(false)}
547 onSubmitEditing={submit}
548 aria-label="Promo code"
549 placeholder="Enter code"
550 placeholderTextColor={pal.faint}
551 selectionColor={pal.accent}
552 autoCapitalize="characters"
553 autoCorrect={false}
554 returnKeyType="done"
555 tabIndex={show ? 0 : -1}
556 style={[styles.promoInput, { color: pal.fg }, Platform.OS === 'web' ? ({ outlineStyle: 'none' } as object) : null]}
557 />
558 </View>
559 <Tap label="Apply promo code" onPress={submit} disabled={!ready} to={0.95}>
560 <View style={[styles.promoApply, { backgroundColor: pal.fg, opacity: ready ? 1 : 0.35 }]}>
561 <Text style={[styles.promoApplyLabel, { color: pal.inverse }]}>Apply</Text>
562 </View>
563 </Tap>
564 </Animated.View>
565 {error ? (
566 <Animated.Text key="error" role="alert" entering={FadeInDown.duration(180)} style={[styles.promoHint, { color: pal.error }]}>
567 That code isn’t valid. Check it and try again.
568 </Animated.Text>
569 ) : (
570 <Text style={[styles.promoHint, { color: pal.muted }]}>
571 Try <Text style={[styles.promoHintCode, { color: pal.fg }]}>{PROMO.code}</Text> for 10% off your first order.
572 </Text>
573 )}
574 </View>
575 </Animated.View>
576 </View>
577 );
578}
579
580// ─── Order summary: changed numbers count to their new values ───────────────
581
582function Summary({ count, subtotal, shipping, discount, total }: { count: number; subtotal: number; shipping: number; discount: number; total: number }) {
583 const pal = usePalette();
584 const discounted = discount > 0;
585 const reveal = useSharedValue(discounted ? 1 : 0);
586 useEffect(() => {
587 reveal.value = withTiming(discounted ? 1 : 0, { duration: 260, easing: OUT });
588 }, [discounted, reveal]);
589 const discountRow = useAnimatedStyle(() => ({ height: reveal.value * 34, opacity: reveal.value }));
590
591 const label: StyleProp<TextStyle> = [styles.summaryLabel, { color: pal.muted }];
592 const value: StyleProp<TextStyle> = [styles.summaryValue, { color: pal.fg }];
593 const row = styles.summaryRow;
594
595 return (
596 <View style={[styles.summary, { backgroundColor: pal.card, borderColor: pal.line }]}>
597 <View style={row}>
598 <Text style={label}>
599 Subtotal · {count} {count === 1 ? 'item' : 'items'}
600 </Text>
601 <Money value={subtotal} style={value} />
602 </View>
603 <View style={row}>
604 <Text style={label}>Shipping</Text>
605 {shipping === 0 ? (
606 <Animated.View key="free" entering={ZoomIn.duration(240)} style={styles.summaryFree}>
607 <Text style={[styles.summaryWas, { color: pal.faint }, TABULAR]}>{money(SHIPPING_FEE)}</Text>
608 <Text style={[styles.summaryFreeLabel, { color: pal.success }]}>Free</Text>
609 </Animated.View>
610 ) : (
611 <Animated.View key="paid" entering={FadeIn.duration(200)}>
612 <Text style={[value, TABULAR]}>{money(shipping)}</Text>
613 </Animated.View>
614 )}
615 </View>
616 <Animated.View style={[styles.summaryDiscount, discountRow]}>
617 <View style={row}>
618 <Text style={label}>Discount · {PROMO.code}</Text>
619 <Money value={discount} prefix="−" style={[value, { color: pal.success }]} />
620 </View>
621 </Animated.View>
622 <View style={[styles.summaryRule, { backgroundColor: pal.line }]} />
623 <View style={styles.summaryTotalRow}>
624 <View>
625 <Text style={[styles.summaryTotalLabel, { color: pal.fg }]}>Total</Text>
626 <Text style={[styles.summaryTaxes, { color: pal.muted }]}>Taxes calculated at checkout</Text>
627 </View>
628 <Money value={total} style={[styles.summaryTotal, { color: pal.fg }]} />
629 </View>
630 </View>
631 );
632}
633
634// ─── Empty state: a drawn bag that bobs while it waits ──────────────────────
635
636function Twinkle({ x, y, size, delay, color }: { x: number; y: number; size: number; delay: number; color: string }) {
637 const t = useSharedValue(0.25);
638 useEffect(() => {
639 t.value = withDelay(delay, withRepeat(withSequence(withTiming(1, { duration: 900, easing: Easing.inOut(Easing.sin) }), withTiming(0.25, { duration: 900, easing: Easing.inOut(Easing.sin) })), -1));
640 return () => cancelAnimation(t);
641 }, [delay, t]);
642 const style = useAnimatedStyle(() => ({ opacity: t.value, transform: [{ scale: 0.7 + t.value * 0.3 }] }));
643 const s = size / 2;
644 return (
645 <Animated.View style={[styles.twinkle, { left: x, top: y }, style]}>
646 <Svg width={size} height={size} viewBox={`${-s} ${-s} ${size} ${size}`}>
647 <Path d={`M0 ${-s} Q0 0 ${s} 0 Q0 0 0 ${s} Q0 0 ${-s} 0 Q0 0 0 ${-s} Z`} fill={color} />
648 </Svg>
649 </Animated.View>
650 );
651}
652
653function EmptyBag({ onRestore, minHeight }: { onRestore: () => void; minHeight: number }) {
654 const pal = usePalette();
655 const bob = useSharedValue(0);
656 useEffect(() => {
657 bob.value = withRepeat(withTiming(1, { duration: 1700, easing: Easing.inOut(Easing.sin) }), -1, true);
658 return () => cancelAnimation(bob);
659 }, [bob]);
660 const bag = useAnimatedStyle(() => ({ transform: [{ translateY: interpolate(bob.value, [0, 1], [3, -7]) }, { rotate: `${interpolate(bob.value, [0, 1], [-2.5, 2.5])}deg` }] }));
661 const shadow = useAnimatedStyle(() => ({ opacity: interpolate(bob.value, [0, 1], [1, 0.55]), transform: [{ scaleX: interpolate(bob.value, [0, 1], [1, 0.82]) }] }));
662 const ink = pal.accentInk;
663
664 return (
665 <View style={[styles.empty, { minHeight }]}>
666 <View style={styles.emptyArt} aria-label="An empty shopping bag" role="img">
667 <View style={[styles.emptyHalo, { backgroundColor: pal.accentSoft }]} />
668 <Twinkle x={14} y={34} size={18} delay={0} color="#F59E0B" />
669 <Twinkle x={168} y={22} size={14} delay={500} color={pal.accent} />
670 <Twinkle x={174} y={104} size={11} delay={950} color="#F59E0B" />
671 <Animated.View style={[styles.emptyShadow, shadow]}>
672 <Svg width={110} height={14} viewBox="0 0 110 14">
673 <Ellipse cx={55} cy={7} rx={52} ry={6} fill={pal.dark ? '#000000' : '#E7E0DA'} />
674 </Svg>
675 </Animated.View>
676 <Animated.View style={[styles.emptyBag, bag]}>
677 <Svg width={160} height={160} viewBox="0 0 160 160">
678 <Path d="M46 58 H114 Q123 58 124 67 L130 126 Q131 140 118 140 H42 Q29 140 30 126 L36 67 Q37 58 46 58 Z" fill={pal.accent} />
679 <Path d="M46 58 H114 Q123 58 124 67 L124.6 73 H35.4 L36 67 Q37 58 46 58 Z" fill={ON_ACCENT} opacity={0.2} />
680 <Circle cx={62} cy={66} r={4} fill={ink} />
681 <Circle cx={98} cy={66} r={4} fill={ink} />
682 <Path d="M62 66 V48 Q62 28 80 28 Q98 28 98 48 V66" stroke={pal.fg} strokeWidth={5} strokeLinecap="round" fill="none" />
683 <Circle cx={57} cy={110} r={6} fill={ON_ACCENT} opacity={0.25} />
684 <Circle cx={103} cy={110} r={6} fill={ON_ACCENT} opacity={0.25} />
685 <Circle cx={68} cy={100} r={4} fill={ink} />
686 <Circle cx={92} cy={100} r={4} fill={ink} />
687 <Circle cx={69.4} cy={98.6} r={1.3} fill="#FFFFFF" />
688 <Circle cx={93.4} cy={98.6} r={1.3} fill="#FFFFFF" />
689 <Path d="M72 110 Q80 118 88 110" stroke={ink} strokeWidth={3.2} strokeLinecap="round" fill="none" />
690 </Svg>
691 </Animated.View>
692 </View>
693 <Text role="heading" style={[styles.emptyTitle, { color: pal.fg }]}>
694 Your bag is empty
695 </Text>
696 <Text style={[styles.emptyBody, { color: pal.muted }]}>
697 Fill it with something you’ll love. Orders over ${FREE_SHIPPING_AT} ship free.
698 </Text>
699 <Tap label="Start shopping" onPress={onRestore} to={0.96} style={styles.emptyCtaSlot}>
700 <View style={[styles.emptyCta, { backgroundColor: pal.fg }]}>
701 <Text style={[styles.emptyCtaLabel, { color: pal.inverse }]}>Start shopping</Text>
702 </View>
703 </Tap>
704 </View>
705 );
706}
707
708// ─── Undo bar: a few seconds to take a removal back ─────────────────────────
709
710function UndoBar({ name, stamp, onUndo }: { name: string; stamp: number; onUndo: () => void }) {
711 const pal = usePalette();
712 const left = useSharedValue(1);
713 useEffect(() => {
714 left.value = 1;
715 left.value = withTiming(0, { duration: UNDO_MS, easing: Easing.linear });
716 }, [stamp, left]);
717 const countdown = useAnimatedStyle(() => ({ width: `${left.value * 100}%` }));
718 return (
719 <Animated.View
720 entering={FadeInDown.duration(240)}
721 exiting={FadeOut.duration(160)}
722 role="status"
723 style={[styles.undo, { backgroundColor: pal.toast }]}
724 >
725 <Trash2 size={17} color={pal.toastMuted} strokeWidth={2.1} />
726 <Text numberOfLines={1} style={[styles.undoText, { color: pal.toastMuted }]}>
727 Removed <Text style={[styles.undoName, { color: pal.toastFg }]}>{name}</Text>
728 </Text>
729 <Tap label={`Undo removing ${name}`} onPress={onUndo} to={0.92}>
730 <View style={styles.undoButton}>
731 <Undo2 size={16} color={pal.toastAccent} strokeWidth={2.6} />
732 <Text style={[styles.undoLabel, { color: pal.toastAccent }]}>Undo</Text>
733 </View>
734 </Tap>
735 <Animated.View style={[styles.undoCountdown, { backgroundColor: pal.toastAccent }, countdown]} />
736 </Animated.View>
737 );
738}
739
740// ─── Checkout bar: pinned above the home indicator with the live total ──────
741
742function CheckoutBar({ total, hidden, height }: { total: number; hidden: boolean; height: number }) {
743 const pal = usePalette();
744 const insets = useSafeAreaInsets();
745 const away = useSharedValue(hidden ? 1 : 0);
746 useEffect(() => {
747 away.value = withTiming(hidden ? 1 : 0, { duration: 300, easing: OUT });
748 }, [hidden, away]);
749 const slide = useAnimatedStyle(() => ({ transform: [{ translateY: away.value * height }] }));
750 const text: StyleProp<TextStyle> = [styles.checkoutText, { color: pal.inverse }];
751 return (
752 <Animated.View
753 style={[
754 styles.checkout,
755 { height, paddingBottom: Math.max(insets.bottom, 14), backgroundColor: pal.bg, borderTopColor: pal.line, pointerEvents: hidden ? 'none' : 'auto' },
756 slide,
757 ]}
758 >
759 <Tap label="Pay with Apple Pay" to={0.95}>
760 <View style={[styles.applePay, { borderColor: pal.border, backgroundColor: pal.card }]}>
761 <AppleLogo color={pal.fg} />
762 <Text style={[styles.applePayLabel, { color: pal.fg }]}>Pay</Text>
763 </View>
764 </Tap>
765 <Tap label={`Checkout, total ${money(total)}`} to={0.97} style={styles.checkoutSlot}>
766 <View style={[styles.checkoutButton, { backgroundColor: pal.fg }]}>
767 <Lock size={16} color={pal.inverse} strokeWidth={2.5} />
768 <Text style={text}>Checkout ·</Text>
769 <Money value={total} style={[text, styles.checkoutTotal]} />
770 </View>
771 </Tap>
772 </Animated.View>
773 );
774}
775
776// ─── Screen ─────────────────────────────────────────────────────────────────
777
778type Removed = { line: Line; index: number; stamp: number };
779
780export default function CartScreen() {
781 const pal = usePalette();
782 const insets = useSafeAreaInsets();
783 const { height: screenHeight } = useWindowDimensions();
784 const [items, setItems] = useState<Line[]>(BAG);
785 const [saved, setSaved] = useState<string[]>([]);
786 const [applied, setApplied] = useState(false);
787 const [removed, setRemoved] = useState<Removed | null>(null);
788 const [intro, setIntro] = useState(true);
789 const [round, setRound] = useState(0);
790 const undoTimer = useRef<ReturnType<typeof setTimeout> | null>(null);
791
792 // Rows stagger in on arrival (and when the bag is refilled); after that they just fade.
793 useEffect(() => {
794 const t = setTimeout(() => setIntro(false), 1000);
795 return () => clearTimeout(t);
796 }, [round]);
797 useEffect(
798 () => () => {
799 if (undoTimer.current) clearTimeout(undoTimer.current);
800 },
801 []
802 );
803
804 const scrollY = useSharedValue(0);
805 const onScroll = useAnimatedScrollHandler((e) => {
806 scrollY.value = e.contentOffset.y;
807 });
808 const hairline = useAnimatedStyle(() => ({ opacity: interpolate(scrollY.value, [0, 16], [0, 1], 'clamp') }));
809
810 const count = items.reduce((n, i) => n + i.qty, 0);
811 const subtotal = items.reduce((n, i) => n + i.price * i.qty, 0);
812 const shipping = subtotal >= FREE_SHIPPING_AT ? 0 : SHIPPING_FEE;
813 const discount = applied ? Math.round(subtotal * PROMO.rate * 100) / 100 : 0;
814 const total = subtotal + shipping - discount;
815 const empty = items.length === 0;
816
817 const HEADER = 52;
818 const barHeight = 12 + 56 + Math.max(insets.bottom, 14);
819
820 // The undo bar rides above the checkout bar, and drops down once that has gone.
821 const undoBottom = useSharedValue(barHeight + 12);
822 useEffect(() => {
823 undoBottom.value = withTiming(empty ? Math.max(insets.bottom, 14) + 8 : barHeight + 12, { duration: 300, easing: OUT });
824 }, [empty, barHeight, insets.bottom, undoBottom]);
825 const undoStyle = useAnimatedStyle(() => ({ bottom: undoBottom.value }));
826
827 const changeQty = (id: string, by: number) => setItems((prev) => prev.map((i) => (i.id === id ? { ...i, qty: Math.min(MAX_QTY, Math.max(1, i.qty + by)) } : i)));
828
829 const remove = (id: string) => {
830 const index = items.findIndex((i) => i.id === id);
831 if (index < 0) return;
832 // Replace with a call to your cart store; keep the removed line around until the undo window closes.
833 setRemoved({ line: items[index], index, stamp: Date.now() });
834 setItems(items.filter((i) => i.id !== id));
835 if (undoTimer.current) clearTimeout(undoTimer.current);
836 undoTimer.current = setTimeout(() => setRemoved(null), UNDO_MS);
837 };
838
839 const undo = () => {
840 if (!removed) return;
841 if (undoTimer.current) clearTimeout(undoTimer.current);
842 setItems((prev) => {
843 const next = [...prev];
844 next.splice(Math.min(removed.index, next.length), 0, removed.line);
845 return next;
846 });
847 setRemoved(null);
848 };
849
850 // "Start shopping" refills the sample bag so the whole flow can be replayed.
851 const restore = () => {
852 if (undoTimer.current) clearTimeout(undoTimer.current);
853 setRemoved(null);
854 setApplied(false);
855 setSaved([]);
856 setIntro(true);
857 setRound((r) => r + 1);
858 setItems(BAG);
859 };
860
861 const toggleSaved = (id: string) => setSaved((prev) => (prev.includes(id) ? prev.filter((s) => s !== id) : [...prev, id]));
862
863 return (
864 <KeyboardAvoidingView behavior={Platform.OS === 'ios' ? 'padding' : undefined} style={[styles.screen, { backgroundColor: pal.bg }]}>
865 <Animated.ScrollView
866 onScroll={onScroll}
867 scrollEventThrottle={16}
868 keyboardShouldPersistTaps="handled"
869 showsVerticalScrollIndicator={false}
870 contentContainerStyle={[styles.content, { paddingTop: insets.top + HEADER + 10, paddingBottom: empty ? insets.bottom + 16 : barHeight + 24 }]}
871 >
872 {!empty && (
873 <Animated.View key="meter" entering={intro ? FadeInDown.delay(60).duration(420) : FadeIn.duration(260)} exiting={FadeOut.duration(140)} style={styles.meterSlot}>
874 <ShippingMeter subtotal={subtotal} />
875 </Animated.View>
876 )}
877
878 {items.map((line, i) => (
879 <Animated.View key={line.id} layout={MOVE} entering={intro ? FadeInDown.delay(140 + i * 70).duration(420) : FadeIn.duration(280)} exiting={FadeOutLeft.duration(240)} style={styles.lineSlot}>
880 <LineItem line={line} saved={saved.includes(line.id)} onChange={(by) => changeQty(line.id, by)} onRemove={() => remove(line.id)} onSave={() => toggleSaved(line.id)} />
881 </Animated.View>
882 ))}
883
884 {!empty && (
885 <Animated.View key="tail" layout={MOVE} entering={intro ? FadeInDown.delay(360).duration(420) : FadeIn.duration(260)} exiting={FadeOut.duration(140)} style={styles.tail}>
886 <PromoCode applied={applied} onApply={() => setApplied(true)} onRemove={() => setApplied(false)} />
887 <Summary count={count} subtotal={subtotal} shipping={shipping} discount={discount} total={total} />
888 <View style={styles.assurances}>
889 <View style={styles.assurance}>
890 <Lock size={13} color={pal.muted} strokeWidth={2.2} />
891 <Text style={[styles.assuranceText, { color: pal.muted }]}>Secure checkout</Text>
892 </View>
893 <View style={styles.assurance}>
894 <RotateCcw size={13} color={pal.muted} strokeWidth={2.2} />
895 <Text style={[styles.assuranceText, { color: pal.muted }]}>Free 30-day returns</Text>
896 </View>
897 </View>
898 </Animated.View>
899 )}
900
901 {empty && (
902 <Animated.View key="empty" entering={FadeIn.delay(220).duration(360)} exiting={FadeOut.duration(120)}>
903 <EmptyBag onRestore={restore} minHeight={screenHeight - insets.top - HEADER - insets.bottom - 40} />
904 </Animated.View>
905 )}
906 </Animated.ScrollView>
907
908 {/* Header: opaque, so the list never ghosts through under the status bar */}
909 <View style={[styles.header, { paddingTop: insets.top, backgroundColor: pal.bg }]}>
910 <View style={[styles.headerBar, { height: HEADER }]}>
911 <Tap label="Back" to={0.9}>
912 <View style={[styles.headerButton, { backgroundColor: pal.card, borderColor: pal.line }]}>
913 <ChevronLeft size={22} color={pal.fg} strokeWidth={2.2} style={styles.backIcon} />
914 </View>
915 </Tap>
916 <View role="heading" aria-label={`Bag, ${count} ${count === 1 ? 'item' : 'items'}`} style={styles.headerTitleRow}>
917 <Text style={[styles.headerTitle, { color: pal.fg }]}>Bag</Text>
918 {count > 0 && (
919 <Animated.View entering={ZoomIn.duration(220)} style={[styles.countBadge, { backgroundColor: pal.accent }]}>
920 <Roll value={count} width={count > 9 ? 17 : 10} height={22} style={styles.countBadgeText} />
921 </Animated.View>
922 )}
923 </View>
924 <Tap label={`Saved for later, ${saved.length} ${saved.length === 1 ? 'item' : 'items'}`} to={0.9}>
925 <View style={[styles.headerButton, { backgroundColor: pal.card, borderColor: pal.line }]}>
926 <Heart size={18} color={pal.fg} strokeWidth={2.1} />
927 {saved.length > 0 && (
928 <Animated.View key={saved.length} entering={ZoomIn.duration(220)} style={[styles.savedBadge, { backgroundColor: pal.fg, borderColor: pal.bg }]}>
929 <Text style={[styles.savedBadgeText, { color: pal.inverse }, TABULAR]}>{saved.length}</Text>
930 </Animated.View>
931 )}
932 </View>
933 </Tap>
934 </View>
935 <Animated.View style={[styles.hairline, { backgroundColor: pal.line }, hairline]} />
936 </View>
937
938 <CheckoutBar total={total} hidden={empty} height={barHeight} />
939
940 <Animated.View style={[styles.undoSlot, undoStyle]}>
941 {removed && <UndoBar name={removed.line.name} stamp={removed.stamp} onUndo={undo} />}
942 </Animated.View>
943 </KeyboardAvoidingView>
944 );
945}
946
947// ─── Styles ─────────────────────────────────────────────────────────────────
948
949const styles = StyleSheet.create({
950 screen: { flex: 1 },
951 content: { paddingHorizontal: 16 },
952
953 // Header
954 header: { position: 'absolute', top: 0, left: 0, right: 0 },
955 headerBar: { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', paddingHorizontal: 16 },
956 headerButton: { width: 40, height: 40, borderRadius: 20, borderWidth: 1, alignItems: 'center', justifyContent: 'center' },
957 backIcon: { marginLeft: -2 },
958 headerTitleRow: { flexDirection: 'row', alignItems: 'center', gap: 8 },
959 headerTitle: { fontSize: 17.5, fontWeight: '700', letterSpacing: -0.3 },
960 countBadge: { height: 22, minWidth: 22, borderRadius: 11, paddingHorizontal: 6, alignItems: 'center', justifyContent: 'center' },
961 countBadgeText: { color: ON_ACCENT, fontSize: 12.5, fontWeight: '800' },
962 savedBadge: {
963 position: 'absolute',
964 top: -3,
965 right: -3,
966 minWidth: 18,
967 height: 18,
968 borderRadius: 9,
969 paddingHorizontal: 4,
970 borderWidth: 2,
971 alignItems: 'center',
972 justifyContent: 'center',
973 },
974 savedBadgeText: { fontSize: 10, fontWeight: '800' },
975 hairline: { height: 1 },
976
977 // Small pieces
978 photo: { overflow: 'hidden' },
979 photoFill: { flex: 1 },
980 photoImage: { width: '100%', height: '100%' },
981 roll: { overflow: 'hidden' },
982 digit: { position: 'absolute', left: 0, right: 0, top: 0, textAlign: 'center' },
983
984 // Free shipping meter
985 meterSlot: { marginBottom: 12 },
986 meter: { flexDirection: 'row', alignItems: 'center', gap: 12, padding: 14, borderRadius: 22, borderWidth: 1 },
987 meterBadgeSlot: { width: 40, height: 40 },
988 meterBadge: { width: 40, height: 40, borderRadius: 20, alignItems: 'center', justifyContent: 'center' },
989 spark: { position: 'absolute', left: 17, top: 17, width: 6, height: 6, borderRadius: 3, pointerEvents: 'none' },
990 meterBody: { flex: 1 },
991 meterText: { fontSize: 14.5, fontWeight: '500' },
992 meterStrong: { fontWeight: '700' },
993 meterAmount: { fontWeight: '800' },
994 meterTrack: { height: 6, borderRadius: 3, marginTop: 9, overflow: 'hidden' },
995 meterFill: { height: 6, borderRadius: 3 },
996
997 // Line item
998 lineSlot: { marginBottom: 10 },
999 line: { flexDirection: 'row', gap: 14, padding: 12, borderRadius: 24, borderWidth: 1 },
1000 lineBody: { flex: 1, justifyContent: 'space-between' },
1001 lineTop: { flexDirection: 'row', alignItems: 'flex-start', gap: 8 },
1002 lineTitles: { flex: 1, paddingTop: 3 },
1003 lineName: { fontSize: 16, fontWeight: '600', letterSpacing: -0.2 },
1004 lineVariant: { fontSize: 13, marginTop: 2 },
1005 lineSave: { width: 30, height: 30, alignItems: 'center', justifyContent: 'center' },
1006 lineBottom: { flexDirection: 'row', alignItems: 'flex-end', justifyContent: 'space-between' },
1007 linePrices: { paddingBottom: 1 },
1008 lineEach: { fontSize: 12, marginBottom: 1 },
1009 lineTotal: { fontSize: 17, fontWeight: '700', letterSpacing: -0.3 },
1010 stepper: { flexDirection: 'row', alignItems: 'center', height: 38, borderRadius: 19, padding: 3 },
1011 stepperQty: { fontSize: 15, fontWeight: '700' },
1012 step: { width: 32, height: 32, borderRadius: 16, alignItems: 'center', justifyContent: 'center' },
1013 // A shadow's props stay together in one style object: React Native Web builds the shadow per object.
1014 stepLight: { shadowColor: '#000', shadowOpacity: 0.08, shadowRadius: 4, shadowOffset: { width: 0, height: 1 } },
1015 stepDark: { shadowColor: '#000', shadowOpacity: 0, shadowRadius: 4, shadowOffset: { width: 0, height: 1 } },
1016
1017 // Promo code
1018 tail: { marginTop: 2, gap: 12 },
1019 promo: { borderRadius: 22, borderWidth: 1, overflow: 'hidden' },
1020 promoIcon: { width: 36, height: 36, borderRadius: 18, alignItems: 'center', justifyContent: 'center' },
1021 promoApplied: { height: 60, flexDirection: 'row', alignItems: 'center', paddingHorizontal: 12, gap: 10 },
1022 promoChip: { flexDirection: 'row', alignItems: 'center', gap: 6, height: 32, paddingLeft: 10, paddingRight: 4, borderRadius: 16 },
1023 promoChipText: { fontSize: 13.5, fontWeight: '700', letterSpacing: 0.5 },
1024 promoChipRemove: { width: 24, height: 24, borderRadius: 12, alignItems: 'center', justifyContent: 'center' },
1025 promoGap: { flex: 1 },
1026 promoRate: { fontSize: 14, fontWeight: '600', paddingRight: 4 },
1027 promoAdd: { height: 60, flexDirection: 'row', alignItems: 'center', paddingHorizontal: 12, gap: 12 },
1028 promoAddLabel: { flex: 1, fontSize: 15.5, fontWeight: '600' },
1029 promoPlus: { paddingRight: 4 },
1030 promoBody: { overflow: 'hidden' },
1031 promoBodyInner: { position: 'absolute', left: 0, right: 0, top: 0, paddingHorizontal: 12, paddingBottom: 14 },
1032 promoForm: { flexDirection: 'row', gap: 8 },
1033 promoField: { flex: 1, height: 48, borderRadius: 14, borderWidth: 1.5, paddingHorizontal: 14, justifyContent: 'center' },
1034 promoInput: { height: '100%', fontSize: 15.5, fontWeight: '600', letterSpacing: 0.6 },
1035 promoApply: { height: 48, paddingHorizontal: 20, borderRadius: 14, alignItems: 'center', justifyContent: 'center' },
1036 promoApplyLabel: { fontSize: 15, fontWeight: '700' },
1037 promoHint: { fontSize: 13, marginTop: 8, marginLeft: 2 },
1038 promoHintCode: { fontWeight: '700' },
1039
1040 // Order summary
1041 summary: { borderRadius: 22, borderWidth: 1, paddingHorizontal: 16, paddingTop: 10, paddingBottom: 16 },
1042 summaryRow: { height: 34, flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between' },
1043 summaryLabel: { fontSize: 15 },
1044 summaryValue: { fontSize: 15, fontWeight: '600' },
1045 summaryFree: { flexDirection: 'row', alignItems: 'center', gap: 8 },
1046 summaryWas: { fontSize: 14, textDecorationLine: 'line-through' },
1047 summaryFreeLabel: { fontSize: 15, fontWeight: '700' },
1048 summaryDiscount: { overflow: 'hidden' },
1049 summaryRule: { height: 1, marginTop: 8, marginBottom: 14 },
1050 summaryTotalRow: { flexDirection: 'row', alignItems: 'flex-end', justifyContent: 'space-between' },
1051 summaryTotalLabel: { fontSize: 17, fontWeight: '700', letterSpacing: -0.2 },
1052 summaryTaxes: { fontSize: 12.5, marginTop: 2 },
1053 summaryTotal: { fontSize: 26, fontWeight: '700', letterSpacing: -0.8 },
1054 assurances: { flexDirection: 'row', justifyContent: 'center', gap: 18, paddingTop: 6 },
1055 assurance: { flexDirection: 'row', alignItems: 'center', gap: 6 },
1056 assuranceText: { fontSize: 12.5 },
1057
1058 // Empty state
1059 empty: { alignItems: 'center', justifyContent: 'center', paddingHorizontal: 32, paddingBottom: 24 },
1060 emptyArt: { width: 200, height: 190 },
1061 emptyHalo: { position: 'absolute', left: 20, top: 10, width: 160, height: 160, borderRadius: 80 },
1062 twinkle: { position: 'absolute' },
1063 emptyShadow: { position: 'absolute', left: 0, right: 0, bottom: 0, alignItems: 'center' },
1064 emptyBag: { position: 'absolute', left: 20, top: 6 },
1065 emptyTitle: { fontSize: 24, fontWeight: '700', letterSpacing: -0.6, marginTop: 22 },
1066 emptyBody: { fontSize: 15.5, lineHeight: 22, textAlign: 'center', marginTop: 8 },
1067 emptyCtaSlot: { marginTop: 24, alignSelf: 'stretch' },
1068 emptyCta: { height: 56, borderRadius: 28, alignItems: 'center', justifyContent: 'center' },
1069 emptyCtaLabel: { fontSize: 16.5, fontWeight: '700' },
1070
1071 // Undo bar
1072 undoSlot: { position: 'absolute', left: 16, right: 16, pointerEvents: 'box-none' },
1073 undo: {
1074 height: 54,
1075 borderRadius: 18,
1076 overflow: 'hidden',
1077 flexDirection: 'row',
1078 alignItems: 'center',
1079 paddingLeft: 16,
1080 paddingRight: 6,
1081 shadowColor: '#000',
1082 shadowOpacity: 0.22,
1083 shadowRadius: 18,
1084 shadowOffset: { width: 0, height: 8 },
1085 },
1086 undoText: { flex: 1, marginLeft: 10, fontSize: 14.5 },
1087 undoName: { fontWeight: '600' },
1088 undoButton: { height: 40, paddingHorizontal: 12, borderRadius: 14, flexDirection: 'row', alignItems: 'center', gap: 6 },
1089 undoLabel: { fontSize: 15, fontWeight: '700' },
1090 undoCountdown: { position: 'absolute', left: 0, bottom: 0, height: 3 },
1091
1092 // Checkout bar
1093 checkout: { position: 'absolute', left: 0, right: 0, bottom: 0, flexDirection: 'row', gap: 10, paddingTop: 12, paddingHorizontal: 16, borderTopWidth: 1 },
1094 applePay: { width: 92, height: 56, borderRadius: 28, borderWidth: 1.5, flexDirection: 'row', alignItems: 'center', justifyContent: 'center', gap: 3 },
1095 applePayLabel: { fontSize: 19, fontWeight: '600', letterSpacing: -0.4 },
1096 checkoutSlot: { flex: 1 },
1097 checkoutButton: { height: 56, borderRadius: 28, flexDirection: 'row', alignItems: 'center', justifyContent: 'center', gap: 8 },
1098 checkoutText: { fontSize: 16.5, fontWeight: '700', letterSpacing: -0.2 },
1099 checkoutTotal: { marginLeft: -3 },
1100});

More screens like this.

All Commerce