airbnb / lottie-android

Render After Effects animations natively on Android and iOS, Web, and React Native
http://airbnb.io/lottie/
Apache License 2.0
34.95k stars 5.4k forks source link

LottieTask listener triggers twice if a cached url is retrieved a second time #2449

Closed awenger closed 6 months ago

awenger commented 8 months ago

Repo case

Problem: Listeners attached to a LottieTask trigger twice if the url is already cached from a previous request.

Case 1

Steps To Reproduce Steps to reproduce the behavior:

This behaviour becomes a problem if the callback is wrapped within a suspendCancellableCoroutine (here)

Leelion96 commented 8 months ago

val task = if ((data.startsWith("http://") || data.startsWith("https://"))) { LottieCompositionFactory.fromUrl(lottieView.context, data) } else { LottieCompositionFactory.fromAsset(lottieView.context, data) } val loadResultListener = LottieListener { composition -> log("Lottie onLoadSuccess") } val loadFailureListener = LottieListener { exception -> log("Lottie onLoadFail: $exception") } task.result?.value?.let { loadResultListener.onResult(it) return } task.result?.exception?.let { loadFailureListener.onResult(it) return } task.addListener(loadResultListener).addFailureListener(loadFailureListener)