I started to learn React Native lately and I'm trying to build my first app, but i'm facing this issue and I don't know how to solve it, I used library React Native Elements and ListItem.Accordion and I create this element:
{meals.map((item, index) => {
return (
<ListItem.Accordion
theme={{ colors: { primary: "#4169e1" } }}
style={tw`px-3 rounded py-3 text-white`}
containerStyle={{ backgroundColor: "#000000", borderRadius: "10px" }}
content={
<>
<Text style={tw`text-5xl mr-2`}>☀️</Text>
<ListItem.Content>
<ListItem.Title style={tw`font-bold text-white`}>{item.title}</ListItem.Title>
<Text style={tw`text-white`}>480 calories</Text>
</ListItem.Content>
</>
}
key={index}
index={index}
noRotation
isExpanded={expanded}
icon={
<Icon
style={tw`mt-3 p-2`}
size={35}
name="add-circle-outline"
color="white"
type="material"
/>
}
onPress={() => {
setExpanded(!expanded);
}}
>
<ListItem
containerStyle={{ backgroundColor: "#000000", borderRadius: "10px" }}
style={tw`px-3 mt-[-25]`}
onPress={() => console.log("hi")}
bottomDivider
>
<ListItem.Content>
<ListItem.Title>
<Divider width={1} style={tw`w-full`} />
<View style={tw`justify-around items-center flex-row w-full`}>
<View>
<Text style={tw`text-gray-400`}>Fats</Text>
<Text style={tw`font-bold text-white`}>28.4</Text>
</View>
<View>
<Text style={tw`text-gray-400`}>Carbs</Text>
<Text style={tw`font-bold text-white`}>42.32</Text>
</View>
<View>
<Text style={tw`text-gray-400`}>Prot</Text>
<Text style={tw`font-bold text-white`}>60,45</Text>
</View>
<View>
<Text style={tw`text-gray-400`}>RDC</Text>
<Text style={tw`font-bold text-white`}>12%</Text>
</View>
</View>
</ListItem.Title>
<ListItem.Subtitle style={tw`p-2`}>
<View style={tw`py-3`}>
<View
style={tw`flex-row py-5 items-center justify-between w-full`}
>
<View style={tw`flex-row ml-2`}>
<Icon
name="restaurant-menu"
size={50}
color="white"
type="material"
/>
<View style={tw`ml-3 justify-center`}>
<Text style={tw`font-bold text-white`}>Pepperoni Sandwich</Text>
<Text style={tw`text-white`}>2 pieces</Text>
</View>
</View>
<Icon name="edit" size={30} color="white" type="material" />
</View>
</View>
</ListItem.Subtitle>
</ListItem.Content>
</ListItem>
</ListItem.Accordion>
)
})}
</View>
);
};
When I press, all items are expanded, when I want to achieve is displaying only the item that I select, can anyone give me some advice please? Thanks in advance :)
item
you could instead of a boolean value use an array with that identifier based on if its in the list or not open the accordion