What's the simplest way, to draw content, same as ...
# compose
p
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
Are you looking for
wrapContentSize
perhaps? Give it
unbounded = true
(or
wrapContentHeight
in this case)
p
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")
        }
    }
}
Maybe I'm missing unbounded, as you suggested, let me try 🙂
unbounded worked, thanks!
💯 1