I need a callback when the Gif finish animating
@Composable
fun AsyncGIFLoader(
) {
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.mygif).apply(block = {
size(Size.ORIGINAL)
}).build(), imageLoader = imageLoader
),
contentDescription = null,
modifier = Modifier.fillMaxWidth(),
)
}
i tried target that displays when image loader shows onSuccess, onError but i it didn't show when Gif finish animating, it calls when the gif image loads successfully.
is there a way to detect when the Gif finish animating?
The ImageRequest.Builder has an onAnimationEnd method (when using io.coil-kt:coil-gif):
rememberAsyncImagePainter(
model = ImageRequest.Builder(context)
.data(data = R.drawable.mygif)
.size(Size.ORIGINAL)
.onAnimationEnd { /*...*/ }
.build(),
imageLoader = imageLoader,
)
From the docs:
Set the callback to be invoked at the end of the animation if the result is an animated Drawable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With