React原生可扩展平面主义者.打开另一个项目时关闭已打开的项目



我有一个可扩展的flatList正在工作,但当另一个选项卡打开时,我需要关闭现有的选项卡。

const [expandable, setExpandable] = useState(false);
const [titleColor, setTitleColor] = useState(colors.blue.primary)
const onPress = () => {
if (!expandable) {
setExpandable(true);
setTitleColor(colors.blue.secondary);
}
else {
setExpandable(false);
setTitleColor(colors.blue.primary);
}
};
return (
<StyledView>
<TouchableWithoutFeedback onPress={onPress}>
<StyledListItem {...props}>
<ListTitle style={{ color: titleColor }}>{title}</ListTitle>
<Icon name="add" size={24} color={titleColor} />
</StyledListItem>
</TouchableWithoutFeedback>
{expandable && <MyListDetails faqDetail={details} />}
<StyledLine></StyledLine>
</StyledView>
);
}

我需要保存我打开的标签的状态并关闭它们,但我不知道该怎么做。有人能帮我吗?Thx!!!

不是每个项目都有一个"可扩展"值。。。在呈现列表的组件的顶层使用"expandedItem"状态值。然后,每次选择一个时,将expandedItem设置为该项。然后将expandedItem和onPress处理程序向下传递到每个renderItem中。

最新更新