RN Neo
Components

Switch

Toggle switch with a sliding thumb

A toggle switch with a sliding thumb animation. The thumb translates across the track when the value changes, and the track background transitions between on and off colors.

Usage

import { Switch } from 'rn-neo';
import { useState } from 'react';

const [value, setValue] = useState(false);

<Switch value={value} onChange={setValue} />

// With size and custom colors
<Switch
  value={value}
  onChange={setValue}
  size="lg"
  backgroundColor={{ true: 'success', false: 'muted' }}
  thumbColor={{ true: 'onSuccess', false: 'onPrimary' }}
/>

// Disabled
<Switch value={value} onChange={setValue} disabled />

Behavior

  • The thumb slides edge to edge when value toggles. Travel distance is computed from container width, border size, padding, and thumb size — so it fits precisely regardless of size or borderSize.
  • Thumb size is 60% of the track height; its radius scales from the container's radius minus internal padding, so it always looks naturally inset.
  • The shadow offset multiplier doubles () when value is true.
  • Track / shadow / opacity and the thumb's translate + color animate when animation is enabled.
  • When disabled, it renders at reduced opacity and ignores interactions.
  • Track defaults to primary (on) and muted (off); thumb defaults to onPrimary for both states.

Size

SizeWidthHeight
sm36px20px
md48px28px
lg60px34px

Props

Switch

PropTypeDefaultDescription
valuebooleanRequiredCurrent on/off state.
onChange(value: boolean) => voidRequiredCalled with the new value on press.
disabledbooleanDisables interaction, reduces opacity.
size'sm' | 'md' | 'lg''md'Controls track width and height.
backgroundColorRecord<'true' | 'false', BgColors | string>{ true: 'primary', false: 'muted' }Track background for each state.
thumbColorRecord<'true' | 'false', Colors | string>{ true: 'onPrimary', false: 'onPrimary' }Thumb color for each state.

Border

PropTypeDefaultDescription
borderbooleanFrom themeWhether to show a border.
borderSizeBorderSize | numberFrom themeBorder width. Affects thumb travel and padding calculations.
borderColorColors | stringFrom themeBorder color.
radiusRadius | numberFrom themeTrack radius. Thumb radius scales from this automatically.

Shadow

PropTypeDefaultDescription
shadowbooleanFrom themeWhether to show a shadow.
shadowSizeShadowSize | numberFrom themeShadow offset size. Doubles when value is true.
shadowColorColors | stringFrom themeShadow color.

Spacing

Accepts the standard margin* props (margin, marginVertical, marginHorizontal, marginTop, …). See Box → Spacing for the full list.

Accessibility

Switch sets accessibilityRole="switch" and passes checked (from value) and disabled to accessibilityState automatically.

On this page