Created
March 28, 2021 00:10
-
-
Save nealsanche/8283c430a01e5eb0a17287cd59fab193 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var expanded by remember { mutableStateOf(false) } | |
DisclosureGroup( | |
label = { Text("Label") }, | |
onClick = { expanded = !expanded }, | |
modifier = Modifier.padding(16.dp), | |
isExpanded = expanded | |
) { | |
Greeting("Android") | |
} | |
@Composable | |
fun Greeting(name: String) { | |
Column { | |
Text(text = "Hello $name!") | |
Text(text = "Hello $name!") | |
Text(text = "Hello $name!") | |
} | |
} | |
@Composable | |
fun DisclosureGroup( | |
modifier: Modifier = Modifier, | |
label: @Composable () -> Unit, | |
onClick: () -> Unit, | |
isExpanded: Boolean, | |
content: @Composable () -> Unit | |
) { | |
Column(modifier = modifier.fillMaxWidth()) { | |
Row( | |
verticalAlignment = Alignment.CenterVertically, | |
modifier = Modifier | |
.fillMaxWidth() | |
.clickable { onClick() }) { | |
Box(modifier = Modifier.weight(1.0f)) { | |
label() | |
} | |
Icon( | |
if (isExpanded) Icons.Default.KeyboardArrowUp | |
else Icons.Default.KeyboardArrowDown, | |
contentDescription = if (isExpanded) "Collapse" else "Expand" | |
) | |
} | |
AnimatedVisibility(isExpanded) { | |
content() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment