React-native可扩展的flatlist。打开另一个项目时关闭打开的项目

我有一个可扩展的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>
  );
}

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

WIND888888 回答:React-native可扩展的flatlist。打开另一个项目时关闭打开的项目

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

本文链接:https://www.f2er.com/3107261.html

大家都在问