Command palette

@yasinsensoy/native

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

import { Switch } from "@yasinsensoy/native";

<Switch label="Turn on notifications" defaultChecked onCheckedChange={setChecked} />

Events

  1. Events appear here when you interact with the preview.

Import

import { Switch } from "@yasinsensoy/native";

Switch

component

On/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.

Switch(props: SwitchProps): JSX.Element

Examples

`<Switch label="Notifications" checked={on} onCheckedChange={setOn} />`

SwitchProps

interface

Switch props.

NameTypeDefaultDescription
name?stringName 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?booleanOn (controlled).
defaultChecked?booleanfalseInitially on (uncontrolled).
onCheckedChange?(checked: boolean) => voidWhen the state changes.
size?"sm" | "md""md"Size: sm 36×20, md 44×24 pixels.
label?ReactNodeLabel next to the switch; the whole thing is tappable.
description?ReactNodeDescription under the label.
error?ReactNodeError message.
disabled?booleanDisabled.
accessibilityLabel?stringScreen reader label (when the label is not text).
effect?EffectPropEffect of the track ("glow", "pulse", "ripple"…). Defaults to appearance.defaults.switch.effect. See BuiltinEffect.
tooltip?TooltipPropTooltip shown on long press. See TooltipProp.
style?StyleProp<ViewStyle>Container style.