https://kotlinlang.org logo
#compose
Title
# compose
a

Alexander Maryanovsky

03/06/2023, 3:05 PM
Suppose I have a
Box(Modifier.fillMaxSize())
and I want to place some content into it such that the content is centered and either takes its intrinsic size (if it has one) or fills the entire box if it doesn’t (like in the case of lazy layouts). Is there a way to do that?
Modifier.size(IntrinsicSize.Min/Max)
throws about being unable to ask a
SubcomposeLayout
about its intrinsic size.
m

mgrazianodecastro

03/06/2023, 3:09 PM
maybe
BoxWithConstraints
with a
hightIn, widthIn, sizeIn, ratio
choice combination?
a

Alexander Maryanovsky

03/06/2023, 3:12 PM
If I understand correctly, BoxWithConstraints lets me access the incoming constraints, which doesn’t really help for sizing the child content according to its own preferences. No?
m

mgrazianodecastro

03/06/2023, 3:29 PM
(edited) I imagined the child having a modifier like:
Modifier.height(height)
, where
height
is calculated considering whether it has a defined height or not, like
maxHeight
in place of a height. But maybe that's not enough for you 😅
5 Views