SwipeUI

Theme switch

A light, dark and system scheme control wired to the theme provider: a sliding choice or a morphing icon, with an optional full-screen ripple or bars transition.

npx @swipeui/cli add theme-switch
Variant
Preset
Material
Scheme
Feel
Real free component with a browser animation bridge. Native motion, haptics and materials need a device.

When to use it

  • A Settings or Appearance screen where people choose Light, Dark or match the system.
  • Onboarding that lets people pick a look up front.
  • Developer or demo menus that preview your presets in both schemes.
  • Any place the user's scheme choice should be saved through SwipeUI's theme provider.

When not to use it

  • Choosing a full preset or brand theme; build a picker with Radio cards.
  • A single on/off dark mode; most people expect System as an option.
  • Changing scheme for one screen only; the switch changes the whole app.

Installation

Run this from your app's root. If SwipeUI isn't set up yet, run npx @swipeui/cli init first; it sets up Uniwind, the theme tokens and the cn helper.

npx @swipeui/cli add theme-switch
  • Adds components/swipeui/ui/theme-switch.tsx and 7 shared helpers.
  • Installs react-native-svg, react-native-reanimated, react-native-worklets, uniwind, expo-haptics, clsx, tailwind-merge, class-variance-authority. In Expo apps it uses npx expo install so versions match your SDK.

Usage

app/settings.tsx
import { ThemeSwitch } from '@/components/swipeui/ui/theme-switch';

<ThemeSwitch accessibilityLabel="Colour scheme" />;

API reference

PropTypeDefaultDescription
appearance?"icon-cycle" | "slider"'slider'

A sliding three-way choice, or one round button whose icon morphs through the schemes.

transition?"bars" | "none" | "ripple"'none'

A full-screen change when Light and Dark actually flip: a ripple that grows from the press, or bars that rise across the screen and lift away. Reduce Motion switches at once.

accessibilityLabel?string'Colour scheme'

Name of the scheme control.

messages?Partial<Record<ThemeScheme, string>>—

Override the visible and spoken scheme names.

disabled?booleanfalse

Disable changing the scheme.

haptics?booleantrue

Selection feedback when the chosen scheme changes.

motion?MotionOverridethe app's feel (smooth without a provider)

Per-component feel.

className?stringundefined

Classes merged over the control.

style?StyleProp<ViewStyle>undefined

Native control styles.

testID?stringundefined

Base ID; radio options append -light, -dark and -system.

Composition and behavior

  • Slider (the default) moves a highlight under the selected choice. Each label is a direct tap target.
  • Icon cycle fits the three choices into a 44pt button. Each tap advances to the next scheme, and the icon morphs from sun to moon to screen.
  • transition adds a full-screen change when Light and Dark actually flip: ripple grows the next appearance's colour out of the press, and bars raises six bars across the screen and lifts them away. The scheme switches while the screen is covered. Reduce Motion switches at once.
  • messages changes the visible and spoken scheme names. Both appearances follow the active preset and support Solid and Glass.
  • 2.0 removed the segmented and appearance-cards appearances; use the slider.
  • Wired to the theme provider's scheme, so there's nothing to control yourself.
  • disabled, haptics and motion work like other controls.

Behavior and gestures

  • Slider: tap Light, Dark or System; the highlight slides to it and the whole app re-colours.
  • Icon cycle: one round button steps Light → Dark → System, and its icon morphs from sun to moon to screen.
  • transition='ripple' grows the next appearance's colour from the press to fill the screen; transition='bars' raises six bars across the screen and lifts them away. The scheme switches while the screen is covered. Only a real Light/Dark flip plays it.
  • Changing the choice plays a light selection tick; tapping the current option does nothing; disabled dims and blocks every option.

Accessibility

  • The slider is a radio group named "Colour scheme" by default; each option is a radio with checked state.
  • The icon cycle announces its current scheme and hints the next one.
  • Each option is at least 44 points tall. The transition layer is hidden from screen readers.
  • Rename the group with accessibilityLabel, for example "Appearance".

Motion

  • Uses the press, select and morph motion roles, so it follows your app's feel. Pass motion to tune this one instance.
  • Options use the shared press scale. The slider moves its highlight on the select role; the icon morphs on the morph role.
  • The ripple and bars use the morph role for cover and reveal and run on the UI thread.
  • Reduce Motion removes the press scale, swaps the icon at once and skips the transition.

Performance

  • Changing scheme updates CSS variables through the provider; components re-style without remounting.

Notes for AI

  • Render it inside the SwipeUI ThemeProvider; it reads and sets the scheme there.

Compatibility

Runs onSupported
Expo SDK 57Yes
Expo SDK 58Yes
React Native CLI (with Expo modules)Yes
Expo GoYes
iOSYes
AndroidYes

This table describes API support and static bundle checks. Native runtime, device accessibility and bare Uniwind compatibility remain pending.

Related items