Home > Net >  Is it possible to display animated gif in jetpack?
Is it possible to display animated gif in jetpack?

Time:02-17

I'm trying to implement a gif in my splash screen using jetpack.Tried this one as suggested but no output .What am I missing?

val context = LocalContext.current

val imageLoader = ImageLoader.Builder(context)
    .componentRegistry {
        if (SDK_INT >= 28) {
            add(ImageDecoderDecoder(context))
        } else {
            add(GifDecoder())
        }
    }
    .build()


Image(
    painter = rememberImagePainter(
        imageLoader = imageLoader,
        data = R.id.mygif,
        builder = {
            size(OriginalSize)
        }
    ),
    contentDescription = null,
    modifier = Modifier
        .padding(top = 100.dp)
)

CodePudding user response:

Apparently Compose is not supporting gif out of the box, I could not find any reference to gif files in the docs. However, one of the popular library out there to deal with gifs is Coil.

-> Here is coil for Compose: https://coil-kt.github.io/coil/compose/

-> Make sure to add the gif extension: https://coil-kt.github.io/coil/gifs/

-> You will have to override the ImageLoader and add the gif extension: https://coil-kt.github.io/coil/compose/#localimageloader

  • Related