import type { RadioGroupContextValue, RadioGroupItemContextValue, } from '@tamagui/radio-headless' import { useRadioGroup, useRadioGroupItem, useRadioGroupItemIndicator, } from '@tamagui/radio-headless' import { RovingFocusGroup } from '@tamagui/roving-focus' import React from 'react' import { Pressable, StyleSheet, Text, View } from 'react-native' import { isWeb, useTheme } from 'tamagui' const RadioGroupContext = React.createContext({}) const RadioGroupItemContext = React.createContext({ checked: false, disabled: false, }) export function RadioGroupHeadlessDemo() { const { providerValue, frameAttrs, rovingFocusGroupAttrs } = useRadioGroup({ orientation: 'vertical', name: 'form', defaultValue: '3', }) return ( ) } function RadioGroupItem(props: { value: string; id: string; label: string }) { const theme = useTheme() const { value, id, label } = props const { providerValue, native, bubbleInput, rovingFocusGroupAttrs, frameAttrs, isFormControl, checked, } = useRadioGroupItem({ radioGroupContext: RadioGroupContext, value, id, }) return ( {isWeb && native ? ( bubbleInput ) : ( {label} {isFormControl && bubbleInput} )} ) } function RadioGroupItemIndicator() { const theme = useTheme() const params = useRadioGroupItemIndicator({ radioGroupItemContext: RadioGroupItemContext, disabled: false, }) if (params.checked) { return ( ) } return null } const styles = StyleSheet.create({ radioGroup: { flexDirection: 'column', gap: 20, alignItems: 'flex-start', }, radioGroupItem: { borderWidth: 2, width: 30, height: 30, justifyContent: 'center', alignItems: 'center', }, radioGroupItemIndicator: { width: '35%', height: '35%', }, radioGroupItemContainer: { justifyContent: 'center', alignItems: 'center', flexDirection: 'row', gap: 12, }, })