Primitives
Animated Number Avatar Badge Button Button Group Toggle Toggle Group Checkbox Chip Countdown Divider Fab Grid Icon Image Input Search Input Textarea Label Loader Marquee Masked Input Message Bubble Notification Banner Offline Banner Progress Progress Ring Radio Group Range Slider Rating Separator Skeleton Slider Stack Stepper Switch Text Theme Toggle Ticker Typing IndicatorComposed
Accordion Achievement Badge Action Bar Action Sheet Action Swap Activity Rings Add to Cart Button Address Card Agenda List Alert Amount Keypad Animated Icons App Bar Audio Message Audio Recorder Autocomplete Avatar Group Balance Display Bar List Barcode Before After Biometric Gate Bloom Menu Bottom Sheet Paywall Sheet Side Sheet Breadcrumb Calendar Calendar Strip Card Carousel Cart Item Character Charts Chat Composer Chat List Item Choice Card Circle Reveal Coach Marks Collapsible Collapsible Header Color Picker Combobox Command Palette Comment Thread Confetti Consent Sheet Context Menu Copy Field Country Picker Coupon Input Currency Input Data Table Date Range Picker Day Schedule Dialog Dock Donut Chart Drawer Driver Card Dropdown Menu Drum Picker Emoji Picker Empty State Error State Event Card Expandable Control Fader Feature Gate File Picker Filter Bar Follow Button Form Gauge Glass Glass Cluster Glass Dock Morph Glass Fab Morph Glass Lab Glass Orb Glass Search Morph Glass Sheet Edge Gradient Button Headline New Heatmap Image Cropper Image Viewer Kanban Card Keyboard Avoiding Keyboard Toolbar Leaderboard Level Progress Lightbox Like Button Line Chart List Reorderable List Swipeable Row Location Card Location Search Map Sheet Map View Markdown View Media Controls Media Picker Media Tile Mention Input Meter Bar Mini Player Mood Slider Morphing Modal Multi Select Navigation Rail Notification Item Number Input Onboarding Pager Order Card Order Summary OTP Input Pagination Paper Clip New Parallax Header Pass Card Password Strength Payment Button Payment Card Payment Method Permission Primer Phone Input PIN Pad Polaroid New Poll Popover Post Card Postage Stamp New Price Tag Pricing Table Product Card Product Gallery Profile Header Promo Banner Prompt Input Property Card Pull To Refresh QR Code Quick Actions Quick Replies Rating Summary Reaction Picker Resend Timer Review Card Review Prompt Ride Option Save Button Scan Frame Scroll Spy Tabs Seat Map Section Header Section Index Segmented Control Select Share Button Share Sheet Shutter Button Signature Pad Slide to Confirm Slot Picker Smart Banner Social Login Button Sparkline Splash Screen Split Button Stat Card Stateful Button Status Dot Step Flow Steps Sticker New Stopwatch Stories Progress Stories Viewer Story Ring Streak Counter Streaming Text Success Seal Swipe Deck Tabs Tag Input Tape New Text Reveal Thinking Indicator Time Picker Timeline Timer Ring Tip Selector Toast Toolbar Tooltip Track Row Transaction Row Trip Progress Variant Picker Video Controls Waveform Weather Card Weekday Picker Zoom TransitionScreens
Account Switcher Biometric Setup Delete Account Forgot Password Grow Auth Login Login — Dark Stage Login — Dense Work Login — Editorial Login — Illustrated Login — Minimal Ink Login — Social Login — Video Loop Food Onboarding Onboarding Onboarding Dark Objects Onboarding Editorial Onboarding Illustrated Onboarding Personalize Onboarding Photo Carousel OTP Verification Passkey — Create Password Reset Permission — Notifications Phone Verification Onboarding Quiz Session Devices Signup Sign-up Chat Sign-up Photo Sheet Social Auth Split Auth Verify Identity Welcome AI Chat AI Assistant Channels List Chat Info Chat List Chat Media Chat Thread Create Group Group Info Message Requests New Message Kept Messages Accessibility Activity Log Appearance Authenticator Blocked Accounts Export Your Data Downloads Edit Profile Edit Profile — Rows Emergency Call Empty States Set Error State Send Feedback Device Locator Help Center Home — Bento Home — Dark Home — Editorial Home Feed Invite Friends Language & Region Linked Accounts Not Found (404) Notification Settings Notifications Password Vault Paywall Paywall — Comparison Paywall — Dark Stage Paywall — Editorial Paywall — Photo Paywall — Trial Timeline Privacy Profile Profile — Gamified Profile — Minimal Profile — Photo Hero QR Scanner Report Issue Saved Items Phone Time Search Search — Command Palette Search — Visual Account Health Settings Settings — Dark Device Settings — Search Storage & Data Terms & Privacy Dating Chat Dating Filters Profile Discover Its A Match Into You Matches Profile Detail Profile Editor Courier Matching Delivery History Delivery Support Package Schedule Parcel Tracking Proof Of Delivery Quick Aisle Quick Home Send Package Substitutions Add Payment Address Book Cart Categories Checkout Checkout — Steps Checkout Success Delivery Filters & Sort Flash Sale Gift Cards Loyalty Points Order Cancel Order Detail Orders Pay Later Checkout Payment Methods Product Detail Product Detail — Hero Product Grid Product Reviews Promo Codes Recently Viewed Return Items Search Results Shop Assistant Store Home Tip & Rate Courier Order Tracking Wishlist Write a Review Event Checkin Event Hero Events Discover My Tickets Seat Selection Ticket Checkout Add Card Bank Accounts Dashboard — Bento Bill Pay Budgets Card Details Crypto Portfolio Finance Dashboard Dashboard — Dark Exchange Currency Expense List Invoice Detail Manage Cards Plan Management Savings Goals Send Money Spending Analytics Split Bill Subscriptions Token Detail Token Swap Transactions Wallet Home Wallet Movers Courier Tracking Food Cart Food Home Food Orders Grocery List Recipe Detail Restaurant — Dark Restaurant Detail Activity Rings Fitness Home Habit Quest Habit Tracker Meal Planner Med Store Meditation Player Mood Check-in Nutrition Home Period Tracker Prior Auth Prior Auth Cases Quest Complete Run Tracking Rx Scan Sleep Tracker Telehealth Booking Walk Map Water Tracker Workout Complete Workout Detail Workout Session Applications Apply Company Interview Schedule Job Detail Job Feed Resume Saved Jobs Create Listing Item Chat Listing Detail Make Offer Market Checkout Market Home Market Search My Listings Offers Inbox Seller Profile Audiobook Player Camera Gallery Albums Game Store Mini Player Music Player Photo Editor Photo Gallery Playlist Detail Podcast Player Clips Feed Serene Home Sound Mixer Stories Video Call Video Player Article Reader Course Detail Event Detail Memory Onboarding Icon Lab Leaderboard Lesson Player Match Detail News Editorial News Home Plant Care Prediction Live Prediction Welcome Smart Home Standings Ticket Wallet Topics Follow Weather Detail Add Task Sheet Alarm Clock Calendar Day Calendar Month Doc Scanner File Manager Focus Timer Journal Kanban Board Mail Inbox Mail Thread Note Editor Notes List Reminders Task List Time Blocks Agent Profile Compare Homes Mortgage Calculator Property Detail Rental Application Saved Homes Schedule Tour Search List Search Map Complete Destination Driver Arriving Ev Charging History Home In Trip Matching Options Parking Receipt Safety Schedule Scooter Unlock Booking Confirmed Booking Review Booking Slots My Bookings Pro On The Way Provider Detail Provider List Rate Service Services Home Arc Create Arc Detail Arc Onboarding Avatar Creator Comments Sheet Create Post Explore Grid Followers List Hashtag Feed Mentions Post Detail Post Hero Social Profile Boarding Pass Booking Confirm Car Rental Trip Discover Flight Live Flight Preferences Flight Results Flight Search Hotel Detail Live Transit Trip — Map Day Trip — Rideshare Request Seat Select Travel Home Trip Itinerary Trip OnboardingNothing matches — try another word.
Theme Toggle
Light and dark mode toggle with a drawn sun that turns into a crescent moon. Comes as an icon, pill or switch, and passes on where you tapped so your app can flood the new theme out from the button.
Preview
import * as React from "react";
import { forwardRef, useEffect } from "react";
import { View, type GestureResponderEvent, type Pressable, type PressableProps } from "react-native";
import Animated, {
useSharedValue,
useAnimatedStyle,
useAnimatedProps,
withDelay,
withSpring,
withTiming,
interpolateColor,
Easing,
} from "react-native-reanimated";
import Svg, { Defs, Mask, Rect } from "react-native-svg";
import {
cn,
ease,
useTheme,
useHaptic,
useReducedMotion,
usePressAnimation,
spring,
timing,
AnimatedPressable,
AnimatedCircle,
AnimatedLine,
LightPool,
} from "@lumioui/core";
/**
* ThemeToggle — lights out / lights on. The glyph performs the change:
* <ThemeToggle />
* <ThemeToggle variant="pill" />
* <ThemeToggle variant="switch" />
* <ThemeToggle onSchemeChange={(next, e) => reveal.current?.reveal(e, bg[next])} />
*
* The sun is drawn as a disc and eight rays. Going dark: the rays dim toward
* the centre (timing.recede, ease.in) while a shadow disc slides 6px across
* the core on spring.swap, so the sun becomes the crescent — no icon
* crossfade. Going light: a small accent pool brightens at the toggle first
* (timing.instant), the shadow slides off and the rays draw back on 40ms
* apart. Pass `onSchemeChange` to let the new scheme flood out of the toggle
* (e.g. with CircleReveal: flood tempo.settle, content ignites 160ms after);
* without it the toggle sets the ThemeProvider override itself. Reduced
* motion keeps the light and colour, drops the slide and the ray travel.
*/
export type ThemeToggleVariant = "icon" | "pill" | "switch";
export type ThemeScheme = "light" | "dark";
export interface ThemeToggleProps extends Omit<PressableProps, "children"> {
/** Visual style. Default "icon". */
variant?: ThemeToggleVariant;
/** Controlled scheme. Default: the ThemeProvider's scheme. */
scheme?: ThemeScheme;
/** Called with the next scheme and the press — use it to flood the new
* scheme out of the toggle. When set, the toggle does not change the
* ThemeProvider override itself. */
onSchemeChange?: (next: ThemeScheme, event: GestureResponderEvent) => void;
/** Accessible label. Default announces the action — "Switch to
* light theme" / "Switch to dark theme" based on current state. */
accessibilityLabel?: string;
className?: string;
}
// Same proportions as Switch (51×31 track, 27pt thumb) so the switch
// variant sits in a settings row beside a Switch without looking off.
const TRACK_WIDTH = 51;
const THUMB_SIZE = 27;
const TRACK_PADDING = 2;
const THUMB_TRAVEL = TRACK_WIDTH - THUMB_SIZE - TRACK_PADDING * 2;
/** Track colour shift — an in-place state change. */
const TINT_SHIFT = { duration: timing.fast.duration, easing: Easing.bezier(...ease.inOut) };
const RAY_DIM = { duration: timing.recede.duration, easing: Easing.bezier(...ease.in) };
const RAY_IGNITE = { duration: timing.fast.duration, easing: Easing.bezier(...ease.out) };
/** Rays come back one at a time on the row rhythm. */
const RAY_STAGGER = 40;
/** Light leads going light: the pool brightens this long before the flood. */
const LIGHT_LEAD = timing.instant.duration;
/** Without a flood host the scheme commits once the glyph has performed. */
const COMMIT_AFTER = timing.normal.duration;
// Glyph geometry on a 24 grid.
const SUN_R = 4.5;
const MOON_R = 7;
/** The shadow disc slides this far across the core to make the crescent. */
const SHADOW_SLIDE = 6;
const SHADOW_R = 6;
const SHADOW_OFF_X = 12 + SUN_R + SHADOW_R + 1.5;
const SHADOW_Y = 9;
const RAYS = Array.from({ length: 8 }, (_, i) => (i * Math.PI) / 4);
function Ray({ angle, index, on, color, reduce }: { angle: number; index: number; on: boolean; color: string; reduce: boolean }) {
const t = useSharedValue(on ? 1 : 0);
const first = React.useRef(true);
useEffect(() => {
if (first.current) {
first.current = false;
return;
}
t.value = on ? withDelay(index * RAY_STAGGER, withTiming(1, RAY_IGNITE)) : withTiming(0, RAY_DIM);
}, [on, index, t]);
const cos = Math.cos(angle);
const sin = Math.sin(angle);
const props = useAnimatedProps(() => {
// Rays collapse toward the core as they dim; reduced motion only dims.
const k = reduce ? 1 : t.value;
const inner = 5 + 2.5 * k;
const outer = 5 + 5 * k;
return {
x1: 12 + cos * inner,
y1: 12 + sin * inner,
x2: 12 + cos * outer,
y2: 12 + sin * outer,
opacity: t.value,
};
});
return <AnimatedLine animatedProps={props} stroke={color} strokeWidth={2} strokeLinecap="round" />;
}
/** Sun ↔ crescent, one drawing. */
function SunMoon({ dark, size, color }: { dark: boolean; size: number; color: string }) {
const reduce = useReducedMotion();
const id = React.useId().replace(/[^a-zA-Z0-9]/g, "");
const phase = useSharedValue(dark ? 1 : 0);
useEffect(() => {
phase.value = reduce ? withTiming(dark ? 1 : 0, timing.fast) : withSpring(dark ? 1 : 0, spring.swap);
}, [dark, reduce, phase]);
const coreProps = useAnimatedProps(() => ({ r: SUN_R + (MOON_R - SUN_R) * phase.value }));
const shadowProps = useAnimatedProps(() => ({ cx: SHADOW_OFF_X - SHADOW_SLIDE * phase.value }));
return (
<Svg width={size} height={size} viewBox="0 0 24 24">
<Defs>
<Mask id={id} x="0" y="0" width="24" height="24" maskUnits="userSpaceOnUse">
<Rect x="0" y="0" width="24" height="24" fill="#FFFFFF" />
<AnimatedCircle animatedProps={shadowProps} cy={SHADOW_Y} r={SHADOW_R} fill="#000000" />
</Mask>
</Defs>
<AnimatedCircle animatedProps={coreProps} cx={12} cy={12} fill={color} mask={`url(#${id})`} />
{RAYS.map((a, i) => (
<Ray key={i} angle={a} index={i} on={!dark} color={color} reduce={reduce} />
))}
</Svg>
);
}
export const ThemeToggle = forwardRef<React.ElementRef<typeof Pressable>, ThemeToggleProps>(
function ThemeToggle({ variant = "icon", scheme: controlled, onSchemeChange, accessibilityLabel, className, ...props }, ref) {
const { scheme: themeScheme, setSchemeOverride, colors } = useTheme();
const haptics = useHaptic();
const reduce = useReducedMotion();
// Shared across variants — only one pressable renders at a time.
const press = usePressAnimation({ pressedScale: 0.94 });
const isDark = (controlled ?? themeScheme) === "dark";
// The glyph performs on press, ahead of the scheme commit.
const [acting, setActing] = React.useState<boolean | null>(null);
const shownDark = acting ?? isDark;
if (acting !== null && acting === isDark) setActing(null);
const [pool, setPool] = React.useState(false);
// The icons and pill text are hidden from AT, so the label carries the
// state — announce the action a press will take, not a static role.
const stateLabel = accessibilityLabel ?? (isDark ? "Switch to light theme" : "Switch to dark theme");
const tint = useSharedValue(isDark ? 1 : 0);
const thumbX = useSharedValue(isDark ? THUMB_TRAVEL : 0);
// Held state — the switch-variant thumb squishes and leans like Switch.
const thumbPressed = useSharedValue(0);
useEffect(() => {
tint.value = withTiming(shownDark ? 1 : 0, TINT_SHIFT);
thumbX.value = reduce
? shownDark ? THUMB_TRAVEL : 0
: withSpring(shownDark ? THUMB_TRAVEL : 0, spring.switch);
}, [shownDark, reduce, tint, thumbX]);
const timers = React.useRef<ReturnType<typeof setTimeout>[]>([]);
useEffect(() => () => timers.current.forEach(clearTimeout), []);
const thumbStyle = useAnimatedStyle(() => {
const stretch = 1 + thumbPressed.value * 0.15;
const squish = 1 - thumbPressed.value * 0.1;
const lean = thumbPressed.value * (thumbX.value < THUMB_TRAVEL / 2 ? 2 : -2);
return {
transform: [{ translateX: thumbX.value + lean }, { scaleX: stretch }, { scaleY: squish }],
};
});
// Track colour shifts on its own short clock while the thumb lands.
const trackStyle = useAnimatedStyle(() => ({
backgroundColor: interpolateColor(tint.value, [0, 1], [colors.muted, colors.primary]),
}));
const handlePress = (e: GestureResponderEvent) => {
haptics.selection();
const next: ThemeScheme = isDark ? "light" : "dark";
setActing(next === "dark");
e.persist?.();
if (next === "light") {
// Lights on: the pool brightens at the toggle before the flood.
setPool(true);
timers.current.push(setTimeout(() => setPool(false), timing.slow.duration + timing.normal.duration));
}
const commit = () => {
if (onSchemeChange) onSchemeChange(next, e);
else setSchemeOverride(next);
};
const wait = onSchemeChange ? (next === "light" ? LIGHT_LEAD : 0) : COMMIT_AFTER;
if (wait) timers.current.push(setTimeout(commit, wait));
else commit();
};
const handlePressIn = () => {
press.onPressIn();
if (!reduce) thumbPressed.value = withSpring(1, spring.press);
};
const handlePressOut = () => {
press.onPressOut();
if (!reduce) thumbPressed.value = withSpring(0, spring.press);
};
const a11y = {
accessibilityRole: "switch" as const,
accessibilityLabel: stateLabel,
accessibilityState: { checked: isDark },
// accessibilityState isn't forwarded to the DOM on web — mirror it.
"aria-checked": isDark,
};
const lightPool = (size: number) => (
<LightPool
on={pool}
size={size}
color={colors.primary}
strength={0.5}
className="absolute"
style={{ left: "50%", top: "50%", marginLeft: -size / 2, marginTop: -size / 2 }}
/>
);
if (variant === "pill") {
return (
<AnimatedPressable
ref={ref}
onPress={handlePress}
onPressIn={handlePressIn}
onPressOut={handlePressOut}
style={press.animatedStyle}
{...a11y}
className={cn("h-11 flex-row items-center gap-2 rounded-full bg-secondary px-3", className)}
{...props}
>
<View className="h-4 w-4 items-center justify-center" accessibilityElementsHidden importantForAccessibility="no-hide-descendants">
{lightPool(64)}
<SunMoon dark={shownDark} size={16} color={colors.foreground} />
</View>
<Animated.Text className="text-sm font-medium text-foreground" accessibilityElementsHidden>
{shownDark ? "Dark" : "Light"}
</Animated.Text>
</AnimatedPressable>
);
}
if (variant === "switch") {
return (
<AnimatedPressable
ref={ref}
onPress={handlePress}
onPressIn={handlePressIn}
onPressOut={handlePressOut}
{...a11y}
className={cn("justify-center rounded-full", className)}
style={[{ width: TRACK_WIDTH, height: THUMB_SIZE + TRACK_PADDING * 2 }, trackStyle, press.animatedStyle]}
hitSlop={8}
{...props}
>
<Animated.View
style={[
{
width: THUMB_SIZE,
height: THUMB_SIZE,
borderRadius: THUMB_SIZE / 2,
// Keep the thumb tied to the active track foreground so
// custom themes do not inherit an arbitrary white surface.
backgroundColor: colors.primaryForeground,
marginLeft: TRACK_PADDING,
alignItems: "center",
justifyContent: "center",
// The thumb's contact shadow — the only thing separating a
// white thumb from a pale track in light mode.
shadowColor: "#000",
shadowOpacity: 0.15,
shadowRadius: 3,
shadowOffset: { width: 0, height: 2 },
elevation: 2,
},
thumbStyle,
]}
>
<View accessibilityElementsHidden importantForAccessibility="no-hide-descendants">
<SunMoon dark={shownDark} size={16} color={colors.primary} />
</View>
</Animated.View>
</AnimatedPressable>
);
}
// Default icon variant
return (
<AnimatedPressable
ref={ref}
onPress={handlePress}
onPressIn={handlePressIn}
onPressOut={handlePressOut}
style={press.animatedStyle}
{...a11y}
className={cn("h-11 w-11 items-center justify-center rounded-full", className)}
hitSlop={4}
{...props}
>
<View className="items-center justify-center" accessibilityElementsHidden importantForAccessibility="no-hide-descendants">
{lightPool(88)}
<SunMoon dark={shownDark} size={24} color={colors.foreground} />
</View>
</AnimatedPressable>
);
}
);
ThemeToggle.displayName = "ThemeToggle"; import { ThemeToggle } from "@/components/ui/theme-toggle/theme-toggle";
export function Example() {
return (
<ThemeToggle />
);
} Installation
Install the dependencies
npx expo install react-native-reanimated react-native-svgCopy the source from the Code tab into your project
components/ui/theme-toggle/theme-toggle.tsxcomponents/ui/theme-toggle/index.tsUpdate the import paths to match your project setup.
Usage
import { ThemeToggle } from "@/components/ui/theme-toggle/theme-toggle"; <ThemeToggle /> Examples
The reader is the hero.
import * as React from "react";
import { View } from "react-native";
import { Accent, darkColors, lightColors, useTheme } from "@lumioui/core";
import { ThemeToggle, type ThemeScheme } from "../theme-toggle";
import { CircleReveal, type CircleRevealHandle } from "../../circle-reveal/circle-reveal";
import { Icon } from "../../icon/icon";
import { Text } from "../../text/text";
const PALETTE = { light: lightColors, dark: darkColors } as const;
/** ThemeToggleIcon — the reader is the hero. Tap the sun in the article
* toolbar: its rays dim, the shadow slides across and it becomes the moon,
* then night floods out of the toggle through the article text. Tap the
* moon and a small light comes up at the toggle first, the day floods back
* and the rays draw on one by one. */
export function ThemeToggleIcon() {
const reveal = React.useRef<CircleRevealHandle>(null);
const { scheme: inherited } = useTheme();
const [picked, setPicked] = React.useState<ThemeScheme | null>(null);
const scheme: ThemeScheme = picked ?? inherited;
const pending = React.useRef<ThemeScheme>(scheme);
return (
<Accent color={PALETTE[scheme].primary} scheme={scheme} className="w-full overflow-hidden rounded-3xl bg-background">
<View className="flex-row items-center gap-1 border-b border-border px-2 py-1">
<View className="h-11 w-11 items-center justify-center">
<Icon name="chevron-left" size="md" accessibilityLabel="Back to library" />
</View>
<Text className="flex-1 text-center text-[15px] font-semibold" numberOfLines={1}>
Reader
</Text>
<View className="h-11 w-11 items-center justify-center">
<Icon name="type" size="md" accessibilityLabel="Text settings" />
</View>
<ThemeToggle
variant="icon"
scheme={scheme}
onSchemeChange={(next, e) => {
pending.current = next;
reveal.current?.reveal(e, PALETTE[next].background);
}}
/>
</View>
<View className="gap-4 px-5 pb-8 pt-6">
<View className="gap-2">
<Text className="text-xs font-semibold uppercase tracking-wider text-muted-foreground">Long read · Rail</Text>
<Text className="text-[30px] font-bold leading-tight tracking-tight">
The sleeper trains are full again
</Text>
<Text variant="muted">Halden Review · Ada Okoro · 14 min read</Text>
</View>
<Text className="text-[17px] leading-7">
At 21:38 the night service to Carrow leaves Marrin Central with every couchette sold. Five years ago the route did not
exist; the carriages were parked in a siding outside Venn, waiting for scrap.
</Text>
<Text className="text-[17px] leading-7">
Operators that retired their sleepers are now buying them back, and the waiting list for the winter timetable already
runs into spring.
</Text>
<Text className="text-[17px] leading-7 text-muted-foreground">
“People want to arrive rested,” says the line's planner, who has added a third couchette car twice since March.
</Text>
</View>
<CircleReveal ref={reveal} className="top-[53px]" onCovered={() => setPicked(pending.current)} />
</Accent>
);
} The labeled toggle in a project tool's account menu, between the settings rows and sign out.
import * as React from "react";
import { View } from "react-native";
import { ThemeToggle } from "../theme-toggle";
import { Avatar } from "../../avatar/avatar";
import { Icon, type IconName } from "../../icon/icon";
import { Text } from "../../text/text";
const ROWS: { icon: IconName; label: string; trailing?: string }[] = [
{ icon: "user", label: "Profile" },
{ icon: "bell", label: "Notifications", trailing: "Mentions only" },
{ icon: "settings", label: "Workspace settings" },
];
/** ThemeTogglePill — the labeled toggle in a project tool's account menu,
* between the settings rows and sign out. */
export function ThemeTogglePill() {
return (
<View className="w-full overflow-hidden rounded-3xl bg-card">
<View className="flex-row items-center gap-3 px-4 py-4">
<Avatar size="md" source={{ uri: "https://i.pravatar.cc/150?img=52" }} fallback="RK" alt="Rhea Kapoor" />
<View className="flex-1">
<Text className="text-base font-semibold">Rhea Kapoor</Text>
<Text variant="muted" numberOfLines={1}>[email protected]</Text>
</View>
</View>
{ROWS.map((r) => (
<View key={r.label} className="min-h-12 flex-row items-center gap-3 border-t border-border px-4">
<Icon name={r.icon} size="md" color="mutedForeground" />
<Text className="flex-1 text-base">{r.label}</Text>
{r.trailing ? <Text variant="muted">{r.trailing}</Text> : null}
<Icon name="chevron-right" size="sm" color="mutedForeground" />
</View>
))}
<View className="min-h-14 flex-row items-center gap-3 border-t border-border px-4">
<Icon name="palette" size="md" color="mutedForeground" />
<Text className="flex-1 text-base">Theme</Text>
<ThemeToggle variant="pill" />
</View>
<View className="min-h-12 flex-row items-center gap-3 border-t border-border px-4">
<Icon name="log-out" size="md" color="destructive" />
<Text className="flex-1 text-base text-destructive">Sign out</Text>
</View>
</View>
);
} The dark-mode switch in a Display settings group, next to the rows it lives with.
import * as React from "react";
import { View } from "react-native";
import { ThemeToggle } from "../theme-toggle";
import { Form } from "../../form/form";
import { Icon, type IconName } from "../../icon/icon";
import { Text } from "../../text/text";
/** Settings-style tile — the row's colour lives in its icon. */
function Tile({ name, className }: { name: IconName; className: string }) {
return (
<View className={`h-8 w-8 items-center justify-center rounded-lg ${className}`}>
<Icon name={name} size="sm" color="#FFFFFF" />
</View>
);
}
/** ThemeToggleSwitch — the dark-mode switch in a Display settings group,
* next to the rows it lives with. Flip it and the screen follows. */
export function ThemeToggleSwitch() {
return (
<View className="w-full gap-6">
<Text className="px-1 text-3xl font-bold tracking-tight">Display</Text>
<View className="gap-2">
<View className="overflow-hidden rounded-2xl bg-card">
<Form.Row
label="Dark Mode"
leading={<Tile name="moon" className="bg-tint-teal" />}
trailing={<ThemeToggle variant="switch" />}
/>
<Form.Separator />
<Form.Row
label="Text Size"
leading={<Tile name="type" className="bg-tint-orange" />}
trailing={
<View className="flex-row items-center gap-1">
<Text variant="muted">Default</Text>
<Icon name="chevron-right" size="sm" color="mutedForeground" />
</View>
}
/>
<Form.Separator />
<Form.Row
label="Auto-Lock"
leading={<Tile name="lock" className="bg-neutral-500" />}
trailing={
<View className="flex-row items-center gap-1">
<Text variant="muted">30 seconds</Text>
<Icon name="chevron-right" size="sm" color="mutedForeground" />
</View>
}
/>
</View>
<Text variant="muted" className="px-4">
Dark Mode applies to every screen in the app.
</Text>
</View>
</View>
);
} API reference
variant ThemeToggleVariant Visual style. Default "icon".
"icon" scheme ThemeScheme Controlled scheme. Default: the ThemeProvider's scheme.
—onSchemeChange (next: ThemeScheme …
(next: ThemeScheme, event: GestureResponderEvent) => void Called with the next scheme and the press — use it to flood the new scheme out of the toggle. When set, the toggle does not change the ThemeProvider override itself.
—accessibilityLabel string Accessible label. Default announces the action — "Switch to light theme" / "Switch to dark theme" based on current state.
—className string —