From c61ed8b178170d7b800e180e3c9f5cb629322bc5 Mon Sep 17 00:00:00 2001 From: Afsal Date: Tue, 23 Jun 2026 11:27:01 +0800 Subject: [PATCH 1/3] =?UTF-8?q?fix:=20=F0=9F=90=9B=20Aninations=20disappea?= =?UTF-8?q?r=20on=20recycler=20view=20after=20scroll?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/widget/DotLottieAnimation.kt | 35 +++++++++++++++++-- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/dotlottie/src/main/java/com/lottiefiles/dotlottie/core/widget/DotLottieAnimation.kt b/dotlottie/src/main/java/com/lottiefiles/dotlottie/core/widget/DotLottieAnimation.kt index 5a4e758..8815ccd 100644 --- a/dotlottie/src/main/java/com/lottiefiles/dotlottie/core/widget/DotLottieAnimation.kt +++ b/dotlottie/src/main/java/com/lottiefiles/dotlottie/core/widget/DotLottieAnimation.kt @@ -35,6 +35,7 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job import kotlinx.coroutines.SupervisorJob import kotlinx.coroutines.cancel +import kotlinx.coroutines.isActive import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import com.dotlottie.dlplayer.Config as DLConfig @@ -70,7 +71,7 @@ class DotLottieAnimation @JvmOverloads constructor( private var height: Int = 0 private var mConfig: Config? = null private var mLottieDrawable: DotLottieDrawable? = null - private val coroutineScope = CoroutineScope(SupervisorJob()) + private var coroutineScope = CoroutineScope(SupervisorJob()) private var setupConfigJob: Job? = null private var setupDrawableJob: Job? = null private var layoutListener: ViewTreeObserver.OnGlobalLayoutListener? = null @@ -337,8 +338,8 @@ class DotLottieAnimation @JvmOverloads constructor( layoutListener = object : ViewTreeObserver.OnGlobalLayoutListener { override fun onGlobalLayout() { if (width > 0 && height > 0) { - // Start animation setup only when dimensions are available - setupDotLottieDrawable() + // Start animation setup only when dimensions are available. + setupDrawableIfNeeded() // Remove the listener to avoid redundant calls removeLayoutListener() } @@ -365,8 +366,24 @@ class DotLottieAnimation @JvmOverloads constructor( } + private fun ensureScopeActive() { + if (!coroutineScope.isActive) { + coroutineScope = CoroutineScope(SupervisorJob()) + } + } + + private fun setupDrawableIfNeeded() { + if (mLottieDrawable != null) return + if (setupConfigJob?.isActive == true || setupDrawableJob?.isActive == true) return + when { + mConfig != null -> setupConfig() + ::attributes.isInitialized && attributes.src.isNotBlank() -> setupDotLottieDrawable() + } + } + private fun setupConfig() { val config = mConfig ?: return + ensureScopeActive() setupConfigJob?.cancel() setupConfigJob = coroutineScope.launch { runCatching { @@ -416,6 +433,7 @@ class DotLottieAnimation @JvmOverloads constructor( } private fun setupDotLottieDrawable() { + ensureScopeActive() setupDrawableJob?.cancel() setupDrawableJob = coroutineScope.launch { runCatching { @@ -482,6 +500,17 @@ class DotLottieAnimation @JvmOverloads constructor( } } + override fun onAttachedToWindow() { + super.onAttachedToWindow() + if (mLottieDrawable == null) { + if (width > 0 && height > 0) { + setupDrawableIfNeeded() + } else if (layoutListener == null) { + waitForLayout() + } + } + } + override fun onDetachedFromWindow() { super.onDetachedFromWindow() removeLayoutListener() From 248c3119b8405d04fc9d5d63ceacf76109f31548 Mon Sep 17 00:00:00 2001 From: Afsal Date: Tue, 23 Jun 2026 11:28:12 +0800 Subject: [PATCH 2/3] =?UTF-8?q?chore:=20=F0=9F=A4=96=20bumped=20version=20?= =?UTF-8?q?to=200.14.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dotlottie/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dotlottie/build.gradle.kts b/dotlottie/build.gradle.kts index 895473f..bfe133f 100644 --- a/dotlottie/build.gradle.kts +++ b/dotlottie/build.gradle.kts @@ -37,7 +37,7 @@ dotlottieRust { } group = "com.github.LottieFiles" -version = "0.14.0" +version = "0.14.1" android { namespace = "com.lottiefiles.dotlottie.core" From 67543e57538436830e88b521a78710ce26e75bd9 Mon Sep 17 00:00:00 2001 From: Afsal Date: Tue, 23 Jun 2026 15:56:37 +0800 Subject: [PATCH 3/3] =?UTF-8?q?fix:=20=F0=9F=90=9B=20pr=20comment?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/lottiefiles/dotlottie/core/widget/DotLottieAnimation.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dotlottie/src/main/java/com/lottiefiles/dotlottie/core/widget/DotLottieAnimation.kt b/dotlottie/src/main/java/com/lottiefiles/dotlottie/core/widget/DotLottieAnimation.kt index 8815ccd..cbbdeeb 100644 --- a/dotlottie/src/main/java/com/lottiefiles/dotlottie/core/widget/DotLottieAnimation.kt +++ b/dotlottie/src/main/java/com/lottiefiles/dotlottie/core/widget/DotLottieAnimation.kt @@ -444,6 +444,8 @@ class DotLottieAnimation @JvmOverloads constructor( DotLottieUtils.getContent(context, DotLottieSource.Asset(attributes.src)) } + if (!isActive || !this@DotLottieAnimation.isAttachedToWindow) return@launch + mLottieDrawable = DotLottieDrawable( animationData = content, width = width,