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

Joseph Hawkes-Cates

06/10/2022, 9:22 PM
Is there a way to set the modifier on an Image so it is full size unless it’s bigger than X% of the bounds at which point we scale it to fit within that percentage of the layout?
🤔 1
Kind of like weight, but I don’t want it to take up more space than it’s actual size if the screen is big enough.
b

Berkeli Alashov

06/11/2022, 4:06 AM
Not sure if it's gonna work but I would try:
Copy code
// max 5% larger than available width (layout or screen width)
val maxWidth = availableWidth * (1.05)
val modifier = Modifier.widthIn(min=availableWidth, max=maxWidth)
j

Joseph Hawkes-Cates

06/11/2022, 5:00 PM
Yeah, that should work. I thought of that yesterday, but I don’t have the available height immediately handy. Easy enough to get, though. Thanks!
z

Zach Klippenstein (he/him) [MOD]

06/13/2022, 3:37 PM
Probably a good time for a custom layout modifier (don't use BoxWithConstraints)
j

Joseph Hawkes-Cates

06/13/2022, 4:55 PM
Yeah, thanks! I was thinking layout modifier may be the best approach. I’m up against a timeline at the moment so I went with just using
weight(0.4f, fill=false)
so it fills 40% of the view up until that exceeds the actual size of the image. The only downside is on smaller screens the image gets a bit smaller than we’d like, but it’s good enough for us for now.
2 Views