What's the simplest way, to draw content, same as with unbounded height?
I'm making a custom composable, that has "show more/less". Child height needs to be limited, based on the collapsed state.
If I simply set fixed height, some composables will draw based on the available height. Either center content, scale down, etc. I want them to be unaware of the height constraints.
What's simplest way to achieve this? I guess custom layout logic (measure + placement)?
v
vide
03/07/2024, 7:19 PM
Are you looking for
wrapContentSize
perhaps? Give it
unbounded = true
vide
03/07/2024, 7:19 PM
(or
wrapContentHeight
in this case)
p
Peter
03/07/2024, 7:32 PM
I'm not sure. The idea is to use it like:
Copy code
Expandable {
// Any child
}
My first thought was to do following, but in that case
content
is drawn based on specified height and not cut-off.
Copy code
fun Expandable(content: @Composable () -> Unit) {
var isExpanded: Boolean = TODO()
Column {
Box(Modifier.let { if (isExpanded) it else it.height(200.dp) }) {
content()
}
Button(onClick = { isExpanded = !isExpanded }) {
Text("toggle")
}
}
}
Peter
03/07/2024, 7:42 PM
Maybe I'm missing unbounded, as you suggested, let me try 🙂