From 0e24b4652515008d9ca0824a5e7330612f082df4 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Tue, 2 Apr 2024 10:22:31 +0800 Subject: [PATCH] Feat(ToolGroupCard): Automatically manage expansion and hiding of cards Automatically manage the expansion and hiding of cards when clicking on the card title --- .../oxygen/toolbox/ui/component/ToolGroupCard.kt | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/app/src/main/kotlin/top/fatweb/oxygen/toolbox/ui/component/ToolGroupCard.kt b/app/src/main/kotlin/top/fatweb/oxygen/toolbox/ui/component/ToolGroupCard.kt index c92489d..796f34b 100644 --- a/app/src/main/kotlin/top/fatweb/oxygen/toolbox/ui/component/ToolGroupCard.kt +++ b/app/src/main/kotlin/top/fatweb/oxygen/toolbox/ui/component/ToolGroupCard.kt @@ -43,12 +43,12 @@ import top.fatweb.oxygen.toolbox.ui.theme.OxygenTheme @Composable fun ToolGroupCard( modifier: Modifier = Modifier, - toolGroup: ToolGroup, - isExpanded: Boolean = true, - onExpandSwitch: (() -> Unit)? = null + toolGroup: ToolGroup ) { val (_, icon, title, tools) = toolGroup + var isExpanded by remember { mutableStateOf(true) } + Card( modifier = modifier, shape = RoundedCornerShape(8.dp), @@ -60,7 +60,7 @@ fun ToolGroupCard( icon = icon, title = title, isExpanded = isExpanded, - onClick = onExpandSwitch + onClick = { isExpanded = !isExpanded } ) AnimatedVisibility(visible = isExpanded) { ToolGroupContent(modifier = Modifier.padding(16.dp), toolList = tools) @@ -163,13 +163,9 @@ private fun ToolGroupCardPreview() { if (index != 0) { Spacer(modifier = Modifier.height(10.dp)) } - var isExpanded by remember { - mutableStateOf(true) - } ToolGroupCard( - toolGroup = item, - isExpanded = isExpanded, - onExpandSwitch = { isExpanded = !isExpanded }) + toolGroup = item + ) } } }