The Today view of a habit app: a week strip of completion rings, a progress card whose ring sweeps and counter rolls, and habit rows whose round button fills, draws its tick and throws confetti. Counter habits step a segmented bar (long-press resets), rows swipe to Skip and Edit, a 15-week heatmap shows a tooltip per day, an Add habit sheet animates a new row in, and the card turns green on a perfect day.
Details
Using gluestack-ui?
Optional. The screen is plain React Native; these components can stand in for its primitives.
1import { useEffect, useMemo, useRef, useState, type ComponentRef, type ReactNode } from 'react';2import { KeyboardAvoidingView, PanResponder, Platform, Pressable, ScrollView, StyleSheet, Text, TextInput, View, useColorScheme, useWindowDimensions, type LayoutChangeEvent } from 'react-native';3import Animated, {4 Easing,5 FadeIn,6 FadeInDown,7 LinearTransition,8 ZoomIn,9 interpolate,10 interpolateColor,11 runOnJS,12 useAnimatedProps,13 useAnimatedStyle,14 useSharedValue,15 withDelay,16 withRepeat,17 withSequence,18 withSpring,19 withTiming,20 type SharedValue,21} from 'react-native-reanimated';22import { LinearGradient } from 'expo-linear-gradient';23import { useSafeAreaInsets } from 'react-native-safe-area-context';24import Svg, { Circle, Path } from 'react-native-svg';25import { Bell, Check, Flame, Lock, Minus, MoreHorizontal, Pencil, Plus, SkipForward, Undo2, X, type LucideIcon } from 'lucide-react-native';2627// ─── Brand ──────────────────────────────────────────────────────────────────28// The screen's accent (each habit's own colour is not the brand). Every accent colour below derives from these, so changing them rebrands the screen.2930const ACCENT = '#10B981';31const ACCENT_DARK = '#34D399'; // the accent as text and highlights on dark backgrounds32const ON_ACCENT = '#FFFFFF'; // text and icons on an accent fill3334/** `hex` at `alpha` opacity, as rgba(). */35function tint(hex: string, alpha: number) {36 const n = parseInt(hex.slice(1), 16);37 return `rgba(${(n >> 16) & 255}, ${(n >> 8) & 255}, ${n & 255}, ${alpha})`;38}3940/** `hex` mixed toward black (amount > 0) or white (amount < 0); amount from -1 to 1. */41function shade(hex: string, amount: number) {42 const n = parseInt(hex.slice(1), 16);43 const target = amount < 0 ? 255 : 0;44 const p = Math.abs(amount);45 const c = (v: number) => Math.round(v + (target - v) * p).toString(16).padStart(2, '0');46 return `#${c((n >> 16) & 255)}${c((n >> 8) & 255)}${c(n & 255)}`.toUpperCase();47}4849// ─── Sample data ────────────────────────────────────────────────────────────5051const WEEKDAYS = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];52const DAY_SHORT = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'];53const MONTH_SHORT = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];54const MONTH = 'November';55const TODAY = 6; // Sunday, the last day of the strip56const STREAK_DAYS = 12;5758type Freq = 'Daily' | 'Weekdays' | 'Custom';59type Habit = {60 id: string;61 name: string;62 emoji: string;63 color: string;64 kind: 'check' | 'count';65 goal: number;66 unit: string;67 note: string;68 /** Days in a row before today; today is added once the habit is done. */69 streak: number;70 freq: Freq;71 days: boolean[];72 /** Reminder, in minutes after midnight. */73 reminder: number;74 fresh?: boolean;75};7677const EVERY_DAY = [true, true, true, true, true, true, true];78const HABITS: Habit[] = [79 { id: 'water', name: 'Drink water', emoji: '💧', color: '#0EA5E9', kind: 'count', goal: 8, unit: 'glasses', note: '', streak: 3, freq: 'Daily', days: EVERY_DAY, reminder: 600 },80 { id: 'read', name: 'Read 20 pages', emoji: '📖', color: '#F59E0B', kind: 'check', goal: 1, unit: '', note: 'Evening', streak: 11, freq: 'Daily', days: EVERY_DAY, reminder: 1290 },81 { id: 'run', name: 'Morning run', emoji: '🏃', color: '#FF6B5E', kind: 'check', goal: 1, unit: '', note: '3 km', streak: 4, freq: 'Daily', days: EVERY_DAY, reminder: 420 },82 { id: 'meditate', name: 'Meditate', emoji: '🧘', color: '#14B8A6', kind: 'check', goal: 1, unit: '', note: '10 min', streak: 21, freq: 'Daily', days: EVERY_DAY, reminder: 450 },83 { id: 'sugar', name: 'No sugar', emoji: '🍬', color: '#84CC16', kind: 'check', goal: 1, unit: '', note: 'All day', streak: 3, freq: 'Daily', days: EVERY_DAY, reminder: 540 },84 { id: 'journal', name: 'Journal', emoji: '📓', color: '#EC4899', kind: 'check', goal: 1, unit: '', note: 'Before bed', streak: 1, freq: 'Daily', days: EVERY_DAY, reminder: 1320 },85];8687// Monday to Saturday, one value per habit in the order above. Sunday is live.88const HISTORY = [89 [8, 1, 1, 1, 0, 1],90 [8, 1, 0, 1, 1, 1],91 [6, 1, 1, 1, 0, 0],92 [8, 1, 1, 1, 1, 1],93 [8, 1, 1, 1, 1, 0],94 [8, 1, 1, 1, 1, 1],95];96const WEEK = DAY_SHORT.map((label, i) => {97 const row = HISTORY[i];98 const values: Record<string, number> = {};99 HABITS.forEach((h, j) => (values[h.id] = row ? row[j] : 0));100 return { label: label[0], date: 23 + i, values, done: row ? HABITS.filter((h, j) => row[j] >= h.goal).length : 0 };101});102const START: Record<string, number> = { water: 5, read: 1, run: 1, meditate: 1, sugar: 1, journal: 0 };103104// The heatmap: 15 weeks of daily counts, Monday 17 August to today. The last week mirrors the strip.105const WEEKS = 15;106const HEAT = Array.from({ length: WEEKS * 7 }, (_, i) => {107 if (i >= (WEEKS - 1) * 7) return WEEK[i - (WEEKS - 1) * 7].done;108 const wave = Math.sin(i * 1.7) * 1.5 + Math.sin(i * 0.37) * 1.4;109 return Math.max(0, Math.min(6, Math.round(2.3 + (i / 105) * 2.6 + wave)));110});111function heatDay(i: number) {112 const d = new Date(2026, 7, 17 + i);113 return { month: d.getMonth(), label: `${DAY_SHORT[i % 7]}, ${d.getDate()} ${MONTH_SHORT[d.getMonth()]}` };114}115116const ICONS = ['🌱', '🎸', '😴', '🦷', '🚶', '🥗', '📵'];117const COLORS = [118 { name: 'Teal', value: '#14B8A6' },119 { name: 'Amber', value: '#F59E0B' },120 { name: 'Sky', value: '#0EA5E9' },121 { name: 'Coral', value: '#FF6B5E' },122 { name: 'Lime', value: '#84CC16' },123 { name: 'Pink', value: '#EC4899' },124];125const FREQS: Freq[] = ['Daily', 'Weekdays', 'Custom'];126const CONFETTI = [ACCENT, '#F59E0B', '#38BDF8', '#FF6B5E', '#A3E635', '#FDE047'];127128function clock(minutes: number) {129 const h = Math.floor(minutes / 60);130 const m = minutes % 60;131 return `${h % 12 === 0 ? 12 : h % 12}:${m < 10 ? '0' : ''}${m} ${h < 12 ? 'AM' : 'PM'}`;132}133134function cheer(done: number, total: number, perfectDays: number, past: string | null) {135 const left = total - done;136 if (past) return left === 0 ? `Every habit closed on ${past}.` : `You closed ${done} of ${total} on ${past}.`;137 if (total === 0) return 'Add a habit to get going.';138 if (left === 0) return `Every habit closed. ${perfectDays} perfect ${perfectDays === 1 ? 'day' : 'days'} this week.`;139 if (done === 0) return 'A fresh day. Start with the easy one.';140 if (left === 1) return 'One more and today is perfect.';141 if (left === 2) return 'Two to go. You have got this.';142 return `${left} to go. Keep the chain alive.`;143}144145// ─── Palette ────────────────────────────────────────────────────────────────146147const EMBER = '#FB923C';148const POP = { damping: 11, stiffness: 260, mass: 0.6 };149const SPRING = { damping: 16, stiffness: 220, mass: 0.7 };150const SLIDE = { damping: 20, stiffness: 240, mass: 0.8 };151const MOVE = LinearTransition.duration(280);152const ACTIONS_W = 140;153const GAP = 4;154const TIP_W = 172;155const WEB_INPUT = Platform.OS === 'web' ? ({ outlineStyle: 'none' } as object) : null;156157function usePalette() {158 const dark = useColorScheme() === 'dark';159 return {160 dark,161 bg: dark ? '#090B0A' : '#F3F5F2',162 card: dark ? '#131615' : '#FFFFFF',163 fg: dark ? '#F3F6F4' : '#0D1512',164 muted: dark ? '#8A948F' : '#66716C',165 faint: dark ? '#565F5B' : '#A3ADA8',166 line: dark ? '#222725' : '#E4E9E5',167 chip: dark ? '#1B1F1D' : '#E9EEEA',168 track: dark ? '#262C29' : '#E4EAE6',169 accentText: dark ? ACCENT_DARK : shade(ACCENT, 0.19),170 accentSoft: dark ? tint(ACCENT, 0.16) : tint(ACCENT, 0.12),171 // Two-digit alpha appended to a habit's colour for its tile and button.172 tint: dark ? '2B' : '1F',173 hero: (dark ? ['#17231E', '#0F1614'] : ['#14271F', '#0B1612']) as [string, string],174 heroDone: (dark ? [shade(ACCENT, -0.03), shade(ACCENT, 0.22)] : [shade(ACCENT, -0.08), shade(ACCENT, 0.14)]) as [string, string],175 heroLine: dark ? '#24302B' : '#0B1612',176 heroLineDone: dark ? shade(ACCENT, -0.09) : shade(ACCENT, 0.03),177 // Heatmap levels, from an empty day to every habit kept.178 heat: dark179 ? ['#1A1F1D', shade(ACCENT_DARK, 0.72), shade(ACCENT_DARK, 0.53), shade(ACCENT, 0.19), ACCENT_DARK]180 : ['#E7ECE8', shade(ACCENT, -0.72), shade(ACCENT, -0.45), shade(ACCENT, -0.13), shade(ACCENT, 0.17)],181 sheet: dark ? '#161918' : '#FFFFFF',182 field: dark ? '#0E1110' : '#F3F5F2',183 tip: dark ? '#F3F6F4' : '#0D1512',184 tipText: dark ? '#0D1512' : '#FFFFFF',185 skip: dark ? '#2A2F2D' : '#DDE3DF',186 };187}188189// ─── Small pieces ───────────────────────────────────────────────────────────190191function Tap({ children, label, onPress, to = 0.92 }: { children: ReactNode; label: string; onPress?: () => void; to?: number }) {192 const scale = useSharedValue(1);193 const style = useAnimatedStyle(() => ({ transform: [{ scale: scale.value }] }));194 return (195 <Pressable role="button" aria-label={label} onPress={onPress} hitSlop={6} onPressIn={() => (scale.value = withSpring(to, SPRING))} onPressOut={() => (scale.value = withSpring(1, SPRING))}>196 <Animated.View style={style}>{children}</Animated.View>197 </Pressable>198 );199}200201/** Eases a number toward its target on the JS thread, so SVG props and text can follow it together. */202function useTween(target: number, duration = 700) {203 const [value, setValue] = useState(0);204 const latest = useRef(0);205 useEffect(() => {206 const from = latest.current;207 const started = Date.now();208 let frame = 0;209 const tick = () => {210 const t = Math.min(1, (Date.now() - started) / duration);211 latest.current = from + (target - from) * (1 - Math.pow(1 - t, 3));212 setValue(latest.current);213 if (t < 1) frame = requestAnimationFrame(tick);214 };215 frame = requestAnimationFrame(tick);216 return () => cancelAnimationFrame(frame);217 }, [target, duration]);218 return value;219}220221/** Mounts on open, unmounts after the closing animation. */222function useReveal(open: boolean) {223 const [mounted, setMounted] = useState(open);224 const p = useSharedValue(open ? 1 : 0);225 useEffect(() => {226 if (open) {227 setMounted(true);228 p.value = withTiming(1, { duration: 320, easing: Easing.out(Easing.cubic) });229 } else {230 p.value = withTiming(0, { duration: 220, easing: Easing.in(Easing.quad) }, (done) => {231 if (done) runOnJS(setMounted)(false);232 });233 }234 }, [open, p]);235 return { mounted, p };236}237238function Ring({ size, stroke, share, color, track }: { size: number; stroke: number; share: number; color: string; track: string }) {239 const r = (size - stroke) / 2;240 const length = 2 * Math.PI * r;241 return (242 // Turned a quarter back so the arc starts at twelve o'clock.243 <View style={styles.quarterBack}>244 <Svg width={size} height={size}>245 <Circle cx={size / 2} cy={size / 2} r={r} stroke={track} strokeWidth={stroke} fill="none" />246 {share > 0.004 && (247 <Circle cx={size / 2} cy={size / 2} r={r} stroke={color} strokeWidth={stroke} strokeLinecap="round" strokeDasharray={`${length} ${length}`} strokeDashoffset={length * (1 - Math.min(1, share))} fill="none" />248 )}249 </Svg>250 </View>251 );252}253254// ─── Confetti ───────────────────────────────────────────────────────────────255256function Particle({ p, index, count, reach }: { p: SharedValue<number>; index: number; count: number; reach: number }) {257 const angle = (index / count) * Math.PI * 2 + (index % 2 ? 0.35 : -0.2);258 const far = reach * (0.55 + ((index * 37) % 10) / 22);259 const spin = index % 2 ? 240 : -200;260 const style = useAnimatedStyle(() => {261 const t = p.value;262 return {263 opacity: t <= 0 ? 0 : interpolate(t, [0, 0.65, 1], [1, 1, 0]),264 transform: [265 { translateX: Math.cos(angle) * far * t },266 { translateY: Math.sin(angle) * far * t + reach * 0.4 * t * t },267 { rotate: `${t * spin}deg` },268 { scale: interpolate(t, [0, 0.25, 1], [0.3, 1, 0.7]) },269 ],270 };271 });272 return <Animated.View style={[index % 3 === 0 ? styles.confettiDot : styles.confettiBar, { backgroundColor: CONFETTI[index % CONFETTI.length] }, style]} />;273}274275/** A burst from its own centre each time `fire` goes up. */276function Burst({ fire, count = 10, reach = 38 }: { fire: number; count?: number; reach?: number }) {277 const p = useSharedValue(0);278 useEffect(() => {279 if (!fire) return;280 p.value = 0;281 p.value = withTiming(1, { duration: reach > 60 ? 1100 : 720, easing: Easing.out(Easing.cubic) });282 }, [fire, p, reach]);283 return (284 <View pointerEvents="none" style={styles.burst}>285 {Array.from({ length: count }, (_, i) => (286 <Particle key={i} p={p} index={i} count={count} reach={reach} />287 ))}288 </View>289 );290}291292// ─── Week strip ─────────────────────────────────────────────────────────────293294function DayCell({ label, date, share, today, selected, onPress }: { label: string; date: number; share: number; today: boolean; selected: boolean; onPress: () => void }) {295 const c = usePalette();296 const on = useSharedValue(selected ? 1 : 0);297 const scale = useSharedValue(1);298 useEffect(() => {299 on.value = withTiming(selected ? 1 : 0, { duration: 200 });300 }, [selected, on]);301 const box = useAnimatedStyle(() => ({302 backgroundColor: interpolateColor(on.value, [0, 1], [c.bg, c.card]),303 borderColor: interpolateColor(on.value, [0, 1], [c.bg, c.line]),304 transform: [{ scale: scale.value }],305 }));306 return (307 <Pressable role="tab" aria-selected={selected} aria-label={`${WEEKDAYS[date - 23]} ${date} ${MONTH}`} onPress={onPress} onPressIn={() => (scale.value = withSpring(0.92, SPRING))} onPressOut={() => (scale.value = withSpring(1, SPRING))} style={styles.fill}>308 <Animated.View style={[styles.day, box]}>309 <Text style={[styles.dayLabel, { color: today ? c.accentText : c.muted }]}>{label}</Text>310 <View style={styles.dayRing}>311 <Ring size={36} stroke={3.5} share={share} color={ACCENT} track={c.track} />312 <Text style={[styles.dayDate, { color: selected || today ? c.fg : c.muted }]}>{date}</Text>313 </View>314 <View style={[styles.dayDot, { backgroundColor: today ? ACCENT : 'transparent' }]} />315 </Animated.View>316 </Pressable>317 );318}319320// ─── Progress card ──────────────────────────────────────────────────────────321322function StreakPill({ ink }: { ink: string }) {323 const flicker = useSharedValue(0);324 useEffect(() => {325 flicker.value = withRepeat(withTiming(1, { duration: 900, easing: Easing.inOut(Easing.sin) }), -1, true);326 }, [flicker]);327 const flame = useAnimatedStyle(() => ({ transform: [{ scale: 1 + flicker.value * 0.1 }, { rotate: `${interpolate(flicker.value, [0, 1], [-4, 4])}deg` }] }));328 return (329 <View style={[styles.streakPill, { backgroundColor: tint(ink, 0.12) }]}>330 <Animated.View style={flame}>331 <Flame size={14} color={EMBER} fill={EMBER} strokeWidth={2} />332 </Animated.View>333 <Text style={[styles.streakText, { color: ink }]}>{STREAK_DAYS}-day streak</Text>334 </View>335 );336}337338function ProgressCard({ done, total, perfectDays, past, party }: { done: number; total: number; perfectDays: number; past: string | null; party: number }) {339 const c = usePalette();340 const complete = total > 0 && done === total;341 const share = useTween(total ? done / total : 0);342 const percent = Math.round(share * 100);343 const finish = useSharedValue(complete ? 1 : 0);344 useEffect(() => {345 finish.value = withTiming(complete ? 1 : 0, { duration: 450 });346 }, [complete, finish]);347 const finished = useAnimatedStyle(() => ({ opacity: finish.value }));348 // Text on the hero: white on the ink, the on-accent colour once the accent finish is showing.349 const ink = complete ? ON_ACCENT : '#FFFFFF';350351 return (352 <View style={c.dark ? styles.heroShadowDark : complete ? styles.heroShadowDone : styles.heroShadow}>353 <View style={[styles.hero, { borderColor: complete ? c.heroLineDone : c.heroLine }]}>354 <LinearGradient colors={c.hero} start={{ x: 0, y: 0 }} end={{ x: 1, y: 1 }} style={StyleSheet.absoluteFill} />355 <View style={styles.heroGlow} />356 {/* The emerald finish fades in over the ink when the last habit is checked. */}357 <Animated.View style={[StyleSheet.absoluteFill, finished]}>358 <LinearGradient colors={c.heroDone} start={{ x: 0, y: 0 }} end={{ x: 1, y: 1 }} style={styles.fill} />359 <View style={styles.heroOrb} />360 </Animated.View>361362 <View role="progressbar" aria-label="Habits done" aria-valuemin={0} aria-valuemax={100} aria-valuenow={percent} style={styles.heroRing}>363 <Ring size={96} stroke={10} share={share} color={complete ? ON_ACCENT : ACCENT_DARK} track={tint(ink, 0.14)} />364 <View style={styles.heroRingCenter}>365 {complete && percent === 100 ? (366 <Animated.View key="check" entering={ZoomIn.duration(260)}>367 <Check size={34} color={ON_ACCENT} strokeWidth={3} />368 </Animated.View>369 ) : (370 <Text style={styles.heroPercent}>371 {percent}372 <Text style={styles.heroPercentSign}>%</Text>373 </Text>374 )}375 </View>376 </View>377378 <View style={styles.heroText}>379 <Text style={[styles.heroEyebrow, { color: tint(ink, 0.6) }]}>{complete ? 'ALL DONE' : 'DAILY PROGRESS'}</Text>380 {complete && !past ? (381 <Animated.Text key="perfect" entering={FadeInDown.duration(260)} style={[styles.heroTitle, { color: ink }]}>382 Perfect day383 </Animated.Text>384 ) : (385 <View style={styles.heroCount}>386 {/* Only the number rolls. */}387 <View style={styles.heroRoll}>388 <Animated.Text key={done} entering={FadeInDown.duration(240)} style={[styles.heroTitle, { color: ink }]}>389 {done}390 </Animated.Text>391 </View>392 <Text style={[styles.heroTitle, { color: ink }]}> of {total} done</Text>393 </View>394 )}395 <Text style={[styles.heroCheer, { color: tint(ink, 0.74) }]}>{cheer(done, total, perfectDays, past)}</Text>396 <StreakPill ink={ink} />397 </View>398 </View>399 <View pointerEvents="none" style={styles.heroBurst}>400 <Burst fire={party} count={22} reach={120} />401 </View>402 </View>403 );404}405406// ─── A habit ────────────────────────────────────────────────────────────────407408const AnimatedPath = Animated.createAnimatedComponent(Path);409410/** The round button: a check habit fills and draws its tick, a counter adds one per tap around a progress arc. */411function CheckButton({ habit, value, skipped, disabled, onPress, onLongPress }: { habit: Habit; value: number; skipped: boolean; disabled: boolean; onPress: () => void; onLongPress: () => void }) {412 const c = usePalette();413 const count = habit.kind === 'count';414 const done = value >= habit.goal;415 const fill = useSharedValue(done ? 1 : 0);416 const draw = useSharedValue(done ? 1 : 0);417 const halo = useSharedValue(1);418 const press = useSharedValue(1);419 const pop = useSharedValue(1);420 const [burst, setBurst] = useState(0);421 const was = useRef({ done, value });422423 useEffect(() => {424 const before = was.current;425 was.current = { done, value };426 if (before.value !== value && !done) pop.value = withSequence(withTiming(1.16, { duration: 90 }), withSpring(1, POP));427 if (before.done === done) return;428 // The fill overshoots on the way in, then the tick is drawn across it.429 fill.value = done ? withSpring(1, POP) : withTiming(0, { duration: 160 });430 draw.value = done ? withDelay(110, withTiming(1, { duration: 300, easing: Easing.out(Easing.cubic) })) : withTiming(0, { duration: 100 });431 if (done) {432 halo.value = 0;433 halo.value = withTiming(1, { duration: 560, easing: Easing.out(Easing.cubic) });434 setBurst((n) => n + 1);435 }436 }, [done, value, fill, draw, halo, pop]);437438 const box = useAnimatedStyle(() => ({ transform: [{ scale: press.value * pop.value }] }));439 const fillStyle = useAnimatedStyle(() => ({ opacity: Math.min(1, fill.value * 3), transform: [{ scale: fill.value }] }));440 const haloStyle = useAnimatedStyle(() => ({ opacity: (1 - halo.value) * 0.5, transform: [{ scale: 1 + halo.value * 0.8 }] }));441 const mark = useAnimatedProps(() => ({ strokeDashoffset: 24 * (1 - draw.value) }));442443 return (444 <Pressable445 role={count ? 'button' : 'checkbox'}446 aria-checked={count ? undefined : done}447 aria-label={skipped ? `Bring back ${habit.name}` : count ? `Add one to ${habit.name}` : habit.name}448 disabled={disabled}449 hitSlop={6}450 delayLongPress={420}451 onPress={onPress}452 onLongPress={count ? onLongPress : undefined}453 onPressIn={() => (press.value = withSpring(0.88, SPRING))}454 onPressOut={() => (press.value = withSpring(1, SPRING))}455 >456 <Animated.View style={[styles.check, box]}>457 <Animated.View style={[styles.checkHalo, haloStyle]} />458 {skipped ? (459 <View style={[styles.checkBase, styles.checkSkipped, { borderColor: c.faint }]}>460 <SkipForward size={17} color={c.muted} strokeWidth={2.2} />461 </View>462 ) : count ? (463 <View style={[styles.checkBase, { backgroundColor: `${habit.color}${c.tint}` }]}>464 <View style={StyleSheet.absoluteFill}>465 <Ring size={46} stroke={3.5} share={value / habit.goal} color={habit.color} track={`${habit.color}33`} />466 </View>467 <Plus size={20} color={habit.color} strokeWidth={2.8} />468 </View>469 ) : (470 <View style={[styles.checkBase, styles.checkOpen, { backgroundColor: `${habit.color}${c.tint}`, borderColor: `${habit.color}73` }]}>471 <Check size={18} color={habit.color} strokeWidth={2.6} opacity={0.5} />472 </View>473 )}474 <Animated.View style={[styles.checkFill, fillStyle]}>475 <Svg width={24} height={24} viewBox="0 0 24 24">476 <AnimatedPath d="M5 12.5l4.5 4.5L19 7.5" stroke={ON_ACCENT} strokeWidth={3.2} strokeLinecap="round" strokeLinejoin="round" strokeDasharray="24 48" animatedProps={mark} fill="none" />477 </Svg>478 </Animated.View>479 <Burst fire={burst} />480 </Animated.View>481 </Pressable>482 );483}484485function Segment({ on, color }: { on: boolean; color: string }) {486 const c = usePalette();487 const f = useSharedValue(on ? 1 : 0);488 useEffect(() => {489 f.value = withTiming(on ? 1 : 0, { duration: 260, easing: Easing.out(Easing.cubic) });490 }, [on, f]);491 const style = useAnimatedStyle(() => ({ width: `${f.value * 100}%` }));492 return (493 <View style={[styles.segment, { backgroundColor: c.track }]}>494 <Animated.View style={[styles.segmentFill, { backgroundColor: color }, style]} />495 </View>496 );497}498499function RowAction({ icon: Icon, label, name, tone, onPress }: { icon: LucideIcon; label: string; name: string; tone: string; onPress: () => void }) {500 const c = usePalette();501 return (502 <Pressable role="button" aria-label={`${label} ${name}`} onPress={onPress} style={({ pressed }) => [styles.action, { backgroundColor: tone, opacity: pressed ? 0.7 : 1 }]}>503 <Icon size={18} color={c.fg} strokeWidth={2.2} />504 <Text style={[styles.actionText, { color: c.fg }]}>{label}</Text>505 </Pressable>506 );507}508509type RowProps = {510 habit: Habit;511 value: number;512 skipped: boolean;513 readOnly: boolean;514 open: boolean;515 enterDelay: number | null;516 onOpen: (open: boolean) => void;517 onPress: () => void;518 onReset: () => void;519 onSkip: () => void;520 onEdit: () => void;521};522523function HabitRow({ habit, value, skipped, readOnly, open, enterDelay, onOpen, onPress, onReset, onSkip, onEdit }: RowProps) {524 const c = usePalette();525 const done = value >= habit.goal;526 const streak = habit.streak + (done && !readOnly ? 1 : 0);527 const x = useSharedValue(0);528 const flash = useSharedValue(habit.fresh && enterDelay !== null ? 1 : 0);529 const live = useRef({ open, onOpen, readOnly });530 live.current = { open, onOpen, readOnly };531532 useEffect(() => {533 x.value = withSpring(open ? -ACTIONS_W : 0, SLIDE);534 }, [open, x]);535 useEffect(() => {536 // A habit that was just added arrives with an emerald outline that fades.537 if (flash.value) flash.value = withDelay(700, withTiming(0, { duration: 900 }));538 }, [flash]);539540 const pan = useMemo(541 () =>542 PanResponder.create({543 onMoveShouldSetPanResponder: (_e, g) => !live.current.readOnly && Math.abs(g.dx) > 8 && Math.abs(g.dx) > Math.abs(g.dy) * 1.5,544 onPanResponderMove: (_e, g) => {545 x.value = Math.max(-ACTIONS_W - 24, Math.min(0, (live.current.open ? -ACTIONS_W : 0) + g.dx));546 },547 onPanResponderRelease: (_e, g) => {548 const to = (live.current.open ? -ACTIONS_W : 0) + g.dx < -ACTIONS_W / 2;549 x.value = withSpring(to ? -ACTIONS_W : 0, SLIDE);550 live.current.onOpen(to);551 },552 onPanResponderTerminate: () => {553 x.value = withSpring(live.current.open ? -ACTIONS_W : 0, SLIDE);554 },555 }),556 [x]557 );558559 const slide = useAnimatedStyle(() => ({ transform: [{ translateX: x.value }], borderColor: interpolateColor(flash.value, [0, 1], [c.line, ACCENT]) }));560 const reveal = useAnimatedStyle(() => ({ opacity: interpolate(x.value, [-ACTIONS_W * 0.5, -4], [1, 0], 'clamp') }));561 const entering = enterDelay === null ? FadeIn.duration(200) : FadeInDown.delay(enterDelay).duration(380);562563 return (564 <Animated.View entering={entering} layout={MOVE} style={styles.rowWrap}>565 <Animated.View style={[styles.actions, reveal]}>566 <RowAction icon={skipped ? Undo2 : SkipForward} label={skipped ? 'Unskip' : 'Skip'} name={habit.name} tone={c.skip} onPress={onSkip} />567 <RowAction icon={Pencil} label="Edit" name={habit.name} tone={c.accentSoft} onPress={onEdit} />568 </Animated.View>569570 <Animated.View {...pan.panHandlers} style={[styles.row, { backgroundColor: c.card }, slide]}>571 <View style={[styles.rowInner, { opacity: readOnly ? 0.62 : skipped ? 0.5 : 1 }]}>572 <View style={[styles.tile, { backgroundColor: `${habit.color}${c.tint}` }]}>573 <Text style={styles.tileEmoji}>{habit.emoji}</Text>574 </View>575576 <View style={styles.rowBody}>577 <Text numberOfLines={1} style={[styles.rowName, { color: c.fg }]}>578 {habit.name}579 </Text>580 <View style={styles.rowMeta}>581 {skipped ? (582 <Text style={[styles.rowMetaText, { color: c.muted }]}>Skipped today</Text>583 ) : habit.kind === 'count' ? (584 <Text style={[styles.rowMetaText, { color: c.muted }]}>585 <Text style={[styles.rowMetaStrong, { color: c.fg }]}>{value}</Text> / {habit.goal} {habit.unit}586 </Text>587 ) : (588 <Text numberOfLines={1} style={[styles.rowMetaText, styles.rowMetaShrink, { color: c.muted }]}>589 {habit.note}590 </Text>591 )}592 <View style={[styles.rowMetaDot, { backgroundColor: c.faint }]} />593 <Flame size={12.5} color={streak > 0 ? EMBER : c.faint} fill={streak > 0 ? EMBER : 'transparent'} strokeWidth={2} />594 <Text style={[styles.rowMetaText, { color: c.muted }]}>{streak}</Text>595 </View>596 {habit.kind === 'count' && (597 <View style={styles.segments}>598 {Array.from({ length: habit.goal }, (_, i) => (599 <Segment key={i} on={i < value} color={done ? ACCENT : habit.color} />600 ))}601 </View>602 )}603 </View>604605 {!readOnly && (606 <Pressable role="button" aria-label={`More actions for ${habit.name}`} aria-expanded={open} hitSlop={8} onPress={() => onOpen(!open)} style={({ pressed }) => [styles.more, { backgroundColor: pressed ? c.chip : 'transparent' }]}>607 <MoreHorizontal size={18} color={c.faint} />608 </Pressable>609 )}610 <CheckButton habit={habit} value={skipped ? 0 : value} skipped={skipped} disabled={readOnly} onPress={onPress} onLongPress={onReset} />611 </View>612 </Animated.View>613 </Animated.View>614 );615}616617// ─── Heatmap ────────────────────────────────────────────────────────────────618619function level(count: number, total: number) {620 if (count <= 0 || total <= 0) return 0;621 const share = count / total;622 return share >= 1 ? 4 : share > 0.6 ? 3 : share > 0.4 ? 2 : 1;623}624625function Heatmap({ todayDone, todayTotal }: { todayDone: number; todayTotal: number }) {626 const c = usePalette();627 const { width } = useWindowDimensions();628 const [picked, setPicked] = useState<number | null>(null);629 const gridW = width - 32 - 32;630 const cell = (gridW - GAP * (WEEKS - 1)) / WEEKS;631 const step = cell + GAP;632 const last = WEEKS * 7 - 1;633 const count = (i: number) => (i === last ? todayDone : HEAT[i]);634 const total = (i: number) => (i === last ? todayTotal : HABITS.length);635 const kept = Math.round((HEAT.reduce((sum, n, i) => sum + (i === last ? todayDone : n), 0) / (HEAT.length * HABITS.length)) * 100);636 const months = Array.from({ length: WEEKS }, (_, w) => ({ w, month: heatDay(w * 7).month })).filter((m, i, all) => i === 0 || m.month !== all[i - 1].month);637638 const col = picked === null ? 0 : Math.floor(picked / 7);639 const row = picked === null ? 0 : picked % 7;640 const tipLeft = Math.max(0, Math.min(gridW - TIP_W, col * step + cell / 2 - TIP_W / 2));641 const tipTop = row < 2 ? row * step + cell + 6 : row * step - 38;642643 return (644 <Animated.View entering={FadeInDown.delay(560).duration(380)} layout={MOVE} style={[styles.heatCard, { backgroundColor: c.card, borderColor: c.line }]}>645 <View style={styles.heatHead}>646 <View>647 <Text style={[styles.cardTitle, { color: c.fg }]}>Year in pixels</Text>648 <Text style={[styles.cardHint, { color: c.muted }]}>Last 15 weeks</Text>649 </View>650 <View style={styles.heatStat}>651 <Text style={[styles.heatStatValue, { color: c.accentText }]}>{kept}%</Text>652 <Text style={[styles.cardHint, { color: c.muted }]}>kept</Text>653 </View>654 </View>655656 <View style={styles.heatMonths}>657 {months.map((m) => (658 <Text key={m.w} style={[styles.heatMonth, { color: c.muted, left: m.w * step }]}>659 {MONTH_SHORT[m.month]}660 </Text>661 ))}662 </View>663664 <View style={[styles.heatGrid, { height: step * 7 - GAP }]}>665 {HEAT.map((_, i) => (666 <Pressable667 key={i}668 role="button"669 aria-label={`${heatDay(i).label}: ${count(i)} of ${total(i)} done`}670 onPress={() => setPicked(picked === i ? null : i)}671 style={[672 styles.heatCell,673 { left: Math.floor(i / 7) * step, top: (i % 7) * step, width: cell, height: cell, backgroundColor: c.heat[level(count(i), total(i))], borderColor: picked === i ? c.fg : 'transparent' },674 ]}675 />676 ))}677 {picked !== null && (678 <Animated.View key={picked} entering={ZoomIn.duration(160)} pointerEvents="none" style={[styles.tip, { left: tipLeft, top: tipTop, backgroundColor: c.tip }]}>679 <Text style={[styles.tipText, { color: c.tipText }]}>680 {heatDay(picked).label} · {count(picked)} of {total(picked)} done681 </Text>682 </Animated.View>683 )}684 </View>685686 <View style={styles.legend}>687 <Text style={[styles.legendText, { color: c.muted }]}>Less</Text>688 {c.heat.map((color) => (689 <View key={color} style={[styles.legendCell, { backgroundColor: color }]} />690 ))}691 <Text style={[styles.legendText, { color: c.muted }]}>More</Text>692 </View>693 </Animated.View>694 );695}696697// ─── Add / edit sheet ───────────────────────────────────────────────────────698699type Draft = { name: string; emoji: string; color: string; freq: Freq; days: boolean[]; reminder: number };700const BLANK: Draft = { name: '', emoji: ICONS[0], color: COLORS[0].value, freq: 'Daily', days: [true, false, true, false, true, false, false], reminder: 1200 };701702function Choice({ label, selected, onPress, children, round }: { label: string; selected: boolean; onPress: () => void; children: ReactNode; round?: boolean }) {703 const c = usePalette();704 return (705 <Pressable role="radio" aria-checked={selected} aria-label={label} onPress={onPress} style={({ pressed }) => [round ? styles.choiceRound : styles.choice, { backgroundColor: selected ? c.accentSoft : c.field, borderColor: selected ? ACCENT : c.line, opacity: pressed ? 0.7 : 1 }]}>706 {children}707 </Pressable>708 );709}710711function HabitSheet({ open, editing, onClose, onSave }: { open: boolean; editing: Habit | null; onClose: () => void; onSave: (draft: Draft) => void }) {712 const c = usePalette();713 const insets = useSafeAreaInsets();714 const { mounted, p } = useReveal(open);715 const [draft, setDraft] = useState<Draft>(BLANK);716 const [focused, setFocused] = useState(false);717 useEffect(() => {718 if (open) setDraft(editing ? { name: editing.name, emoji: editing.emoji, color: editing.color, freq: editing.freq, days: editing.days, reminder: editing.reminder } : BLANK);719 }, [open, editing]);720 const backdrop = useAnimatedStyle(() => ({ opacity: p.value }));721 const sheet = useAnimatedStyle(() => ({ transform: [{ translateY: (1 - p.value) * 640 }] }));722 if (!mounted) return null;723724 const set = (patch: Partial<Draft>) => setDraft((d) => ({ ...d, ...patch }));725 const icons = ICONS.includes(draft.emoji) || !editing ? ICONS : [editing.emoji, ...ICONS.slice(0, 6)];726 const ready = draft.name.trim().length > 0;727728 return (729 <KeyboardAvoidingView behavior={Platform.OS === 'ios' ? 'padding' : undefined} style={[StyleSheet.absoluteFill, styles.sheetLayer]}>730 <Animated.View style={[StyleSheet.absoluteFill, styles.scrim, backdrop]}>731 <Pressable role="button" aria-label="Close sheet" onPress={onClose} style={styles.fill} />732 </Animated.View>733 <Animated.View role="dialog" aria-label={editing ? 'Edit habit' : 'New habit'} style={[styles.sheet, { backgroundColor: c.sheet, paddingBottom: insets.bottom + 16 }, sheet]}>734 <View style={[styles.grabber, { backgroundColor: c.track }]} />735 <View style={styles.sheetHead}>736 <Text role="heading" style={[styles.sheetTitle, { color: c.fg }]}>737 {editing ? 'Edit habit' : 'New habit'}738 </Text>739 <Tap label="Close" onPress={onClose}>740 <View style={[styles.sheetClose, { backgroundColor: c.chip }]}>741 <X size={17} color={c.muted} strokeWidth={2.4} />742 </View>743 </Tap>744 </View>745746 <View style={[styles.nameField, { backgroundColor: c.field, borderColor: focused ? ACCENT : c.line }]}>747 <View style={[styles.nameTile, { backgroundColor: `${draft.color}${c.tint}` }]}>748 <Text style={styles.nameEmoji}>{draft.emoji}</Text>749 </View>750 <TextInput751 aria-label="Habit name"752 value={draft.name}753 onChangeText={(name) => set({ name })}754 onFocus={() => setFocused(true)}755 onBlur={() => setFocused(false)}756 placeholder="Stretch for 5 minutes"757 placeholderTextColor={c.faint}758 maxLength={28}759 returnKeyType="done"760 style={[styles.nameInput, { color: c.fg }, WEB_INPUT]}761 />762 </View>763764 <Text style={[styles.sheetLabel, { color: c.muted }]}>ICON</Text>765 <View role="radiogroup" aria-label="Icon" style={styles.choiceRow}>766 {icons.map((emoji) => (767 <Choice key={emoji} round label={`Icon ${emoji}`} selected={draft.emoji === emoji} onPress={() => set({ emoji })}>768 <Text style={styles.choiceEmoji}>{emoji}</Text>769 </Choice>770 ))}771 </View>772773 <Text style={[styles.sheetLabel, { color: c.muted }]}>COLOUR</Text>774 <View role="radiogroup" aria-label="Colour" style={styles.colorRow}>775 {COLORS.map((color) => (776 <Pressable key={color.value} role="radio" aria-checked={draft.color === color.value} aria-label={color.name} hitSlop={4} onPress={() => set({ color: color.value })} style={[styles.swatchRing, { borderColor: draft.color === color.value ? color.value : 'transparent' }]}>777 <View style={[styles.swatch, { backgroundColor: color.value }]}>{draft.color === color.value && <Check size={15} color="#FFFFFF" strokeWidth={3.2} />}</View>778 </Pressable>779 ))}780 </View>781782 <Text style={[styles.sheetLabel, { color: c.muted }]}>REPEAT</Text>783 <View role="radiogroup" aria-label="Repeat" style={styles.freqRow}>784 {FREQS.map((freq) => (785 <View key={freq} style={styles.fill}>786 <Choice label={freq} selected={draft.freq === freq} onPress={() => set({ freq })}>787 <Text style={[styles.choiceText, { color: draft.freq === freq ? c.accentText : c.fg }]}>{freq}</Text>788 </Choice>789 </View>790 ))}791 </View>792 {draft.freq === 'Custom' && (793 <Animated.View entering={FadeInDown.duration(220)} style={styles.daysRow}>794 {DAY_SHORT.map((day, i) => (795 <Pressable key={day} role="checkbox" aria-checked={draft.days[i]} aria-label={WEEKDAYS[i]} onPress={() => set({ days: draft.days.map((on, j) => (j === i ? !on : on)) })} style={[styles.dayToggle, { backgroundColor: draft.days[i] ? ACCENT : c.field, borderColor: draft.days[i] ? ACCENT : c.line }]}>796 <Text style={[styles.dayToggleText, { color: draft.days[i] ? ON_ACCENT : c.muted }]}>{day[0]}</Text>797 </Pressable>798 ))}799 </Animated.View>800 )}801802 <View style={[styles.reminder, { backgroundColor: c.field, borderColor: c.line }]}>803 <Bell size={18} color={c.muted} strokeWidth={2.1} />804 <Text style={[styles.reminderLabel, { color: c.fg }]}>Reminder</Text>805 <Tap label="Earlier reminder" onPress={() => set({ reminder: (draft.reminder + 1410) % 1440 })}>806 <View style={[styles.stepper, { backgroundColor: c.sheet, borderColor: c.line }]}>807 <Minus size={15} color={c.fg} strokeWidth={2.6} />808 </View>809 </Tap>810 <Text aria-label="Reminder time" style={[styles.reminderTime, { color: c.fg }]}>811 {clock(draft.reminder)}812 </Text>813 <Tap label="Later reminder" onPress={() => set({ reminder: (draft.reminder + 30) % 1440 })}>814 <View style={[styles.stepper, { backgroundColor: c.sheet, borderColor: c.line }]}>815 <Plus size={15} color={c.fg} strokeWidth={2.6} />816 </View>817 </Tap>818 </View>819820 <Pressable role="button" aria-label="Save habit" aria-disabled={!ready} disabled={!ready} onPress={() => onSave({ ...draft, name: draft.name.trim() })} style={({ pressed }) => [styles.save, ready ? styles.saveReady : { backgroundColor: c.chip }, { opacity: pressed ? 0.85 : 1 }]}>821 <Text style={[styles.saveText, { color: ready ? ON_ACCENT : c.faint }]}>{editing ? 'Save changes' : 'Save habit'}</Text>822 </Pressable>823 </Animated.View>824 </KeyboardAvoidingView>825 );826}827828function repeatNote(d: Draft) {829 const n = d.days.filter(Boolean).length;830 return `${d.freq === 'Daily' ? 'Daily' : d.freq === 'Weekdays' ? 'Weekdays' : `${n} ${n === 1 ? 'day' : 'days'}`} · ${clock(d.reminder)}`;831}832833// ─── Screen ─────────────────────────────────────────────────────────────────834835export default function HabitTrackerScreen() {836 const c = usePalette();837 const insets = useSafeAreaInsets();838 const { height } = useWindowDimensions();839 const scroller = useRef<ComponentRef<typeof ScrollView>>(null);840 const listEnd = useRef(0);841 const [habits, setHabits] = useState(HABITS);842 const [values, setValues] = useState(START);843 const [skipped, setSkipped] = useState<Record<string, boolean>>({});844 const [viewing, setViewing] = useState(TODAY);845 const [openId, setOpenId] = useState<string | null>(null);846 const [sheet, setSheet] = useState<{ open: boolean; editing: Habit | null }>({ open: false, editing: null });847 const [party, setParty] = useState(0);848 const [intro, setIntro] = useState(true);849 useEffect(() => {850 const t = setTimeout(() => setIntro(false), 1200);851 return () => clearTimeout(t);852 }, []);853854 // Today is live; a past day is a read-only snapshot of the habits that existed then.855 const past = viewing !== TODAY;856 const active = habits.filter((h) => !skipped[h.id]);857 const todayDone = active.filter((h) => (values[h.id] ?? 0) >= h.goal).length;858 const todayTotal = active.length;859 const shown = past ? habits.filter((h) => !h.fresh) : habits;860 const shownValues = past ? WEEK[viewing].values : values;861 const done = past ? WEEK[viewing].done : todayDone;862 const total = past ? HABITS.length : todayTotal;863 const perfect = todayTotal > 0 && todayDone === todayTotal;864 const perfectDays = WEEK.filter((d, i) => i !== TODAY && d.done === HABITS.length).length + (perfect ? 1 : 0);865866 // The burst fires only when today becomes perfect, not when a perfect past day is opened.867 const wasPerfect = useRef(perfect);868 useEffect(() => {869 if (perfect && !wasPerfect.current) setParty((n) => n + 1);870 wasPerfect.current = perfect;871 }, [perfect]);872873 const tap = (h: Habit) => {874 setOpenId(null);875 if (skipped[h.id]) return setSkipped((s) => ({ ...s, [h.id]: false }));876 setValues((v) => {877 const now = v[h.id] ?? 0;878 return { ...v, [h.id]: h.kind === 'count' ? Math.min(h.goal, now + 1) : now ? 0 : 1 };879 });880 };881 const skip = (h: Habit) => {882 setOpenId(null);883 setSkipped((s) => ({ ...s, [h.id]: !s[h.id] }));884 };885 const save = (draft: Draft) => {886 const editing = sheet.editing;887 if (editing) {888 setHabits((list) => list.map((h) => (h.id === editing.id ? { ...h, ...draft, note: h.fresh ? repeatNote(draft) : h.note } : h)));889 } else {890 setHabits((list) => [...list, { ...draft, id: `new-${list.length}`, kind: 'check', goal: 1, unit: '', note: repeatNote(draft), streak: 0, fresh: true }]);891 setViewing(TODAY);892 // Bring the new row into view once the sheet is on its way out.893 setTimeout(() => scroller.current?.scrollTo({ y: Math.max(0, listEnd.current - height * 0.5), animated: true }), 260);894 }895 setSheet((s) => ({ ...s, open: false }));896 };897898 const left = total - done;899 return (900 <View style={[styles.screen, { backgroundColor: c.bg }]}>901 <ScrollView902 ref={scroller}903 showsVerticalScrollIndicator={false}904 keyboardShouldPersistTaps="handled"905 onScrollBeginDrag={() => setOpenId(null)}906 contentContainerStyle={[styles.content, { paddingTop: insets.top + 12, paddingBottom: insets.bottom + 28 }]}907 >908 <Animated.View entering={FadeInDown.duration(380)}>909 <View style={styles.header}>910 <View style={styles.fill}>911 <Text style={[styles.date, { color: c.muted }]}>912 {WEEKDAYS[viewing]}, {WEEK[viewing].date} {MONTH}913 </Text>914 <Text role="heading" numberOfLines={1} style={[styles.title, { color: c.fg }]}>915 {past ? WEEKDAYS[viewing] : 'Today'}916 </Text>917 </View>918 {past && (919 <Animated.View entering={FadeIn.duration(200)}>920 <Tap label="Back to today" onPress={() => setViewing(TODAY)} to={0.95}>921 <View style={[styles.backPill, { backgroundColor: c.accentSoft }]}>922 <Undo2 size={14} color={c.accentText} strokeWidth={2.6} />923 <Text style={[styles.backPillText, { color: c.accentText }]}>Today</Text>924 </View>925 </Tap>926 </Animated.View>927 )}928 <Tap label="Add habit" onPress={() => setSheet({ open: true, editing: null })}>929 <View style={styles.add}>930 <Plus size={22} color={ON_ACCENT} strokeWidth={2.6} />931 </View>932 </Tap>933 </View>934935 <View role="tablist" aria-label="This week" style={styles.week}>936 {WEEK.map((d, i) => (937 <DayCell938 key={d.date}939 label={d.label}940 date={d.date}941 share={i === TODAY ? (todayTotal ? todayDone / todayTotal : 0) : d.done / HABITS.length}942 today={i === TODAY}943 selected={i === viewing}944 onPress={() => {945 setOpenId(null);946 setViewing(i);947 }}948 />949 ))}950 </View>951 </Animated.View>952953 <Animated.View entering={FadeInDown.delay(80).duration(380)} style={styles.heroWrap}>954 <ProgressCard done={done} total={total} perfectDays={perfectDays} past={past ? WEEKDAYS[viewing] : null} party={party} />955 </Animated.View>956957 <Animated.View entering={FadeInDown.delay(140).duration(380)} style={styles.section}>958 <Text style={[styles.sectionTitle, { color: c.fg }]}>Habits</Text>959 {past ? (960 <View style={styles.sectionNote}>961 <Lock size={12} color={c.muted} strokeWidth={2.4} />962 <Text style={[styles.sectionNoteText, { color: c.muted }]}>Read only</Text>963 </View>964 ) : (965 <Text style={[styles.sectionNoteText, { color: left === 0 ? c.accentText : c.muted }]}>{left === 0 ? 'All done' : `${left} left`}</Text>966 )}967 </Animated.View>968969 <View style={styles.list} onLayout={(e: LayoutChangeEvent) => (listEnd.current = e.nativeEvent.layout.y + e.nativeEvent.layout.height)}>970 {shown.map((h, i) => (971 <HabitRow972 key={`${viewing}-${h.id}`}973 habit={h}974 value={shownValues[h.id] ?? 0}975 skipped={!past && !!skipped[h.id]}976 readOnly={past}977 open={!past && openId === h.id}978 enterDelay={intro ? 180 + i * 55 : h.fresh && !past && i === shown.length - 1 && sheet.editing === null ? 240 : null}979 onOpen={(open) => setOpenId(open ? h.id : null)}980 onPress={() => tap(h)}981 onReset={() => setValues((v) => ({ ...v, [h.id]: 0 }))}982 onSkip={() => skip(h)}983 onEdit={() => {984 setOpenId(null);985 setSheet({ open: true, editing: h });986 }}987 />988 ))}989 </View>990991 {!past && (992 <Animated.View entering={FadeInDown.delay(520).duration(380)} layout={MOVE}>993 <Pressable role="button" aria-label="New habit" onPress={() => setSheet({ open: true, editing: null })} style={({ pressed }) => [styles.newRow, { borderColor: c.faint, opacity: pressed ? 0.6 : 1 }]}>994 <Plus size={17} color={c.muted} strokeWidth={2.4} />995 <Text style={[styles.newRowText, { color: c.muted }]}>Add habit</Text>996 </Pressable>997 </Animated.View>998 )}9991000 <Heatmap todayDone={todayDone} todayTotal={todayTotal} />1001 </ScrollView>10021003 {/* Keeps scrolled content out from under the status bar. */}1004 <View style={[styles.statusCover, { height: insets.top, backgroundColor: c.bg }]} />1005 <HabitSheet open={sheet.open} editing={sheet.editing} onClose={() => setSheet((s) => ({ ...s, open: false }))} onSave={save} />1006 </View>1007 );1008}10091010// ─── Styles ─────────────────────────────────────────────────────────────────10111012const styles = StyleSheet.create({1013 screen: { flex: 1 },1014 fill: { flex: 1 },1015 content: { paddingHorizontal: 16 },1016 statusCover: { position: 'absolute', top: 0, left: 0, right: 0 },1017 quarterBack: { transform: [{ rotate: '-90deg' }] },10181019 // Header and week strip1020 header: { flexDirection: 'row', alignItems: 'flex-end', gap: 10, paddingHorizontal: 4 },1021 date: { fontSize: 13, fontWeight: '600', letterSpacing: 0.1 },1022 title: { fontSize: 34, lineHeight: 40, fontWeight: '800', letterSpacing: -1 },1023 backPill: { flexDirection: 'row', alignItems: 'center', gap: 6, height: 36, borderRadius: 18, paddingHorizontal: 13, marginBottom: 4 },1024 backPillText: { fontSize: 13, fontWeight: '700' },1025 add: { width: 44, height: 44, borderRadius: 22, backgroundColor: ACCENT, alignItems: 'center', justifyContent: 'center', shadowColor: ACCENT, shadowOpacity: 0.35, shadowRadius: 10, shadowOffset: { width: 0, height: 5 } },1026 week: { flexDirection: 'row', gap: 2, marginTop: 16 },1027 day: { alignItems: 'center', gap: 7, paddingTop: 9, paddingBottom: 7, borderRadius: 18, borderWidth: 1 },1028 dayLabel: { fontSize: 12, fontWeight: '700' },1029 dayRing: { width: 36, height: 36, alignItems: 'center', justifyContent: 'center' },1030 dayDate: { position: 'absolute', fontSize: 13, fontWeight: '700', fontVariant: ['tabular-nums'] },1031 dayDot: { width: 4, height: 4, borderRadius: 2 },10321033 // Progress card1034 heroWrap: { marginTop: 14 },1035 heroShadow: { borderRadius: 28, shadowColor: '#0B1612', shadowOpacity: 0.22, shadowRadius: 20, shadowOffset: { width: 0, height: 12 } },1036 heroShadowDone: { borderRadius: 28, shadowColor: ACCENT, shadowOpacity: 0.4, shadowRadius: 22, shadowOffset: { width: 0, height: 12 } },1037 heroShadowDark: { borderRadius: 28 },1038 hero: { flexDirection: 'row', alignItems: 'center', gap: 18, borderRadius: 28, borderWidth: 1, padding: 20, overflow: 'hidden' },1039 heroGlow: { position: 'absolute', right: -110, top: -150, width: 320, height: 320, borderRadius: 160, backgroundColor: tint(ACCENT, 0.09) },1040 heroOrb: { position: 'absolute', right: -60, bottom: -100, width: 220, height: 220, borderRadius: 110, backgroundColor: tint(ON_ACCENT, 0.12) },1041 heroRing: { width: 96, height: 96, alignItems: 'center', justifyContent: 'center' },1042 heroRingCenter: { position: 'absolute', alignItems: 'center', justifyContent: 'center' },1043 heroPercent: { color: '#FFFFFF', fontSize: 24, fontWeight: '800', letterSpacing: -0.6, fontVariant: ['tabular-nums'] },1044 heroPercentSign: { fontSize: 13, fontWeight: '700' },1045 heroText: { flex: 1, alignItems: 'flex-start' },1046 heroEyebrow: { fontSize: 11, fontWeight: '700', letterSpacing: 1.1 },1047 heroCount: { flexDirection: 'row', marginTop: 4 },1048 heroRoll: { height: 30, overflow: 'hidden' },1049 heroTitle: { fontSize: 24, lineHeight: 30, fontWeight: '800', letterSpacing: -0.6, fontVariant: ['tabular-nums'] },1050 heroCheer: { fontSize: 14, lineHeight: 19, marginTop: 2 },1051 streakPill: { flexDirection: 'row', alignItems: 'center', gap: 6, height: 28, borderRadius: 14, paddingHorizontal: 10, marginTop: 12 },1052 streakText: { fontSize: 12.5, fontWeight: '700' },1053 heroBurst: { position: 'absolute', left: 69, top: '50%' },10541055 // Confetti1056 burst: { position: 'absolute', left: '50%', top: '50%', width: 0, height: 0, alignItems: 'center', justifyContent: 'center' },1057 confettiDot: { position: 'absolute', width: 6, height: 6, borderRadius: 3 },1058 confettiBar: { position: 'absolute', width: 4, height: 9, borderRadius: 2 },10591060 // Habit rows1061 section: { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', marginTop: 24, marginBottom: 12, paddingHorizontal: 4 },1062 sectionTitle: { fontSize: 20, fontWeight: '800', letterSpacing: -0.4 },1063 sectionNote: { flexDirection: 'row', alignItems: 'center', gap: 5 },1064 sectionNoteText: { fontSize: 13, fontWeight: '600' },1065 list: { gap: 10 },1066 rowWrap: { justifyContent: 'center' },1067 actions: { position: 'absolute', right: 0, top: 0, bottom: 0, width: ACTIONS_W, flexDirection: 'row', gap: 8, paddingLeft: 8 },1068 action: { flex: 1, borderRadius: 18, alignItems: 'center', justifyContent: 'center', gap: 5 },1069 actionText: { fontSize: 12, fontWeight: '700' },1070 // Text selection would steal a mouse drag on web, so the row opts out of it.1071 row: { borderRadius: 22, borderWidth: 1, userSelect: 'none' },1072 rowInner: { flexDirection: 'row', alignItems: 'center', gap: 12, paddingVertical: 13, paddingLeft: 13, paddingRight: 14 },1073 tile: { width: 46, height: 46, borderRadius: 15, alignItems: 'center', justifyContent: 'center' },1074 tileEmoji: { fontSize: 22, lineHeight: 28 },1075 rowBody: { flex: 1 },1076 rowName: { fontSize: 16, lineHeight: 21, fontWeight: '700', letterSpacing: -0.2 },1077 rowMeta: { flexDirection: 'row', alignItems: 'center', gap: 5, marginTop: 2 },1078 rowMetaText: { fontSize: 13, lineHeight: 18, fontWeight: '500', fontVariant: ['tabular-nums'] },1079 rowMetaShrink: { flexShrink: 1 },1080 rowMetaStrong: { fontWeight: '800' },1081 rowMetaDot: { width: 3, height: 3, borderRadius: 1.5, marginHorizontal: 2 },1082 segments: { flexDirection: 'row', gap: 3, marginTop: 8 },1083 segment: { flex: 1, height: 5, borderRadius: 2.5, overflow: 'hidden' },1084 segmentFill: { height: 5, borderRadius: 2.5 },1085 more: { width: 30, height: 30, borderRadius: 15, alignItems: 'center', justifyContent: 'center', marginRight: -4 },1086 check: { width: 46, height: 46, alignItems: 'center', justifyContent: 'center' },1087 checkHalo: { position: 'absolute', width: 46, height: 46, borderRadius: 23, borderWidth: 2, borderColor: ACCENT },1088 checkBase: { width: 46, height: 46, borderRadius: 23, alignItems: 'center', justifyContent: 'center' },1089 checkOpen: { borderWidth: 2 },1090 checkSkipped: { borderWidth: 1.5, borderStyle: 'dashed' },1091 checkFill: { position: 'absolute', width: 46, height: 46, borderRadius: 23, backgroundColor: ACCENT, alignItems: 'center', justifyContent: 'center' },1092 newRow: { flexDirection: 'row', alignItems: 'center', justifyContent: 'center', gap: 8, height: 52, borderRadius: 22, borderWidth: 1.5, borderStyle: 'dashed', marginTop: 10 },1093 newRowText: { fontSize: 15, fontWeight: '700' },10941095 // Heatmap1096 heatCard: { borderRadius: 24, borderWidth: 1, padding: 16, marginTop: 24 },1097 heatHead: { flexDirection: 'row', alignItems: 'flex-start', justifyContent: 'space-between' },1098 cardTitle: { fontSize: 17, fontWeight: '800', letterSpacing: -0.3 },1099 cardHint: { fontSize: 13, fontWeight: '500', marginTop: 2 },1100 heatStat: { alignItems: 'flex-end' },1101 heatStatValue: { fontSize: 17, fontWeight: '800', letterSpacing: -0.3, fontVariant: ['tabular-nums'] },1102 heatMonths: { height: 16, marginTop: 14, marginBottom: 6 },1103 heatMonth: { position: 'absolute', fontSize: 11, fontWeight: '600' },1104 heatGrid: { alignSelf: 'stretch' },1105 heatCell: { position: 'absolute', borderRadius: 5, borderWidth: 1.5 },1106 tip: { position: 'absolute', width: TIP_W, height: 30, borderRadius: 10, alignItems: 'center', justifyContent: 'center', shadowColor: '#000000', shadowOpacity: 0.22, shadowRadius: 10, shadowOffset: { width: 0, height: 4 } },1107 tipText: { fontSize: 12, fontWeight: '700', fontVariant: ['tabular-nums'] },1108 legend: { flexDirection: 'row', alignItems: 'center', justifyContent: 'flex-end', gap: 4, marginTop: 14 },1109 legendText: { fontSize: 11, fontWeight: '600', marginHorizontal: 3 },1110 legendCell: { width: 12, height: 12, borderRadius: 3.5 },11111112 // Sheet1113 sheetLayer: { zIndex: 30, justifyContent: 'flex-end' },1114 scrim: { backgroundColor: 'rgba(0,0,0,0.5)' },1115 sheet: { borderTopLeftRadius: 28, borderTopRightRadius: 28, paddingHorizontal: 16 },1116 grabber: { alignSelf: 'center', width: 38, height: 5, borderRadius: 2.5, marginTop: 8 },1117 sheetHead: { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', marginTop: 12, marginBottom: 14 },1118 sheetTitle: { fontSize: 22, fontWeight: '800', letterSpacing: -0.5 },1119 sheetClose: { width: 32, height: 32, borderRadius: 16, alignItems: 'center', justifyContent: 'center' },1120 nameField: { flexDirection: 'row', alignItems: 'center', gap: 12, height: 60, borderRadius: 18, borderWidth: 1.5, paddingHorizontal: 9 },1121 nameTile: { width: 42, height: 42, borderRadius: 13, alignItems: 'center', justifyContent: 'center' },1122 nameEmoji: { fontSize: 20, lineHeight: 26 },1123 nameInput: { flex: 1, height: 56, fontSize: 17, fontWeight: '600' },1124 sheetLabel: { fontSize: 11, fontWeight: '700', letterSpacing: 1, marginTop: 18, marginBottom: 8, marginLeft: 2 },1125 choiceRow: { flexDirection: 'row', justifyContent: 'space-between' },1126 choiceRound: { width: 44, height: 44, borderRadius: 14, borderWidth: 1.5, alignItems: 'center', justifyContent: 'center' },1127 choiceEmoji: { fontSize: 20, lineHeight: 26 },1128 choice: { height: 42, borderRadius: 14, borderWidth: 1.5, alignItems: 'center', justifyContent: 'center' },1129 choiceText: { fontSize: 14, fontWeight: '700' },1130 colorRow: { flexDirection: 'row', gap: 10 },1131 swatchRing: { width: 40, height: 40, borderRadius: 20, borderWidth: 2, alignItems: 'center', justifyContent: 'center' },1132 swatch: { width: 30, height: 30, borderRadius: 15, alignItems: 'center', justifyContent: 'center' },1133 freqRow: { flexDirection: 'row', gap: 8 },1134 daysRow: { flexDirection: 'row', justifyContent: 'space-between', marginTop: 10 },1135 dayToggle: { width: 42, height: 42, borderRadius: 21, borderWidth: 1.5, alignItems: 'center', justifyContent: 'center' },1136 dayToggleText: { fontSize: 14, fontWeight: '700' },1137 reminder: { flexDirection: 'row', alignItems: 'center', gap: 10, height: 56, borderRadius: 18, borderWidth: 1, paddingHorizontal: 14, marginTop: 18 },1138 reminderLabel: { flex: 1, fontSize: 15, fontWeight: '600' },1139 reminderTime: { width: 78, textAlign: 'center', fontSize: 15, fontWeight: '700', fontVariant: ['tabular-nums'] },1140 stepper: { width: 32, height: 32, borderRadius: 16, borderWidth: 1, alignItems: 'center', justifyContent: 'center' },1141 save: { height: 54, borderRadius: 18, alignItems: 'center', justifyContent: 'center', marginTop: 18 },1142 saveReady: { backgroundColor: ACCENT, shadowColor: ACCENT, shadowOpacity: 0.35, shadowRadius: 14, shadowOffset: { width: 0, height: 8 } },1143 saveText: { fontSize: 16, fontWeight: '800' },1144});