如何禁用Moshan的react-native-simple-radio-button的一些单选按钮



我正在使用Moschan的react原生简单单选按钮,并且很难禁用一些单选按钮。我已经尝试传递值为true1disabled项参数,但没有成功,它仍然是可选的。

来源

radio_props = [
{ value: 1, label: 'one', disabled: true },
{ value: 2, label: 'two' },
{ value: 3, label: 'three', disabled: true },
];

组件

import RadioForm from 'react-native-simple-radio-button';
...
<RadioForm
radio_props={radio_props}
initial={-1}
buttonColor={'#169976'}
selectedButtonColor={'#169976'}
buttonSize={12}
buttonOuterSize={25}
onPress={(value) => { this.setState({ value:value }); }}
/>
...

知道怎么解决这个问题吗?请提供建议。

您可以将禁用的道具传递给RadioButtonLabel和RadioButtonInput。如果它被禁用,它将不会调用onPress功能。例如,你可以做一些类似的事情

<RadioButton>
<RadioButtonInput
{...otherRadioButtonInputProps}
disabled={shouldDisable}
buttonInnerColor={shouldDisable ? '#EEE' : '#000'}
buttonOuterColor={shouldDisable ? '#EEE' : '#000'}
/>
<RadioButtonLabel
{...otherRadioButtonLabelProps}
disabled={shouldDisable}
/>
</RadioButton>

我通过以下步骤解决了这个问题:

  • 打开node_modules/areact本机简单单选按钮/lib/SimpleRadioButton.js
  • 在第72行附近找到disabled={this.props.disabled},修改为:disabled={this.props.disabled || obj.disabled ? obj.disabled : false}
  • 保存并重试

希望这能有所帮助。

最新更新