Skip to main content

Switch

Switch is a visual toggle between two mutually exclusive states — on and off.

How to use

import React from 'react';
import {Switch} from '@gyri/native-ui-components';

const MyComponent = () => {
const [isSwitchOn, setIsSwitchOn] = React.useState(false);

const onToggleSwitch = () => setIsSwitchOn(!isSwitchOn);

return <Switch
style={style}
className={className}
value={isSwitchOn}
onValueChange={onToggleSwitch}
trackColor={{false: 'black', true: 'white'}}
thumbColor={isDarkThemeEnabled ? 'black' : 'white'}
/>;
};

export default MyComponent;

Props

#NameData typeDefault valueValuesDescription
1styleobjectCustom style object
2classNamestring''It defined nativewind style classes.

For more details https://callstack.github.io/react-native-paper/docs/components/Switch/