Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KamelImage fills up max size #94

Open
zeroeightysix opened this issue Feb 18, 2024 · 5 comments
Open

KamelImage fills up max size #94

zeroeightysix opened this issue Feb 18, 2024 · 5 comments

Comments

@zeroeightysix
Copy link

Rather counterintuitively, and annoyingly, KamelImage without a Modifier to restrict its size will consume all space it can get due to this default modifier:

val onSuccess: @Composable (BoxScope.(Painter) -> Unit) = { painter ->
Image(
painter,
contentDescription,
Modifier.fillMaxSize(),
alignment,
contentScale,
alpha,
colorFilter
)

This leads to it being the case that if you include any image in an unbounded box that the entire UI just becomes that image. For our usecase, we have a very wide banner image that is supposed to fill up the parent's entire width but not the height. This default prevents that from happening 🙁

Can't we make the inner Image have no modifier?

@luca992
Copy link
Member

luca992 commented Feb 18, 2024

@zeroeightysix So that modifier will actually cause it to fill the size of KamelImageBox. and the modifier here lets you apply whatever modifiers you want to the box. Is that not working for you?

Also you can always make your own version of KamelImage using KamelImageBox if you need some non-standard behavior

@zeroeightysix
Copy link
Author

zeroeightysix commented Feb 18, 2024

@zeroeightysix So that modifier will actually cause it to fill the size of KamelImageBox. and the modifier here lets you apply whatever modifiers you want to the box. Is that not working for you?

Also you can always make your own version of KamelImage using KamelImageBox if you need some non-standard behavior

As the box sizes to fit its contents, it will grow larger than the image dimensions themselves.

You'd expect, without any modifiers, for the box to be the same size as the actual image, tightly wrapping around it. Instead, both the box and inner Image take up more space than is required to display the image; is that intentional?

@luca992
Copy link
Member

luca992 commented Feb 19, 2024

Yeah I suppose it makes more sense to display an image in its actual size by default. I think it should just work that way if I removed that modifier... The only thing I'm worried about is that it may cause issues with contentScale. I'd have to check I think

@wuujcik
Copy link

wuujcik commented Jun 27, 2024

I have the same issue. I'm loading image that can have basically any dimentions and I want the contentScale to adjust the size to hardcoded height of 50.dp, but the below code does not wrap the width of the image, but uses the whole width of the Row in which it is placed. In the same Row I need Spacer with weight (to take any space left) and some other items on the right, so I really need the width to be taken from scaling the content, which does not happen right now

KamelImage(
    resource = asyncPainterResource(logoUrl),
    modifier = Modifier
        .height(50.dp)
        .wrapContentWidth(),
    contentDescription = null,
    contentScale = ContentScale.FillHeight,
    alignment = Alignment.CenterStart

I was able to resove my issue by using custom KamelImageBox, but I find this default behaviour to be counter-intuitive.

@luca992
Copy link
Member

luca992 commented Jun 28, 2024

If you want to make a proposal as a pr with your custom kamel image I can take a look and we can go from there @wuujcik

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants