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?
dev mobile is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
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.