/* @flow */ import * as React from 'react'; import { StyleSheet, View } from 'react-native'; import color from 'color'; import { RadioButtonContext } from './RadioButtonGroup'; import Icon from './Icon'; import TouchableRipple from './TouchableRipple'; import { withTheme } from '../core/theming'; import type { Theme, $RemoveChildren } from '../types'; type Props = $RemoveChildren & {| /** * Value of the radio button */ value: string, /** * Status of radio button. */ status?: 'checked' | 'unchecked', /** * Whether radio is disabled. */ disabled?: boolean, /** * Function to execute on press. */ onPress?: () => mixed, /** * Custom color for radio. */ color?: string, /** * @optional */ theme: Theme, |}; /** * Radio buttons allow the selection a single option from a set. * This component follows platform guidelines for iOS. * *
*
* *
Enabled
*
*
* *
Disabled
*
*
*/ class RadioButtonIOS extends React.Component { static displayName = 'RadioButton.IOS'; render() { return ( {context => { const { disabled, onPress, theme, ...rest } = this.props; const checkedColor = disabled ? theme.colors.disabled : this.props.color || theme.colors.accent; let rippleColor; const checked = context ? context.value === this.props.value : this.props.status === 'checked'; if (disabled) { rippleColor = color(theme.colors.text) .alpha(0.16) .rgb() .string(); } else { rippleColor = color(checkedColor) .fade(0.32) .rgb() .string(); } return ( { context && context.onValueChange(this.props.value); onPress && onPress(); } } accessibilityTraits={disabled ? ['button', 'disabled'] : 'button'} accessibilityComponentType={ checked ? 'radiobutton_checked' : 'radiobutton_unchecked' } accessibilityRole="button" accessibilityStates={disabled ? ['disabled'] : undefined} accessibilityLiveRegion="polite" style={styles.container} > ); }} ); } } const styles = StyleSheet.create({ container: { borderRadius: 18, padding: 6, }, }); export default withTheme(RadioButtonIOS);