import React, { useRef, useEffect } from 'react'; import { Pressable, Animated, Text, View, StyleSheet } from 'react-native'; import { useTheme } from '../../theme/useTheme'; import type { RadioGroupProps, RadioSize } from './Radio.types'; interface RadioButtonProps { selected: boolean; onPress: () => void; label: string; color: string; size: RadioSize; disabled: boolean; labelStyle?: object; } const RadioButton: React.FC = ({ selected, onPress, label, color, size, disabled, labelStyle, }) => { const theme = useTheme(); const animatedValue = useRef(new Animated.Value(selected ? 1 : 0)).current; useEffect(() => { Animated.timing(animatedValue, { toValue: selected ? 1 : 0, duration: 150, useNativeDriver: false, }).start(); }, [selected, animatedValue]); const sizeMap: Record = { sm: { outer: 18, inner: 8, fontSize: theme.typography.fontSize.sm }, md: { outer: 22, inner: 10, fontSize: theme.typography.fontSize.md }, lg: { outer: 28, inner: 14, fontSize: theme.typography.fontSize.lg }, }; const { outer, inner, fontSize } = sizeMap[size]; const borderColor = animatedValue.interpolate({ inputRange: [0, 1], outputRange: [theme.colors.border, color], }); const innerScale = animatedValue.interpolate({ inputRange: [0, 1], outputRange: [0, 1], }); return ( {label} ); }; export function RadioGroup({ options, value, onValueChange, color = 'primary', size = 'md', direction = 'vertical', spacing, disabled = false, style, labelStyle, }: RadioGroupProps) { const theme = useTheme(); const colorValue = theme.colors[color]; const gap = spacing ?? theme.spacing.sm; return ( {options.map((option) => ( onValueChange(option.value)} label={option.label} color={colorValue} size={size} disabled={disabled || !!option.disabled} labelStyle={labelStyle} /> ))} ); } const styles = StyleSheet.create({ radioWrapper: { flexDirection: 'row', alignItems: 'center', }, outerCircle: { alignItems: 'center', justifyContent: 'center', }, radioLabel: {}, disabled: { opacity: 0.5, }, });