React native React本地可扩展平面列表。打开另一个项目时关闭打开的项目

React native React本地可扩展平面列表。打开另一个项目时关闭打开的项目,react-native,layout,expandablelistview,React Native,Layout,Expandablelistview,我有一个可扩展的平面列表正在工作,但当另一个选项卡打开时,我需要关闭一个现有的选项卡 const [expandable, setExpandable] = useState(false); const [titleColor, setTitleColor] = useState(colors.blue.primary) const onPress = () => { if (!expandable) { setExpandable(true);

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

  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>
  );
}
const[expandable,setExpandable]=useState(false);
常量[titleColor,setTitleColor]=useState(colors.blue.primary)
const onPress=()=>{
如果(!可扩展){
设置可扩展(真);
SETTITLECLOR(颜色。蓝色。次级);
}
否则{
设置可扩展(假);
设置颜色(颜色。蓝色。原色);
}
};
返回(
{title}
{可扩展&&}
);
}

我需要保存打开选项卡的状态并关闭它们,但我不知道如何才能做到这一点。有人能帮我吗?谢谢

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