Skip to content
Native Animation
Base Switch animation previewBase Switch animation preview

This preview uses fictional demo content. See the props below for the customization options available in this component.

npx nativeanimation add base-switch

Base Switch

React Native Switch Component

A switch with a stretching, spring-driven thumb that takes its colors and radius from a configurable theme.

Native Animation Base · Free · MIT

Add to your project

Copy the component and its assets into your app with the Native Animation CLI, or paste the agent prompt into Claude Code, Codex or Cursor once the MCP server is connected.

About this component

A switch with a stretching, spring-driven thumb that takes its colors and radius from a configurable theme.

How it works

  1. The track is 32 × 18.4 pt with a 16 pt thumb.
  2. On touch-down the thumb stretches to 19/16 of its width, anchored so it grows toward the side it will move to.
  3. On release it springs across (stiffness 300, damping 25, mass 1) and shrinks back; track and thumb colors fade in 200 ms.
  4. A layout wrapper reserves a 48 dp Android or 44 pt iOS/web touch target around the unchanged track.

Install

npx nativeanimation add base-switch

The CLI also copies base-theme. Dependencies, if you copy by hand:

npx expo install react-native-gesture-handler react-native-reanimated react-native-worklets

Usage

import { BaseSwitch } from './base-switch';

<BaseSwitch value={enabled} onValueChange={setEnabled} accessibilityLabel="Push notifications" />

Uncontrolled and disabled:

<BaseSwitch defaultValue accessibilityLabel="Wi-Fi sync" />
<BaseSwitch disabled accessibilityLabel="Locked setting" />

Wrap your app in BaseThemeProvider (from base-theme) to choose light/dark and an accent; without it, pieces use the light neutral theme. Every piece also takes a theme prop that wins over the provider.

Props

PropTypeDefaultDescription
valueboolean—On or off (controlled).
defaultValuebooleanfalseInitial state (uncontrolled).
onValueChange(value: boolean) => void—Called when toggled.
disabledbooleanfalseDims and blocks toggling.
accessibilityLabelstring—What the switch controls.
themeBaseThemeproviderOverrides the theme from BaseThemeProvider.
testIDstring—Test identifier on the root view.

Compatibility

Expo SDK 58 · React Native 0.88 · Reanimated 4.7 · react-native-worklets 0.13. Runs on iOS, Android and web, in Expo Go and in development builds. Part of Native Animation Base, a free family that shares one theme: install base-theme once (the CLI does it for you) and every Base piece picks it up.

Accessibility

Announced as a switch with synchronized checked and disabled states. Supports screen-reader activation and Enter/Space on web. With Reduce Motion on, the thumb moves without the spring or the stretch.

Source code

Loading public source…