Messaging inbox with a large title that collapses into a compact bar on scroll, live search with an empty state, a pulsing online-now strip, sliding filter pills and rows that animate in and out. Tapping a thread marks it read: the badge scales out and the unread counts tick down, next to a bouncing typing indicator and read receipts.

Details
1import { useEffect, useMemo, useRef, useState, type ReactNode } from 'react';2import { Image, Platform, Pressable, ScrollView, StyleSheet, Text, TextInput, View, useColorScheme, type LayoutChangeEvent } from 'react-native';3import Animated, {4 cancelAnimation,5 Easing,6 FadeIn,7 FadeInDown,8 FadeOut,9 interpolate,10 interpolateColor,11 LinearTransition,12 useAnimatedScrollHandler,13 useAnimatedStyle,14 useSharedValue,15 withDelay,16 withRepeat,17 withSequence,18 withSpring,19 withTiming,20 ZoomIn,21} from 'react-native-reanimated';22import { LinearGradient } from 'expo-linear-gradient';23import { useSafeAreaInsets } from 'react-native-safe-area-context';24import {25 BellOff,26 Camera,27 Check,28 CheckCheck,29 MessageCircle,30 Mic,31 Phone,32 Pin,33 Plus,34 Search,35 SearchX,36 Settings,37 SquarePen,38 UsersRound,39 X,40 type LucideIcon,41} from 'lucide-react-native';4243// ─── Brand ──────────────────────────────────────────────────────────────────44// The screen's accent. Every accent colour below derives from these, so changing them rebrands the screen.4546const ACCENT = '#1064FF';47const ACCENT_DARK = '#4C8DFF'; // the accent as text or a glyph on dark backgrounds48const ON_ACCENT = '#FFFFFF'; // text and icons on an accent fill4950/** `hex` at `alpha` opacity, as rgba(). */51function tint(hex: string, alpha: number) {52 const n = parseInt(hex.slice(1), 16);53 return `rgba(${(n >> 16) & 255}, ${(n >> 8) & 255}, ${n & 255}, ${alpha})`;54}5556// ─── Sample data ────────────────────────────────────────────────────────────5758const photo = (id: string) => `https://images.unsplash.com/photo-${id}?w=200&q=80&fit=crop`;5960const FACE = {61 sofia: photo('1494790108377-be9c29b29330'),62 james: photo('1500648767791-00dcc994a43e'),63 emma: photo('1438761681033-6461ffad8d80'),64 marcus: photo('1507003211169-0a1dd7228f2d'),65 elena: photo('1544005313-94ddf0286df2'),66 maya: photo('1534528741775-53994a69daeb'),67 omar: photo('1506794778202-cad84cf45f1d'),68 hannah: photo('1517841905240-472988babdf9'),69 leo: photo('1539571696357-5a69c17a67c6'),70 chloe: photo('1524504388940-b1c1722653e1'),71 priya: photo('1531746020798-e6953c6e8e04'),72};7374const ME = { name: 'Maya Chen', avatar: FACE.maya };7576const ONLINE_NOW = [77 { id: 'o1', name: 'Sofia', avatar: FACE.sofia },78 { id: 'o2', name: 'James', avatar: FACE.james },79 { id: 'o3', name: 'Marcus', avatar: FACE.marcus },80 { id: 'o4', name: 'Leo', avatar: FACE.leo },81 { id: 'o5', name: 'Chloe', avatar: FACE.chloe },82 { id: 'o6', name: 'Elena', avatar: FACE.elena },83 { id: 'o7', name: 'Hannah', avatar: FACE.hannah },84];8586type Receipt = 'sent' | 'delivered' | 'read';8788type Thread = {89 id: string;90 name: string;91 /** One photo for a person, two for a group, none for an initials tile. */92 faces: string[];93 tint?: readonly [string, string];94 group?: boolean;95 online?: boolean;96 pinned?: boolean;97 muted?: boolean;98 typing?: boolean;99 time: string;100 unread: number;101 /** Set when the last message is yours. */102 receipt?: Receipt;103 /** Who sent the last message in a group. */104 from?: string;105 kind?: 'photo' | 'voice';106 text: string;107};108109const THREADS: Thread[] = [110 { id: 't1', name: 'Sofia Martinez', faces: [FACE.sofia], online: true, pinned: true, time: '9:41', unread: 2, text: 'Running 5 min late, grab us a table?' },111 { id: 't2', name: 'Weekend hike crew', faces: [FACE.hannah, FACE.leo], group: true, pinned: true, time: '9:12', unread: 5, from: 'Leo', text: 'Trailhead at 7, bring layers' },112 { id: 't3', name: 'Marcus Reyes', faces: [FACE.marcus], online: true, pinned: true, time: '8:47', unread: 0, receipt: 'read', text: 'Perfect, see you at the gym at 6' },113 { id: 't4', name: 'James Carter', faces: [FACE.james], online: true, typing: true, time: '9:38', unread: 0, text: 'Did the contract come through?' },114 { id: 't5', name: 'Priya Nair', faces: [FACE.priya], time: '9:05', unread: 1, kind: 'photo', text: 'Photo' },115 { id: 't6', name: 'Design team', faces: [FACE.omar, FACE.priya], group: true, muted: true, time: 'Yesterday', unread: 12, from: 'Omar', text: 'v3 of the onboarding flow is up' },116 { id: 't7', name: 'Noor Abbasi', faces: [], tint: ['#2DD4BF', '#0D9488'], time: 'Yesterday', unread: 1, kind: 'voice', text: 'Voice message, 0:42' },117 { id: 't8', name: 'Emma Lindqvist', faces: [FACE.emma], time: 'Yesterday', unread: 0, receipt: 'delivered', text: 'Haha that is exactly what I said' },118 { id: 't9', name: 'Omar Haddad', faces: [FACE.omar], time: 'Sat', unread: 0, receipt: 'sent', text: 'Sending the invoice over tonight' },119 { id: 't10', name: 'Chloe Bennett', faces: [FACE.chloe], online: true, time: 'Fri', unread: 0, text: 'Did you try the new place on Alder St?' },120 { id: 't11', name: 'Tomás Vidal', faces: [], tint: ['#FBBF24', '#EA7A0C'], time: 'Thu', unread: 0, text: 'Thanks again for the lift on Sunday' },121 { id: 't12', name: 'Flat 4B', faces: [FACE.chloe, FACE.emma], group: true, time: 'Wed', unread: 0, from: 'Chloe', text: 'Who is in for dinner on Friday?' },122];123124const FILTERS = ['All', 'Unread', 'Groups'] as const;125type Filter = (typeof FILTERS)[number];126127const TABS: { id: string; icon: LucideIcon }[] = [128 { id: 'Chats', icon: MessageCircle },129 { id: 'Calls', icon: Phone },130 { id: 'Contacts', icon: UsersRound },131 { id: 'Settings', icon: Settings },132];133134// ─── Palette ────────────────────────────────────────────────────────────────135136const ONLINE = '#22C55E';137const ALERT = '#FF3B5C';138const POP = { damping: 14, stiffness: 280, mass: 0.6 };139const BAR = 44;140const TAB_BAR = 56;141const ROW = 68;142const MOVE = LinearTransition.duration(260);143const PILL_INSET = 16;144const PILL_GAP = 8;145// What the selected pill animates to, worked out here so the worklets only read plain strings.146const PILL_EDGE_ON = tint(ACCENT, 0);147const PILL_CHIP_ON = tint(ON_ACCENT, 0.22);148149function usePalette() {150 const dark = useColorScheme() === 'dark';151 return {152 dark,153 bg: dark ? '#000000' : '#FFFFFF',154 fg: dark ? '#FAFAFA' : '#0A0A0A',155 muted: dark ? '#8E8E93' : '#6E6E76',156 faint: dark ? '#5C5C63' : '#A9A9B2',157 line: dark ? '#1F1F23' : '#ECECEF',158 chip: dark ? '#1A1A1D' : '#F1F1F3',159 press: dark ? '#131315' : '#F5F5F7',160 skeleton: dark ? '#141416' : '#F1F1F3',161 shine: dark ? '#26262A' : '#E2E2E6',162 // Accent as text or a glyph; filled shapes use ACCENT itself under ON_ACCENT text.163 accent: dark ? ACCENT_DARK : ACCENT,164 wash: dark ? tint(ACCENT_DARK, 0.17) : tint(ACCENT, 0.09),165 quiet: dark ? '#3A3A40' : '#8E8E96',166 };167}168169// ─── Small pieces ───────────────────────────────────────────────────────────170171function Tap({ children, label, onPress, to = 0.9 }: { children: ReactNode; label: string; onPress?: () => void; to?: number }) {172 const scale = useSharedValue(1);173 const style = useAnimatedStyle(() => ({ transform: [{ scale: scale.value }] }));174 return (175 <Pressable176 role="button"177 aria-label={label}178 onPress={onPress}179 hitSlop={6}180 onPressIn={() => (scale.value = withSpring(to, POP))}181 onPressOut={() => (scale.value = withSpring(1, POP))}182 >183 <Animated.View style={style}>{children}</Animated.View>184 </Pressable>185 );186}187188/** A round photo that pulses as a placeholder, then fades in once it has loaded. */189function Face({ uri, size, alt = '' }: { uri: string; size: number; alt?: string }) {190 const c = usePalette();191 const shown = useSharedValue(0);192 const pulse = useSharedValue(0.4);193 useEffect(() => {194 pulse.value = withRepeat(withSequence(withTiming(1, { duration: 700 }), withTiming(0.4, { duration: 700 })), -1);195 return () => cancelAnimation(pulse);196 }, [pulse]);197 const image = useAnimatedStyle(() => ({ opacity: shown.value }));198 const placeholder = useAnimatedStyle(() => ({ opacity: (1 - shown.value) * pulse.value }));199 return (200 <View style={[styles.face, { width: size, height: size, borderRadius: size / 2, backgroundColor: c.skeleton }]}>201 <Animated.View style={[StyleSheet.absoluteFill, { backgroundColor: c.shine }, placeholder]} />202 <Animated.View style={[styles.fill, image]}>203 <Image204 source={{ uri }}205 alt={alt}206 resizeMode="cover"207 style={styles.faceImage}208 onLoad={() => {209 cancelAnimation(pulse);210 shown.value = withTiming(1, { duration: 320 });211 }}212 />213 </Animated.View>214 </View>215 );216}217218function Initials({ name, tint, size }: { name: string; tint: readonly [string, string]; size: number }) {219 const letters = name220 .split(' ')221 .map((w) => w[0])222 .slice(0, 2)223 .join('');224 return (225 <LinearGradient colors={tint} start={{ x: 0, y: 0 }} end={{ x: 1, y: 1 }} style={[styles.initials, { width: size, height: size, borderRadius: size / 2 }]}>226 <Text style={[styles.initialsText, { fontSize: size * 0.36 }]}>{letters}</Text>227 </LinearGradient>228 );229}230231/** The green dot on an avatar. In the online strip it breathes: a halo grows out of it and fades. */232function Presence({ ring, size = 14, pulse = false, delay = 0 }: { ring: string; size?: number; pulse?: boolean; delay?: number }) {233 const t = useSharedValue(0);234 useEffect(() => {235 if (!pulse) return;236 t.value = withDelay(delay, withRepeat(withTiming(1, { duration: 2000, easing: Easing.out(Easing.quad) }), -1));237 return () => cancelAnimation(t);238 }, [pulse, delay, t]);239 const halo = useAnimatedStyle(() => ({ opacity: 0.45 * (1 - t.value), transform: [{ scale: 1 + t.value }] }));240 return (241 <View style={[styles.presence, { width: size, height: size }]}>242 {pulse && <Animated.View style={[styles.presenceHalo, { width: size, height: size, borderRadius: size / 2 }, halo]} />}243 <View style={[styles.presenceDot, { width: size, height: size, borderRadius: size / 2, borderColor: ring }]} />244 </View>245 );246}247248function SectionLabel({ title, icon: Icon }: { title: string; icon?: LucideIcon }) {249 const c = usePalette();250 return (251 <View style={styles.sectionLabel}>252 {Icon ? <Icon size={12} color={c.muted} strokeWidth={2.4} /> : null}253 <Text role="heading" style={[styles.sectionTitle, { color: c.muted }]}>254 {title.toUpperCase()}255 </Text>256 </View>257 );258}259260// ─── Search ─────────────────────────────────────────────────────────────────261262function SearchField({ value, onChange }: { value: string; onChange: (v: string) => void }) {263 const c = usePalette();264 const [focused, setFocused] = useState(false);265 const ring = useSharedValue(0);266 useEffect(() => {267 ring.value = withTiming(focused ? 1 : 0, { duration: 180 });268 }, [focused, ring]);269 const box = useAnimatedStyle(() => ({ borderColor: interpolateColor(ring.value, [0, 1], [c.chip, c.accent]) }));270 return (271 <Animated.View style={[styles.search, { backgroundColor: c.chip }, box]}>272 <Search size={17} color={focused ? c.accent : c.muted} strokeWidth={2.2} />273 <TextInput274 value={value}275 onChangeText={onChange}276 onFocus={() => setFocused(true)}277 onBlur={() => setFocused(false)}278 placeholder="Search people and messages"279 placeholderTextColor={c.muted}280 selectionColor={c.accent}281 aria-label="Search conversations"282 autoCapitalize="none"283 autoCorrect={false}284 returnKeyType="search"285 style={[styles.searchInput, { color: c.fg }, Platform.OS === 'web' ? ({ outlineStyle: 'none' } as object) : null]}286 />287 {value ? (288 <Animated.View entering={ZoomIn.duration(140)}>289 <Pressable role="button" aria-label="Clear search" hitSlop={10} onPress={() => onChange('')} style={[styles.searchClear, { backgroundColor: c.faint }]}>290 <X size={12} color={c.chip} strokeWidth={3.2} />291 </Pressable>292 </Animated.View>293 ) : null}294 </Animated.View>295 );296}297298// ─── Online now ─────────────────────────────────────────────────────────────299300function YourNote() {301 const c = usePalette();302 return (303 <Tap label="Add a note" to={0.93}>304 <View style={styles.person}>305 <View style={styles.personFace}>306 <Face uri={ME.avatar} size={56} />307 <View style={[styles.noteBadge, { borderColor: c.bg }]}>308 <Plus size={12} color={ON_ACCENT} strokeWidth={3.4} />309 </View>310 </View>311 <Text numberOfLines={1} style={[styles.noteLabel, { color: c.muted }]}>312 Your note313 </Text>314 </View>315 </Tap>316 );317}318319function OnlinePerson({ name, avatar, index }: { name: string; avatar: string; index: number }) {320 const c = usePalette();321 return (322 <Tap label={`${name}, online now`} to={0.93}>323 <View style={styles.person}>324 <View style={styles.personFace}>325 <Face uri={avatar} size={56} />326 <Presence ring={c.bg} size={16} pulse delay={index * 260} />327 </View>328 <Text numberOfLines={1} style={[styles.personName, { color: c.fg }]}>329 {name}330 </Text>331 </View>332 </Tap>333 );334}335336// ─── Filter pills: one filled thumb slides and resizes to the selected pill ──337338function Pill({ label, selected, count, onPress, onWidth }: { label: string; selected: boolean; count?: number; onPress: () => void; onWidth: (w: number) => void }) {339 const c = usePalette();340 const on = useSharedValue(selected ? 1 : 0);341 useEffect(() => {342 on.value = withTiming(selected ? 1 : 0, { duration: 220 });343 }, [selected, on]);344 const edge = useAnimatedStyle(() => ({ borderColor: interpolateColor(on.value, [0, 1], [c.line, PILL_EDGE_ON]) }));345 const text = useAnimatedStyle(() => ({ color: interpolateColor(on.value, [0, 1], [c.fg, ON_ACCENT]) }));346 const chip = useAnimatedStyle(() => ({ backgroundColor: interpolateColor(on.value, [0, 1], [c.wash, PILL_CHIP_ON]) }));347 const chipText = useAnimatedStyle(() => ({ color: interpolateColor(on.value, [0, 1], [c.accent, ON_ACCENT]) }));348 return (349 <Pressable350 role="tab"351 aria-selected={selected}352 aria-label={count ? `${label}, ${count}` : label}353 onPress={onPress}354 onLayout={(e: LayoutChangeEvent) => onWidth(e.nativeEvent.layout.width)}355 >356 <Animated.View style={[styles.pill, edge]}>357 <Animated.Text style={[styles.pillLabel, text]}>{label}</Animated.Text>358 {count ? (359 <Animated.View style={[styles.pillCount, chip]}>360 <Animated.Text key={count} entering={FadeInDown.duration(220)} style={[styles.pillCountText, styles.tabular, chipText]}>361 {count}362 </Animated.Text>363 </Animated.View>364 ) : null}365 </Animated.View>366 </Pressable>367 );368}369370function Filters({ value, onChange, unread, onReadAll }: { value: Filter; onChange: (f: Filter) => void; unread: number; onReadAll: () => void }) {371 const c = usePalette();372 // Widths are measured; positions are derived from them, so a pill that resizes moves the ones after it.373 const [widths, setWidths] = useState<Partial<Record<Filter, number>>>({});374 const index = FILTERS.indexOf(value);375 const before = FILTERS.slice(0, index).map((f) => widths[f]);376 const width = widths[value];377 const measured = width !== undefined && before.every((v) => v !== undefined);378 const left = PILL_INSET + before.reduce<number>((sum, v) => sum + (v ?? 0) + PILL_GAP, 0);379 const placed = useRef(false);380 const x = useSharedValue(0);381 const w = useSharedValue(0);382 useEffect(() => {383 if (!measured || width === undefined) return;384 // The first measurement places the thumb; after that it travels.385 const move = placed.current ? (v: number) => withTiming(v, { duration: 280, easing: Easing.out(Easing.cubic) }) : (v: number) => v;386 x.value = move(left);387 w.value = move(width);388 placed.current = true;389 }, [measured, left, width, x, w]);390 const thumb = useAnimatedStyle(() => ({ width: w.value, transform: [{ translateX: x.value }] }));391 return (392 <View style={styles.filters}>393 {measured ? <Animated.View style={[styles.filterThumb, thumb]} /> : null}394 <View role="tablist" aria-label="Filter conversations" style={styles.filterList}>395 {FILTERS.map((f) => (396 <Pill397 key={f}398 label={f}399 selected={f === value}400 count={f === 'Unread' ? unread : undefined}401 onPress={() => onChange(f)}402 onWidth={(next) => setWidths((all) => (all[f] === next ? all : { ...all, [f]: next }))}403 />404 ))}405 </View>406 {unread > 0 ? (407 <Animated.View entering={FadeIn.duration(220)} exiting={FadeOut.duration(160)}>408 <Pressable409 role="button"410 aria-label="Mark all as read"411 hitSlop={8}412 onPress={onReadAll}413 style={({ pressed }) => [styles.readAll, { opacity: pressed ? 0.5 : 1 }]}414 >415 <CheckCheck size={15} color={c.accent} strokeWidth={2.4} />416 <Text style={[styles.readAllLabel, { color: c.accent }]}>Read all</Text>417 </Pressable>418 </Animated.View>419 ) : null}420 </View>421 );422}423424// ─── A thread row ───────────────────────────────────────────────────────────425426function ThreadAvatar({ thread, ring }: { thread: Thread; ring: string }) {427 const size = 50;428 return (429 <View style={{ width: size, height: size }}>430 {thread.faces.length > 1 ? (431 // A group: two members, the one in front ringed in the row's own colour.432 <>433 <View style={styles.groupBack}>434 <Face uri={thread.faces[0]} size={33} />435 </View>436 <View style={[styles.groupFront, { borderColor: ring }]}>437 <Face uri={thread.faces[1]} size={34} />438 </View>439 </>440 ) : thread.faces.length === 1 ? (441 <Face uri={thread.faces[0]} size={size} />442 ) : (443 <Initials name={thread.name} tint={thread.tint ?? [ACCENT, ACCENT]} size={size} />444 )}445 {thread.online ? <Presence ring={ring} /> : null}446 </View>447 );448}449450function TypingDot({ index, color }: { index: number; color: string }) {451 const t = useSharedValue(0);452 useEffect(() => {453 // Up, down, then a rest, each dot starting a beat after the one before it.454 t.value = withDelay(455 index * 150,456 withRepeat(withSequence(withTiming(1, { duration: 260, easing: Easing.out(Easing.quad) }), withTiming(0, { duration: 260, easing: Easing.in(Easing.quad) }), withTiming(0, { duration: 480 })), -1)457 );458 return () => cancelAnimation(t);459 }, [index, t]);460 const style = useAnimatedStyle(() => ({ opacity: 0.45 + t.value * 0.55, transform: [{ translateY: -3.5 * t.value }] }));461 return <Animated.View style={[styles.typingDot, { backgroundColor: color }, style]} />;462}463464function Typing() {465 const c = usePalette();466 return (467 <View style={styles.typing}>468 <View style={styles.typingDots}>469 {[0, 1, 2].map((i) => (470 <TypingDot key={i} index={i} color={c.accent} />471 ))}472 </View>473 <Text style={[styles.typingLabel, { color: c.accent }]}>typing…</Text>474 </View>475 );476}477478/** Stays mounted after the count reaches zero, so it can scale out and give its width back to the preview. */479function UnreadBadge({ count, muted }: { count: number; muted?: boolean }) {480 const c = usePalette();481 const last = useRef(count);482 if (count > 0) last.current = count;483 const width = last.current > 9 ? 28 : 21;484 const p = useSharedValue(count > 0 ? 1 : 0);485 useEffect(() => {486 p.value = count > 0 ? withTiming(1, { duration: 220, easing: Easing.out(Easing.back(2)) }) : withTiming(0, { duration: 260, easing: Easing.in(Easing.back(1.5)) });487 }, [count, p]);488 const slot = useAnimatedStyle(() => {489 const k = Math.max(0, Math.min(1, p.value));490 return { width: width * k, marginLeft: 8 * k };491 });492 const dot = useAnimatedStyle(() => ({ opacity: Math.max(0, Math.min(1, p.value * 2)), transform: [{ scale: Math.max(0, p.value) }] }));493 return (494 <Animated.View style={[styles.badgeSlot, slot]}>495 <Animated.View style={[styles.badge, { width, backgroundColor: muted ? c.quiet : ACCENT }, dot]}>496 <Text style={[styles.badgeText, styles.tabular, { color: muted ? '#FFFFFF' : ON_ACCENT }]}>{last.current}</Text>497 </Animated.View>498 </Animated.View>499 );500}501502function ReceiptMark({ state }: { state: Receipt }) {503 const c = usePalette();504 const Icon = state === 'sent' ? Check : CheckCheck;505 return <Icon size={15} color={state === 'read' ? c.accent : c.faint} strokeWidth={2.5} />;506}507508const RECEIPT_LABEL: Record<Receipt, string> = { sent: 'sent', delivered: 'delivered', read: 'read' };509510function ThreadRow({ thread, divider, onPress }: { thread: Thread; divider: boolean; onPress: () => void }) {511 const c = usePalette();512 const unread = thread.unread > 0;513 const KindIcon = thread.kind === 'photo' ? Camera : thread.kind === 'voice' ? Mic : null;514 const said = `${thread.from ? `${thread.from}: ` : ''}${thread.text}`;515 const label = [516 thread.name,517 unread ? `${thread.unread} unread` : null,518 thread.typing ? 'typing' : thread.receipt ? `You: ${said}, ${RECEIPT_LABEL[thread.receipt]}` : said,519 thread.time,520 thread.muted ? 'muted' : null,521 ]522 .filter(Boolean)523 .join(', ');524 const ink = unread ? c.fg : c.muted;525 return (526 <Pressable role="button" aria-label={label} onPress={onPress}>527 {({ pressed }) => {528 const ground = pressed ? c.press : c.bg;529 return (530 <View style={[styles.thread, { backgroundColor: ground }]}>531 <ThreadAvatar thread={thread} ring={ground} />532 <View style={[styles.threadBody, { borderBottomColor: divider ? c.line : ground }]}>533 <View style={styles.threadTop}>534 <Text numberOfLines={1} style={[styles.threadName, { color: c.fg, fontWeight: unread ? '700' : '600' }]}>535 {thread.name}536 </Text>537 <View style={styles.threadMeta}>538 {thread.receipt ? <ReceiptMark state={thread.receipt} /> : null}539 <Text style={[styles.threadTime, { color: unread && !thread.muted ? c.accent : c.muted, fontWeight: unread && !thread.muted ? '600' : '400' }, styles.tabular]}>{thread.time}</Text>540 </View>541 </View>542 <View style={styles.threadBottom}>543 {thread.typing ? (544 <Typing />545 ) : (546 <View style={styles.threadPreview}>547 {KindIcon ? <KindIcon size={15} color={ink} strokeWidth={2.2} /> : null}548 <Text numberOfLines={1} style={[styles.threadText, { color: ink, fontWeight: unread ? '500' : '400' }]}>549 {thread.from ? <Text style={{ color: c.fg, fontWeight: unread ? '600' : '500' }}>{thread.from}: </Text> : null}550 {thread.text}551 </Text>552 </View>553 )}554 {thread.muted ? <BellOff size={14} color={c.faint} strokeWidth={2.2} style={styles.mutedIcon} /> : null}555 {thread.pinned && !unread ? (556 <Animated.View entering={ZoomIn.delay(260).duration(200)} style={styles.pin}>557 <Pin size={14} color={c.faint} fill={c.faint} strokeWidth={2} />558 </Animated.View>559 ) : null}560 <UnreadBadge count={thread.unread} muted={thread.muted} />561 </View>562 </View>563 </View>564 );565 }}566 </Pressable>567 );568}569570// ─── Empty states ───────────────────────────────────────────────────────────571572function Empty({ query, onReset }: { query: string; onReset: () => void }) {573 const c = usePalette();574 const searching = query.length > 0;575 const Icon = searching ? SearchX : CheckCheck;576 return (577 <View style={styles.empty}>578 <View style={[styles.emptyIcon, { backgroundColor: c.chip }]}>579 <Icon size={27} color={c.muted} strokeWidth={1.9} />580 </View>581 <Text style={[styles.emptyTitle, { color: c.fg }]}>{searching ? 'No conversations found' : 'You are all caught up'}</Text>582 <Text numberOfLines={2} style={[styles.emptyBody, { color: c.muted }]}>583 {searching ? `Nothing matches “${query}”. Try a name or a word from a message.` : 'Nothing here right now. New messages will show up as they arrive.'}584 </Text>585 <Pressable586 role="button"587 aria-label={searching ? 'Clear search' : 'Show all conversations'}588 onPress={onReset}589 style={({ pressed }) => [styles.emptyAction, { backgroundColor: c.wash, opacity: pressed ? 0.6 : 1 }]}590 >591 <Text style={[styles.emptyActionLabel, { color: c.accent }]}>{searching ? 'Clear search' : 'Show all'}</Text>592 </Pressable>593 </View>594 );595}596597// ─── Tab bar ────────────────────────────────────────────────────────────────598599function TabBar({ unread }: { unread: number }) {600 const c = usePalette();601 const insets = useSafeAreaInsets();602 // Replace with your navigator's tab bar.603 const [tab, setTab] = useState('Chats');604 return (605 <View role="tablist" style={[styles.tabBar, { paddingBottom: insets.bottom, backgroundColor: c.bg, borderTopColor: c.line }]}>606 {TABS.map(({ id, icon: Icon }) => {607 const selected = tab === id;608 const badge = id === 'Chats' && unread > 0;609 return (610 <Pressable key={id} role="tab" aria-label={badge ? `${id}, ${unread} unread` : id} aria-selected={selected} onPress={() => setTab(id)} style={styles.tab}>611 <View>612 <Icon size={24} color={selected ? c.accent : c.muted} strokeWidth={selected ? 2.4 : 2} />613 {badge ? (614 <View style={[styles.tabBadge, { borderColor: c.bg }]}>615 <Animated.Text key={unread} entering={FadeInDown.duration(220)} style={[styles.tabBadgeText, styles.tabular]}>616 {unread}617 </Animated.Text>618 </View>619 ) : null}620 </View>621 <Text style={[styles.tabLabel, { fontWeight: selected ? '700' : '500', color: selected ? c.accent : c.muted }]}>{id}</Text>622 </Pressable>623 );624 })}625 </View>626 );627}628629// ─── Screen ─────────────────────────────────────────────────────────────────630631export default function ChatInboxScreen() {632 const c = usePalette();633 const insets = useSafeAreaInsets();634 // Replace with your conversations query, sorted by last message.635 const [threads, setThreads] = useState(THREADS);636 const [query, setQuery] = useState('');637 const [filter, setFilter] = useState<Filter>('All');638 // Rows stagger in once; after that, rows a filter brings back simply fade in.639 const [intro, setIntro] = useState(true);640 useEffect(() => {641 const t = setTimeout(() => setIntro(false), 1200);642 return () => clearTimeout(t);643 }, []);644645 const unreadCount = threads.filter((t) => t.unread > 0).length;646 const visible = useMemo(() => {647 const q = query.trim().toLowerCase();648 return threads.filter((t) => {649 if (filter === 'Unread' && t.unread === 0) return false;650 if (filter === 'Groups' && !t.group) return false;651 return !q || t.name.toLowerCase().includes(q) || t.text.toLowerCase().includes(q) || (t.from ?? '').toLowerCase().includes(q);652 });653 }, [threads, query, filter]);654 const pinned = visible.filter((t) => t.pinned);655 const rest = visible.filter((t) => !t.pinned);656657 // Opening a thread marks it read. Push your conversation screen from here too.658 const readAll = () => setThreads((all) => all.map((t) => (t.unread > 0 ? { ...t, unread: 0 } : t)));659 const open = (id: string) => setThreads((all) => all.map((t) => (t.id === id && t.unread > 0 ? { ...t, unread: 0 } : t)));660661 const scrollY = useSharedValue(0);662 const onScroll = useAnimatedScrollHandler((e) => {663 scrollY.value = e.contentOffset.y;664 });665 // The large title slides under the bar as the bar's own title and hairline arrive.666 const largeTitle = useAnimatedStyle(() => ({667 opacity: interpolate(scrollY.value, [0, 36], [1, 0], 'clamp'),668 transform: [{ scale: interpolate(scrollY.value, [-120, 0], [1.1, 1], 'clamp') }],669 }));670 const hairline = useAnimatedStyle(() => ({ opacity: interpolate(scrollY.value, [8, 36], [0, 1], 'clamp') }));671 const barTitle = useAnimatedStyle(() => ({672 opacity: interpolate(scrollY.value, [26, 50], [0, 1], 'clamp'),673 transform: [{ translateY: interpolate(scrollY.value, [26, 50], [6, 0], 'clamp') }],674 }));675676 const rise = (i: number) => FadeInDown.delay(60 + i * 70).duration(420);677 const rowIn = (i: number) => (intro ? FadeInDown.delay(240 + Math.min(i, 7) * 45).duration(380) : FadeIn.duration(240));678 const row = (t: Thread, i: number, count: number, offset: number) => (679 <Animated.View key={t.id} layout={MOVE} entering={rowIn(offset + i)} exiting={FadeOut.duration(140)}>680 <ThreadRow thread={t} divider={i < count - 1} onPress={() => open(t.id)} />681 </Animated.View>682 );683684 return (685 <View style={[styles.fill, { backgroundColor: c.bg }]}>686 <Animated.ScrollView687 onScroll={onScroll}688 scrollEventThrottle={16}689 showsVerticalScrollIndicator={false}690 keyboardShouldPersistTaps="handled"691 contentContainerStyle={{ paddingTop: insets.top + BAR + 2, paddingBottom: insets.bottom + TAB_BAR + 20 }}692 >693 <Animated.Text694 role="heading"695 entering={FadeIn.duration(400)}696 style={[styles.largeTitle, { color: c.fg }, largeTitle]}697 >698 Messages699 </Animated.Text>700701 <Animated.View entering={rise(0)} style={styles.searchWrap}>702 <SearchField value={query} onChange={setQuery} />703 </Animated.View>704705 <Animated.View entering={rise(1)}>706 <SectionLabel title="Online now" />707 <ScrollView horizontal showsHorizontalScrollIndicator={false} contentContainerStyle={styles.onlineStrip}>708 <YourNote />709 {ONLINE_NOW.map((p, i) => (710 <OnlinePerson key={p.id} name={p.name} avatar={p.avatar} index={i} />711 ))}712 </ScrollView>713 </Animated.View>714715 <Animated.View entering={rise(2)} style={styles.filtersWrap}>716 <Filters value={filter} onChange={setFilter} unread={unreadCount} onReadAll={readAll} />717 </Animated.View>718719 <View style={styles.list}>720 {pinned.length > 0 ? (721 <Animated.View key="pinned-title" layout={MOVE} entering={intro ? rise(3) : FadeIn.duration(240)} exiting={FadeOut.duration(120)}>722 <SectionLabel title="Pinned" icon={Pin} />723 </Animated.View>724 ) : null}725 {pinned.map((t, i) => row(t, i, pinned.length, 0))}726 {rest.length > 0 ? (727 <Animated.View key="rest-title" layout={MOVE} entering={intro ? rise(4) : FadeIn.duration(240)} exiting={FadeOut.duration(120)}>728 <SectionLabel title="All messages" />729 </Animated.View>730 ) : null}731 {rest.map((t, i) => row(t, i, rest.length, pinned.length))}732 {visible.length === 0 ? (733 <Animated.View key="empty" entering={FadeIn.delay(140).duration(280)} exiting={FadeOut.duration(100)}>734 <Empty735 query={query.trim()}736 onReset={() => {737 setQuery('');738 setFilter('All');739 }}740 />741 </Animated.View>742 ) : null}743 </View>744 </Animated.ScrollView>745746 {/* Header bar: opaque, over the list and under the status bar */}747 <View style={[styles.header, { paddingTop: insets.top, backgroundColor: c.bg }]}>748 <View style={styles.bar}>749 <Tap label={`${ME.name}, your profile`}>750 <Face uri={ME.avatar} size={32} />751 </Tap>752 <View pointerEvents="none" style={[StyleSheet.absoluteFill, styles.barTitleWrap]}>753 <Animated.Text style={[styles.barTitle, { color: c.fg }, barTitle]}>Messages</Animated.Text>754 </View>755 <Tap label="New message">756 <View style={[styles.compose, { backgroundColor: c.wash }]}>757 <SquarePen size={18} color={c.accent} strokeWidth={2.2} />758 </View>759 </Tap>760 </View>761 <Animated.View style={[styles.hairline, { backgroundColor: c.line }, hairline]} />762 </View>763764 <TabBar unread={unreadCount} />765 </View>766 );767}768769// ─── Styles ─────────────────────────────────────────────────────────────────770771const styles = StyleSheet.create({772 fill: { flex: 1 },773 tabular: { fontVariant: ['tabular-nums'] },774775 // Avatars776 face: { overflow: 'hidden' },777 faceImage: { width: '100%', height: '100%' },778 initials: { alignItems: 'center', justifyContent: 'center' },779 initialsText: { color: '#fff', fontWeight: '700', letterSpacing: 0.3 },780 presence: { position: 'absolute', right: -1, bottom: -1, alignItems: 'center', justifyContent: 'center' },781 presenceHalo: { position: 'absolute', backgroundColor: ONLINE },782 presenceDot: { backgroundColor: ONLINE, borderWidth: 2.5 },783 sectionLabel: { flexDirection: 'row', alignItems: 'center', gap: 6, paddingHorizontal: 16, paddingTop: 12, paddingBottom: 4 },784 sectionTitle: { fontSize: 12.5, fontWeight: '600', letterSpacing: 0.5 },785786 // Search787 search: { height: 40, borderRadius: 12, borderWidth: 1.5, flexDirection: 'row', alignItems: 'center', paddingHorizontal: 11, gap: 8 },788 searchInput: { flex: 1, height: '100%', padding: 0, fontSize: 16 },789 searchClear: { width: 19, height: 19, borderRadius: 10, alignItems: 'center', justifyContent: 'center' },790791 // Online now792 person: { width: 64, alignItems: 'center' },793 personFace: { width: 56, height: 56 },794 noteBadge: { position: 'absolute', right: -3, bottom: -3, width: 23, height: 23, borderRadius: 12, backgroundColor: ACCENT, borderWidth: 2.5, alignItems: 'center', justifyContent: 'center' },795 noteLabel: { marginTop: 6, fontSize: 12 },796 personName: { marginTop: 6, fontSize: 12, fontWeight: '500' },797798 // Filter pills799 pill: { height: 34, borderRadius: 17, borderWidth: 1, paddingHorizontal: 14, flexDirection: 'row', alignItems: 'center', gap: 7 },800 pillLabel: { fontSize: 14, fontWeight: '600' },801 pillCount: { minWidth: 20, height: 20, borderRadius: 10, paddingHorizontal: 6, marginRight: -6, alignItems: 'center', justifyContent: 'center' },802 pillCountText: { fontSize: 12, fontWeight: '700' },803 filters: { flexDirection: 'row', alignItems: 'center', paddingHorizontal: PILL_INSET },804 filterThumb: { position: 'absolute', left: 0, top: 0, height: 34, borderRadius: 17, backgroundColor: ACCENT },805 filterList: { flex: 1, flexDirection: 'row', gap: PILL_GAP },806 readAll: { height: 34, flexDirection: 'row', alignItems: 'center', gap: 5 },807 readAllLabel: { fontSize: 13.5, fontWeight: '600' },808809 // Thread row810 groupBack: { position: 'absolute', top: 0, right: 0 },811 groupFront: { position: 'absolute', left: -1, bottom: -1, borderRadius: 20, borderWidth: 2.5 },812 typingDot: { width: 5, height: 5, borderRadius: 2.5 },813 typing: { flex: 1, flexDirection: 'row', alignItems: 'center', gap: 7 },814 typingDots: { flexDirection: 'row', alignItems: 'center', gap: 3, height: 18, paddingTop: 4 },815 typingLabel: { fontSize: 14.5, fontWeight: '500' },816 badgeSlot: { height: 21, alignItems: 'center', justifyContent: 'center' },817 badge: { height: 21, borderRadius: 11, alignItems: 'center', justifyContent: 'center' },818 badgeText: { fontSize: 12, fontWeight: '700' },819 thread: { height: ROW, flexDirection: 'row', alignItems: 'center', gap: 12, paddingLeft: 16 },820 threadBody: { flex: 1, height: ROW, justifyContent: 'center', gap: 4, paddingRight: 16, borderBottomWidth: 1 },821 threadTop: { flexDirection: 'row', alignItems: 'center', gap: 8 },822 threadName: { flex: 1, fontSize: 16, letterSpacing: -0.2 },823 threadMeta: { flexDirection: 'row', alignItems: 'center', gap: 4 },824 threadTime: { fontSize: 12.5 },825 threadBottom: { flexDirection: 'row', alignItems: 'center', height: 21 },826 threadPreview: { flex: 1, flexDirection: 'row', alignItems: 'center', gap: 5 },827 threadText: { flex: 1, fontSize: 14.5 },828 mutedIcon: { marginLeft: 8 },829 pin: { marginLeft: 8, transform: [{ rotate: '45deg' }] },830831 // Empty states832 empty: { alignItems: 'center', paddingTop: 44, paddingHorizontal: 40 },833 emptyIcon: { width: 64, height: 64, borderRadius: 32, alignItems: 'center', justifyContent: 'center' },834 emptyTitle: { marginTop: 16, fontSize: 18, fontWeight: '700', letterSpacing: -0.3 },835 emptyBody: { marginTop: 6, fontSize: 14.5, lineHeight: 20, textAlign: 'center' },836 emptyAction: { marginTop: 18, height: 38, paddingHorizontal: 18, borderRadius: 19, justifyContent: 'center' },837 emptyActionLabel: { fontSize: 14.5, fontWeight: '600' },838839 // Tab bar840 tabBar: { position: 'absolute', left: 0, right: 0, bottom: 0, borderTopWidth: 1, flexDirection: 'row' },841 tab: { flex: 1, height: TAB_BAR, alignItems: 'center', justifyContent: 'center', gap: 3 },842 tabBadge: { position: 'absolute', top: -5, left: 13, minWidth: 18, height: 18, borderRadius: 9, paddingHorizontal: 4, backgroundColor: ALERT, borderWidth: 2, alignItems: 'center', justifyContent: 'center' },843 tabBadgeText: { color: '#fff', fontSize: 10, fontWeight: '800' },844 tabLabel: { fontSize: 10.5 },845846 // Screen847 largeTitle: { fontSize: 34, lineHeight: 41, fontWeight: '800', letterSpacing: -1, marginHorizontal: 16, marginBottom: 8, transformOrigin: 'left center' },848 searchWrap: { paddingHorizontal: 16 },849 onlineStrip: { paddingHorizontal: 12, paddingTop: 2, paddingBottom: 4, gap: 6 },850 filtersWrap: { marginTop: 12 },851 list: { marginTop: 2 },852 header: { position: 'absolute', top: 0, left: 0, right: 0 },853 bar: { height: BAR, flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', paddingHorizontal: 16 },854 barTitleWrap: { alignItems: 'center', justifyContent: 'center' },855 barTitle: { fontSize: 17, fontWeight: '600', letterSpacing: -0.2 },856 compose: { width: 36, height: 36, borderRadius: 18, alignItems: 'center', justifyContent: 'center' },857 hairline: { height: 1 },858});