From 7cfaa3788c00a0fc53a5973b275e812e5698b8d6 Mon Sep 17 00:00:00 2001 From: Marek Majchrzak Date: Thu, 7 May 2020 16:23:33 +0200 Subject: [PATCH 1/2] feat: radio button item disabled --- example/src/Examples/RadioButtonExample.tsx | 87 ++++++++++--------- .../RadioButton/RadioButtonItem.tsx | 21 +++-- 2 files changed, 60 insertions(+), 48 deletions(-) diff --git a/example/src/Examples/RadioButtonExample.tsx b/example/src/Examples/RadioButtonExample.tsx index d77eb6f3c9..2328e4cd55 100644 --- a/example/src/Examples/RadioButtonExample.tsx +++ b/example/src/Examples/RadioButtonExample.tsx @@ -1,14 +1,8 @@ import * as React from 'react'; import { View, StyleSheet } from 'react-native'; -import { - Paragraph, - RadioButton, - Colors, - TouchableRipple, - useTheme, -} from 'react-native-paper'; +import { Paragraph, RadioButton, Colors, useTheme } from 'react-native-paper'; -type State = 'normal' | 'normal-ios' | 'custom'; +type State = 'normal' | 'normal-ios' | 'normal-item' | 'custom'; const RadioButtonExample = () => { const [checked, setChecked] = React.useState('normal'); @@ -25,40 +19,37 @@ const RadioButtonExample = () => { }, ]} > - setChecked('normal')}> - - Normal - Android - - - - - - setChecked('normal-ios')}> - - Normal 2 - IOS - - - - - - setChecked('custom')}> - - Custom - - - - - + + Normal - Android + setChecked('normal')} + /> + + + Normal 2 - IOS + setChecked('normal-ios')} + /> + + + Custom + setChecked('custom')} + status={checked === 'custom' ? 'checked' : 'unchecked'} + /> + + setChecked('normal-item')} + /> Checked (Disabled) @@ -67,6 +58,18 @@ const RadioButtonExample = () => { Unchecked (Disabled) + + ); }; diff --git a/src/components/RadioButton/RadioButtonItem.tsx b/src/components/RadioButton/RadioButtonItem.tsx index 9cffcc3d67..b9cd890dd8 100644 --- a/src/components/RadioButton/RadioButtonItem.tsx +++ b/src/components/RadioButton/RadioButtonItem.tsx @@ -23,6 +23,10 @@ export type Props = { * Label to be displayed on the item. */ label: string; + /** + * Whether radio is disabled. + */ + disabled?: boolean; /** * Function to execute on press. */ @@ -98,6 +102,7 @@ class RadioButtonItem extends React.Component { style, labelStyle, onPress, + disabled, color, uncheckedColor, status, @@ -109,12 +114,15 @@ class RadioButtonItem extends React.Component { {(context?: RadioButtonContextType) => { return ( - handlePress({ - onPress: onPress, - onValueChange: context?.onValueChange, - value, - }) + onPress={ + disabled + ? undefined + : () => + handlePress({ + onPress: onPress, + onValueChange: context?.onValueChange, + value, + }) } > @@ -125,6 +133,7 @@ class RadioButtonItem extends React.Component { Date: Thu, 7 May 2020 17:01:37 +0200 Subject: [PATCH 2/2] fix: revert changes for normal items --- example/src/Examples/RadioButtonExample.tsx | 67 +++++++++++++-------- 1 file changed, 41 insertions(+), 26 deletions(-) diff --git a/example/src/Examples/RadioButtonExample.tsx b/example/src/Examples/RadioButtonExample.tsx index 2328e4cd55..6ccf8ea542 100644 --- a/example/src/Examples/RadioButtonExample.tsx +++ b/example/src/Examples/RadioButtonExample.tsx @@ -1,6 +1,12 @@ import * as React from 'react'; import { View, StyleSheet } from 'react-native'; -import { Paragraph, RadioButton, Colors, useTheme } from 'react-native-paper'; +import { + Paragraph, + RadioButton, + Colors, + TouchableRipple, + useTheme, +} from 'react-native-paper'; type State = 'normal' | 'normal-ios' | 'normal-item' | 'custom'; @@ -19,31 +25,40 @@ const RadioButtonExample = () => { }, ]} > - - Normal - Android - setChecked('normal')} - /> - - - Normal 2 - IOS - setChecked('normal-ios')} - /> - - - Custom - setChecked('custom')} - status={checked === 'custom' ? 'checked' : 'unchecked'} - /> - + setChecked('normal')}> + + Normal - Android + + + + + + setChecked('normal-ios')}> + + Normal 2 - IOS + + + + + + setChecked('custom')}> + + Custom + + + + +