import * as SwitchPrimitives from '@rn-primitives/switch'; import * as React from 'react'; import { Platform } from 'react-native'; import Animated, { interpolateColor, useAnimatedStyle, useDerivedValue, withTiming, } from 'react-native-reanimated'; import { cn } from '../../lib/utils'; import { useThemeChange } from '../ThemeProvider'; function SwitchWeb({ className, ...props }: SwitchPrimitives.RootProps & { ref?: React.RefObject; }) { return ( ); } const RGB_COLORS = { light: { primary: 'rgb(24, 24, 27)', input: 'rgb(228, 228, 231)', }, dark: { primary: 'rgb(250, 250, 250)', input: 'rgb(39, 39, 42)', }, } as const; function SwitchNative({ className, ...props }: SwitchPrimitives.RootProps & { ref?: React.RefObject; }) { const { colorScheme } = useThemeChange(); const translateX = useDerivedValue(() => (props.checked ? 18 : 0)); const animatedRootStyle = useAnimatedStyle(() => { return { backgroundColor: interpolateColor( translateX.value, [0, 18], [RGB_COLORS[colorScheme].input, RGB_COLORS[colorScheme].primary], ), }; }); const animatedThumbStyle = useAnimatedStyle(() => ({ transform: [ { translateX: withTiming(translateX.value, { duration: 200 }) }, ], })); return ( ); } const Switch = Platform.select({ web: SwitchWeb, default: SwitchNative, }); export { Switch };