Skip to main content
This page documents all exported TypeScript types used in React Native Switchery.

SwitchProps

The props interface for the Switch component.
type SwitchProps = {
  value: boolean;
  activeColor?: string;
  inactiveColor?: string;
  thumbColor?: string;
  onValueChange?: (nextValue: boolean) => void;
  disabled?: boolean;
  size?: 'mini' | 'small' | 'default' | 'large';
  testID?: string;
  variant?: SwitchVariant;
  trackBorderColor?: string;
  trackBorderWidth?: number;
  thumbBorderColor?: string;
  thumbBorderWidth?: number;
  accessibilityLabel?: string;
  accessibilityHint?: string;
};

Properties

value
boolean
required
Current state of the switch (true = on, false = off).
activeColor
string
Fill color of the animated pill when expanded (visible when switch is OFF). Overrides variant color if provided.
inactiveColor
string
Track background color when pill is collapsed (visible when switch is ON). Overrides variant color if provided.
thumbColor
string
Color of the sliding thumb. Overrides variant color if provided.
onValueChange
(nextValue: boolean) => void
Callback invoked when the switch is toggled.
disabled
boolean
Whether the switch is disabled.
size
'mini' | 'small' | 'default' | 'large'
Size preset for the switch.
testID
string
Test identifier for automated testing.
variant
SwitchVariant
Predefined color variant.
trackBorderColor
string
Custom border color for the track.
trackBorderWidth
number
Border width for the track.
thumbBorderColor
string
Custom border color for the thumb.
thumbBorderWidth
number
Border width for the thumb.
accessibilityLabel
string
Accessibility label for screen readers.
accessibilityHint
string
Additional accessibility context.

SwitchVariant

Union type defining available color variants.
type SwitchVariant =
  | 'primary'
  | 'danger'
  | 'warning'
  | 'success'
  | 'info';
Each variant comes with predefined colors:
VariantActive ColorInactive ColorHex Color
primaryWhiteBlue#2196F3
dangerWhiteRed#E53935
warningWhiteOrange#FB8C00
successWhiteGreen#43A047
infoWhiteLight Blue#1E88E5

Usage

import { SwitchVariant } from 'react-native-switchery';

const variant: SwitchVariant = 'success';

<Switch value={true} variant={variant} />

SwitchMetrics

Metrics defining the physical dimensions of the switch.
type SwitchMetrics = {
  pillWidth: number;
  pillHeight: number;
  thumbSize: number;
  thumbMargin: number;
};

Properties

pillWidth
number
Total width of the switch track in pixels.
pillHeight
number
Total height of the switch track in pixels.
thumbSize
number
Diameter of the thumb circle in pixels.
thumbMargin
number
Margin around the thumb inside the track in pixels.

Size Presets

The library provides the following size presets:
const METRICS = {
  mini: { pillWidth: 38, pillHeight: 20, thumbSize: 16, thumbMargin: 2 },
  small: { pillWidth: 48, pillHeight: 26, thumbSize: 22, thumbMargin: 2 },
  default: { pillWidth: 56, pillHeight: 30, thumbSize: 26, thumbMargin: 2 },
  large: { pillWidth: 68, pillHeight: 36, thumbSize: 32, thumbMargin: 2 },
};

UseSwitchAnimationParams

Parameters for the switch animation hook (internal).
type UseSwitchAnimationParams = {
  value: boolean;
  pillWidth: number;
  thumbSize: number;
  thumbMargin: number;
};
This type is used internally by the useSwitchAnimation hook to calculate animation values.

Properties

value
boolean
Current switch state used to determine animation direction.
pillWidth
number
Width of the switch track.
thumbSize
number
Size of the thumb.
thumbMargin
number
Margin around the thumb.

UseSwitchStylesParams

Parameters for the switch styles hook (internal).
type UseSwitchStylesParams = {
  variant?: SwitchVariant;
  activeColor?: string;
  inactiveColor?: string;
  thumbColor?: string;
  trackBorderColor?: string;
  trackBorderWidth?: number;
  thumbBorderColor?: string;
  thumbBorderWidth?: number;
  value: boolean;
  pillWidth: number;
  pillHeight: number;
  thumbSize: number;
};
This type is used internally by the useSwitchStyles hook to compute the component’s styles based on props and state.

Properties

variant
SwitchVariant
Color variant to use.
activeColor
string
Custom active track color.
inactiveColor
string
Custom inactive track color.
thumbColor
string
Custom thumb color.
trackBorderColor
string
Custom track border color.
trackBorderWidth
number
Track border width.
thumbBorderColor
string
Custom thumb border color.
thumbBorderWidth
number
Thumb border width.
value
boolean
Current switch state.
pillWidth
number
Width of the switch track.
pillHeight
number
Height of the switch track.
thumbSize
number
Size of the thumb.

Type Imports

All types can be imported from the main package:
import {
  SwitchProps,
  SwitchVariant,
  SwitchMetrics,
  UseSwitchAnimationParams,
  UseSwitchStylesParams,
} from 'react-native-switchery';

Type Examples

Defining Component Props with SwitchProps

import { SwitchProps } from 'react-native-switchery';

type SettingsRowProps = {
  label: string;
  switchProps: Omit<SwitchProps, 'value' | 'onValueChange'>;
};

function SettingsRow({ label, switchProps }: SettingsRowProps) {
  const [enabled, setEnabled] = useState(false);
  
  return (
    <View>
      <Text>{label}</Text>
      <Switch {...switchProps} value={enabled} onValueChange={setEnabled} />
    </View>
  );
}

Using SwitchVariant in State

import { useState } from 'react';
import { SwitchVariant } from 'react-native-switchery';

function DynamicSwitch() {
  const [variant, setVariant] = useState<SwitchVariant>('primary');
  const [enabled, setEnabled] = useState(false);

  return (
    <Switch
      value={enabled}
      onValueChange={setEnabled}
      variant={variant}
    />
  );
}

Working with SwitchMetrics

import { SwitchMetrics } from 'react-native-switchery';
import { getSwitchMetrics } from 'react-native-switchery/utils';

function CustomComponent() {
  const metrics: SwitchMetrics = getSwitchMetrics('large');
  
  console.log(metrics.pillWidth); // 68
  console.log(metrics.thumbSize); // 32
  
  return <View style={{ width: metrics.pillWidth }} />;
}

Build docs developers (and LLMs) love