coil-kt/coil

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

Open

#1,688 创建于 2023年3月26日

在 GitHub 查看
 (3 评论) (3 反应) (0 负责人)Kotlin (757 fork)batch import
help wanted

仓库指标

Star
 (11,779 star)
PR 合并指标
 (平均合并 20小时 14分钟) (30 天内合并 28 个 PR)

描述

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).

贡献者指南