Feat(ToolGroupCard): Automatically manage expansion and hiding of cards

Automatically manage the expansion and hiding of cards when clicking on the card title
This commit is contained in:
2024-04-02 10:22:31 +08:00
parent cba2e83074
commit 0e24b46525

View File

@@ -43,12 +43,12 @@ import top.fatweb.oxygen.toolbox.ui.theme.OxygenTheme
@Composable @Composable
fun ToolGroupCard( fun ToolGroupCard(
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
toolGroup: ToolGroup, toolGroup: ToolGroup
isExpanded: Boolean = true,
onExpandSwitch: (() -> Unit)? = null
) { ) {
val (_, icon, title, tools) = toolGroup val (_, icon, title, tools) = toolGroup
var isExpanded by remember { mutableStateOf(true) }
Card( Card(
modifier = modifier, modifier = modifier,
shape = RoundedCornerShape(8.dp), shape = RoundedCornerShape(8.dp),
@@ -60,7 +60,7 @@ fun ToolGroupCard(
icon = icon, icon = icon,
title = title, title = title,
isExpanded = isExpanded, isExpanded = isExpanded,
onClick = onExpandSwitch onClick = { isExpanded = !isExpanded }
) )
AnimatedVisibility(visible = isExpanded) { AnimatedVisibility(visible = isExpanded) {
ToolGroupContent(modifier = Modifier.padding(16.dp), toolList = tools) ToolGroupContent(modifier = Modifier.padding(16.dp), toolList = tools)
@@ -163,13 +163,9 @@ private fun ToolGroupCardPreview() {
if (index != 0) { if (index != 0) {
Spacer(modifier = Modifier.height(10.dp)) Spacer(modifier = Modifier.height(10.dp))
} }
var isExpanded by remember {
mutableStateOf(true)
}
ToolGroupCard( ToolGroupCard(
toolGroup = item, toolGroup = item
isExpanded = isExpanded, )
onExpandSwitch = { isExpanded = !isExpanded })
} }
} }
} }