user-interfaceandroid-jetpack-composesplash-screengif

Is it possible to display animated gif in jetpack?


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

Solution

  • 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