Skip to main content

Switch

Switch

This component was built on top of React Native's Switch component and so it inherits all the props the native component has. This is a controlled component which requires the onValueChange prop so you can update the value state.

Switch

Usage

Imports:

import { Switch } from 'galio-framework';

Simple example:

<Switch
value={this.state["switch-1"]}
onValueChange={() => this.toggleSwitch("switch-1")}
/>

Modern usage with hooks:

const [isEnabled, setIsEnabled] = useState(false);

<Switch
value={isEnabled}
onValueChange={setIsEnabled}
color="primary"
disabled={false}
/>

Props

PropTypeDefaultDescription
valueboolfalseThe switch value
onValueChangefunctionnullCallback when switch value changes
coloroneOfType(['primary', 'theme', 'error', 'warning', 'success', 'info']), stringGalioTheme.COLORS.PRIMARYSwitch color
disabledboolfalseDisables the switch
initialValueboolfalseInitial switch value
styleobjectnullCustom styles
trackColorobjectnullTrack colors for on/off states
thumbColorstringnullThumb color
ios_backgroundColorstringnulliOS background color
...Switch.props--All React Native Switch props are supported