https://kotlinlang.org logo
Title
z

zalewski.se

04/02/2022, 2:30 PM
Is there a composable/modifier that would scale a composable to fit (or preferably fill) in the available space? (something like FittedBox from Flutter)
a

Albert Chang

04/02/2022, 4:48 PM
Box(propagateMinConstraints = true) {}
👍 1
t

Tobias Gronbach

04/04/2022, 12:19 AM
Modifier.weight(1f) could also work
a

Albert Chang

04/04/2022, 12:24 AM
We are talking about forcing the children of a layout to fill max size from the parent size (i.e. without applying modifiers to children). If you can use modifiers on children, why don’t you use
Modifier.fillMaxSize()
?
z

zalewski.se

04/04/2022, 1:43 PM
propagateMinConstraints
and
fillMaxSize
doesn’t really work for me In my case, I would like to scale the view down to fit the container. So let’s assume the composable is just a
Column()
with an image and some text below it, depending on the text value and font size (which can vary a lot with accessibility settings) this view can grow significantly. In case it get’s bigger than the container, I would like it to automatically scale down (adjusting just the text size is not ok as I would like to keep proper ratio between an image size and the text size). Anyway I think I’m able to achieve it with
.aspectRatio(ratio)
.wrapContentHeight(unbounded = true)
.scale(scaleValue)
where proper
scaleValue
I can calculate based on the container size and my view size