skydoves / landscapist

🌻 A pluggable, highly optimized Jetpack Compose and Kotlin Multiplatform image loading library that fetches and displays network images with Glide, Coil, and Fresco.
https://skydoves.github.io/landscapist/
Apache License 2.0
2.15k stars 114 forks source link

[Coil] Placeholder plugin duplicates parent's padding #317

Closed wisemuji closed 1 year ago

wisemuji commented 1 year ago

Please complete the following information:

Describe the Bug: When I ran as follows, I found that Placeholder runs in a smaller size compared to the original image.

CoilImage(
    imageModel = { "https://picsum.photos/200" },
    component = rememberImageComponent {
        +PlaceholderPlugin.Loading(placeholder)
        +PlaceholderPlugin.Failure(placeholder)
    },
    imageOptions = ImageOptions(
        contentScale = ContentScale.Crop,
        alignment = Alignment.Center,
    ),
    modifier = Modifier
        .padding(16.dp)
        .size(100.dp)
        .clip(CircleShape),
)
Placeholder Original Image

After some workarounds, I found out that Modifier.padding was the cause, and when I put the Box on the outside of CoilImage and padded it, it worked as expected.

Box(modifier = Modifier.padding(16.dp)) {
    CoilImage(
        ...
        modifier = Modifier
            .size(100.dp)
            .clip(CircleShape),
    )
}

Expected Behavior: The placeholder image must have the same size as the original image.

skydoves commented 1 year ago

@wisemuji Thank you for bringing this issue to my attention! Originally, the plan was to emit the modifiers into composable plugins, but it seems to be a little bit buggy. Rest assured, the fix will be included in the upcoming release (2.2.4). I will keep you informed as soon as the upcoming version is released.

skydoves commented 1 year ago

@wisemuji The new version 2.2.5 has been released. Please build your project again with this new release, and make sure it works well as expected.

wisemuji commented 1 year ago

@skydoves It works as expected in 2.2.5! Thank you for fixing them this fast. I really appreciate it 🙇

skydoves commented 1 year ago

I'm happy to hear that. Cheers!