React Native · Components
Switch
On/off switch.
2 exports
Live example
The preview runs in the browser with the web component; the native component takes the same props and looks the same on iOS and Android.
Preview
Code
Events
- Events appear here when you interact with the preview.
Import
Switch
componentOn/off switch. React Native's Switch looks Material on Android and Cupertino on iOS; this component is the same on both platforms (the web Switch dimensions). The thumb slides on the native driver.
Examples
SwitchProps
interfaceSwitch props.
| Name | Type | Default | Description |
|---|---|---|---|
name? | string | Name in the form. Inside a Form, the state, error and disabled state come from the form. | |
ref? | Ref<ViewRef> | Ref of the underlying native element. | |
checked? | boolean | On (controlled). | |
defaultChecked? | boolean | false | Initially on (uncontrolled). |
onCheckedChange? | (checked: boolean) => void | When the state changes. | |
size? | "sm" | "md" | "md" | Size: sm 36×20, md 44×24 pixels. |
label? | ReactNode | Label next to the switch; the whole thing is tappable. | |
description? | ReactNode | Description under the label. | |
error? | ReactNode | Error message. | |
disabled? | boolean | Disabled. | |
accessibilityLabel? | string | Screen reader label (when the label is not text). | |
effect? | EffectProp | Effect of the track ("glow", "pulse", "ripple"…). Defaults to appearance.defaults.switch.effect. See BuiltinEffect. | |
tooltip? | TooltipProp | Tooltip shown on long press. See TooltipProp. | |
style? | StyleProp<ViewStyle> | Container style. |