This is documentation for the next SDK version. For up-to-date documentation, see the latest version (SDK 54).
A SwiftUI Switch component for toggle controls.
iOS
tvOS
A switch component that provides toggle functionality with different visual styles.
Installation
Terminal
- npx expo install @expo/uiIf you are installing this in an existing React Native app, make sure to install expo in your project.
Toggle switch
Note: Also known as Toggle.
import { Host, Switch } from '@expo/ui/swift-ui'; <Host matchContents> <Switch checked={checked} onValueChange={checked => { setChecked(checked); }} color="#ff0000" label="Play music" variant="switch" /> </Host>
See official SwiftUI documentation for more information.
Checkbox
import { Host, Switch } from '@expo/ui/swift-ui'; <Host matchContents> <Switch checked={checked} onValueChange={checked => { setChecked(checked); }} label="Play music" variant="checkbox" /> </Host>
See official SwiftUI documentation for more information.
API
Component
Type: React.Element<SwitchProps>
Displays a native switch component.
Optional • Type:
(value: boolean) => voidCallback function that is called when the checked state changes.
Optional • Literal type:
string • Default: 'switch'Type of the switch component. Can be 'checkbox', 'switch', or 'button'.
Acceptable values are: 'checkbox' | 'switch' | 'button'