Audiobook player with cover and sleep timer
import * as React from "react";
import { ScrollView, View } from "react-native";
import { SafeAreaView, useSafeAreaInsets } from "react-native-safe-area-context";
import { Button, Chip, Glass, Icon, Image, List, Waveform, Text, } from "@lumioui/ui";
import { useHaptic } from "@lumioui/core";
import { LumioMark, Mount, Press, SEPARATOR_INSET, SERIF, World } from "../shared";
export interface BookChapter {
id: string;
number: number;
title: string;
duration: string;
current?: boolean;
}
export interface AudiobookPlayerScreenProps {
book?: string;
author?: string;
narrator?: string;
coverUrl?: string;
chapters?: BookChapter[];
position?: number;
positionLabel?: string;
remainingLabel?: string;
playing?: boolean;
onChapterPress?: (id: string) => void;
onPlayPause?: () => void;
onSleepTimer?: () => void;
onBack?: () => void;
}
const DEFAULT_CHAPTERS: BookChapter[] = [
{ id: "b1", number: 1, title: "The Observatory", duration: "41 min" },
{ id: "b2", number: 2, title: "A Map of Salt", duration: "38 min" },
{ id: "b3", number: 3, title: "The Longitude Prize", duration: "52 min", current: true },
{ id: "b4", number: 4, title: "Storm Glass", duration: "44 min" },
{ id: "b5", number: 5, title: "Going Home to Sea", duration: "47 min" },
];
/** Audiobook player — tall cover, transport, chapter list, sleep timer. */
export function AudiobookPlayerScreen({
book = "The Navigator's Almanac",
author = "Ines Holt",
narrator = "Read by Marcus Aurelius Cole",
coverUrl = "https://images.unsplash.com/photo-1519682337058-a94d519337bc?w=600&h=900&fit=crop&q=70&auto=format",
chapters = DEFAULT_CHAPTERS,
position = 62,
positionLabel = "31:44",
remainingLabel = "-20:16",
playing = true,
onChapterPress,
onPlayPause,
onSleepTimer,
onBack,
}: AudiobookPlayerScreenProps) {
const haptics = useHaptic();
const insets = useSafeAreaInsets();
const [isPlaying, setIsPlaying] = React.useState(playing);
const [pos, setPos] = React.useState(position);
const [speed, setSpeed] = React.useState<1 | 1.25 | 1.5>(1);
const [sleepOn, setSleepOn] = React.useState(false);
React.useEffect(() => setIsPlaying(playing), [playing]);
React.useEffect(() => setPos(position), [position]);
return (
<World primary="#65A30D">
<SafeAreaView className="flex-1 bg-[#F4F5F9] dark:bg-[#111114]" edges={["top"]}>
<View pointerEvents="box-none" className="absolute inset-x-4 z-10" style={{ top: insets.top + 8 }}>
<View className="flex-row items-center justify-between">
<Glass interactive effect="regular" className="h-11 w-11 items-center justify-center rounded-full">
<Press
haptic="light"
onPress={() => onBack?.()}
accessibilityRole="button"
accessibilityLabel="Go back"
className="h-9 w-9 items-center justify-center"
>
<Icon name="chevron-left" size="md" color="foreground" />
</Press>
</Glass>
{/* Sleep timer — the audiobook-specific affordance. */}
<Glass interactive effect="regular" className="h-11 w-11 items-center justify-center rounded-full">
<Press
haptic="light"
onPress={() => {
haptics.selection();
setSleepOn((s) => !s);
onSleepTimer?.();
}}
accessibilityRole="button"
accessibilityLabel={sleepOn ? "Sleep timer on" : "Sleep timer off"}
accessibilityState={{ checked: sleepOn }}
className="h-9 w-9 items-center justify-center"
>
<Icon name="moon" size="sm" color={sleepOn ? "primary" : "foreground"} />
</Press>
</Glass>
</View>
<View pointerEvents="none" className="absolute inset-0 items-center justify-center">
<View className="h-11 flex-row items-center justify-center gap-2 rounded-full pl-3.5 pr-5">
<Glass effect="regular" className="absolute inset-0 rounded-full" />
<LumioMark size={18} />
<Text accessibilityRole="header" className="text-sm font-bold tracking-tight">
Audiobook
</Text>
</View>
</View>
</View>
<ScrollView
showsVerticalScrollIndicator={false}
contentContainerStyle={{ paddingTop: insets.top + 60, paddingBottom: insets.bottom + 24 }}
>
{/* Book cover — tall like a real book jacket. */}
<Mount className="items-center px-16 pt-2">
<Image
source={{ uri: coverUrl }}
className="aspect-[2/3] w-full rounded-3xl bg-muted"
accessibilityLabel={`${book} cover`}
/>
<Text variant="h3" className="mt-3 text-center" numberOfLines={1} style={{ fontFamily: SERIF }}>
{book}
</Text>
<Text variant="small" className="text-muted-foreground" numberOfLines={1}>
{author} · {narrator}
</Text>
</Mount>
{/* Scrub + transport. */}
<Mount delay={60} className="mt-4 px-6">
<Waveform
value={pos}
onValueChange={setPos}
min={0}
max={100}
accessibilityLabel="Chapter position"
/>
<View className="flex-row items-center justify-between">
<Text variant="small" className="text-muted-foreground">
{positionLabel}
</Text>
{/* Book progress — listeners want the whole-book number. */}
<Text variant="muted" className="text-[10px]">
32% through the book
</Text>
<Text variant="small" className="text-muted-foreground">
{remainingLabel}
</Text>
</View>
<View className="mt-2 flex-row items-center justify-center gap-8">
<Button
variant="ghost"
size="icon"
haptic="light"
onPress={() => haptics.light()}
accessibilityLabel="Previous chapter"
className="h-12 w-12"
>
<Icon name="skip-back" size="md" color="foreground" />
</Button>
<Button
size="icon"
haptic="medium"
onPress={() => {
haptics.medium();
setIsPlaying((p) => !p);
onPlayPause?.();
}}
accessibilityLabel={isPlaying ? "Pause" : "Play"}
accessibilityState={{ checked: isPlaying }}
className="bg-[#1B1B26] h-16 w-16 rounded-full p-0"
>
<Icon
name={isPlaying ? "pause" : "play"}
size="lg"
color="#BEF04C"
/>
</Button>
<Button
variant="ghost"
size="icon"
haptic="light"
onPress={() => haptics.light()}
accessibilityLabel="Next chapter"
className="h-12 w-12"
>
<Icon name="skip-forward" size="md" color="foreground" />
</Button>
</View>
<View className="mt-3 items-center">
<Chip
variant="filter"
selected={speed !== 1}
onPress={() => {
haptics.selection();
setSpeed((s) => (s === 1 ? 1.25 : s === 1.25 ? 1.5 : 1));
}}
accessibilityLabel={`Playback speed ${speed}x`}
>
{`${speed}x`}
</Chip>
</View>
</Mount>
{/* Chapters. */}
<Mount delay={120} className="mt-4">
<List inset>
<List.Section title="Chapters">
{chapters.map((ch, ii) => (
<React.Fragment key={ch.id}>
{ii > 0 && <List.Separator className={SEPARATOR_INSET} />}
<List.Item
title={ch.title}
subtitle={`Chapter ${ch.number}`}
titleClassName={ch.current ? "font-semibold text-[#65A30D]" : undefined}
trailing={
<Text variant="small" className="text-muted-foreground">
{ch.duration}
</Text>
}
haptic="light"
onPress={() => onChapterPress?.(ch.id)}
accessibilityState={{ selected: ch.current }}
className="py-3"
/>
</React.Fragment>
))}
</List.Section>
</List>
</Mount>
</ScrollView>
</SafeAreaView>
</World>
);
}
AudiobookPlayerScreen.displayName = "AudiobookPlayerScreen";
Recreate the "Audiobook Player Screen" screen in React Native using LumioUI.
Goal: Audiobook player with cover and sleep timer Match the reference implementation's layout, behavior, and motion exactly — this is a production screen, not a mockup.
## Setup
Fastest path — install the screen plus its component deps:
```bash
npx lumioui add media-audiobook-player
```
Or pull just the components: `npx lumioui add button chip icon image list text waveform`
Native packages:
- @lumioui/ui@latest
- @lumioui/core@latest
- react-native-safe-area-context@*
- react-native-reanimated@*
- react-native-svg@*
- nativewind@*
Stack assumptions: Expo SDK 54 / RN 0.81, Reanimated 4, NativeWind v4, TypeScript strict, Expo Go compatible.
## Components — how, where, when
### `button` — Tactile pill button with press spring, ink wash and async loading.
- `<Button>` ×3
### `chip` — Compact selectable pill with press scale and ink overlay.
- `<Chip>` ×1
### `icon` — Lucide icon set mapped to theme colors and sizes.
- `<Icon>` ×5
### `image` — Cached image with placeholder, fallback and aspect handling.
- `<Image>` ×1
### `list` — Settings-style rows with separators and press feedback.
- `<List>` ×1
### `text` — Themed type scale from caption to display.
- `<Text>` ×7
### `waveform` — Audio scrubber that renders playback position as a filled amplitude waveform — the podcast and audiobook signature. Scrubbing rides an invisible Slider, so tap-to-seek, drag, per-step haptics, and adjustable accessibility come free.
- `<Waveform>` ×1
## Conventions (non-negotiable)
- Styling via NativeWind `className` with semantic tokens only: `bg-background`, `text-foreground`, `bg-card`, `text-card-foreground`, `bg-secondary`, `bg-muted`, `text-muted-foreground`, `bg-accent`, `bg-destructive`, `border-border`. Hard-coded colors only inside media overlays (`text-white`, `bg-black/N`).
- Motion via the token presets from `@lumioui/core` (`spring.press`, `spring.surface`, `spring.glide`, `timing.fast`, `timing.slow`, …) — no bespoke spring configs or durations.
- Gate transform motion behind `useReducedMotion()`; keep opacity/color feedback, drop travel and overshoot.
- Haptics via `useHaptic()`: `light` on press, `selection` on toggle/select, `warning` on invalid input. Never import expo-haptics directly.
- Press feedback via `usePressAnimation()` (~0.97 scale), not `activeOpacity` tricks.
- a11y: `accessibilityRole` + `accessibilityLabel` on every control, touch targets ≥44pt.
- Entrance choreography: staggered `Mount` wrappers (delay 0/60/120…) so regions land in sequence instead of popping in at once.
- Wrap the screen in `SafeAreaView`; keep dark mode working via the semantic tokens.
## Deliverable
One file: `screens/media/audiobook-player.tsx` exporting AudiobookPlayerScreen. Preserve the props interface — the host app wires the callbacks (navigation, submit handlers) through them.
## Reference implementation
The LumioUI source for this screen — reproduce it faithfully:
```tsx
import * as React from "react";
import { ScrollView, View } from "react-native";
import { SafeAreaView, useSafeAreaInsets } from "react-native-safe-area-context";
import { Button, Chip, Glass, Icon, Image, List, Waveform, Text, } from "@lumioui/ui";
import { useHaptic } from "@lumioui/core";
import { LumioMark, Mount, Press, SEPARATOR_INSET, SERIF, World } from "../shared";
export interface BookChapter {
id: string;
number: number;
title: string;
duration: string;
current?: boolean;
}
export interface AudiobookPlayerScreenProps {
book?: string;
author?: string;
narrator?: string;
coverUrl?: string;
chapters?: BookChapter[];
position?: number;
positionLabel?: string;
remainingLabel?: string;
playing?: boolean;
onChapterPress?: (id: string) => void;
onPlayPause?: () => void;
onSleepTimer?: () => void;
onBack?: () => void;
}
const DEFAULT_CHAPTERS: BookChapter[] = [
{ id: "b1", number: 1, title: "The Observatory", duration: "41 min" },
{ id: "b2", number: 2, title: "A Map of Salt", duration: "38 min" },
{ id: "b3", number: 3, title: "The Longitude Prize", duration: "52 min", current: true },
{ id: "b4", number: 4, title: "Storm Glass", duration: "44 min" },
{ id: "b5", number: 5, title: "Going Home to Sea", duration: "47 min" },
];
/** Audiobook player — tall cover, transport, chapter list, sleep timer. */
export function AudiobookPlayerScreen({
book = "The Navigator's Almanac",
author = "Ines Holt",
narrator = "Read by Marcus Aurelius Cole",
coverUrl = "https://images.unsplash.com/photo-1519682337058-a94d519337bc?w=600&h=900&fit=crop&q=70&auto=format",
chapters = DEFAULT_CHAPTERS,
position = 62,
positionLabel = "31:44",
remainingLabel = "-20:16",
playing = true,
onChapterPress,
onPlayPause,
onSleepTimer,
onBack,
}: AudiobookPlayerScreenProps) {
const haptics = useHaptic();
const insets = useSafeAreaInsets();
const [isPlaying, setIsPlaying] = React.useState(playing);
const [pos, setPos] = React.useState(position);
const [speed, setSpeed] = React.useState<1 | 1.25 | 1.5>(1);
const [sleepOn, setSleepOn] = React.useState(false);
React.useEffect(() => setIsPlaying(playing), [playing]);
React.useEffect(() => setPos(position), [position]);
return (
<World primary="#65A30D">
<SafeAreaView className="flex-1 bg-[#F4F5F9] dark:bg-[#111114]" edges={["top"]}>
<View pointerEvents="box-none" className="absolute inset-x-4 z-10" style={{ top: insets.top + 8 }}>
<View className="flex-row items-center justify-between">
<Glass interactive effect="regular" className="h-11 w-11 items-center justify-center rounded-full">
<Press
haptic="light"
onPress={() => onBack?.()}
accessibilityRole="button"
accessibilityLabel="Go back"
className="h-9 w-9 items-center justify-center"
>
<Icon name="chevron-left" size="md" color="foreground" />
</Press>
</Glass>
{/* Sleep timer — the audiobook-specific affordance. */}
<Glass interactive effect="regular" className="h-11 w-11 items-center justify-center rounded-full">
<Press
haptic="light"
onPress={() => {
haptics.selection();
setSleepOn((s) => !s);
onSleepTimer?.();
}}
accessibilityRole="button"
accessibilityLabel={sleepOn ? "Sleep timer on" : "Sleep timer off"}
accessibilityState={{ checked: sleepOn }}
className="h-9 w-9 items-center justify-center"
>
<Icon name="moon" size="sm" color={sleepOn ? "primary" : "foreground"} />
</Press>
</Glass>
</View>
<View pointerEvents="none" className="absolute inset-0 items-center justify-center">
<View className="h-11 flex-row items-center justify-center gap-2 rounded-full pl-3.5 pr-5">
<Glass effect="regular" className="absolute inset-0 rounded-full" />
<LumioMark size={18} />
<Text accessibilityRole="header" className="text-sm font-bold tracking-tight">
Audiobook
</Text>
</View>
</View>
</View>
<ScrollView
showsVerticalScrollIndicator={false}
contentContainerStyle={{ paddingTop: insets.top + 60, paddingBottom: insets.bottom + 24 }}
>
{/* Book cover — tall like a real book jacket. */}
<Mount className="items-center px-16 pt-2">
<Image
source={{ uri: coverUrl }}
className="aspect-[2/3] w-full rounded-3xl bg-muted"
accessibilityLabel={`${book} cover`}
/>
<Text variant="h3" className="mt-3 text-center" numberOfLines={1} style={{ fontFamily: SERIF }}>
{book}
</Text>
<Text variant="small" className="text-muted-foreground" numberOfLines={1}>
{author} · {narrator}
</Text>
</Mount>
{/* Scrub + transport. */}
<Mount delay={60} className="mt-4 px-6">
<Waveform
value={pos}
onValueChange={setPos}
min={0}
max={100}
accessibilityLabel="Chapter position"
/>
<View className="flex-row items-center justify-between">
<Text variant="small" className="text-muted-foreground">
{positionLabel}
</Text>
{/* Book progress — listeners want the whole-book number. */}
<Text variant="muted" className="text-[10px]">
32% through the book
</Text>
<Text variant="small" className="text-muted-foreground">
{remainingLabel}
</Text>
</View>
<View className="mt-2 flex-row items-center justify-center gap-8">
<Button
variant="ghost"
size="icon"
haptic="light"
onPress={() => haptics.light()}
accessibilityLabel="Previous chapter"
className="h-12 w-12"
>
<Icon name="skip-back" size="md" color="foreground" />
</Button>
<Button
size="icon"
haptic="medium"
onPress={() => {
haptics.medium();
setIsPlaying((p) => !p);
onPlayPause?.();
}}
accessibilityLabel={isPlaying ? "Pause" : "Play"}
accessibilityState={{ checked: isPlaying }}
className="bg-[#1B1B26] h-16 w-16 rounded-full p-0"
>
<Icon
name={isPlaying ? "pause" : "play"}
size="lg"
color="#BEF04C"
/>
</Button>
<Button
variant="ghost"
size="icon"
haptic="light"
onPress={() => haptics.light()}
accessibilityLabel="Next chapter"
className="h-12 w-12"
>
<Icon name="skip-forward" size="md" color="foreground" />
</Button>
</View>
<View className="mt-3 items-center">
<Chip
variant="filter"
selected={speed !== 1}
onPress={() => {
haptics.selection();
setSpeed((s) => (s === 1 ? 1.25 : s === 1.25 ? 1.5 : 1));
}}
accessibilityLabel={`Playback speed ${speed}x`}
>
{`${speed}x`}
</Chip>
</View>
</Mount>
{/* Chapters. */}
<Mount delay={120} className="mt-4">
<List inset>
<List.Section title="Chapters">
{chapters.map((ch, ii) => (
<React.Fragment key={ch.id}>
{ii > 0 && <List.Separator className={SEPARATOR_INSET} />}
<List.Item
title={ch.title}
subtitle={`Chapter ${ch.number}`}
titleClassName={ch.current ? "font-semibold text-[#65A30D]" : undefined}
trailing={
<Text variant="small" className="text-muted-foreground">
{ch.duration}
</Text>
}
haptic="light"
onPress={() => onChapterPress?.(ch.id)}
accessibilityState={{ selected: ch.current }}
className="py-3"
/>
</React.Fragment>
))}
</List.Section>
</List>
</Mount>
</ScrollView>
</SafeAreaView>
</World>
);
}
AudiobookPlayerScreen.displayName = "AudiobookPlayerScreen";
```
Screen: https://lumioui.dev/screens/media-audiobook-player