【发布时间】:2021-10-02 08:23:30
【问题描述】:
有没有办法在反应原生功能组件中单击按钮时显示和隐藏组件?我有一个功能,其中有两个自定义按钮。如果选择了一个按钮并且如果选择了第二个按钮然后第一个按钮视图隐藏并显示第二个按钮视图,我想显示视图。我怎样才能做到这一点? 这是我的功能代码..
const SupportScreen = ({ props, navigation }) => {
const lists = [
{id: 1, title: 'Pending Tickets'},
{id: 2, title: 'Resolved Tickets'},
];
const [selected, setSelected] = useState(1);
<View style={{flexDirection: 'row', marginTop: 10}}>
{lists.map(list => (
<CustomButton
key={list.id}
customclick={() => {
handleColor(list);
}}
title={list.title}
style={{
backgroundColor:
list.id === selected
? Constants.Colors.PRIMARY
: Constants.Colors.WALLTE_TXT_GRAY_COLOR,
width: 180,
elevation: 3,
}}
tColor={Constants.Colors.WHITE}
tfz={12}></CustomButton>
))}
</View>
const handleColor = row => {
setSelected(row.id);
};
</SafeAreaView>
);
};
【问题讨论】: