Rate your experience

A post-order review led by an SVG face whose mouth, eyes, brows and colour morph with the score: tap a star and the row fills left to right with a pop each while the label cross-fades. Quick-pick chips swap between praise and complaints, a tip row with a gliding highlight appears for happy scores, and the submit button runs from spinner to a confetti thank-you before resetting.

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

Details

File
components/patterns/rate-experience.tsx
Lines
851
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/rate-experience.tsx
1import { useEffect, useRef, useState, type ComponentRef } from 'react';
2import { Image, KeyboardAvoidingView, Platform, Pressable, ScrollView, StyleSheet, Text, TextInput, View, useColorScheme, useWindowDimensions } from 'react-native';
3import Animated, {
4 cancelAnimation,
5 Easing,
6 FadeIn,
7 FadeInDown,
8 interpolate,
9 interpolateColor,
10 useAnimatedProps,
11 useAnimatedStyle,
12 useDerivedValue,
13 useSharedValue,
14 withDelay,
15 withRepeat,
16 withSequence,
17 withSpring,
18 withTiming,
19 ZoomIn,
20 type SharedValue,
21} from 'react-native-reanimated';
22import { useSafeAreaInsets } from 'react-native-safe-area-context';
23import Svg, { Circle, Defs, Path, RadialGradient, Stop } from 'react-native-svg';
24import { Bike, Check, Minus, Plus, Star, X } from 'lucide-react-native';
25
26// ─── Brand ──────────────────────────────────────────────────────────────────
27// The screen's accent. Every accent colour below derives from these, so changing them rebrands the screen.
28
29const ACCENT = '#0F8544';
30const ACCENT_DARK = '#34C56F'; // the accent on dark backgrounds
31const ON_ACCENT = '#FFFFFF'; // text and icons on an accent fill
32
33/** `hex` at `alpha` opacity, as rgba(). */
34function tint(hex: string, alpha: number) {
35 const n = parseInt(hex.slice(1), 16);
36 return `rgba(${(n >> 16) & 255}, ${(n >> 8) & 255}, ${n & 255}, ${alpha})`;
37}
38
39/** `hex` mixed toward black (amount > 0) or white (amount < 0); amount from -1 to 1. */
40function shade(hex: string, amount: number) {
41 const n = parseInt(hex.slice(1), 16);
42 const target = amount < 0 ? 255 : 0;
43 const p = Math.abs(amount);
44 const c = (v: number) => Math.round(v + (target - v) * p).toString(16).padStart(2, '0');
45 return `#${c((n >> 16) & 255)}${c((n >> 8) & 255)}${c(n & 255)}`.toUpperCase();
46}
47
48// ─── Sample data ────────────────────────────────────────────────────────────
49
50const photo = (id: string, w = 300) => `https://images.unsplash.com/photo-${id}?w=${w}&q=80&fit=crop`;
51
52const ORDER = {
53 restaurant: 'Green Bowl Kitchen',
54 delivered: 'Delivered today, 7:42 PM',
55 items: 3,
56 courier: 'Leo',
57 photo: photo('1546069901-ba9599a7e63c'),
58};
59
60// Index 0 is the unrated prompt, 1 to 5 follow the stars.
61const LABELS = ['Tap a star to rate', 'Terrible', 'Poor', 'Okay', 'Good', 'Loved it'];
62const THANKS = 'Thanks for the feedback';
63
64type Tone = 'praise' | 'issue';
65const CHIPS: Record<Tone, { title: string; options: string[] }> = {
66 praise: { title: 'What stood out?', options: ['On time', 'Hot and fresh', 'Good value', 'Great packaging', 'Friendly courier'] },
67 issue: { title: 'What went wrong?', options: ['Late', 'Cold food', 'Missing items', 'Wrong order', 'Rude courier'] },
68};
69
70type Tip = number | 'other' | null;
71const TIPS: { value: Exclude<Tip, null>; label: string }[] = [
72 { value: 2, label: '$2' },
73 { value: 4, label: '$4' },
74 { value: 6, label: '$6' },
75 { value: 'other', label: 'Other' },
76];
77
78const MAX_COMMENT = 280;
79// What the screen opens on.
80const START = { rating: 4, tags: ['On time', 'Hot and fresh'] };
81
82const toneOf = (rating: number): Tone => (rating === 0 || rating >= 4 ? 'praise' : 'issue');
83
84// ─── Palette ────────────────────────────────────────────────────────────────
85
86const GOLD = '#FFB020';
87// Ink on the dark-mode accent, which is light: a deep shade of the accent.
88const ACCENT_INK = shade(ACCENT, 0.73);
89const TABULAR = { fontVariant: ['tabular-nums' as const] };
90const PRESS = { damping: 15, stiffness: 300 };
91
92function usePalette() {
93 const dark = useColorScheme() === 'dark';
94 return {
95 dark,
96 bg: dark ? '#000000' : '#FAFAF7',
97 card: dark ? '#121214' : '#FFFFFF',
98 fg: dark ? '#FAFAFA' : '#11110F',
99 muted: dark ? '#8E8E93' : '#6C6C66',
100 faint: dark ? '#56565C' : '#B2B2AA',
101 line: dark ? '#26262A' : '#E8E8E2',
102 chip: dark ? '#1A1A1D' : '#F0F0EB',
103 shine: dark ? '#2A2A2E' : '#E2E2DC',
104 starOff: dark ? '#3A3A40' : '#D6D6CE',
105 accent: dark ? ACCENT_DARK : ACCENT,
106 onAccent: dark ? ACCENT_INK : ON_ACCENT,
107 onAccentSoft: dark ? tint(ACCENT_INK, 0.25) : tint(ON_ACCENT, 0.35),
108 warn: dark ? '#FF8A5C' : '#D9480F',
109 photo: dark ? '#16241B' : '#E4EFE6',
110 photoShine: dark ? '#22382A' : '#CFE3D3',
111 };
112}
113
114// ─── Small pieces ───────────────────────────────────────────────────────────
115
116/** A photo that pulses as a tinted placeholder, then fades in once it has loaded. */
117function Photo({ uri, alt, size, radius }: { uri: string; alt: string; size: number; radius: number }) {
118 const c = usePalette();
119 const shown = useSharedValue(0);
120 const pulse = useSharedValue(0.4);
121 useEffect(() => {
122 pulse.value = withRepeat(withSequence(withTiming(1, { duration: 700 }), withTiming(0.4, { duration: 700 })), -1);
123 return () => cancelAnimation(pulse);
124 }, [pulse]);
125 const image = useAnimatedStyle(() => ({ opacity: shown.value }));
126 const placeholder = useAnimatedStyle(() => ({ opacity: (1 - shown.value) * pulse.value }));
127 return (
128 <View style={[styles.photo, { width: size, height: size, borderRadius: radius, backgroundColor: c.photo }]}>
129 <Animated.View style={[StyleSheet.absoluteFill, { backgroundColor: c.photoShine }, placeholder]} />
130 <Animated.View style={[styles.photoFill, image]}>
131 <Image
132 source={{ uri }}
133 alt={alt}
134 resizeMode="cover"
135 style={styles.photoImage}
136 onLoad={() => {
137 cancelAnimation(pulse);
138 shown.value = withTiming(1, { duration: 320 });
139 }}
140 />
141 </Animated.View>
142 </View>
143 );
144}
145
146function Spinner({ color, track }: { color: string; track: string }) {
147 const r = useSharedValue(0);
148 useEffect(() => {
149 r.value = withRepeat(withTiming(360, { duration: 800, easing: Easing.linear }), -1);
150 return () => cancelAnimation(r);
151 }, [r]);
152 const style = useAnimatedStyle(() => ({ transform: [{ rotate: `${r.value}deg` }] }));
153 return <Animated.View style={[styles.spinner, { borderColor: track, borderTopColor: color }, style]} />;
154}
155
156/** One of a stack of lines sharing a slot: the active one fades up, the others fade away. */
157function FadeLine({ text, active, color, size = 24 }: { text: string; active: boolean; color: string; size?: number }) {
158 const on = useSharedValue(active ? 1 : 0);
159 useEffect(() => {
160 on.value = withTiming(active ? 1 : 0, { duration: active ? 240 : 140, easing: Easing.out(Easing.cubic) });
161 }, [active, on]);
162 const style = useAnimatedStyle(() => ({ opacity: on.value, transform: [{ translateY: interpolate(on.value, [0, 1], [7, 0]) }] }));
163 return (
164 <Animated.Text
165 aria-hidden={!active}
166 numberOfLines={1}
167 style={[styles.fadeLine, { color, fontSize: size }, style]}
168 >
169 {text}
170 </Animated.Text>
171 );
172}
173
174// ─── The face: one mood value drives every feature ──────────────────────────
175
176const AnimatedCircle = Animated.createAnimatedComponent(Circle);
177const AnimatedPath = Animated.createAnimatedComponent(Path);
178
179const MOODS = [1, 2, 3, 4, 5];
180const SKIN = ['#F26B5E', '#F7954D', '#F9BC3F', '#FFD43B', '#B7E052'];
181const SKIN_IDLE = '#C3C8D1';
182const INK = '#2B2118';
183// Each row is one feature at ratings 1 to 5, in a 120 by 120 box.
184const SHAPE = {
185 mouthHalf: [15, 14, 14, 19, 23],
186 mouthY: [87, 84, 80, 74, 71],
187 lipTop: [-17, -10, 0, 16, 5],
188 lipBottom: [-17, -10, 0, 16, 40],
189 eyeY: [53, 53, 52, 50, 50],
190 eyeHalf: [4.8, 5, 5, 5.4, 7.5],
191 eyeUp: [6.4, 6.7, 6.7, 7.2, 13],
192 eyeDown: [6.4, 6.7, 6.7, 7.2, -7],
193 browOuter: [33, 38, 37, 34, 32],
194 browInner: [42, 33, 37, 34, 32],
195 browOpacity: [1, 1, 0.9, 0, 0],
196 blush: [0, 0, 0, 0.3, 0.2],
197 glint: [1, 1, 1, 1, 0],
198};
199
200function at(mood: number, keys: number[]) {
201 'worklet';
202 return interpolate(mood, MOODS, keys);
203}
204// Two arcs between the same corners: a round eye when they mirror, a happy crescent when both bow upward.
205function eye(x: number, y: number, half: number, up: number, down: number) {
206 'worklet';
207 return `M${x - half},${y} C${x - half},${y - up} ${x + half},${y - up} ${x + half},${y} C${x + half},${y + down} ${x - half},${y + down} ${x - half},${y}Z`;
208}
209
210const SPARKS = Array.from({ length: 10 }, (_, i) => ({
211 angle: (i / 10) * Math.PI * 2 + 0.3,
212 reach: 92 + (i % 3) * 16,
213 size: 8 + (i % 3) * 3,
214 color: [GOLD, '#34C56F', '#F26B5E', '#5B8DEF'][i % 4],
215}));
216
217function Spark({ t, spark }: { t: SharedValue<number>; spark: (typeof SPARKS)[number] }) {
218 const style = useAnimatedStyle(() => ({
219 opacity: interpolate(t.value, [0, 0.08, 0.9, 1], [0, 1, 1, 0]),
220 transform: [
221 { translateX: Math.cos(spark.angle) * spark.reach * t.value },
222 { translateY: Math.sin(spark.angle) * spark.reach * t.value },
223 { scale: interpolate(t.value, [0, 0.2, 1], [0.4, 1, 0.8]) },
224 ],
225 }));
226 return <Animated.View style={[styles.spark, { width: spark.size, height: spark.size, borderRadius: spark.size / 2, backgroundColor: spark.color }, style]} />;
227}
228
229const HALO = 164;
230const FACE = 124;
231
232function Face({ rating, cheer, intro }: { rating: number; cheer: boolean; intro: boolean }) {
233 // 3.5 is the unrated face: grey, with the start of a smile.
234 const mood = useSharedValue(3.5);
235 const colour = useSharedValue(0);
236 const bounce = useSharedValue(1);
237 const hop = useSharedValue(0);
238 const tilt = useSharedValue(0);
239 const blink = useSharedValue(1);
240 const burst = useSharedValue(0);
241
242 useEffect(() => {
243 const wait = intro ? 260 : 0;
244 mood.value = withDelay(wait, withTiming(cheer ? 5 : rating || 3.5, { duration: 420, easing: Easing.out(Easing.back(1.6)) }));
245 colour.value = withDelay(wait, withTiming(cheer || rating ? 1 : 0, { duration: 360 }));
246 if (intro) return;
247 bounce.value = withSequence(
248 withTiming(0.9, { duration: 80 }),
249 withTiming(1.07, { duration: 150, easing: Easing.out(Easing.quad) }),
250 withTiming(1, { duration: 180, easing: Easing.out(Easing.back(2)) })
251 );
252 if (cheer) {
253 // Two happy hops and a scatter of confetti.
254 hop.value = withSequence(
255 withTiming(-24, { duration: 170, easing: Easing.out(Easing.quad) }),
256 withTiming(0, { duration: 300, easing: Easing.bounce }),
257 withTiming(-12, { duration: 140, easing: Easing.out(Easing.quad) }),
258 withTiming(0, { duration: 260, easing: Easing.bounce })
259 );
260 burst.value = 0;
261 burst.value = withTiming(1, { duration: 1000, easing: Easing.out(Easing.cubic) });
262 } else if (rating >= 4) {
263 hop.value = withSequence(withTiming(rating === 5 ? -14 : -8, { duration: 150, easing: Easing.out(Easing.quad) }), withTiming(0, { duration: 320, easing: Easing.bounce }));
264 } else if (rating > 0 && rating <= 2) {
265 // A low score gets a shake of the head.
266 tilt.value = withSequence(withTiming(-8, { duration: 70 }), withTiming(8, { duration: 100 }), withTiming(-4, { duration: 90 }), withTiming(0, { duration: 90 }));
267 }
268 // eslint-disable-next-line react-hooks/exhaustive-deps
269 }, [rating, cheer]);
270
271 useEffect(() => {
272 blink.value = withRepeat(withSequence(withDelay(4200, withTiming(0.08, { duration: 80 })), withTiming(1, { duration: 130 })), -1);
273 return () => cancelAnimation(blink);
274 }, [blink]);
275
276 const skin = useDerivedValue(() => interpolateColor(colour.value, [0, 1], [SKIN_IDLE, interpolateColor(mood.value, MOODS, SKIN)]));
277
278 const mouthProps = useAnimatedProps(() => {
279 const m = mood.value;
280 const half = at(m, SHAPE.mouthHalf);
281 const y = at(m, SHAPE.mouthY);
282 return { d: `M${60 - half},${y} Q60,${y + at(m, SHAPE.lipTop)} ${60 + half},${y} Q60,${y + at(m, SHAPE.lipBottom)} ${60 - half},${y}Z` };
283 });
284 const leftEyeProps = useAnimatedProps(() => {
285 const m = mood.value;
286 return { d: eye(42, at(m, SHAPE.eyeY), at(m, SHAPE.eyeHalf), at(m, SHAPE.eyeUp) * blink.value, at(m, SHAPE.eyeDown) * blink.value) };
287 });
288 const rightEyeProps = useAnimatedProps(() => {
289 const m = mood.value;
290 return { d: eye(78, at(m, SHAPE.eyeY), at(m, SHAPE.eyeHalf), at(m, SHAPE.eyeUp) * blink.value, at(m, SHAPE.eyeDown) * blink.value) };
291 });
292 const browProps = useAnimatedProps(() => {
293 const m = mood.value;
294 const outer = at(m, SHAPE.browOuter);
295 const inner = at(m, SHAPE.browInner);
296 return { d: `M31,${outer} L50,${inner} M89,${outer} L70,${inner}`, opacity: Math.max(0, Math.min(1, at(m, SHAPE.browOpacity))) };
297 });
298 const blushProps = useAnimatedProps(() => ({ opacity: Math.max(0, at(mood.value, SHAPE.blush)) * colour.value }));
299 const leftGlintProps = useAnimatedProps(() => ({ cy: at(mood.value, SHAPE.eyeY) - 2.2, opacity: Math.max(0, Math.min(1, at(mood.value, SHAPE.glint))) * (blink.value > 0.5 ? 0.9 : 0) }));
300 const rightGlintProps = useAnimatedProps(() => ({ cy: at(mood.value, SHAPE.eyeY) - 2.2, opacity: Math.max(0, Math.min(1, at(mood.value, SHAPE.glint))) * (blink.value > 0.5 ? 0.9 : 0) }));
301
302 // The skin is a plain view under the drawing: react-native-svg on web ignores an animated fill.
303 const skinStyle = useAnimatedStyle(() => ({ backgroundColor: skin.value }));
304 const body = useAnimatedStyle(() => ({ transform: [{ translateY: hop.value }, { rotate: `${tilt.value}deg` }, { scale: bounce.value }] }));
305 const outerHalo = useAnimatedStyle(() => ({ backgroundColor: skin.value, transform: [{ scale: 1 + (bounce.value - 1) * 1.2 }] }));
306 const innerHalo = useAnimatedStyle(() => ({ backgroundColor: skin.value, transform: [{ scale: 1 + (bounce.value - 1) * 0.6 }] }));
307
308 return (
309 <View role="img" aria-label={cheer ? 'A delighted face' : `Face showing: ${LABELS[rating]}`} style={styles.face}>
310 <Animated.View style={[styles.haloOuter, outerHalo]} />
311 <Animated.View style={[styles.haloInner, innerHalo]} />
312 <View style={styles.sparks}>
313 {SPARKS.map((s) => (
314 <Spark key={s.angle} t={burst} spark={s} />
315 ))}
316 </View>
317 <Animated.View style={[styles.faceBody, body]}>
318 <Animated.View style={[styles.skin, skinStyle]} />
319 <Svg width={FACE} height={FACE} viewBox="0 0 120 120" style={styles.faceArt}>
320 <Defs>
321 <RadialGradient id="rate-face-gloss" cx="36%" cy="28%" r="78%">
322 <Stop offset="0" stopColor="#FFFFFF" stopOpacity={0.5} />
323 <Stop offset="0.5" stopColor="#FFFFFF" stopOpacity={0} />
324 <Stop offset="1" stopColor="#3A1D00" stopOpacity={0.2} />
325 </RadialGradient>
326 </Defs>
327 <Circle cx={60} cy={60} r={57} fill="url(#rate-face-gloss)" />
328 <AnimatedCircle cx={25} cy={69} r={9} fill="#FF6F7D" animatedProps={blushProps} />
329 <AnimatedCircle cx={95} cy={69} r={9} fill="#FF6F7D" animatedProps={blushProps} />
330 <AnimatedPath stroke={INK} strokeWidth={4} strokeLinecap="round" fill="none" animatedProps={browProps} />
331 <AnimatedPath fill={INK} stroke={INK} strokeWidth={2.4} strokeLinejoin="round" animatedProps={leftEyeProps} />
332 <AnimatedPath fill={INK} stroke={INK} strokeWidth={2.4} strokeLinejoin="round" animatedProps={rightEyeProps} />
333 <AnimatedCircle cx={43.8} r={1.7} fill="#FFFFFF" animatedProps={leftGlintProps} />
334 <AnimatedCircle cx={79.8} r={1.7} fill="#FFFFFF" animatedProps={rightGlintProps} />
335 <AnimatedPath fill={INK} stroke={INK} strokeWidth={4.4} strokeLinejoin="round" strokeLinecap="round" animatedProps={mouthProps} />
336 </Svg>
337 </Animated.View>
338 </View>
339 );
340}
341
342// ─── Stars: a tap fills them left to right, each with a pop ─────────────────
343
344function StarButton({ value, rating, wave, intro, onPress }: { value: number; rating: number; wave: number; intro: boolean; onPress: () => void }) {
345 const c = usePalette();
346 const fill = useSharedValue(0);
347 const pop = useSharedValue(1);
348 useEffect(() => {
349 if (value <= rating) {
350 const wait = (intro ? 380 : 0) + (value - 1) * 65;
351 fill.value = withDelay(wait, withTiming(1, { duration: 150 }));
352 pop.value = withDelay(wait, withSequence(withTiming(1.3, { duration: 130, easing: Easing.out(Easing.quad) }), withTiming(1, { duration: 240, easing: Easing.out(Easing.back(3)) })));
353 } else {
354 // Emptying runs back from the right.
355 fill.value = withDelay((5 - value) * 30, withTiming(0, { duration: 140 }));
356 }
357 // eslint-disable-next-line react-hooks/exhaustive-deps
358 }, [rating, wave]);
359 const popStyle = useAnimatedStyle(() => ({ transform: [{ scale: pop.value }] }));
360 const fillStyle = useAnimatedStyle(() => ({ opacity: fill.value, transform: [{ scale: interpolate(fill.value, [0, 1], [0.5, 1]) }] }));
361 return (
362 <Pressable role="radio" aria-checked={value === rating} aria-label={`${value} ${value === 1 ? 'star' : 'stars'}, ${LABELS[value]}`} onPress={onPress} style={styles.star}>
363 <Animated.View style={popStyle}>
364 <Star size={42} color={c.starOff} fill={c.chip} strokeWidth={1.6} />
365 <Animated.View style={[StyleSheet.absoluteFill, fillStyle]}>
366 <Star size={42} color={GOLD} fill={GOLD} strokeWidth={1.6} />
367 </Animated.View>
368 </Animated.View>
369 </Pressable>
370 );
371}
372
373// ─── Quick-pick chips ───────────────────────────────────────────────────────
374
375function Chip({ label, selected, tone, index, intro, onPress }: { label: string; selected: boolean; tone: Tone; index: number; intro: boolean; onPress: () => void }) {
376 const c = usePalette();
377 const on = useSharedValue(selected ? 1 : 0);
378 const scale = useSharedValue(1);
379 useEffect(() => {
380 on.value = withTiming(selected ? 1 : 0, { duration: 200, easing: Easing.out(Easing.cubic) });
381 }, [selected, on]);
382 // Praise fills with the accent, complaints with plain ink.
383 const fill = tone === 'praise' ? c.accent : c.fg;
384 const onFill = tone === 'praise' ? c.onAccent : c.bg;
385 const box = useAnimatedStyle(() => ({
386 backgroundColor: interpolateColor(on.value, [0, 1], [c.card, fill]),
387 borderColor: interpolateColor(on.value, [0, 1], [c.line, fill]),
388 transform: [{ scale: scale.value }],
389 }));
390 const text = useAnimatedStyle(() => ({ color: interpolateColor(on.value, [0, 1], [c.fg, onFill]) }));
391 return (
392 <Animated.View entering={intro ? undefined : ZoomIn.delay(index * 40).duration(220)}>
393 <Pressable
394 role="checkbox"
395 aria-checked={selected}
396 aria-label={label}
397 onPress={() => {
398 scale.value = withSequence(withTiming(0.93, { duration: 70 }), withTiming(1, { duration: 220, easing: Easing.out(Easing.back(3)) }));
399 onPress();
400 }}
401 >
402 <Animated.View style={[styles.chip, box]}>
403 <Animated.Text style={[styles.chipText, text]}>{label}</Animated.Text>
404 </Animated.View>
405 </Pressable>
406 </Animated.View>
407 );
408}
409
410// ─── Tip: shown for happy scores, with a highlight that glides between pills ─
411
412const TIP_BASE = 24 + 22 + 12 + 48;
413const TIP_CUSTOM = 10 + 48;
414
415function TipSection({ show, tip, custom, onTip, onCustom }: { show: boolean; tip: Tip; custom: number; onTip: (t: Tip) => void; onCustom: (n: number) => void }) {
416 const c = usePalette();
417 const { width } = useWindowDimensions();
418 const slot = (width - 40 - 8) / TIPS.length;
419 const index = TIPS.findIndex((t) => t.value === tip);
420 const last = useRef(index);
421 const target = show ? TIP_BASE + (tip === 'other' ? TIP_CUSTOM : 0) : 0;
422 const height = useSharedValue(target);
423 const x = useSharedValue(Math.max(0, index) * slot);
424 const lit = useSharedValue(index >= 0 ? 1 : 0);
425
426 useEffect(() => {
427 height.value = withTiming(target, { duration: 300, easing: Easing.out(Easing.cubic) });
428 }, [target, height]);
429 useEffect(() => {
430 if (index >= 0) {
431 // The first pick appears in place; later picks glide.
432 x.value = last.current < 0 ? index * slot : withTiming(index * slot, { duration: 280, easing: Easing.out(Easing.back(1.4)) });
433 lit.value = withTiming(1, { duration: 180 });
434 } else {
435 lit.value = withTiming(0, { duration: 160 });
436 }
437 last.current = index;
438 }, [index, slot, x, lit]);
439
440 const wrap = useAnimatedStyle(() => ({ height: height.value, opacity: interpolate(height.value, [0, TIP_BASE], [0, 1], 'clamp') }));
441 const thumb = useAnimatedStyle(() => ({ opacity: lit.value, transform: [{ translateX: x.value }, { scale: interpolate(lit.value, [0, 1], [0.85, 1]) }] }));
442 const amount = tip === 'other' ? custom : tip;
443
444 return (
445 <Animated.View aria-hidden={!show} style={[styles.tip, { pointerEvents: show ? 'auto' : 'none' }, wrap]}>
446 <View style={styles.tipHead}>
447 <Text style={[styles.sectionTitle, { color: c.fg }]}>Add a tip for {ORDER.courier}</Text>
448 {amount ? (
449 <Animated.Text key={amount} entering={FadeInDown.duration(180)} style={[styles.tipAmount, { color: c.accent }, TABULAR]}>
450 ${amount.toFixed(2)}
451 </Animated.Text>
452 ) : (
453 <Text style={[styles.sectionAside, { color: c.muted }]}>100% goes to {ORDER.courier}</Text>
454 )}
455 </View>
456 <View role="radiogroup" aria-label="Tip amount" style={[styles.tipTrack, { backgroundColor: c.chip }]}>
457 <Animated.View style={[styles.tipThumb, { width: slot, backgroundColor: c.accent }, thumb]} />
458 {TIPS.map((t) => {
459 const selected = t.value === tip;
460 return (
461 <Pressable
462 key={t.label}
463 role="radio"
464 aria-checked={selected}
465 aria-label={t.value === 'other' ? 'Other tip amount' : `Tip ${t.label}`}
466 tabIndex={show ? 0 : -1}
467 onPress={() => onTip(selected ? null : t.value)}
468 style={styles.tipOption}
469 >
470 <Text style={[styles.tipLabel, { color: selected ? c.onAccent : c.fg }, TABULAR]}>{t.label}</Text>
471 </Pressable>
472 );
473 })}
474 </View>
475 {/* A custom amount, stepped a dollar at a time */}
476 <View aria-hidden={tip !== 'other'} style={[styles.custom, { borderColor: c.line, backgroundColor: c.card }]}>
477 <Text style={[styles.customLabel, { color: c.fg }]}>Custom amount</Text>
478 <Pressable role="button" aria-label="Decrease tip" tabIndex={tip === 'other' ? 0 : -1} disabled={custom <= 1} onPress={() => onCustom(custom - 1)} style={[styles.stepper, { backgroundColor: c.chip, opacity: custom <= 1 ? 0.4 : 1 }]}>
479 <Minus size={16} color={c.fg} strokeWidth={2.6} />
480 </Pressable>
481 <Text style={[styles.customValue, { color: c.fg }, TABULAR]}>${custom}</Text>
482 <Pressable role="button" aria-label="Increase tip" tabIndex={tip === 'other' ? 0 : -1} disabled={custom >= 50} onPress={() => onCustom(custom + 1)} style={[styles.stepper, { backgroundColor: c.chip, opacity: custom >= 50 ? 0.4 : 1 }]}>
483 <Plus size={16} color={c.fg} strokeWidth={2.6} />
484 </Pressable>
485 </View>
486 </Animated.View>
487 );
488}
489
490// ─── Comment box with a live counter ────────────────────────────────────────
491
492function CommentBox({ value, onChangeText, onFocus }: { value: string; onChangeText: (v: string) => void; onFocus: () => void }) {
493 const c = usePalette();
494 const [focused, setFocused] = useState(false);
495 const ring = useSharedValue(0);
496 useEffect(() => {
497 ring.value = withTiming(focused ? 1 : 0, { duration: 180 });
498 }, [focused, ring]);
499 const box = useAnimatedStyle(() => ({ borderColor: interpolateColor(ring.value, [0, 1], [c.line, c.accent]), shadowOpacity: ring.value * 0.22 }));
500 const left = MAX_COMMENT - value.length;
501 return (
502 <Animated.View style={[styles.comment, { backgroundColor: c.card, shadowColor: c.accent, shadowRadius: 10, shadowOffset: { width: 0, height: 0 } }, box]}>
503 <TextInput
504 value={value}
505 onChangeText={onChangeText}
506 onFocus={() => {
507 setFocused(true);
508 onFocus();
509 }}
510 onBlur={() => setFocused(false)}
511 multiline
512 maxLength={MAX_COMMENT}
513 aria-label="Comment"
514 placeholder={`Tell ${ORDER.restaurant} a little more`}
515 placeholderTextColor={c.faint}
516 selectionColor={c.accent}
517 style={[styles.commentInput, { color: c.fg }, Platform.OS === 'web' ? ({ outlineStyle: 'none' } as object) : null]}
518 />
519 <View style={styles.commentFoot}>
520 <Text style={[styles.commentNote, { color: c.muted }]}>Shared with the restaurant</Text>
521 <Text aria-label={`${value.length} of ${MAX_COMMENT} characters`} style={[styles.commentCount, { color: left <= 20 ? c.warn : c.muted }, TABULAR]}>
522 {value.length}/{MAX_COMMENT}
523 </Text>
524 </View>
525 </Animated.View>
526 );
527}
528
529// ─── Submit: disabled, ready, spinning, sent ────────────────────────────────
530
531type Status = 'idle' | 'loading' | 'done';
532
533function SubmitButton({ status, disabled, onPress }: { status: Status; disabled: boolean; onPress: () => void }) {
534 const c = usePalette();
535 const scale = useSharedValue(1);
536 const ready = useSharedValue(disabled ? 0 : 1);
537 useEffect(() => {
538 ready.value = withTiming(disabled ? 0 : 1, { duration: 220 });
539 }, [disabled, ready]);
540 const style = useAnimatedStyle(() => ({
541 backgroundColor: interpolateColor(ready.value, [0, 1], [c.chip, c.accent]),
542 shadowOpacity: ready.value * (c.dark ? 0.25 : 0.3),
543 transform: [{ scale: scale.value }],
544 }));
545 return (
546 <Pressable
547 role="button"
548 aria-label="Submit review"
549 aria-disabled={disabled}
550 aria-busy={status === 'loading'}
551 disabled={disabled || status !== 'idle'}
552 onPress={onPress}
553 onPressIn={() => (scale.value = withSpring(0.97, PRESS))}
554 onPressOut={() => (scale.value = withSpring(1, PRESS))}
555 style={styles.submitSlot}
556 >
557 <Animated.View style={[styles.submit, { shadowColor: c.accent, shadowRadius: 14, shadowOffset: { width: 0, height: 6 } }, style]}>
558 {status === 'idle' && (
559 <Animated.Text entering={FadeIn.duration(160)} style={[styles.submitLabel, { color: disabled ? c.faint : c.onAccent }]}>
560 Submit review
561 </Animated.Text>
562 )}
563 {status === 'loading' && <Spinner color={c.onAccent} track={c.onAccentSoft} />}
564 {status === 'done' && (
565 <Animated.View entering={ZoomIn.duration(240)} style={styles.submitDone}>
566 <Check size={19} color={c.onAccent} strokeWidth={3} />
567 <Text style={[styles.submitLabel, { color: c.onAccent }]}>Review sent</Text>
568 </Animated.View>
569 )}
570 </Animated.View>
571 </Pressable>
572 );
573}
574
575// ─── Screen ─────────────────────────────────────────────────────────────────
576
577const HEADER_H = 50;
578const BAR_H = 12 + 54 + 6;
579
580export default function RateExperienceScreen() {
581 const c = usePalette();
582 const insets = useSafeAreaInsets();
583 const [rating, setRating] = useState(START.rating);
584 const [wave, setWave] = useState(0);
585 const [tags, setTags] = useState<string[]>(START.tags);
586 const [comment, setComment] = useState('');
587 const [tip, setTip] = useState<Tip>(null);
588 const [custom, setCustom] = useState(8);
589 const [status, setStatus] = useState<Status>('idle');
590 const [intro, setIntro] = useState(true);
591 const scrollRef = useRef<ComponentRef<typeof ScrollView>>(null);
592 const timers = useRef<ReturnType<typeof setTimeout>[]>([]);
593
594 useEffect(() => {
595 const t = setTimeout(() => setIntro(false), 1100);
596 const pending = timers.current;
597 return () => {
598 clearTimeout(t);
599 pending.forEach(clearTimeout);
600 };
601 }, []);
602
603 // The chips on show trail the score by a beat, so the old set can fade before the new one pops in.
604 const tone = toneOf(rating);
605 const [shown, setShown] = useState<Tone>(tone);
606 const chipsFade = useSharedValue(1);
607 useEffect(() => {
608 if (tone === shown) return;
609 chipsFade.value = withTiming(0, { duration: 130 });
610 const t = setTimeout(() => {
611 setShown(tone);
612 chipsFade.value = withTiming(1, { duration: 160 });
613 }, 140);
614 return () => clearTimeout(t);
615 }, [tone, shown, chipsFade]);
616 const chipsStyle = useAnimatedStyle(() => ({ opacity: chipsFade.value, transform: [{ translateY: interpolate(chipsFade.value, [0, 1], [6, 0]) }] }));
617
618 const scrollY = useSharedValue(0);
619 const hairline = useAnimatedStyle(() => ({ opacity: interpolate(scrollY.value, [0, 16], [0, 1], 'clamp') }));
620
621 const idle = status === 'idle';
622 const rate = (value: number) => {
623 if (!idle) return;
624 setWave((w) => w + 1);
625 if (toneOf(value) !== tone) setTags([]);
626 if (value < 4) setTip(null);
627 setRating(value);
628 };
629 const toggleTag = (tag: string) => idle && setTags((prev) => (prev.includes(tag) ? prev.filter((t) => t !== tag) : [...prev, tag]));
630
631 const submit = () => {
632 if (!rating || !idle) return;
633 setStatus('loading');
634 // Replace the timers with your reviews API call.
635 timers.current.push(
636 setTimeout(() => {
637 setStatus('done');
638 scrollRef.current?.scrollTo({ y: 0, animated: true });
639 }, 1200),
640 setTimeout(() => {
641 setRating(0);
642 setTags([]);
643 setComment('');
644 setTip(null);
645 setStatus('idle');
646 }, 1200 + 2100)
647 );
648 };
649
650 const rise = (i: number) => (intro ? FadeInDown.delay(40 + i * 70).duration(420) : undefined);
651 const set = CHIPS[shown];
652 const labelIndex = status === 'done' ? 6 : rating;
653
654 return (
655 <KeyboardAvoidingView behavior={Platform.OS === 'ios' ? 'padding' : undefined} style={[styles.screen, { backgroundColor: c.bg }]}>
656 <ScrollView
657 ref={scrollRef}
658 keyboardShouldPersistTaps="handled"
659 showsVerticalScrollIndicator={false}
660 scrollEventThrottle={16}
661 onScroll={(e) => {
662 scrollY.value = e.nativeEvent.contentOffset.y;
663 }}
664 contentContainerStyle={[styles.content, { paddingTop: insets.top + HEADER_H + 8, paddingBottom: insets.bottom + BAR_H + 24 }]}
665 >
666 {/* Order recap */}
667 <Animated.View entering={rise(0)} style={[styles.recap, { borderColor: c.line, backgroundColor: c.card }]}>
668 <View>
669 <Photo uri={ORDER.photo} alt="A grain bowl with tofu, corn, edamame and red cabbage" size={56} radius={16} />
670 <View style={[styles.recapBadge, { backgroundColor: c.accent, borderColor: c.card }]}>
671 <Check size={11} color={c.onAccent} strokeWidth={3.6} />
672 </View>
673 </View>
674 <View style={styles.recapText}>
675 <Text numberOfLines={1} style={[styles.recapTitle, { color: c.fg }]}>
676 {ORDER.restaurant}
677 </Text>
678 <Text numberOfLines={1} style={[styles.recapMeta, { color: c.muted }, TABULAR]}>
679 {ORDER.delivered} · {ORDER.items} items
680 </Text>
681 <View style={styles.recapCourier}>
682 <Bike size={13} color={c.muted} />
683 <Text style={[styles.recapMeta, { color: c.muted }]}>
684 <Text style={[styles.recapCourierName, { color: c.fg }]}>{ORDER.courier}</Text> was your courier
685 </Text>
686 </View>
687 </View>
688 </Animated.View>
689
690 {/* Face, label, stars */}
691 <Animated.View entering={rise(1)} style={styles.rating}>
692 <Face rating={rating} cheer={status === 'done'} intro={intro} />
693 <View aria-live="polite" style={styles.ratingLabel}>
694 {[...LABELS, THANKS].map((text, i) => (
695 <FadeLine key={text} text={text} active={i === labelIndex} color={i === 0 ? c.muted : c.fg} size={i === 0 ? 19 : 24} />
696 ))}
697 </View>
698 <View role="radiogroup" aria-label="Rating" style={styles.stars}>
699 {[1, 2, 3, 4, 5].map((value) => (
700 <StarButton key={value} value={value} rating={rating} wave={wave} intro={intro} onPress={() => rate(value)} />
701 ))}
702 </View>
703 </Animated.View>
704
705 {/* Chips: praise at 4 and 5 stars, complaints below */}
706 <Animated.View entering={rise(2)} style={styles.chipsSection}>
707 <Animated.View style={chipsStyle}>
708 <View style={styles.sectionHead}>
709 <Text style={[styles.sectionTitle, { color: c.fg }]}>{set.title}</Text>
710 <Text style={[styles.sectionAside, { color: c.muted }, TABULAR]}>{tags.length ? `${tags.length} selected` : 'Pick any'}</Text>
711 </View>
712 <View style={styles.chips}>
713 {set.options.map((label, i) => (
714 <Chip key={`${shown}-${label}`} label={label} tone={shown} index={i} intro={intro} selected={tags.includes(label)} onPress={() => toggleTag(label)} />
715 ))}
716 </View>
717 </Animated.View>
718 </Animated.View>
719
720 <Animated.View entering={rise(3)}>
721 <TipSection show={rating >= 4} tip={tip} custom={custom} onTip={(t) => idle && setTip(t)} onCustom={setCustom} />
722 </Animated.View>
723
724 <Animated.View entering={rise(4)} style={styles.commentSection}>
725 <View style={[styles.sectionHead, styles.commentHead]}>
726 <Text style={[styles.sectionTitle, { color: c.fg }]}>Add a comment</Text>
727 <Text style={[styles.sectionAside, { color: c.muted }]}>Optional</Text>
728 </View>
729 <CommentBox value={comment} onChangeText={setComment} onFocus={() => setTimeout(() => scrollRef.current?.scrollToEnd({ animated: true }), 60)} />
730 </Animated.View>
731 </ScrollView>
732
733 {/* Header, opaque, under the status bar */}
734 <View style={[styles.header, { paddingTop: insets.top, backgroundColor: c.bg }]}>
735 <View style={styles.headerBar}>
736 <Pressable role="button" aria-label="Close" hitSlop={8} style={[styles.close, { backgroundColor: c.chip }]}>
737 <X size={18} color={c.fg} strokeWidth={2.4} />
738 </Pressable>
739 <Text role="heading" style={[styles.headerTitle, { color: c.fg }]}>
740 Rate your order
741 </Text>
742 <View style={styles.headerSpacer} />
743 </View>
744 <Animated.View style={[styles.hairline, { backgroundColor: c.line }, hairline]} />
745 </View>
746
747 {/* Bottom bar, opaque, over the home indicator */}
748 <View style={[styles.bottomBar, { paddingBottom: insets.bottom + 6, backgroundColor: c.bg, borderTopColor: c.line }]}>
749 <Pressable role="button" aria-label="Skip" disabled={!idle} hitSlop={6} style={[styles.skip, { opacity: idle ? 1 : 0.4 }]}>
750 <Text style={[styles.skipText, { color: c.muted }]}>Skip</Text>
751 </Pressable>
752 <SubmitButton status={status} disabled={rating === 0} onPress={submit} />
753 </View>
754 </KeyboardAvoidingView>
755 );
756}
757
758// ─── Styles ─────────────────────────────────────────────────────────────────
759
760const styles = StyleSheet.create({
761 screen: { flex: 1 },
762 content: { paddingHorizontal: 20 },
763 sectionHead: { height: 22, flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between' },
764 sectionTitle: { fontSize: 17, fontWeight: '700', letterSpacing: -0.3 },
765 sectionAside: { fontSize: 13 },
766
767 // Small pieces
768 photo: { overflow: 'hidden' },
769 photoFill: { flex: 1 },
770 photoImage: { width: '100%', height: '100%' },
771 spinner: { width: 20, height: 20, borderRadius: 10, borderWidth: 2.5 },
772 fadeLine: { position: 'absolute', left: 0, right: 0, textAlign: 'center', fontWeight: '700', letterSpacing: -0.5 },
773
774 // Face
775 spark: { position: 'absolute' },
776 face: { width: HALO, height: HALO, alignItems: 'center', justifyContent: 'center' },
777 haloOuter: { position: 'absolute', width: HALO, height: HALO, borderRadius: HALO / 2, opacity: 0.1 },
778 haloInner: { position: 'absolute', width: HALO - 22, height: HALO - 22, borderRadius: HALO / 2, opacity: 0.14 },
779 sparks: { position: 'absolute', alignItems: 'center', justifyContent: 'center', pointerEvents: 'none' },
780 faceBody: { width: FACE, height: FACE },
781 skin: { position: 'absolute', top: FACE * 0.025, left: FACE * 0.025, width: FACE * 0.95, height: FACE * 0.95, borderRadius: FACE / 2 },
782 faceArt: { position: 'absolute', top: 0, left: 0 },
783
784 // Stars and chips
785 star: { width: 54, height: 54, alignItems: 'center', justifyContent: 'center' },
786 chip: { height: 38, paddingHorizontal: 14, borderRadius: 19, borderWidth: 1.5, justifyContent: 'center' },
787 chipText: { fontSize: 14.5, fontWeight: '600' },
788
789 // Tip
790 tip: { overflow: 'hidden' },
791 tipHead: { height: 22, marginTop: 24, flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between' },
792 tipAmount: { fontSize: 15, fontWeight: '700' },
793 tipTrack: { height: 48, marginTop: 12, padding: 4, borderRadius: 16, flexDirection: 'row' },
794 tipThumb: { position: 'absolute', top: 4, left: 4, height: 40, borderRadius: 12 },
795 tipOption: { flex: 1, alignItems: 'center', justifyContent: 'center' },
796 tipLabel: { fontSize: 15, fontWeight: '700' },
797 custom: { height: 48, marginTop: 10, paddingLeft: 16, paddingRight: 6, borderRadius: 16, borderWidth: 1.5, flexDirection: 'row', alignItems: 'center' },
798 customLabel: { flex: 1, fontSize: 15, fontWeight: '600' },
799 stepper: { width: 34, height: 34, borderRadius: 17, alignItems: 'center', justifyContent: 'center' },
800 customValue: { width: 52, textAlign: 'center', fontSize: 16, fontWeight: '700' },
801
802 // Comment
803 comment: { borderRadius: 18, borderWidth: 1.5, paddingHorizontal: 14, paddingTop: 12, paddingBottom: 10 },
804 commentInput: { height: 82, padding: 0, fontSize: 16, lineHeight: 22, textAlignVertical: 'top' },
805 commentFoot: { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', marginTop: 6 },
806 commentNote: { fontSize: 12.5 },
807 commentCount: { fontSize: 12.5, fontWeight: '600' },
808
809 // Submit
810 submitSlot: { flex: 1 },
811 submit: { height: 54, borderRadius: 17, alignItems: 'center', justifyContent: 'center' },
812 submitLabel: { fontSize: 16.5, fontWeight: '700' },
813 submitDone: { flexDirection: 'row', alignItems: 'center', gap: 8 },
814
815 // Screen
816 recap: { flexDirection: 'row', alignItems: 'center', gap: 12, padding: 12, borderRadius: 22, borderWidth: 1 },
817 recapBadge: { position: 'absolute', right: -5, bottom: -5, width: 22, height: 22, borderRadius: 11, borderWidth: 2.5, alignItems: 'center', justifyContent: 'center' },
818 recapText: { flex: 1, gap: 2 },
819 recapTitle: { fontSize: 16, fontWeight: '700', letterSpacing: -0.3 },
820 recapMeta: { fontSize: 13 },
821 recapCourier: { flexDirection: 'row', alignItems: 'center', gap: 5 },
822 recapCourierName: { fontWeight: '600' },
823 rating: { alignItems: 'center', marginTop: 14 },
824 ratingLabel: { alignSelf: 'stretch', height: 32, marginTop: 6 },
825 stars: { flexDirection: 'row', marginTop: 6 },
826 chipsSection: { marginTop: 20 },
827 chips: { flexDirection: 'row', flexWrap: 'wrap', gap: 8, marginTop: 12, minHeight: 84 },
828 commentSection: { marginTop: 24 },
829 commentHead: { marginBottom: 12 },
830 header: { position: 'absolute', top: 0, left: 0, right: 0 },
831 headerBar: { height: HEADER_H, flexDirection: 'row', alignItems: 'center', paddingHorizontal: 16 },
832 close: { width: 36, height: 36, borderRadius: 18, alignItems: 'center', justifyContent: 'center' },
833 headerTitle: { flex: 1, textAlign: 'center', fontSize: 17, fontWeight: '700', letterSpacing: -0.3 },
834 headerSpacer: { width: 36 },
835 hairline: { height: 1 },
836 bottomBar: {
837 position: 'absolute',
838 left: 0,
839 right: 0,
840 bottom: 0,
841 paddingTop: 12,
842 paddingHorizontal: 20,
843 borderTopWidth: 1,
844 flexDirection: 'row',
845 alignItems: 'center',
846 gap: 6,
847 },
848 skip: { height: 54, paddingLeft: 4, paddingRight: 18, justifyContent: 'center' },
849 skipText: { fontSize: 15.5, fontWeight: '600' },
850});

More screens like this.

All Feedback & States