import { StyleSheet, Animated, TouchableWithoutFeedback, View } from 'react-native'; import React, { ComponentType, useState, useEffect } from 'react'; import { useTheme } from './ThemeContext'; const noop = () => undefined; export type Props = { readonly value?: boolean; readonly onValueChange?: (boolean) => void; }; const Switch: ComponentType = ({ value = false, onValueChange = noop }) => { const theme = useTheme(); const offset = value ? theme._switch.thumbOn.left : theme._switch.thumbOff.left; const [animatedOffset] = useState(() => new Animated.Value(offset)); useEffect(() => { Animated.timing(animatedOffset, { toValue: offset, duration: 200.0, useNativeDriver: false, }).start(); }, [value]); return ( onValueChange(!value)}> ); }; export default Switch;