import * as React from 'react' import {View, TouchableWithoutFeedback, Animated} from 'react-native' interface SwitchProps { color: string, onValueChanged?(value:boolean):void } interface SwitchState { isActive: boolean } export default class Switch extends React.Component { constructor(props) { super(props); this.state = {isActive: false} } ButtonTransform = new Animated.Value(0); render() { return ( {this.state.isActive?this.disable():this.enable()}}> ) } disable = () => { this.setState({isActive: false}, () => { if (this.props.onValueChanged) { this.props.onValueChanged(false); } }); Animated.timing( this.ButtonTransform, { useNativeDriver: true, toValue: 0, duration: 100, } ).start(); }; enable = () => { this.setState({isActive: true}, () => { if (this.props.onValueChanged) { this.props.onValueChanged(true); } }); Animated.timing( this.ButtonTransform, { useNativeDriver: true, toValue: 16, duration: 100, } ).start(); } }