【发布时间】:2020-01-22 20:43:38
【问题描述】:
有没有办法在进入屏幕时显示中间单选按钮打开?即使当我按下同一个单选按钮时,它也不会自行关闭,但我只能在它们之间切换,并且当我按下它们时不会关闭它们。
这是我的例子:
import React, { useState } from 'react';
import { View, Text, StyleSheet, Platform } from 'react-native';
import { CheckBox } from 'react-native-elements';
const SettingsScreen = props => {
const [checked6, setChecked6] = useState(true);
const [checked7, setChecked7] = useState(null);
const [checked8, setChecked8] = useState(null);
const handlePress = title => {
checked6 === title ? setChecked6(null) : setChecked6(title)
checked7 === title ? setChecked7(null) : setChecked7(title)
checked8 === title ? setChecked8(null) : setChecked8(title)
}
return (
<CheckBox
iconLeft
checkedColor='green'
title='bomba6'
checkedIcon='dot-circle-o'
uncheckedIcon='circle-o'
checked={checked6 === 'bomba6'}
onPress={() => handlePress('bomba6')}
/>
<CheckBox
iconLeft
checkedColor='green'
title='bomba7'
checkedIcon='dot-circle-o'
uncheckedIcon='circle-o'
checked={checked7 === 'bomba7'}
onPress={() => handlePress('bomba7')}
/>
<CheckBox
iconLeft
checkedColor='green'
title='bomba8'
checkedIcon='dot-circle-o'
uncheckedIcon='circle-o'
checked={checked8 === 'bomba8'}
onPress={() => handlePress('bomba8)')}
/>
);
};
export default SettingsScreen;
【问题讨论】:
-
您需要使用
defaultChecked而不是checked才能修改单选按钮
标签: javascript react-native checkbox radio-button expo