Switch
A Switch component allows users to toggle between two states. Built on top of heroui-native Switch.
React Native components render to native views, so this is the component running in the example app, in the theme you are reading in.
9:41


Switch.tsx
import { View } from 'react-native';import { useState } from 'react';import { NSwitch, NText } from '@nayan-ui/native';export default function SwitchScreen() {const [wifi, setWifi] = useState(true);const [bluetooth, setBluetooth] = useState(false);return (<View className="p-4 gap-4"><NText className="text-lg font-bold">Basic</NText><NSwitch label="Wi-Fi" isSelected={wifi} onSelectedChange={setWifi} /><NSwitch label="Bluetooth" isSelected={bluetooth} onSelectedChange={setBluetooth} /><NText className="text-muted">Wi-Fi: {wifi ? 'On' : 'Off'}, Bluetooth: {bluetooth ? 'On' : 'Off'}</NText><NText className="text-lg font-bold">Disabled</NText><NSwitch label="Disabled on" isSelected isDisabled onSelectedChange={() => {}} /><NSwitch label="Disabled off" isSelected={false} isDisabled onSelectedChange={() => {}} /></View>);}
| Name | Type | Default | Details |
|---|---|---|---|
| label | string | Optional | Label for the switch. |
| isSelected | boolean | false | Whether the switch is selected. |
| isDisabled | boolean | false | Whether the switch is disabled. |
| onSelectedChange | (selected: boolean) => void | Optional | Callback when switch state changes. |
| className | string | ' ' | You can customise switch by passing tailwind classes. |
| containerClassName | string | ' ' | You can customise container by passing tailwind classes. |
| labelClassName | string | ' ' | You can customise label by passing tailwind classes. |
Other components solving nearby problems.
- React Native Switch
- React Native Toggle
- React Native Toggle Switch
- Mobile Switch React Native
- React Native Switch Component
- React Native Switch Library
- React Native Toggle Button
- React Native Boolean Switch
- React Native On Off Switch
- React Native Custom Switch
- React Native Form Switch
- Mobile Switch Component
- Cross Platform Switch
- Expo Switch Component
- React Native Switch Tutorial
- React Native Switch TypeScript
- React Native Switch UI