import React from 'react'; import {StyleProp, Text, TextStyle, TouchableWithoutFeedback, View} from 'react-native'; import {MaterialIcons as Icon} from '@expo/vector-icons'; import {WithTheme, WithThemeStyles} from '../style'; import variables from '../style/themes/default'; import {RadioPropsType} from './PropsType'; import RadioStyles, {RadioStyle} from './style'; export interface RadioNativeProps extends RadioPropsType, WithThemeStyles { style?: StyleProp; } export default class Radio extends React.Component { static RadioItem: any; constructor(props: RadioNativeProps, context: any) { super(props, context); this.state = { checked: props.checked || props.defaultChecked || false, }; } UNSAFE_componentWillReceiveProps(nextProps: RadioNativeProps): void { if ('checked' in nextProps) { this.setState({ checked: !!nextProps.checked, }); } } handleClick = () => { if (this.props.disabled) { return; } if (!('checked' in this.props)) { this.setState({ checked: true, }); } if (this.props.onChange) { this.props.onChange({target: {checked: true}}); } }; render(): JSX.Element { const {style, disabled, children} = this.props; return ( {(styles) => { const checked = this.state.checked; let icon = undefined; if (checked) { // @ts-ignore // @ts-ignore icon = disabled ? null : ; } return ( {icon} {typeof children === 'string' ? ( // tslint:disable-next-line:jsx-no-multiline-js {this.props.children} ) : ( children )} ); }} ); } }