Hi, How to create an animated icon in KMP Compose?...
# compose-desktop
z
Hi, How to create an animated icon in KMP Compose?
AnimatedImageVector.animatedVectorResource()
and
rememberAnimatedVectorPainter()
in Android cannot be used in KMP Desktop 😢
m
You can use a GIF
k
how ? Coil-gif only shares this example and nothing else:
Copy code
@Composable
fun GifImage(
    modifier: Modifier = Modifier,
) {
    val context = LocalContext.current
    val imageLoader = ImageLoader.Builder(context)
        .components {
            if (SDK_INT >= 28) {
                add(ImageDecoderDecoder.Factory())
            } else {
                add(GifDecoder.Factory())
            }
        }
        .build()
    Image(
        painter = rememberAsyncImagePainter(
            ImageRequest.Builder(context).data(data = R.drawable.YOUR_GIF_HERE).apply(block = {
                size(Size.ORIGINAL)
            }).build(), imageLoader = imageLoader
        ),
        contentDescription = null,
        modifier = modifier.fillMaxWidth(),
    )
}
this thing doesn't have anything to do with Compose Desktop. I can't find any resource on playing GIF on Desktop. Initially I have an mp4 video which is an HD 10 second loop of a rotating earth, turning this into GIF is slightly expensive but it's better than trying to use the retardedd experimental JB video player that captures all focus and mouse clicks and doesn't let you disable it via any parameter.
m
Here is the AnimatedImage component that plays GIFs: https://github.com/JetBrains/compose-multiplatform/tree/master/components/AnimatedImage It's a separate dependency
🙌 1