If the last collapsed item is opened its bottom border should be removed, but all the other collapsable components should have a bottom border. How can i remove the bottom border of the last of type element? In React i could use :last-of-type but how to achieve this with React Native?
Summary : How to change style of last collapsed item, without using any third party library?
export function Dropdown() {
return <View>{children}</View>;
}
export function ColapseItem() {
const [isCollapsed, setIsCollapsed] = React.useState(collapsedByDefault ?? true);
function onToggle() {
setIsCollapsed((isCollapsed) => !isCollapsed);
}
return (
<View>
<Pressable style={itemStyles.container} onPress={onToggle}>
<Text>{title}</Text>
<Icon size={14} name='icon1' />
</Pressable>
{!isCollapsed && <View style={itemStyles.collapsibleItem}>{children}</View>}
</View>
);
}
const itemStyles = StyleSheet.create({
container: {
justifyContent: "space-between",
flexDirection: "row",
borderBottomWidth: 1,
borderBottomColor: 'red'
paddingVertical: 20,
},
collapsibleItem: {
paddingVertical: 20,
},
});
children file
<ColapseItem title="Label">
<Text>children</Text>
</ColapseItem>
<ColapseItem title="Label">
<Text>children</Text>
</ColapseItem>
<ColapseItem title="Label">
<Text>children</Text>
</ColapseItem>
