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-switchWhen 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.tsxand 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 installso versions match your SDK.
Usage
import { ThemeSwitch } from '@/components/swipeui/ui/theme-switch';
<ThemeSwitch accessibilityLabel="Colour scheme" />;API reference
| Prop | Type | Default | Description |
|---|---|---|---|
appearance? | | | A sliding three-way choice, or one round button whose icon morphs through the schemes. |
transition? | | | A full-screen change when Light and Dark actually flip: a |
accessibilityLabel? | | | Name of the scheme control. |
messages? | | — | Override the visible and spoken scheme names. |
disabled? | | | Disable changing the scheme. |
haptics? | | | Selection feedback when the chosen scheme changes. |
motion? | | | Per-component feel. |
className? | | | Classes merged over the control. |
style? | | | Native control styles. |
testID? | | | 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:
ripplegrows the next appearance's colour out of the press, andbarsraises 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
segmentedandappearance-cardsappearances; 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,selectandmorphmotion roles, so it follows your app's feel. Passmotionto 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 on | Supported |
|---|---|
| Expo SDK 57 | Yes |
| Expo SDK 58 | Yes |
| React Native CLI (with Expo modules) | Yes |
| Expo Go | Yes |
| iOS | Yes |
| Android | Yes |
This table describes API support and static bundle checks. Native runtime, device accessibility and bare Uniwind compatibility remain pending.