Saltar al contenido principal

Interruptor

Interruptor

Este componente fue construido sobre el componente Switch de React Native y por lo tanto hereda todas las props que tiene el componente nativo. Este es un componente controlado que requiere la prop onValueChange para que puedas actualizar el estado del valor.

Interruptor

Uso

Importaciones:

import { Switch } from 'galio-framework';

Ejemplo simple:

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

Uso moderno con hooks:

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

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

Props

PropTipoPredeterminadoDescripción
valueboolfalseEl valor del interruptor
onValueChangefunctionnullCallback cuando cambia el valor del interruptor
coloroneOfType(['primary', 'theme', 'error', 'warning', 'success', 'info']), stringGalioTheme.COLORS.PRIMARYColor del interruptor
disabledboolfalseDeshabilita el interruptor
initialValueboolfalseValor inicial del interruptor
styleobjectnullEstilos personalizados
trackColorobjectnullColores de la pista para estados on/off
thumbColorstringnullColor del pulgar
ios_backgroundColorstringnullColor de fondo para iOS
...Switch.props--Todas las props de React Native Switch son compatibles