import React, { memo, useCallback, useContext } from 'react'; import { StyleProp, StyleSheet, TextStyle, View, ViewStyle } from 'react-native'; import { RadioButton, TouchableRipple } from 'react-native-paper'; import GestureHandlerAdapterNucleon from './nucleons/GestureHandlerAdapterNucleon'; import TextRoleNucleon from './nucleons/TextRoleNucleon'; import selectedRadioItemContextAtom from './selectedRadioItemContextAtom'; import { useColorRoles } from '../theme/colorSystem'; export const RADIO_ITEM_HEIGHT = 40; const styles = StyleSheet.create({ row: { flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center' }, label: { textAlignVertical: 'center' }, item: { height: RADIO_ITEM_HEIGHT } }); const UIRadioItemAtom = memo(function RadioItem({ value, label, onSelectedValueChange, labelStyle, style }: { value: V; label: string; onSelectedValueChange: (v: any) => void; labelStyle?: StyleProp; style?: StyleProp; }) { const onPress = useCallback( () => onSelectedValueChange(value), [value, onSelectedValueChange] ); const selected = useContext(selectedRadioItemContextAtom) === value; const { pressable, selectable, surface } = useColorRoles(); const color = selected ? selectable.activeBackground : selectable.inactiveBackground; return ( {label} ); }); type UIRadioItemAtom = typeof UIRadioItemAtom; export default UIRadioItemAtom;