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

CoilImage: Size modifier not working properly when drawable data is passed. #163

Closed
OliverRhyme opened this issue Dec 6, 2020 · 2 comments

Comments

@OliverRhyme
Copy link

I am trying to display a drawable via CoilImage but when setting its size whether via size or preferredSize the image is not centered properly and have seemed to be crop and not centered. Although I seemed to have found a slight workaround where you set CircleCropTransform and it will work just fine, or I can also remove the size modifier and let it set its own size. But I do not want the image to be cropped and also I want to be able to set the size.

Here is my code snippet and the image of what happens

CoilImage(
    data = remember {
        ContextCompat.getDrawable(
            context,
            R.mipmap.ic_launcher
        )!!
    }
    modifier = Modifier.preferredSize(100.dp)
)

image

Compose Version: 1.0.0-alpha08

@OliverRhyme OliverRhyme changed the title CoilImage: Size modifier not work properly when drawable data is passed. CoilImage: Size modifier not working properly when drawable data is passed. Dec 6, 2020
@chrisbanes
Copy link
Contributor

CoilImage is not meant to take a Drawable. The data parameter is there for you to tell Coil what image to load. If you want to load a drawable, you can do: CoilImage(R.mipmap.ic_launcher).

The fact that this drawn anything is undefined, so closing this.

@OliverRhyme
Copy link
Author

CoilImage is not meant to take a Drawable. The data parameter is there for you to tell Coil what image to load. If you want to load a drawable, you can do: CoilImage(R.mipmap.ic_launcher).

The fact that this drawn anything is undefined, so closing this.

AFAIK there is a Fetcher for the Drawable so I can pass it directly. Anyways I tried CoilImage(R.mipmap.ic_launcher) still the same output with my previous code. The image is still not centered and aligned if I set a modifier. It works fine if I don't set a modifier but I cannot set the size of the composable without the modifier. I also found that this bug only works with Drawable (id reference or actual object) and not with other images and the modifier works as expected.

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

2 participants