Token price with sparkline and stats
import * as React from "react";
import { ScrollView, View } from "react-native";
import { SafeAreaView, useSafeAreaInsets } from "react-native-safe-area-context";
import { Button, Glass, Icon, List, SegmentedControl, Text } from "@lumioui/ui";
import { useHaptic, useTheme } from "@lumioui/core";
import Svg, { Circle, Line, Path, Polyline } from "react-native-svg";
import { MONO, Mount, Press, StickyBottomBar } from "../shared";
export interface TokenStat {
label: string;
value: string;
}
export interface TokenDetailScreenProps {
symbol?: string;
name?: string;
price?: string;
change?: string;
/** 0–1 sparkline heights — the mini price chart. */
spark?: number[];
stats?: TokenStat[];
onBuy?: () => void;
onSell?: () => void;
onBack?: () => void;
}
const DEFAULT_SPARK = [
0.3, 0.4, 0.35, 0.5, 0.45, 0.6, 0.55, 0.7, 0.62, 0.78, 0.7, 0.85,
0.72, 0.8, 0.9, 0.82, 0.95,
];
const DEFAULT_STATS: TokenStat[] = [
{ label: "Market cap", value: "$1.28T" },
{ label: "24h volume", value: "$38.4B" },
{ label: "Circulating", value: "19.6M BTC" },
{ label: "All-time high", value: "$73,750" },
];
/** Brand-ish coin colors — the ticker is the identity. */
const COIN_COLOR: Record<string, string> = {
BTC: "#F7931A",
ETH: "#627EEA",
SOL: "#9945FF",
USDC: "#2775CA",
};
/** Token detail — price hero, sparkline, stat grid, buy/sell. */
export function TokenDetailScreen({
symbol = "BTC",
name = "Bitcoin",
price = "$64,720",
change = "+2.4% (24h)",
spark = DEFAULT_SPARK,
stats = DEFAULT_STATS,
onBuy,
onSell,
onBack,
}: TokenDetailScreenProps) {
const haptics = useHaptic();
const insets = useSafeAreaInsets();
const { colors } = useTheme();
const [range, setRange] = React.useState("1D");
const up = change.startsWith("+");
const coinColor = COIN_COLOR[symbol] ?? colors.primary;
// Chart geometry — spark heights (0–1) mapped into a 400×140 viewBox,
// inverted so higher values draw higher.
const CW = 400;
const CH = 140;
const pts = spark.map((h, i) => ({
x: (i / Math.max(1, spark.length - 1)) * CW,
y: CH - 12 - h * (CH - 30),
}));
const line = pts.map((p) => `${p.x},${p.y}`).join(" ");
const area = `M${pts[0]?.x ?? 0},${CH} ${pts.map((p) => `L${p.x},${p.y}`).join(" ")} L${CW},${CH} Z`;
const last = pts[pts.length - 1];
const lastFrac = spark[spark.length - 1] ?? 0.5;
return (
<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>
{/* Price alert — the action every token page eventually wants. */}
<Glass interactive effect="regular" className="h-11 w-11 items-center justify-center rounded-full">
<Press
haptic="light"
onPress={() => haptics.light()}
accessibilityRole="button"
accessibilityLabel="Set a price alert"
className="h-9 w-9 items-center justify-center"
>
<Icon name="bell" size="sm" color="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" />
<View
className="h-[18px] w-[18px] items-center justify-center rounded-full"
style={{ backgroundColor: coinColor }}
accessibilityElementsHidden
>
<Text className="text-[9px] font-bold text-white">{symbol[0]}</Text>
</View>
<Text accessibilityRole="header" className="text-sm font-bold tracking-tight">
{name}
</Text>
</View>
</View>
</View>
<ScrollView
showsVerticalScrollIndicator={false}
contentContainerStyle={{ paddingTop: insets.top + 60, paddingBottom: insets.bottom + 96 }}
>
{/* Price + change. */}
<Mount delay={60} className="px-4 pb-1 pt-2">
<Text className="text-5xl font-bold tracking-tight" style={{ fontFamily: MONO, fontVariant: ["tabular-nums"] }}>{price}</Text>
<Text
className={`mt-0.5 text-sm font-medium ${up ? "text-success" : "text-destructive"}`}
>
{change}
</Text>
</Mount>
{/* Price chart — area curve with a live end tick. */}
<Mount delay={120} className="mx-4 pt-3" accessibilityElementsHidden importantForAccessibility="no">
<Svg viewBox={`0 0 ${CW} ${CH}`} style={{ width: "100%", height: 140 }}>
<Line
x1={0} y1={CH / 2} x2={CW} y2={CH / 2}
stroke={colors.muted} strokeWidth={1} strokeDasharray="4 6"
/>
<Path d={area} fill={colors.primary} opacity={0.12} />
<Polyline
points={line}
fill="none"
stroke={colors.primary}
strokeWidth={2.5}
strokeLinecap="round"
strokeLinejoin="round"
/>
{last && (
<>
<Circle cx={last.x} cy={last.y} r={9} fill={colors.primary} opacity={0.2} />
<Circle cx={last.x} cy={last.y} r={4} fill={colors.primary} />
</>
)}
</Svg>
</Mount>
{/* 24h range — where the current price sits inside the day band. */}
<Mount delay={180} className="mx-4 pt-2">
<View className="relative h-1.5 rounded-full bg-secondary">
<View
className="absolute left-0 h-1.5 rounded-full bg-primary"
style={{ width: `${Math.round(lastFrac * 100)}%` }}
/>
<View
className="absolute -top-[3px] h-3 w-3 rounded-full border-2 border-background bg-primary"
style={{ left: `${Math.round(lastFrac * 100)}%`, marginLeft: -6 }}
/>
</View>
<View className="flex-row justify-between pt-1.5">
<Text className="text-xs text-muted-foreground">Low $63,140</Text>
<Text className="text-xs text-muted-foreground">High $65,980</Text>
</View>
</Mount>
{/* Range selector. */}
<View className="px-4 pt-2">
<SegmentedControl
value={range}
onValueChange={(v) => {
haptics.selection();
setRange(v);
}}
options={["1D", "1W", "1M", "1Y", "All"]}
/>
</View>
{/* Your position. */}
<View className="mx-4 mt-4 flex-row items-center gap-3 rounded-2xl bg-white p-4 dark:bg-[#1A1A20]">
<View
className="h-9 w-9 items-center justify-center rounded-full"
style={{ backgroundColor: coinColor }}
accessibilityElementsHidden
>
<Text className="text-xs font-bold text-white">{symbol[0]}</Text>
</View>
<View className="flex-1">
<Text variant="small" className="text-muted-foreground">
Your position
</Text>
<Text className="text-lg font-semibold">0.4821 {symbol}</Text>
</View>
<View className="items-end">
<View className="rounded-full bg-success/15 px-2 py-0.5">
<Text className="text-xs font-medium text-success">+$412 today</Text>
</View>
<Text className="pt-1 text-lg font-semibold">$31,204</Text>
</View>
</View>
{/* Stats. */}
<View className="mt-4">
<List inset>
<List.Section title="About">
{stats.map((s, ii) => (
<React.Fragment key={s.label}>
{ii > 0 && <List.Separator className="ml-4" />}
<List.Item
title={s.label}
trailing={<Text className="font-medium">{s.value}</Text>}
className="py-3"
/>
</React.Fragment>
))}
</List.Section>
</List>
</View>
</ScrollView>
{/* Buy / sell — the two-terminal footer. */}
<StickyBottomBar>
<View className="flex-row gap-3">
<Button
tone="inverse"
haptic="light"
onPress={() => {
haptics.light();
onBuy?.();
}}
accessibilityLabel={`Buy ${name}`}
className="h-11 flex-1 bg-[#1B1B26]"
>
Buy {symbol}
</Button>
<Button
variant="secondary"
haptic="light"
onPress={() => {
haptics.light();
onSell?.();
}}
accessibilityLabel={`Sell ${name}`}
className="h-11 flex-1"
>
Sell {symbol}
</Button>
</View>
</StickyBottomBar>
</SafeAreaView>
);
}
TokenDetailScreen.displayName = "TokenDetailScreen";
Recreate the "Token Detail Screen" screen in React Native using LumioUI.
Goal: Token price with sparkline and stats 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 finance-token-detail
```
Or pull just the components: `npx lumioui add button icon list segmented-control text`
Native packages:
- @lumioui/ui@latest
- @lumioui/core@latest
- react-native-safe-area-context@*
- react-native-svg@*
- react-native-reanimated@*
- 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>` ×2
### `icon` — Lucide icon set mapped to theme colors and sizes.
- `<Icon>` ×2
### `list` — Settings-style rows with separators and press feedback.
- `<List>` ×1
### `segmented-control` — iOS 26 segmented picker — glass capsule track with a gliding liquid indicator pill, spring motion + haptics
- `<SegmentedControl>` ×1
### `text` — Themed type scale from caption to display.
- `<Text>` ×12
## 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/finance/token-detail.tsx` exporting TokenDetailScreen. 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, Glass, Icon, List, SegmentedControl, Text } from "@lumioui/ui";
import { useHaptic, useTheme } from "@lumioui/core";
import Svg, { Circle, Line, Path, Polyline } from "react-native-svg";
import { MONO, Mount, Press, StickyBottomBar } from "../shared";
export interface TokenStat {
label: string;
value: string;
}
export interface TokenDetailScreenProps {
symbol?: string;
name?: string;
price?: string;
change?: string;
/** 0–1 sparkline heights — the mini price chart. */
spark?: number[];
stats?: TokenStat[];
onBuy?: () => void;
onSell?: () => void;
onBack?: () => void;
}
const DEFAULT_SPARK = [
0.3, 0.4, 0.35, 0.5, 0.45, 0.6, 0.55, 0.7, 0.62, 0.78, 0.7, 0.85,
0.72, 0.8, 0.9, 0.82, 0.95,
];
const DEFAULT_STATS: TokenStat[] = [
{ label: "Market cap", value: "$1.28T" },
{ label: "24h volume", value: "$38.4B" },
{ label: "Circulating", value: "19.6M BTC" },
{ label: "All-time high", value: "$73,750" },
];
/** Brand-ish coin colors — the ticker is the identity. */
const COIN_COLOR: Record<string, string> = {
BTC: "#F7931A",
ETH: "#627EEA",
SOL: "#9945FF",
USDC: "#2775CA",
};
/** Token detail — price hero, sparkline, stat grid, buy/sell. */
export function TokenDetailScreen({
symbol = "BTC",
name = "Bitcoin",
price = "$64,720",
change = "+2.4% (24h)",
spark = DEFAULT_SPARK,
stats = DEFAULT_STATS,
onBuy,
onSell,
onBack,
}: TokenDetailScreenProps) {
const haptics = useHaptic();
const insets = useSafeAreaInsets();
const { colors } = useTheme();
const [range, setRange] = React.useState("1D");
const up = change.startsWith("+");
const coinColor = COIN_COLOR[symbol] ?? colors.primary;
// Chart geometry — spark heights (0–1) mapped into a 400×140 viewBox,
// inverted so higher values draw higher.
const CW = 400;
const CH = 140;
const pts = spark.map((h, i) => ({
x: (i / Math.max(1, spark.length - 1)) * CW,
y: CH - 12 - h * (CH - 30),
}));
const line = pts.map((p) => `${p.x},${p.y}`).join(" ");
const area = `M${pts[0]?.x ?? 0},${CH} ${pts.map((p) => `L${p.x},${p.y}`).join(" ")} L${CW},${CH} Z`;
const last = pts[pts.length - 1];
const lastFrac = spark[spark.length - 1] ?? 0.5;
return (
<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>
{/* Price alert — the action every token page eventually wants. */}
<Glass interactive effect="regular" className="h-11 w-11 items-center justify-center rounded-full">
<Press
haptic="light"
onPress={() => haptics.light()}
accessibilityRole="button"
accessibilityLabel="Set a price alert"
className="h-9 w-9 items-center justify-center"
>
<Icon name="bell" size="sm" color="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" />
<View
className="h-[18px] w-[18px] items-center justify-center rounded-full"
style={{ backgroundColor: coinColor }}
accessibilityElementsHidden
>
<Text className="text-[9px] font-bold text-white">{symbol[0]}</Text>
</View>
<Text accessibilityRole="header" className="text-sm font-bold tracking-tight">
{name}
</Text>
</View>
</View>
</View>
<ScrollView
showsVerticalScrollIndicator={false}
contentContainerStyle={{ paddingTop: insets.top + 60, paddingBottom: insets.bottom + 96 }}
>
{/* Price + change. */}
<Mount delay={60} className="px-4 pb-1 pt-2">
<Text className="text-5xl font-bold tracking-tight" style={{ fontFamily: MONO, fontVariant: ["tabular-nums"] }}>{price}</Text>
<Text
className={`mt-0.5 text-sm font-medium ${up ? "text-success" : "text-destructive"}`}
>
{change}
</Text>
</Mount>
{/* Price chart — area curve with a live end tick. */}
<Mount delay={120} className="mx-4 pt-3" accessibilityElementsHidden importantForAccessibility="no">
<Svg viewBox={`0 0 ${CW} ${CH}`} style={{ width: "100%", height: 140 }}>
<Line
x1={0} y1={CH / 2} x2={CW} y2={CH / 2}
stroke={colors.muted} strokeWidth={1} strokeDasharray="4 6"
/>
<Path d={area} fill={colors.primary} opacity={0.12} />
<Polyline
points={line}
fill="none"
stroke={colors.primary}
strokeWidth={2.5}
strokeLinecap="round"
strokeLinejoin="round"
/>
{last && (
<>
<Circle cx={last.x} cy={last.y} r={9} fill={colors.primary} opacity={0.2} />
<Circle cx={last.x} cy={last.y} r={4} fill={colors.primary} />
</>
)}
</Svg>
</Mount>
{/* 24h range — where the current price sits inside the day band. */}
<Mount delay={180} className="mx-4 pt-2">
<View className="relative h-1.5 rounded-full bg-secondary">
<View
className="absolute left-0 h-1.5 rounded-full bg-primary"
style={{ width: `${Math.round(lastFrac * 100)}%` }}
/>
<View
className="absolute -top-[3px] h-3 w-3 rounded-full border-2 border-background bg-primary"
style={{ left: `${Math.round(lastFrac * 100)}%`, marginLeft: -6 }}
/>
</View>
<View className="flex-row justify-between pt-1.5">
<Text className="text-xs text-muted-foreground">Low $63,140</Text>
<Text className="text-xs text-muted-foreground">High $65,980</Text>
</View>
</Mount>
{/* Range selector. */}
<View className="px-4 pt-2">
<SegmentedControl
value={range}
onValueChange={(v) => {
haptics.selection();
setRange(v);
}}
options={["1D", "1W", "1M", "1Y", "All"]}
/>
</View>
{/* Your position. */}
<View className="mx-4 mt-4 flex-row items-center gap-3 rounded-2xl bg-white p-4 dark:bg-[#1A1A20]">
<View
className="h-9 w-9 items-center justify-center rounded-full"
style={{ backgroundColor: coinColor }}
accessibilityElementsHidden
>
<Text className="text-xs font-bold text-white">{symbol[0]}</Text>
</View>
<View className="flex-1">
<Text variant="small" className="text-muted-foreground">
Your position
</Text>
<Text className="text-lg font-semibold">0.4821 {symbol}</Text>
</View>
<View className="items-end">
<View className="rounded-full bg-success/15 px-2 py-0.5">
<Text className="text-xs font-medium text-success">+$412 today</Text>
</View>
<Text className="pt-1 text-lg font-semibold">$31,204</Text>
</View>
</View>
{/* Stats. */}
<View className="mt-4">
<List inset>
<List.Section title="About">
{stats.map((s, ii) => (
<React.Fragment key={s.label}>
{ii > 0 && <List.Separator className="ml-4" />}
<List.Item
title={s.label}
trailing={<Text className="font-medium">{s.value}</Text>}
className="py-3"
/>
</React.Fragment>
))}
</List.Section>
</List>
</View>
</ScrollView>
{/* Buy / sell — the two-terminal footer. */}
<StickyBottomBar>
<View className="flex-row gap-3">
<Button
tone="inverse"
haptic="light"
onPress={() => {
haptics.light();
onBuy?.();
}}
accessibilityLabel={`Buy ${name}`}
className="h-11 flex-1 bg-[#1B1B26]"
>
Buy {symbol}
</Button>
<Button
variant="secondary"
haptic="light"
onPress={() => {
haptics.light();
onSell?.();
}}
accessibilityLabel={`Sell ${name}`}
className="h-11 flex-1"
>
Sell {symbol}
</Button>
</View>
</StickyBottomBar>
</SafeAreaView>
);
}
TokenDetailScreen.displayName = "TokenDetailScreen";
```
Screen: https://lumioui.dev/screens/finance-token-detail