最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

android - Jetpack Compose Coil3 Disable GIF Animation For A Specific AsyncImage - Stack Overflow

programmeradmin3浏览0评论

Everything is fine with with introducing Coil-GIF into my Jetpack Compose project.

implementation("io.coil-kt.coil3:coil-gif:3.1.0")

Every .gif I add to my AsyncImage is animated fine. Great.

However, I have a specific place in my app where I don't want the GIF to animate but just show the first frame as static image. So just the same behavior as I wouldn't include the library.

The problem is that I don't know which image will be put into this place because I receive only an image URL from an external API. It can be either a .jpg, .png and so on or a .gif.

The coil-gif library is somehow automatically enabled even if I create a ImageLoader by myself via ImageLoader.Builder(context).build().

So my question is, how can I disable the animation just on a specific AsyncImage component?

Everything is fine with with introducing Coil-GIF into my Jetpack Compose project.

implementation("io.coil-kt.coil3:coil-gif:3.1.0")

Every .gif I add to my AsyncImage is animated fine. Great.

However, I have a specific place in my app where I don't want the GIF to animate but just show the first frame as static image. So just the same behavior as I wouldn't include the library.

The problem is that I don't know which image will be put into this place because I receive only an image URL from an external API. It can be either a .jpg, .png and so on or a .gif.

The coil-gif library is somehow automatically enabled even if I create a ImageLoader by myself via ImageLoader.Builder(context).build().

So my question is, how can I disable the animation just on a specific AsyncImage component?

Share Improve this question asked Mar 20 at 11:57 J. HeggJ. Hegg 2,2031 gold badge21 silver badges39 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

You can update the decoder in ImageLoader using BitmapFactoryDecoder Coil3 decode.

Something like this:

@Composable
fun GiftLoadingImage(
    modifier: Modifier = Modifier
) {
    val gifUrl = "https://www.easygifanimator/images/samples/sparkles.gif"

    val context = LocalContext.current
    val loader = ImageLoader.Builder(context)
        ponents {
            add(BitmapFactoryDecoder.Factory())
        }
        .build()
    AsyncImage(
        model = ImageRequest.Builder(context)
            .data(gifUrl)
            .build(),
        imageLoader = loader,
        contentDescription = null,
        modifier = Modifier
            .size(200.dp)
            .clip(RoundedCornerShape(6.dp)),
        contentScale = ContentScale.Crop
    )
}
发布评论

评论列表(0)

  1. 暂无评论