import React from "react"; import { TouchableOpacity, View, Animated } from "react-native"; interface ToggleProps { value: boolean; onValueChange: (value: boolean) => void; disabled?: boolean; } export default function Toggle({ value, onValueChange, disabled = false, }: ToggleProps) { const animatedValue = React.useRef(new Animated.Value(value ? 1 : 0)).current; React.useEffect(() => { Animated.spring(animatedValue, { toValue: value ? 1 : 0, useNativeDriver: true, friction: 6, tension: 40, }).start(); }, [value]); const translateX = animatedValue.interpolate({ inputRange: [0, 1], outputRange: [2, 20], }); const handlePress = () => { if (!disabled) { onValueChange(!value); } }; return ( ); }