Skip to content

Switch

Switch is a toggle control for turning settings on or off. It provides clear visual feedback with smooth animation and supports multiple sizes.


Notifications
Dark Mode
Auto-save
const [notifications, setNotifications] = useState(true);
const [darkMode, setDarkMode] = useState(false);
const [autoSave, setAutoSave] = useState(true);
<Switch
value={notifications}
onValueChange={setNotifications}
accessibilityLabel="Notifications"
/>
<Switch
value={darkMode}
onValueChange={setDarkMode}
accessibilityLabel="Dark mode"
/>
<Switch
value={autoSave}
onValueChange={setAutoSave}
accessibilityLabel="Auto-save"
/>

sm
md
lg
SizeDimensionsThumbUsage
sm36×20px16pxCompact settings lists
md48×28px24pxDefault
lg56×32px28pxProminent controls
<Switch size="sm" value={value} onValueChange={setValue} accessibilityLabel="Small switch" />
<Switch size="md" value={value} onValueChange={setValue} accessibilityLabel="Medium switch" />
<Switch size="lg" value={value} onValueChange={setValue} accessibilityLabel="Large switch" />

<Switch
value={false}
onValueChange={() => {}}
disabled
accessibilityLabel="Disabled off"
/>
<Switch
value={true}
onValueChange={() => {}}
disabled
accessibilityLabel="Disabled on"
/>

Use activeColor to customize the track color when on.

<Switch
value={true}
onValueChange={setValue}
activeColor="#d4af37"
accessibilityLabel="Gold switch"
/>
<Switch
value={true}
onValueChange={setValue}
activeColor="#10b981"
accessibilityLabel="Success switch"
/>
<Switch
value={true}
onValueChange={setValue}
activeColor="#6366f1"
accessibilityLabel="Info switch"
/>

PropTypeDefaultDescription
valuebooleanRequiredCurrent switch state
onValueChange(value: boolean) => voidRequiredCalled when toggled
size'sm' | 'md' | 'lg''md'Switch size
disabledbooleanfalseDisable interaction
activeColorstringGoldCustom track color when on
styleViewStyle-Custom styles
accessibilityLabelstringRequiredA11y label

import { Switch, Card, Text } from '@synchronicity/react-native';
import { View, StyleSheet } from 'react-native';
import { useState } from 'react';
function SettingsScreen() {
const [settings, setSettings] = useState({
notifications: true,
darkMode: false,
haptics: true,
analytics: false,
});
const updateSetting = (key: string, value: boolean) => {
setSettings(prev => ({ ...prev, [key]: value }));
};
return (
<Card>
<SettingRow
label="Push Notifications"
value={settings.notifications}
onChange={(v) => updateSetting('notifications', v)}
/>
<SettingRow
label="Dark Mode"
value={settings.darkMode}
onChange={(v) => updateSetting('darkMode', v)}
/>
<SettingRow
label="Haptic Feedback"
value={settings.haptics}
onChange={(v) => updateSetting('haptics', v)}
/>
<SettingRow
label="Analytics"
value={settings.analytics}
onChange={(v) => updateSetting('analytics', v)}
/>
</Card>
);
}
function SettingRow({ label, value, onChange }) {
return (
<View style={styles.row}>
<Text>{label}</Text>
<Switch
value={value}
onValueChange={onChange}
accessibilityLabel={label}
/>
</View>
);
}
const styles = StyleSheet.create({
row: {
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
paddingVertical: 12,
},
});