Is there a way to set the modifier on an Image so ...
# compose
j
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
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
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
Probably a good time for a custom layout modifier (don't use BoxWithConstraints)
j
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.