Lesson quiz

A bite-sized language lesson with five exercise types that slide in one after another: picture cards, word tiles that fly between the bank and the answer line, match pairs that shake or fade, listen and type, and fill the blank. Chunky buttons press down, the progress bar springs with a shine, hearts crack on a miss, a feedback panel slides up with a sparkle burst and floating XP, and the lesson ends on a medal, rolling stats and a 7-day streak.

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

Details

File
components/patterns/lesson-quiz.tsx
Lines
1204
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/lesson-quiz.tsx
1import { useEffect, useRef, useState, type ReactNode } from 'react';
2import { KeyboardAvoidingView, Platform, Pressable, StyleSheet, Text, TextInput, View, useColorScheme, useWindowDimensions, type LayoutChangeEvent, type StyleProp, type ViewStyle } from 'react-native';
3import Animated, {
4 Easing,
5 FadeIn,
6 FadeInDown,
7 ZoomIn,
8 cancelAnimation,
9 interpolate,
10 runOnJS,
11 useAnimatedStyle,
12 useSharedValue,
13 withDelay,
14 withRepeat,
15 withSequence,
16 withSpring,
17 withTiming,
18 type SharedValue,
19} from 'react-native-reanimated';
20import { useSafeAreaInsets } from 'react-native-safe-area-context';
21import Svg, { Circle, Ellipse, Path, Rect } from 'react-native-svg';
22import { Check, Clock, Flame, Heart, HeartCrack, Target, Volume2, X, Zap } from 'lucide-react-native';
23
24// ─── Brand ──────────────────────────────────────────────────────────────────
25// The screen's accent and name. Every accent colour below derives from these, so changing them rebrands the screen.
26
27const ACCENT = '#14B8A6';
28const ACCENT_DARK = '#3DD9C6'; // the accent on dark backgrounds
29const ON_ACCENT = '#FFFFFF'; // text and icons on an accent fill
30const APP_NAME = 'Lingo Lane';
31
32/** `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}
37
38/** `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}
46
47// ─── Sample data ────────────────────────────────────────────────────────────
48
49const COURSE = 'Food and drink';
50const LESSON = 'Lesson 3 of 6';
51const HEARTS = 4;
52const XP_EACH = 10;
53// The lesson opens a little way in, as if the warm-up card is already behind you.
54const HEAD_START = 0.18;
55
56const STEPS = [
57 { kind: 'New word', title: 'Which one is “la manzana”?', answer: 'la manzana = the apple' },
58 { kind: 'Translate', title: 'Translate this sentence', answer: 'Yo bebo agua' },
59 { kind: 'Match pairs', title: 'Tap the matching pairs', answer: 'All five pairs matched' },
60 { kind: 'Listen', title: 'Type what you hear', answer: 'gracias = thank you' },
61 { kind: 'Fill the blank', title: 'Complete the sentence', answer: 'Ella come pan.' },
62];
63const LAST = STEPS.length - 1;
64
65type FoodId = 'apple' | 'bread' | 'cheese' | 'milk';
66const FOODS: { id: FoodId; label: string }[] = [
67 { id: 'apple', label: 'apple' },
68 { id: 'bread', label: 'bread' },
69 { id: 'cheese', label: 'cheese' },
70 { id: 'milk', label: 'milk' },
71];
72const FOOD_ANSWER: FoodId = 'apple';
73
74const SENTENCE = 'I drink water';
75const BANK = ['Yo', 'bebo', 'agua', 'come', 'pan'];
76const BANK_ANSWER = 'Yo bebo agua';
77
78const PAIRS = [
79 { id: 'pan', es: 'el pan', en: 'bread' },
80 { id: 'leche', es: 'la leche', en: 'milk' },
81 { id: 'queso', es: 'el queso', en: 'cheese' },
82 { id: 'agua', es: 'el agua', en: 'water' },
83 { id: 'manzana', es: 'la manzana', en: 'apple' },
84];
85const RIGHT_COLUMN = [2, 4, 0, 3, 1];
86
87const HEARD = 'gracias';
88const BLANK = { before: 'Ella', after: 'pan.', meaning: 'She eats bread.', choices: ['come', 'bebo', 'comen'], answer: 'come' };
89const WEEK = ['M', 'T', 'W', 'T', 'F', 'S', 'S'];
90const STREAK = 7;
91
92// ─── Palette ────────────────────────────────────────────────────────────────
93
94const ACCENT_EDGE = shade(ACCENT, 0.215);
95const SUN = '#FBBF24';
96const SUN_EDGE = '#D9990B';
97const EMBER = '#FF8A3D';
98const CORAL = '#FF6B5E';
99const CORAL_EDGE = '#DC4A3E';
100const GOOD = '#1FB86B';
101const GOOD_EDGE = '#15924F';
102const SKY = '#38BDF8';
103const SPARKS = [SUN, '#FFFFFF', ACCENT, SUN, GOOD, '#FFFFFF', SUN, ACCENT];
104const DEPTH = 4;
105const PRESS = { damping: 14, stiffness: 420, mass: 0.5 };
106const POP = { damping: 11, stiffness: 240, mass: 0.6 };
107const SLIDE = { damping: 22, stiffness: 240, mass: 0.8 };
108const PANEL_H = 84;
109const PANEL_ROOM = 64;
110const ROW_H = 58;
111const WEB_INPUT = Platform.OS === 'web' ? ({ outlineStyle: 'none' } as object) : null;
112
113function usePalette() {
114 const dark = useColorScheme() === 'dark';
115 return {
116 dark,
117 bg: dark ? '#0D1617' : '#FFFCF5',
118 card: dark ? '#152223' : '#FFFFFF',
119 line: dark ? '#2B3D3E' : '#E7E0D0',
120 fg: dark ? '#F1F7F6' : '#16302D',
121 muted: dark ? '#8EA3A1' : '#687A77',
122 faint: dark ? '#566968' : '#A8B3B0',
123 track: dark ? '#223233' : '#EFE8D9',
124 accentSoft: dark ? shade(ACCENT_DARK, 0.75) : shade(ACCENT, -0.857),
125 accentText: dark ? ACCENT_DARK : shade(ACCENT, 0.28),
126 goodSoft: dark ? '#10301F' : '#DDF7E8',
127 goodText: dark ? '#4ADE8A' : '#11824A',
128 badSoft: dark ? '#3A1B18' : '#FFE7E3',
129 badText: dark ? '#FF8E83' : '#CF3B2E',
130 sunSoft: dark ? '#3A2D0B' : '#FFF3CF',
131 sunText: dark ? '#FCD34D' : '#A16A00',
132 off: dark ? '#223233' : '#EBE5D8',
133 offEdge: dark ? '#182526' : '#DAD3C3',
134 offText: dark ? '#5B6F6E' : '#A9A393',
135 ray: dark ? 'rgba(251,191,36,0.10)' : 'rgba(251,191,36,0.22)',
136 bottle: dark ? '#E8EEF2' : '#F4F7FA',
137 bottleLine: dark ? '#8FA3A1' : '#C4CFD8',
138 scrim: dark ? 'rgba(0,0,0,0.6)' : 'rgba(22,48,45,0.4)',
139 };
140}
141type Palette = ReturnType<typeof usePalette>;
142
143type Tone = 'idle' | 'selected' | 'good' | 'bad';
144function toneOf(c: Palette, tone: Tone) {
145 if (tone === 'selected') return { face: c.accentSoft, edge: ACCENT, text: c.accentText };
146 if (tone === 'good') return { face: c.goodSoft, edge: GOOD, text: c.goodText };
147 if (tone === 'bad') return { face: c.badSoft, edge: CORAL, text: c.badText };
148 return { face: c.card, edge: c.line, text: c.fg };
149}
150
151// ─── Chunky button: a face that presses down onto its solid bottom edge ─────
152
153type ChunkyProps = {
154 label: string;
155 face: string;
156 edge: string;
157 outlined?: boolean;
158 disabled?: boolean;
159 selected?: boolean;
160 radius?: number;
161 onPress?: () => void;
162 style?: StyleProp<ViewStyle>;
163 faceStyle?: StyleProp<ViewStyle>;
164 children: ReactNode;
165};
166
167function Chunky({ label, face, edge, outlined, disabled, selected, radius = 16, onPress, style, faceStyle, children }: ChunkyProps) {
168 const down = useSharedValue(0);
169 const press = useAnimatedStyle(() => ({ transform: [{ translateY: down.value * DEPTH }] }));
170 return (
171 <Pressable
172 role="button"
173 aria-label={label}
174 aria-disabled={disabled}
175 aria-selected={selected}
176 disabled={disabled}
177 onPress={onPress}
178 onPressIn={() => (down.value = withTiming(1, { duration: 50 }))}
179 onPressOut={() => (down.value = withSpring(0, PRESS))}
180 style={[styles.chunk, { backgroundColor: edge, borderRadius: radius }, style]}
181 >
182 <Animated.View style={[styles.face, outlined && styles.faceOutlined, { backgroundColor: face, borderColor: edge, borderRadius: radius }, faceStyle, press]}>
183 {children}
184 </Animated.View>
185 </Pressable>
186 );
187}
188
189// ─── Top bar: progress that springs and shines, hearts that crack ───────────
190
191function ProgressBar({ value }: { value: number }) {
192 const c = usePalette();
193 const [w, setW] = useState(0);
194 const p = useSharedValue(0);
195 const shine = useSharedValue(0);
196 useEffect(() => {
197 p.value = withSpring(value, { damping: 15, stiffness: 130, mass: 0.8 });
198 shine.value = 0;
199 shine.value = withDelay(180, withTiming(1, { duration: 650, easing: Easing.out(Easing.quad) }));
200 }, [value, p, shine]);
201 const fill = useAnimatedStyle(() => ({ width: Math.max(16, p.value * w) }));
202 const sweep = useAnimatedStyle(() => ({
203 opacity: interpolate(shine.value, [0, 0.1, 0.8, 1], [0, 0.7, 0.7, 0]),
204 transform: [{ translateX: interpolate(shine.value, [0, 1], [-40, p.value * w + 10]) }, { skewX: '-20deg' }],
205 }));
206 return (
207 <View
208 role="progressbar"
209 aria-label="Lesson progress"
210 aria-valuenow={Math.round(value * 100)}
211 onLayout={(e: LayoutChangeEvent) => setW(e.nativeEvent.layout.width)}
212 style={[styles.bar, { backgroundColor: c.track }]}
213 >
214 <Animated.View style={[styles.barFill, fill]}>
215 <View style={styles.barGloss} />
216 <Animated.View style={[styles.barShine, sweep]} />
217 </Animated.View>
218 </View>
219 );
220}
221
222function Hearts({ count }: { count: number }) {
223 const before = useRef(count);
224 const beat = useSharedValue(1);
225 const crack = useSharedValue(0);
226 useEffect(() => {
227 if (count < before.current) {
228 beat.value = withSequence(withTiming(1.35, { duration: 110 }), withTiming(0.85, { duration: 120 }), withSpring(1, POP));
229 crack.value = 0;
230 crack.value = withTiming(1, { duration: 750, easing: Easing.in(Easing.quad) });
231 }
232 before.current = count;
233 }, [count, beat, crack]);
234 const heart = useAnimatedStyle(() => ({ transform: [{ scale: beat.value }] }));
235 // The cracked heart drops away from the full one and fades.
236 const shard = useAnimatedStyle(() => ({
237 opacity: interpolate(crack.value, [0, 0.05, 0.6, 1], [0, 1, 1, 0]),
238 transform: [{ translateY: crack.value * 26 }, { rotate: `${crack.value * 24}deg` }, { scale: 1.1 }],
239 }));
240 return (
241 <View role="status" aria-label={`${count} hearts left`} style={styles.hearts}>
242 <View>
243 <Animated.View style={heart}>
244 <Heart size={24} color={CORAL} fill={CORAL} />
245 </Animated.View>
246 <Animated.View pointerEvents="none" style={[styles.shard, shard]}>
247 <HeartCrack size={24} color={CORAL_EDGE} strokeWidth={2.4} />
248 </Animated.View>
249 </View>
250 <Animated.Text key={count} entering={ZoomIn.duration(220)} style={styles.heartCount}>
251 {count}
252 </Animated.Text>
253 </View>
254 );
255}
256
257// ─── Drawings ───────────────────────────────────────────────────────────────
258
259function FoodArt({ id, size = 84 }: { id: FoodId; size?: number }) {
260 const c = usePalette();
261 return (
262 <Svg width={size} height={size} viewBox="0 0 96 96">
263 {id === 'apple' && (
264 <>
265 <Path d="M48 30C40 22 20 24 20 46c0 20 14 36 24 34 2 0 3-1 4-1s2 1 4 1c10 2 24-14 24-34 0-22-20-24-28-16Z" fill="#F0523F" />
266 <Path d="M56 30c9-3 20 2 20 16 0 20-14 36-24 34 12-6 18-30 4-50Z" fill="#D93D2D" />
267 <Ellipse cx={34} cy={44} rx={5} ry={9} fill="#FFFFFF" opacity={0.35} transform="rotate(24 34 44)" />
268 <Path d="M48 31c0-6 2-12 6-16" stroke="#7A4A24" strokeWidth={4} strokeLinecap="round" fill="none" />
269 <Path d="M53 22c4-10 16-10 20-8-2 8-12 12-20 8Z" fill="#3FB56B" />
270 </>
271 )}
272 {id === 'bread' && (
273 <>
274 <Path d="M12 50c0-14 16-22 36-22s36 8 36 22c0 5-3 8-6 10v14c0 3-2 5-5 5H23c-3 0-5-2-5-5V60c-3-2-6-5-6-10Z" fill="#E9A84A" />
275 <Path d="M18 60c-3-2-6-5-6-10 0-14 16-22 36-22s36 8 36 22c0 5-3 8-6 10-8-12-52-12-60 0Z" fill="#C97F24" />
276 <Path d="M32 36l-6 10M49 33l-4 12M66 36l-2 11" stroke="#F6D08C" strokeWidth={4} strokeLinecap="round" />
277 </>
278 )}
279 {id === 'cheese' && (
280 <>
281 <Path d="M10 54 68 24c9 4 16 13 18 24v24H10Z" fill="#F7B21C" />
282 <Path d="M10 54 68 24c9 4 16 13 18 24Z" fill="#FFD95A" />
283 <Circle cx={30} cy={63} r={5} fill="#DD8F0A" />
284 <Circle cx={53} cy={61} r={7} fill="#DD8F0A" />
285 <Circle cx={73} cy={64} r={4} fill="#DD8F0A" />
286 <Circle cx={61} cy={41} r={3.5} fill="#F7B21C" />
287 </>
288 )}
289 {id === 'milk' && (
290 <>
291 <Path d="M38 16h20v8c0 7 10 10 10 22v32c0 4-3 6-6 6H34c-3 0-6-2-6-6V46c0-12 10-15 10-22Z" fill={c.bottle} stroke={c.bottleLine} strokeWidth={2.5} />
292 <Rect x={35} y={9} width={26} height={9} rx={3} fill={SKY} />
293 <Rect x={28} y={50} width={40} height={18} fill={SKY} />
294 <Circle cx={48} cy={59} r={5} fill="#FFFFFF" />
295 </>
296 )}
297 </Svg>
298 );
299}
300
301function star(cx: number, cy: number, outer: number, inner: number) {
302 return (
303 Array.from({ length: 10 }, (_, i) => {
304 const r = i % 2 ? inner : outer;
305 const a = (Math.PI / 5) * i - Math.PI / 2;
306 return `${i ? 'L' : 'M'}${(cx + Math.cos(a) * r).toFixed(1)} ${(cy + Math.sin(a) * r).toFixed(1)}`;
307 }).join('') + 'Z'
308 );
309}
310const RAYS = Array.from({ length: 12 }, (_, i) => {
311 const a = (Math.PI / 6) * i;
312 const b = a + Math.PI / 14;
313 return `M110 110L${(110 + Math.cos(a) * 110).toFixed(1)} ${(110 + Math.sin(a) * 110).toFixed(1)}L${(110 + Math.cos(b) * 110).toFixed(1)} ${(110 + Math.sin(b) * 110).toFixed(1)}Z`;
314}).join('');
315
316function Medal() {
317 return (
318 <Svg width={150} height={150} viewBox="0 0 160 160">
319 <Path d="M54 96 38 150l22-10 12 14 14-52Z" fill={ACCENT} />
320 <Path d="M106 96l16 54-22-10-12 14-14-52Z" fill={ACCENT_EDGE} />
321 <Circle cx={80} cy={66} r={52} fill={SUN_EDGE} />
322 <Circle cx={80} cy={62} r={52} fill={SUN} />
323 <Circle cx={80} cy={62} r={39} fill="#FDD766" />
324 <Path d={star(80, 63, 25, 11)} fill="#FFFFFF" stroke="#FFFFFF" strokeWidth={5} strokeLinejoin="round" />
325 <Path d="M44 46c6-12 16-20 30-22" stroke="#FFFFFF" strokeOpacity={0.6} strokeWidth={5} strokeLinecap="round" fill="none" />
326 </Svg>
327 );
328}
329
330function FlameArt() {
331 return (
332 <Svg width={44} height={52} viewBox="0 0 48 56">
333 <Path d="M24 2c2 12 16 18 16 34 0 10-7 18-16 18S8 46 8 36c0-8 5-12 7-18 3 4 5 5 6 2 1-6 1-12 3-18Z" fill={EMBER} />
334 <Path d="M24 29c4 4 7 8 7 14s-3 8-7 8-7-3-7-8 4-9 7-14Z" fill={SUN} />
335 </Svg>
336 );
337}
338
339// ─── Sparkle burst and floating XP ──────────────────────────────────────────
340
341function Spark({ t, angle, color, dist }: { t: SharedValue<number>; angle: number; color: string; dist: number }) {
342 const style = useAnimatedStyle(() => ({
343 opacity: interpolate(t.value, [0, 0.15, 0.7, 1], [0, 1, 1, 0]),
344 transform: [
345 { translateX: Math.cos(angle) * dist * t.value },
346 { translateY: Math.sin(angle) * dist * t.value },
347 { rotate: '45deg' },
348 { scale: interpolate(t.value, [0, 0.4, 1], [0.3, 1, 0.4]) },
349 ],
350 }));
351 return <Animated.View style={[styles.spark, { backgroundColor: color }, style]} />;
352}
353
354function Burst({ dist = 36, delay = 0 }: { dist?: number; delay?: number }) {
355 const t = useSharedValue(0);
356 useEffect(() => {
357 t.value = withDelay(delay, withTiming(1, { duration: 700, easing: Easing.out(Easing.cubic) }));
358 }, [t, delay]);
359 return (
360 <View pointerEvents="none" style={styles.burst}>
361 {SPARKS.map((color, i) => (
362 <Spark key={i} t={t} angle={(i / SPARKS.length) * Math.PI * 2 - Math.PI / 2} color={color} dist={i % 2 ? dist : dist * 0.68} />
363 ))}
364 </View>
365 );
366}
367
368function XpFloat() {
369 const t = useSharedValue(0);
370 useEffect(() => {
371 t.value = withTiming(1, { duration: 1100, easing: Easing.out(Easing.cubic) });
372 }, [t]);
373 const style = useAnimatedStyle(() => ({
374 opacity: interpolate(t.value, [0, 0.15, 0.7, 1], [0, 1, 1, 0]),
375 transform: [{ translateY: -56 * t.value }, { scale: interpolate(t.value, [0, 0.2, 1], [0.6, 1.15, 1]) }],
376 }));
377 return (
378 <Animated.Text pointerEvents="none" style={[styles.xpFloat, style]}>
379 +{XP_EACH} XP
380 </Animated.Text>
381 );
382}
383
384/** Eases a number toward its target on the JS thread, for the stats that roll up. */
385function useTween(target: number, duration = 800, delay = 250) {
386 const [value, setValue] = useState(0);
387 useEffect(() => {
388 const started = Date.now() + delay;
389 let frame = 0;
390 const tick = () => {
391 const t = Math.min(1, Math.max(0, (Date.now() - started) / duration));
392 setValue(target * (1 - Math.pow(1 - t, 3)));
393 if (t < 1) frame = requestAnimationFrame(tick);
394 };
395 frame = requestAnimationFrame(tick);
396 return () => cancelAnimationFrame(frame);
397 }, [target, duration, delay]);
398 return value;
399}
400
401// ─── Exercise 1: picture cards ──────────────────────────────────────────────
402
403function PictureCards({ pick, checked, onPick }: { pick: FoodId | null; checked: boolean; onPick: (id: FoodId) => void }) {
404 const c = usePalette();
405 return (
406 <View style={styles.grid}>
407 {FOODS.map((food, i) => {
408 const tone: Tone = checked ? (food.id === FOOD_ANSWER ? 'good' : food.id === pick ? 'bad' : 'idle') : food.id === pick ? 'selected' : 'idle';
409 const t = toneOf(c, tone);
410 return (
411 <Animated.View key={food.id} entering={FadeInDown.delay(60 + i * 60).duration(360)} style={styles.gridCell}>
412 <Chunky label={food.label} face={t.face} edge={t.edge} outlined radius={20} selected={food.id === pick} disabled={checked} onPress={() => onPick(food.id)} faceStyle={styles.picture}>
413 <FoodArt id={food.id} />
414 <Text style={[styles.pictureLabel, { color: t.text }]}>{food.label}</Text>
415 <View style={[styles.keyHint, { borderColor: t.edge }]}>
416 <Text style={[styles.keyHintText, { color: tone === 'idle' ? c.faint : t.text }]}>{i + 1}</Text>
417 </View>
418 </Chunky>
419 </Animated.View>
420 );
421 })}
422 </View>
423 );
424}
425
426// ─── Exercise 2: word tiles that fly between the bank and the answer line ───
427
428type Spot = { x: number; y: number; w: number };
429
430function Tile({ word, spot, tone, disabled, onPress }: { word: string; spot: Spot; tone: Tone; disabled: boolean; onPress: () => void }) {
431 const c = usePalette();
432 const x = useSharedValue(spot.x);
433 const y = useSharedValue(spot.y);
434 useEffect(() => {
435 x.value = withSpring(spot.x, SLIDE);
436 y.value = withSpring(spot.y, SLIDE);
437 }, [spot.x, spot.y, x, y]);
438 const move = useAnimatedStyle(() => ({ transform: [{ translateX: x.value }, { translateY: y.value }] }));
439 const t = toneOf(c, tone);
440 return (
441 <Animated.View style={[styles.tile, { width: spot.w }, move]}>
442 <Chunky label={word} face={t.face} edge={t.edge} outlined radius={14} disabled={disabled} onPress={onPress} faceStyle={styles.tileFace}>
443 <Text style={[styles.tileText, { color: t.text }]}>{word}</Text>
444 </Chunky>
445 </Animated.View>
446 );
447}
448
449function WordTiles({ order, checked, right, onChange }: { order: number[]; checked: boolean; right: boolean; onChange: (next: number[]) => void }) {
450 const c = usePalette();
451 const { width } = useWindowDimensions();
452 const [homes, setHomes] = useState<Record<number, Spot>>({});
453 const [bankY, setBankY] = useState(0);
454 const measured = BANK.every((_, i) => homes[i]) && bankY > 0;
455
456 // Flow the chosen tiles along the answer lines, wrapping like text.
457 const placed: Record<number, Spot> = {};
458 let x = 0;
459 let line = 0;
460 order.forEach((i) => {
461 const w = homes[i]?.w ?? 0;
462 if (x + w > width - 40) {
463 x = 0;
464 line += 1;
465 }
466 placed[i] = { x, y: line * ROW_H + 2, w };
467 x += w + 8;
468 });
469
470 return (
471 <View>
472 <View style={[styles.bubbleRow]}>
473 <View style={[styles.sayButton, { backgroundColor: c.accentSoft }]}>
474 <Volume2 size={20} color={c.accentText} strokeWidth={2.4} />
475 </View>
476 <View style={[styles.bubble, { backgroundColor: c.card, borderColor: c.line }]}>
477 <Text style={[styles.bubbleText, { color: c.fg }]}>{SENTENCE}</Text>
478 </View>
479 </View>
480
481 <View style={styles.tilesArea}>
482 <View style={[styles.answerLine, { borderColor: c.line }]} />
483 <View style={[styles.answerLine, { borderColor: c.line }]} />
484 <View style={styles.bank} onLayout={(e: LayoutChangeEvent) => setBankY(e.nativeEvent.layout.y)}>
485 {BANK.map((word, i) => (
486 <View
487 key={word}
488 onLayout={(e: LayoutChangeEvent) => {
489 const { x: hx, y: hy, width: hw } = e.nativeEvent.layout;
490 setHomes((h) => ({ ...h, [i]: { x: hx, y: hy, w: hw } }));
491 }}
492 style={[styles.tileHome, { backgroundColor: c.track }]}
493 >
494 <Text style={[styles.tileText, styles.hidden]}>{word}</Text>
495 </View>
496 ))}
497 </View>
498 {measured &&
499 BANK.map((word, i) => {
500 const inAnswer = order.includes(i);
501 return (
502 <Tile
503 key={word}
504 word={word}
505 spot={inAnswer ? placed[i] : { x: homes[i].x, y: bankY + homes[i].y, w: homes[i].w }}
506 tone={checked && inAnswer ? (right ? 'good' : 'bad') : 'idle'}
507 disabled={checked}
508 onPress={() => onChange(inAnswer ? order.filter((o) => o !== i) : [...order, i])}
509 />
510 );
511 })}
512 </View>
513 </View>
514 );
515}
516
517// ─── Exercise 3: match pairs ────────────────────────────────────────────────
518
519type PairState = 'idle' | 'selected' | 'matched' | 'wrong';
520
521function PairTile({ text, state, onPress }: { text: string; state: PairState; onPress: () => void }) {
522 const c = usePalette();
523 const shake = useSharedValue(0);
524 const fade = useSharedValue(1);
525 useEffect(() => {
526 if (state === 'wrong') {
527 shake.value = withSequence(withTiming(-7, { duration: 50 }), withTiming(7, { duration: 60 }), withTiming(-5, { duration: 60 }), withTiming(5, { duration: 60 }), withTiming(0, { duration: 50 }));
528 }
529 fade.value = state === 'matched' ? withDelay(380, withTiming(0.32, { duration: 320 })) : withTiming(1, { duration: 150 });
530 }, [state, shake, fade]);
531 const style = useAnimatedStyle(() => ({ opacity: fade.value, transform: [{ translateX: shake.value }] }));
532 const t = toneOf(c, state === 'matched' ? 'good' : state === 'wrong' ? 'bad' : state);
533 return (
534 <Animated.View style={style}>
535 <Chunky label={text} face={t.face} edge={t.edge} outlined selected={state === 'selected'} disabled={state === 'matched'} onPress={onPress} faceStyle={styles.pairFace}>
536 <Text style={[styles.pairText, { color: t.text }]}>{text}</Text>
537 </Chunky>
538 </Animated.View>
539 );
540}
541
542function MatchPairs({ matched, onMatch }: { matched: string[]; onMatch: (id: string) => void }) {
543 const [left, setLeft] = useState<string | null>(null);
544 const [right, setRight] = useState<string | null>(null);
545 const [wrong, setWrong] = useState<[string, string] | null>(null);
546
547 const choose = (side: 'l' | 'r', id: string) => {
548 if (wrong) return;
549 const l = side === 'l' ? (left === id ? null : id) : left;
550 const r = side === 'r' ? (right === id ? null : id) : right;
551 setLeft(l);
552 setRight(r);
553 if (!l || !r) return;
554 if (l === r) {
555 onMatch(l);
556 setLeft(null);
557 setRight(null);
558 } else {
559 setWrong([l, r]);
560 setTimeout(() => {
561 setWrong(null);
562 setLeft(null);
563 setRight(null);
564 }, 520);
565 }
566 };
567 const stateOf = (id: string, side: 0 | 1, chosen: string | null): PairState =>
568 matched.includes(id) ? 'matched' : wrong?.[side] === id ? 'wrong' : chosen === id ? 'selected' : 'idle';
569
570 return (
571 <View style={styles.pairs}>
572 <View style={styles.pairColumn}>
573 {PAIRS.map((p) => (
574 <PairTile key={p.id} text={p.es} state={stateOf(p.id, 0, left)} onPress={() => choose('l', p.id)} />
575 ))}
576 </View>
577 <View style={styles.pairColumn}>
578 {RIGHT_COLUMN.map((i) => (
579 <PairTile key={PAIRS[i].id} text={PAIRS[i].en} state={stateOf(PAIRS[i].id, 1, right)} onPress={() => choose('r', PAIRS[i].id)} />
580 ))}
581 </View>
582 </View>
583 );
584}
585
586// ─── Exercise 4: listen and type (the audio is simulated) ───────────────────
587
588function Ring({ playing, delay }: { playing: boolean; delay: number }) {
589 const t = useSharedValue(0);
590 useEffect(() => {
591 if (playing) {
592 t.value = withDelay(delay, withRepeat(withTiming(1, { duration: 1050, easing: Easing.out(Easing.quad) }), -1));
593 } else {
594 cancelAnimation(t);
595 t.value = withTiming(0, { duration: 160 });
596 }
597 }, [playing, delay, t]);
598 const style = useAnimatedStyle(() => ({ opacity: t.value === 0 ? 0 : 0.55 * (1 - t.value), transform: [{ scale: 1 + t.value * 0.75 }] }));
599 return <Animated.View pointerEvents="none" style={[styles.ring, style]} />;
600}
601
602function ListenType({ value, tone, locked, onChange, onSubmit }: { value: string; tone: Tone; locked: boolean; onChange: (v: string) => void; onSubmit: () => void }) {
603 const c = usePalette();
604 const [playing, setPlaying] = useState(false);
605 const [heard, setHeard] = useState(false);
606 const [focused, setFocused] = useState(false);
607 const timer = useRef<ReturnType<typeof setTimeout> | null>(null);
608
609 const play = () => {
610 // Replace with your audio player; the rings stand in for playback.
611 setPlaying(true);
612 setHeard(true);
613 if (timer.current) clearTimeout(timer.current);
614 timer.current = setTimeout(() => setPlaying(false), 1900);
615 };
616 useEffect(() => {
617 const first = setTimeout(play, 350);
618 return () => {
619 clearTimeout(first);
620 if (timer.current) clearTimeout(timer.current);
621 };
622 // eslint-disable-next-line react-hooks/exhaustive-deps
623 }, []);
624
625 const t = toneOf(c, tone === 'idle' && focused ? 'selected' : tone);
626 return (
627 <View style={styles.listen}>
628 <View style={styles.speakerSlot}>
629 <Ring playing={playing} delay={0} />
630 <Ring playing={playing} delay={350} />
631 <Ring playing={playing} delay={700} />
632 <Chunky label="Play audio" face={ACCENT} edge={ACCENT_EDGE} radius={28} onPress={play} faceStyle={styles.speaker}>
633 <Volume2 size={38} color={ON_ACCENT} strokeWidth={2.4} />
634 </Chunky>
635 </View>
636 <View style={styles.captionSlot}>
637 {heard ? (
638 <Animated.View entering={FadeIn.duration(250)} style={[styles.caption, { backgroundColor: c.track }]}>
639 <Text style={[styles.captionLabel, { color: c.muted }]}>{playing ? 'Playing' : 'Captions'}</Text>
640 <Text style={[styles.captionWord, { color: c.fg }]}>{`“${HEARD}”`}</Text>
641 </Animated.View>
642 ) : null}
643 </View>
644 <View style={[styles.inputEdge, { backgroundColor: t.edge }]}>
645 <View style={[styles.inputFace, { backgroundColor: tone === 'idle' ? c.card : t.face, borderColor: t.edge }]}>
646 <TextInput
647 aria-label="Your answer"
648 value={value}
649 onChangeText={onChange}
650 onFocus={() => setFocused(true)}
651 onBlur={() => setFocused(false)}
652 onSubmitEditing={onSubmit}
653 editable={!locked}
654 placeholder="Type in Spanish"
655 placeholderTextColor={c.faint}
656 selectionColor={ACCENT}
657 autoCapitalize="none"
658 autoCorrect={false}
659 returnKeyType="done"
660 style={[styles.input, { color: tone === 'idle' ? c.fg : t.text }, WEB_INPUT]}
661 />
662 </View>
663 </View>
664 </View>
665 );
666}
667
668// ─── Exercise 5: fill the blank ─────────────────────────────────────────────
669
670function FillBlank({ pick, checked, onPick }: { pick: string | null; checked: boolean; onPick: (word: string) => void }) {
671 const c = usePalette();
672 const slot = toneOf(c, !pick ? 'idle' : !checked ? 'selected' : pick === BLANK.answer ? 'good' : 'bad');
673 return (
674 <View>
675 <View style={[styles.sentenceCard, { backgroundColor: c.card, borderColor: c.line }]}>
676 <View style={styles.sentence}>
677 <Text style={[styles.sentenceText, { color: c.fg }]}>{BLANK.before}</Text>
678 <View style={[styles.blank, { backgroundColor: pick ? slot.face : c.track, borderColor: pick ? slot.edge : c.line }]}>
679 {pick ? (
680 <Animated.Text key={pick} entering={ZoomIn.springify().damping(12)} style={[styles.sentenceText, { color: slot.text }]}>
681 {pick}
682 </Animated.Text>
683 ) : null}
684 </View>
685 <Text style={[styles.sentenceText, { color: c.fg }]}>{BLANK.after}</Text>
686 </View>
687 <Text style={[styles.meaning, { color: c.muted }]}>{BLANK.meaning}</Text>
688 </View>
689 <View style={styles.choices}>
690 {BLANK.choices.map((word) => {
691 const tone: Tone = checked ? (word === BLANK.answer ? 'good' : word === pick ? 'bad' : 'idle') : word === pick ? 'selected' : 'idle';
692 const t = toneOf(c, tone);
693 return (
694 <Chunky key={word} label={word} face={t.face} edge={t.edge} outlined selected={word === pick} disabled={checked} onPress={() => onPick(word)} faceStyle={styles.choiceFace}>
695 <Text style={[styles.pairText, { color: t.text }]}>{word}</Text>
696 </Chunky>
697 );
698 })}
699 </View>
700 </View>
701 );
702}
703
704// ─── Bottom sheet: quit, or out of hearts ───────────────────────────────────
705
706type SheetKind = 'quit' | 'hearts';
707
708function Sheet({ kind, bottom, onPrimary, onSecondary }: { kind: SheetKind | null; bottom: number; onPrimary: () => void; onSecondary: () => void }) {
709 const c = usePalette();
710 const [shown, setShown] = useState<SheetKind | null>(kind);
711 const p = useSharedValue(0);
712 useEffect(() => {
713 if (kind) {
714 setShown(kind);
715 p.value = withSpring(1, SLIDE);
716 } else {
717 p.value = withTiming(0, { duration: 200 }, (done) => {
718 if (done) runOnJS(setShown)(null);
719 });
720 }
721 }, [kind, p]);
722 const scrim = useAnimatedStyle(() => ({ opacity: p.value }));
723 const rise = useAnimatedStyle(() => ({ transform: [{ translateY: (1 - p.value) * 420 }] }));
724 if (!shown) return null;
725 const quit = shown === 'quit';
726 return (
727 <View style={StyleSheet.absoluteFill}>
728 <Animated.View style={[StyleSheet.absoluteFill, { backgroundColor: c.scrim }, scrim]}>
729 <Pressable aria-label="Dismiss" style={StyleSheet.absoluteFill} onPress={quit ? onPrimary : undefined} />
730 </Animated.View>
731 <Animated.View role="dialog" aria-label={quit ? 'Quit lesson' : 'Out of hearts'} style={[styles.sheet, { backgroundColor: c.bg, paddingBottom: bottom + 16 }, rise]}>
732 <View style={[styles.grabber, { backgroundColor: c.line }]} />
733 <View style={[styles.sheetIcon, { backgroundColor: c.badSoft }]}>
734 <HeartCrack size={34} color={CORAL} strokeWidth={2.2} />
735 </View>
736 <Text style={[styles.sheetTitle, { color: c.fg }]}>{quit ? 'Quit lesson?' : 'Out of hearts'}</Text>
737 <Text style={[styles.sheetBody, { color: c.muted }]}>
738 {quit ? "You'll lose your progress in this lesson, and the XP you have earned so far." : 'Refill to keep going, or come back when your hearts have recharged.'}
739 </Text>
740 <Chunky label={quit ? 'Keep learning' : 'Refill hearts'} face={ACCENT} edge={ACCENT_EDGE} onPress={onPrimary} style={styles.sheetButton} faceStyle={styles.cta}>
741 <Text style={styles.ctaLabel}>{quit ? 'Keep learning' : 'Refill hearts'}</Text>
742 </Chunky>
743 <Pressable role="button" aria-label={quit ? 'Quit lesson' : 'End lesson'} onPress={onSecondary} style={({ pressed }) => [styles.sheetLink, pressed && styles.pressed]}>
744 <Text style={[styles.sheetLinkLabel, { color: c.badText }]}>{quit ? 'Quit lesson' : 'End lesson'}</Text>
745 </Pressable>
746 </Animated.View>
747 </View>
748 );
749}
750
751// ─── Completion ─────────────────────────────────────────────────────────────
752
753function Stat({ label, color, icon, children, index }: { label: string; color: string; icon: ReactNode; children: ReactNode; index: number }) {
754 const c = usePalette();
755 return (
756 <Animated.View entering={FadeInDown.delay(260 + index * 80).duration(380)} style={[styles.stat, { backgroundColor: color, borderColor: color }]}>
757 <Text style={styles.statLabel}>{label}</Text>
758 <View style={[styles.statBody, { backgroundColor: c.card }]}>
759 {icon}
760 <Text style={[styles.statValue, { color: c.fg }]}>{children}</Text>
761 </View>
762 </Animated.View>
763 );
764}
765
766function Complete({ xp, accuracy, seconds, onContinue }: { xp: number; accuracy: number; seconds: number; onContinue: () => void }) {
767 const c = usePalette();
768 const insets = useSafeAreaInsets();
769 const spin = useSharedValue(0);
770 const bob = useSharedValue(0);
771 useEffect(() => {
772 spin.value = withRepeat(withTiming(360, { duration: 24000, easing: Easing.linear }), -1);
773 bob.value = withDelay(900, withRepeat(withTiming(1, { duration: 1800, easing: Easing.inOut(Easing.sin) }), -1, true));
774 }, [spin, bob]);
775 const rays = useAnimatedStyle(() => ({ transform: [{ rotate: `${spin.value}deg` }] }));
776 const float = useAnimatedStyle(() => ({ transform: [{ translateY: -5 * bob.value }] }));
777 const xpNow = Math.round(useTween(xp));
778 const accNow = Math.round(useTween(accuracy));
779 const secNow = Math.round(useTween(seconds));
780 const time = `${Math.floor(secNow / 60)}:${secNow % 60 < 10 ? '0' : ''}${secNow % 60}`;
781
782 return (
783 <Animated.View entering={FadeIn.duration(260)} style={[styles.complete, { paddingTop: insets.top + 20, paddingBottom: insets.bottom + 12 }]}>
784 <View style={styles.completeTop}>
785 <View style={styles.medalSlot}>
786 <Animated.View style={[styles.rays, rays]}>
787 <Svg width={220} height={220} viewBox="0 0 220 220">
788 <Path d={RAYS} fill={c.ray} />
789 </Svg>
790 </Animated.View>
791 <Animated.View entering={ZoomIn.delay(80).springify().damping(10).stiffness(160)}>
792 <Animated.View style={float}>
793 <Medal />
794 </Animated.View>
795 </Animated.View>
796 <Burst dist={104} delay={320} />
797 </View>
798 <Animated.Text entering={FadeInDown.delay(160).duration(380)} style={[styles.completeTitle, { color: c.fg }]}>
799 Lesson complete!
800 </Animated.Text>
801 <Animated.Text entering={FadeInDown.delay(220).duration(380)} style={[styles.completeSub, { color: c.muted }]}>
802 {COURSE} · {LESSON}
803 </Animated.Text>
804 </View>
805
806 <View style={styles.stats}>
807 <Stat index={0} label="Total XP" color={SUN} icon={<Zap size={18} color={SUN_EDGE} fill={SUN} />}>
808 {xpNow}
809 </Stat>
810 <Stat index={1} label="Accuracy" color={GOOD} icon={<Target size={18} color={GOOD} strokeWidth={2.6} />}>
811 {accNow}%
812 </Stat>
813 <Stat index={2} label="Time" color={SKY} icon={<Clock size={18} color={SKY} strokeWidth={2.6} />}>
814 {time}
815 </Stat>
816 </View>
817
818 <Animated.View entering={FadeInDown.delay(500).duration(380)} style={[styles.streak, { backgroundColor: c.card, borderColor: c.line }]}>
819 <View style={styles.streakHead}>
820 <FlameArt />
821 <View style={styles.streakCopy}>
822 <Text style={[styles.streakTitle, { color: c.fg }]}>{STREAK}-day streak</Text>
823 <Text style={[styles.streakSub, { color: c.muted }]}>A full week. Come back tomorrow for day 8.</Text>
824 </View>
825 </View>
826 <View style={styles.days}>
827 {WEEK.map((day, i) => (
828 <View key={i} style={styles.day}>
829 <View style={[styles.dayDot, { backgroundColor: c.track }]}>
830 <Animated.View entering={ZoomIn.delay(560 + i * 70).springify().damping(11)} style={[styles.dayFill, i === WEEK.length - 1 && styles.dayToday]}>
831 <Check size={15} color="#FFFFFF" strokeWidth={3.5} />
832 </Animated.View>
833 </View>
834 <Text style={[styles.dayLabel, { color: i === WEEK.length - 1 ? c.sunText : c.muted }]}>{day}</Text>
835 </View>
836 ))}
837 </View>
838 </Animated.View>
839
840 <View style={styles.spacer} />
841 <Chunky label="Continue" face={ACCENT} edge={ACCENT_EDGE} onPress={onContinue} faceStyle={styles.cta}>
842 <Text style={styles.ctaLabel}>Continue</Text>
843 </Chunky>
844 </Animated.View>
845 );
846}
847
848// ─── Screen ─────────────────────────────────────────────────────────────────
849
850export default function LessonQuizScreen() {
851 const c = usePalette();
852 const insets = useSafeAreaInsets();
853 const { width } = useWindowDimensions();
854
855 const [step, setStep] = useState(0);
856 const [run, setRun] = useState(0);
857 const [checked, setChecked] = useState(false);
858 const [feedback, setFeedback] = useState({ right: true, answer: '', combo: 0 });
859 const [done, setDone] = useState(0);
860 const [hearts, setHearts] = useState(HEARTS);
861 const [xp, setXp] = useState(0);
862 const [correct, setCorrect] = useState(0);
863 const [combo, setCombo] = useState(0);
864 const [finished, setFinished] = useState(false);
865 const [seconds, setSeconds] = useState(0);
866 const [sheet, setSheet] = useState<SheetKind | null>(null);
867 const startedAt = useRef(Date.now());
868
869 // One answer per exercise. The first card starts chosen so the opening frame shows a live Check button; use null in your app.
870 const [food, setFood] = useState<FoodId | null>('apple');
871 const [order, setOrder] = useState<number[]>([]);
872 const [matched, setMatched] = useState<string[]>([]);
873 const [typed, setTyped] = useState('');
874 const [blank, setBlank] = useState<string | null>(null);
875
876 const ready = [food !== null, order.length > 0, matched.length === PAIRS.length, typed.trim().length > 0, blank !== null][step];
877 const isRight = [food === FOOD_ANSWER, order.map((i) => BANK[i]).join(' ') === BANK_ANSWER, true, typed.trim().toLowerCase() === HEARD, blank === BLANK.answer][step];
878
879 // Steps slide out one way and in from the other: forward on Continue, backward when the lesson restarts.
880 const slide = useSharedValue(0);
881 const open = useSharedValue(0);
882 const dir = useRef<1 | -1>(1);
883 const first = useRef(true);
884 const busy = useRef(false);
885 useEffect(() => {
886 if (first.current) {
887 first.current = false;
888 return;
889 }
890 slide.value = dir.current;
891 slide.value = withSpring(0, SLIDE);
892 busy.current = false;
893 }, [step, run, slide]);
894 useEffect(() => {
895 open.value = checked ? withSpring(1, SLIDE) : withTiming(0, { duration: 200 });
896 }, [checked, open]);
897
898 const leave = (to: 1 | -1, then: () => void) => {
899 if (busy.current) return;
900 busy.current = true;
901 dir.current = to;
902 slide.value = withTiming(-to, { duration: 170, easing: Easing.in(Easing.cubic) }, (ended) => {
903 if (ended) runOnJS(then)();
904 });
905 };
906
907 const check = () => {
908 if (!ready || checked) return;
909 const streak = isRight ? combo + 1 : 0;
910 setFeedback({ right: isRight, answer: STEPS[step].answer, combo: streak });
911 setChecked(true);
912 setDone((d) => d + 1);
913 setCombo(streak);
914 if (isRight) {
915 setXp((v) => v + XP_EACH);
916 setCorrect((v) => v + 1);
917 } else {
918 setHearts((h) => Math.max(0, h - 1));
919 }
920 };
921
922 const advance = () => {
923 setChecked(false);
924 if (step === LAST) {
925 setSeconds(Math.max(1, Math.round((Date.now() - startedAt.current) / 1000)));
926 setFinished(true);
927 busy.current = false;
928 } else {
929 setStep(step + 1);
930 }
931 };
932
933 const restart = () => {
934 // Replace with navigation back to your course; here the lesson starts over.
935 setStep(0);
936 setChecked(false);
937 setDone(0);
938 setHearts(HEARTS);
939 setXp(0);
940 setCorrect(0);
941 setCombo(0);
942 setFood(null);
943 setOrder([]);
944 setMatched([]);
945 setTyped('');
946 setBlank(null);
947 setFinished(false);
948 setRun((r) => r + 1);
949 startedAt.current = Date.now();
950 };
951
952 const next = () => (hearts === 0 && step < LAST ? setSheet('hearts') : leave(1, advance));
953
954 const bodyStyle = useAnimatedStyle(() => ({
955 opacity: 1 - Math.abs(slide.value),
956 transform: [{ translateX: slide.value * width * 0.6 }],
957 }));
958 const footerH = 12 + 56 + DEPTH + insets.bottom + 12;
959 const panelStyle = useAnimatedStyle(() => ({ transform: [{ translateY: (1 - open.value) * (PANEL_H + footerH + 8) }] }));
960
961 const button = checked
962 ? feedback.right
963 ? { face: GOOD, edge: GOOD_EDGE, text: '#FFFFFF' }
964 : { face: CORAL, edge: CORAL_EDGE, text: '#FFFFFF' }
965 : ready
966 ? { face: ACCENT, edge: ACCENT_EDGE, text: ON_ACCENT }
967 : { face: c.off, edge: c.offEdge, text: c.offText };
968 const info = STEPS[step];
969
970 if (finished) {
971 return (
972 <View style={[styles.screen, { backgroundColor: c.bg }]}>
973 <Complete xp={xp} accuracy={Math.round((correct / STEPS.length) * 100)} seconds={seconds} onContinue={restart} />
974 </View>
975 );
976 }
977
978 return (
979 <KeyboardAvoidingView behavior={Platform.OS === 'ios' ? 'padding' : undefined} style={[styles.screen, { backgroundColor: c.bg }]}>
980 <View style={[styles.topBar, { paddingTop: insets.top + 10 }]}>
981 <Pressable role="button" aria-label="Close lesson" hitSlop={10} onPress={() => setSheet('quit')} style={({ pressed }) => [styles.close, pressed && styles.pressed]}>
982 <X size={26} color={c.muted} strokeWidth={2.6} />
983 </Pressable>
984 <ProgressBar value={HEAD_START + (1 - HEAD_START) * (done / STEPS.length)} />
985 <Hearts count={hearts} />
986 </View>
987
988 <Animated.View style={[styles.body, bodyStyle]}>
989 <View style={styles.kindRow}>
990 <View style={[styles.kind, { backgroundColor: c.sunSoft }]}>
991 <Zap size={12} color={c.sunText} fill={c.sunText} />
992 <Text style={[styles.kindLabel, { color: c.sunText }]}>{info.kind}</Text>
993 </View>
994 <Text style={[styles.course, { color: c.faint }]}>{APP_NAME} · Spanish</Text>
995 </View>
996 <Text role="heading" style={[styles.prompt, { color: c.fg }]}>
997 {info.title}
998 </Text>
999 <View key={`${run}-${step}`} style={styles.exercise}>
1000 {step === 0 && <PictureCards pick={food} checked={checked} onPick={setFood} />}
1001 {step === 1 && <WordTiles order={order} checked={checked} right={feedback.right} onChange={setOrder} />}
1002 {step === 2 && <MatchPairs matched={matched} onMatch={(id) => setMatched((m) => [...m, id])} />}
1003 {step === 3 && <ListenType value={typed} tone={checked ? (feedback.right ? 'good' : 'bad') : 'idle'} locked={checked} onChange={setTyped} onSubmit={check} />}
1004 {step === 4 && <FillBlank pick={blank} checked={checked} onPick={setBlank} />}
1005 </View>
1006 </Animated.View>
1007
1008 {/* Sticky footer: the feedback panel rises behind the button, which turns into Continue */}
1009 <View style={[styles.footer, { backgroundColor: c.bg, paddingBottom: insets.bottom + 12 }]}>
1010 <View pointerEvents="none" style={styles.panelClip}>
1011 <Animated.View role="status" style={[styles.panel, { backgroundColor: feedback.right ? c.goodSoft : c.badSoft }, panelStyle]}>
1012 <View style={styles.panelRow}>
1013 <View style={[styles.panelIcon, feedback.right ? styles.panelIconGood : styles.panelIconBad]}>
1014 {feedback.right ? <Check size={22} color="#FFFFFF" strokeWidth={3.5} /> : <X size={22} color="#FFFFFF" strokeWidth={3.5} />}
1015 {checked && feedback.right ? <Burst key={step} /> : null}
1016 </View>
1017 <View style={styles.panelCopy}>
1018 <Text style={[styles.panelTitle, { color: feedback.right ? c.goodText : c.badText }]}>{feedback.right ? 'Nice!' : 'Correct answer:'}</Text>
1019 <Text numberOfLines={1} style={[styles.panelAnswer, { color: feedback.right ? c.goodText : c.badText }]}>
1020 {feedback.answer}
1021 </Text>
1022 </View>
1023 {feedback.right ? (
1024 <View>
1025 <View style={styles.xpChip}>
1026 <Zap size={13} color="#7A4E00" fill="#7A4E00" />
1027 <Text style={styles.xpChipLabel}>+{XP_EACH} XP</Text>
1028 </View>
1029 {checked ? <XpFloat key={step} /> : null}
1030 </View>
1031 ) : null}
1032 </View>
1033 {checked && feedback.right && feedback.combo >= 3 ? (
1034 <Animated.View key={step} entering={ZoomIn.delay(250).springify().damping(10)} style={styles.combo}>
1035 <Flame size={14} color="#FFFFFF" fill="#FFFFFF" />
1036 <Text style={styles.comboLabel}>{feedback.combo} in a row!</Text>
1037 </Animated.View>
1038 ) : null}
1039 </Animated.View>
1040 </View>
1041 <Chunky label={checked ? 'Continue' : 'Check'} face={button.face} edge={button.edge} disabled={!checked && !ready} onPress={checked ? next : check} faceStyle={styles.cta}>
1042 <Text style={[styles.ctaLabel, { color: button.text }]}>{checked ? 'Continue' : 'Check'}</Text>
1043 </Chunky>
1044 </View>
1045
1046 <Sheet
1047 kind={sheet}
1048 bottom={insets.bottom}
1049 onPrimary={() => {
1050 const refill = sheet === 'hearts';
1051 setSheet(null);
1052 if (refill) {
1053 setHearts(HEARTS);
1054 leave(1, advance);
1055 }
1056 }}
1057 onSecondary={() => {
1058 setSheet(null);
1059 leave(-1, restart);
1060 }}
1061 />
1062 </KeyboardAvoidingView>
1063 );
1064}
1065
1066// ─── Styles ─────────────────────────────────────────────────────────────────
1067
1068const styles = StyleSheet.create({
1069 screen: { flex: 1, overflow: 'hidden' },
1070 pressed: { opacity: 0.55 },
1071 hidden: { opacity: 0 },
1072 spacer: { flex: 1, minHeight: 12 },
1073
1074 // Chunky button
1075 chunk: { paddingBottom: DEPTH },
1076 face: { flexGrow: 1, alignItems: 'center', justifyContent: 'center' },
1077 faceOutlined: { borderWidth: 2 },
1078 cta: { height: 56 },
1079 ctaLabel: { color: ON_ACCENT, fontSize: 17, fontWeight: '800', letterSpacing: 0.6, textTransform: 'uppercase' },
1080
1081 // Top bar
1082 topBar: { flexDirection: 'row', alignItems: 'center', gap: 14, paddingHorizontal: 20, paddingBottom: 8 },
1083 close: { width: 28, height: 28, alignItems: 'center', justifyContent: 'center' },
1084 bar: { flex: 1, height: 18, borderRadius: 9, overflow: 'hidden' },
1085 barFill: { height: 18, borderRadius: 9, backgroundColor: ACCENT, overflow: 'hidden' },
1086 barGloss: { position: 'absolute', top: 4, left: 8, right: 8, height: 5, borderRadius: 3, backgroundColor: tint(ON_ACCENT, 0.32) },
1087 barShine: { position: 'absolute', top: 0, bottom: 0, left: 0, width: 26, backgroundColor: tint(ON_ACCENT, 0.6) },
1088 hearts: { flexDirection: 'row', alignItems: 'center', gap: 6 },
1089 shard: { position: 'absolute', top: 0, left: 0 },
1090 heartCount: { color: CORAL, fontSize: 18, fontWeight: '800', minWidth: 12, fontVariant: ['tabular-nums'] },
1091
1092 // Step body
1093 body: { flex: 1, paddingHorizontal: 20, paddingTop: 20 },
1094 kindRow: { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between' },
1095 course: { fontSize: 13, fontWeight: '700' },
1096 kind: { flexDirection: 'row', alignItems: 'center', gap: 5, height: 26, paddingHorizontal: 10, borderRadius: 13 },
1097 kindLabel: { fontSize: 12, fontWeight: '800', letterSpacing: 0.8, textTransform: 'uppercase' },
1098 prompt: { marginTop: 12, fontSize: 26, lineHeight: 32, fontWeight: '800', letterSpacing: -0.4 },
1099 exercise: { marginTop: 24 },
1100
1101 // Picture cards
1102 grid: { flexDirection: 'row', flexWrap: 'wrap', gap: 12 },
1103 gridCell: { width: '48.2%' },
1104 picture: { height: 188, gap: 12 },
1105 pictureLabel: { fontSize: 17, fontWeight: '700' },
1106 keyHint: { position: 'absolute', top: 10, left: 10, width: 24, height: 24, borderRadius: 8, borderWidth: 2, alignItems: 'center', justifyContent: 'center' },
1107 keyHintText: { fontSize: 12, fontWeight: '800' },
1108
1109 // Word tiles
1110 bubbleRow: { flexDirection: 'row', alignItems: 'center', gap: 10 },
1111 sayButton: { width: 44, height: 44, borderRadius: 14, alignItems: 'center', justifyContent: 'center' },
1112 bubble: { height: 48, paddingHorizontal: 16, borderRadius: 16, borderTopLeftRadius: 4, borderWidth: 2, justifyContent: 'center' },
1113 bubbleText: { fontSize: 18, fontWeight: '700' },
1114 tilesArea: { marginTop: 20 },
1115 answerLine: { height: ROW_H, borderBottomWidth: 2 },
1116 bank: { marginTop: 32, flexDirection: 'row', flexWrap: 'wrap', justifyContent: 'center', gap: 8, rowGap: 10 },
1117 tileHome: { height: 44 + DEPTH, paddingHorizontal: 16, borderRadius: 14, justifyContent: 'center' },
1118 tile: { position: 'absolute', top: 0, left: 0 },
1119 tileFace: { height: 44 },
1120 tileText: { fontSize: 17, fontWeight: '700' },
1121
1122 // Match pairs
1123 pairs: { flexDirection: 'row', gap: 12 },
1124 pairColumn: { flex: 1, gap: 12 },
1125 pairFace: { height: 58 },
1126 pairText: { fontSize: 17, fontWeight: '700' },
1127
1128 // Listen and type
1129 listen: { alignItems: 'center' },
1130 speakerSlot: { marginTop: 8, width: 104, height: 104 + DEPTH, alignItems: 'center', justifyContent: 'center' },
1131 speaker: { width: 104, height: 104 },
1132 ring: { position: 'absolute', top: 0, left: 0, width: 104, height: 104, borderRadius: 32, borderWidth: 3, borderColor: ACCENT },
1133 captionSlot: { height: 36, marginTop: 20, justifyContent: 'center' },
1134 caption: { flexDirection: 'row', alignItems: 'center', gap: 8, height: 36, paddingHorizontal: 14, borderRadius: 18 },
1135 captionLabel: { fontSize: 12, fontWeight: '800', letterSpacing: 0.6, textTransform: 'uppercase' },
1136 captionWord: { fontSize: 15, fontWeight: '700' },
1137 inputEdge: { alignSelf: 'stretch', marginTop: 24, paddingBottom: DEPTH, borderRadius: 16 },
1138 inputFace: { height: 60, borderRadius: 16, borderWidth: 2, paddingHorizontal: 16, justifyContent: 'center' },
1139 input: { height: '100%', fontSize: 19, fontWeight: '600' },
1140
1141 // Fill the blank
1142 sentenceCard: { borderWidth: 2, borderRadius: 20, paddingVertical: 24, paddingHorizontal: 16, alignItems: 'center' },
1143 sentence: { flexDirection: 'row', alignItems: 'center', gap: 10 },
1144 sentenceText: { fontSize: 24, fontWeight: '800' },
1145 blank: { minWidth: 104, height: 48, paddingHorizontal: 12, borderRadius: 12, borderWidth: 2, alignItems: 'center', justifyContent: 'center' },
1146 meaning: { marginTop: 14, fontSize: 15, fontWeight: '500' },
1147 choices: { marginTop: 20, gap: 10 },
1148 choiceFace: { height: 54 },
1149
1150 // Footer and feedback panel
1151 footer: { paddingHorizontal: 20, paddingTop: 12 },
1152 // The clip keeps the hidden panel from extending the page; its headroom leaves space for the combo badge and the floating XP.
1153 panelClip: { position: 'absolute', left: 0, right: 0, bottom: 0, top: -PANEL_H - PANEL_ROOM, overflow: 'hidden' },
1154 panel: { position: 'absolute', left: 0, right: 0, bottom: 0, top: PANEL_ROOM, paddingHorizontal: 20, paddingTop: 18 },
1155 panelRow: { flexDirection: 'row', alignItems: 'center', gap: 12 },
1156 panelIcon: { width: 44, height: 44, borderRadius: 22, alignItems: 'center', justifyContent: 'center' },
1157 panelIconGood: { backgroundColor: GOOD },
1158 panelIconBad: { backgroundColor: CORAL },
1159 panelCopy: { flex: 1 },
1160 panelTitle: { fontSize: 20, fontWeight: '800', letterSpacing: -0.2 },
1161 panelAnswer: { marginTop: 2, fontSize: 15, fontWeight: '600' },
1162 xpChip: { flexDirection: 'row', alignItems: 'center', gap: 4, height: 30, paddingHorizontal: 10, borderRadius: 15, backgroundColor: SUN },
1163 xpChipLabel: { color: '#7A4E00', fontSize: 13, fontWeight: '800' },
1164 xpFloat: { position: 'absolute', top: 2, right: 6, color: SUN_EDGE, fontSize: 18, fontWeight: '800' },
1165 combo: { position: 'absolute', top: -16, right: 20, flexDirection: 'row', alignItems: 'center', gap: 5, height: 32, paddingHorizontal: 12, borderRadius: 16, backgroundColor: EMBER, transform: [{ rotate: '-3deg' }] },
1166 comboLabel: { color: '#FFFFFF', fontSize: 14, fontWeight: '800' },
1167 burst: { position: 'absolute', top: '50%', left: '50%', width: 0, height: 0 },
1168 spark: { position: 'absolute', top: -4, left: -4, width: 8, height: 8, borderRadius: 2 },
1169
1170 // Sheet
1171 sheet: { position: 'absolute', left: 0, right: 0, bottom: 0, borderTopLeftRadius: 28, borderTopRightRadius: 28, paddingHorizontal: 20, paddingTop: 10, alignItems: 'center' },
1172 grabber: { width: 40, height: 5, borderRadius: 3 },
1173 sheetIcon: { marginTop: 20, width: 72, height: 72, borderRadius: 24, alignItems: 'center', justifyContent: 'center' },
1174 sheetTitle: { marginTop: 16, fontSize: 24, fontWeight: '800', letterSpacing: -0.3 },
1175 sheetBody: { marginTop: 8, fontSize: 16, lineHeight: 23, textAlign: 'center', paddingHorizontal: 12 },
1176 sheetButton: { alignSelf: 'stretch', marginTop: 24 },
1177 sheetLink: { height: 52, marginTop: 4, alignSelf: 'stretch', alignItems: 'center', justifyContent: 'center' },
1178 sheetLinkLabel: { fontSize: 15, fontWeight: '800', letterSpacing: 0.6, textTransform: 'uppercase' },
1179
1180 // Completion
1181 complete: { flex: 1, paddingHorizontal: 20 },
1182 completeTop: { alignItems: 'center' },
1183 medalSlot: { width: 220, height: 200, alignItems: 'center', justifyContent: 'center' },
1184 rays: { position: 'absolute', top: -10, left: 0 },
1185 completeTitle: { marginTop: 4, fontSize: 32, fontWeight: '800', letterSpacing: -0.8 },
1186 completeSub: { marginTop: 6, fontSize: 16, fontWeight: '500' },
1187 stats: { marginTop: 28, flexDirection: 'row', gap: 10 },
1188 stat: { flex: 1, borderWidth: 2, borderRadius: 18, overflow: 'hidden' },
1189 statLabel: { height: 26, lineHeight: 24, textAlign: 'center', color: '#FFFFFF', fontSize: 11, fontWeight: '800', letterSpacing: 0.8, textTransform: 'uppercase' },
1190 statBody: { height: 58, borderRadius: 14, flexDirection: 'row', alignItems: 'center', justifyContent: 'center', gap: 6 },
1191 statValue: { fontSize: 21, fontWeight: '800', fontVariant: ['tabular-nums'] },
1192 streak: { marginTop: 14, borderWidth: 2, borderRadius: 20, padding: 16 },
1193 streakHead: { flexDirection: 'row', alignItems: 'center', gap: 14 },
1194 streakCopy: { flex: 1 },
1195 streakTitle: { fontSize: 22, fontWeight: '800', letterSpacing: -0.3 },
1196 streakSub: { marginTop: 2, fontSize: 14, lineHeight: 19 },
1197 days: { marginTop: 16, flexDirection: 'row', justifyContent: 'space-between' },
1198 day: { alignItems: 'center', gap: 6 },
1199 dayDot: { width: 34, height: 34, borderRadius: 17 },
1200 dayFill: { width: 34, height: 34, borderRadius: 17, backgroundColor: EMBER, alignItems: 'center', justifyContent: 'center' },
1201 dayToday: { backgroundColor: SUN_EDGE },
1202 dayLabel: { fontSize: 12, fontWeight: '800' },
1203});

More screens like this.

All Learning