coil-kt/coil

Placeholder affects image scaling when we use CrossfadeTransition and the placeholder image is larger

Open

#1688 opened on Mar 26, 2023

View on GitHub
 (3 comments) (3 reactions) (0 assignees)Kotlin (11,779 stars) (757 forks)batch import
help wanted

Description

Describe the bug When I have CrossfadeTransition.Factory() passed to the ImageLoader, I get a different final scale in an AsyncImage if it uses a placeholder that is larger than the final image. Everything is fine if I remove the crossfade, remove the placeholder, or use a placeholder that matches the size of the final image.

To Reproduce Minimum reprodicible example here: https://github.com/tfcporciuncula/coil-crossfade

You can clone the repo, run the code, and observe that:

  • If we keep CrossfadeTransition.Factory() around, we'll get different scaling results depending on whether we keep or remove the placeholder.
  • If we remove CrossfadeTransition.Factory(), the scaling is the same regardless if we have the placeholder or not.
  • If we keep CrossfadeTransition.Factory() but change the placeholder from R.drawable.placeholder_larger to R.drawable.placeholder, which has the exact same size as our final imagem, then everything is fine.

Logs/Screenshots

Image on the left is what we get with crossfade and the large placeholder. Image on the right is the correct scaling which we get by either removing the crossfade, removing the placeholder, or using a placeholder that matches the final image size.

1 2

We're using ContentScale.Crop above, but we can move to ContentScale.Fit to make the difference more visible:

w c

Version Coil 2.3.0, reproduced on a Pixel 4 running Android 13 and on a Pixel 6 emulator (1080x2400 420dpi) running Android 10 (screenshots from the latter).

Contributor guide