From f93ac43e8060158e71addf6f56243a3ff778e54d Mon Sep 17 00:00:00 2001 From: Colin White Date: Wed, 13 Nov 2024 19:28:53 -0800 Subject: [PATCH] Fold RequestDelegate.assertActive into RequestDelegate.start. (#2683) --- .../kotlin/coil3/request/RequestDelegate.android.kt | 6 +++--- coil-core/src/commonMain/kotlin/coil3/RealImageLoader.kt | 2 +- .../src/commonMain/kotlin/coil3/request/RequestDelegate.kt | 4 ---- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/coil-core/src/androidMain/kotlin/coil3/request/RequestDelegate.android.kt b/coil-core/src/androidMain/kotlin/coil3/request/RequestDelegate.android.kt index ce8b3527f6..b095b420a3 100644 --- a/coil-core/src/androidMain/kotlin/coil3/request/RequestDelegate.android.kt +++ b/coil-core/src/androidMain/kotlin/coil3/request/RequestDelegate.android.kt @@ -52,14 +52,14 @@ internal class ViewTargetRequestDelegate( imageLoader.enqueue(initialRequest) } - override fun assertActive() { + override fun start() { + // Cancel the request before starting if the view is not attached. + // It will be restarted automatically when the view is attached. if (!target.view.isAttachedToWindow) { target.view.requestManager.setRequest(this) throw CancellationException("'ViewTarget.view' must be attached to a window.") } - } - override fun start() { lifecycle?.addObserver(this) if (target is LifecycleObserver) { lifecycle?.removeAndAddObserver(target) diff --git a/coil-core/src/commonMain/kotlin/coil3/RealImageLoader.kt b/coil-core/src/commonMain/kotlin/coil3/RealImageLoader.kt index 7a6e157b79..aca0ebcb36 100644 --- a/coil-core/src/commonMain/kotlin/coil3/RealImageLoader.kt +++ b/coil-core/src/commonMain/kotlin/coil3/RealImageLoader.kt @@ -94,7 +94,7 @@ internal class RealImageLoader( request = initialRequest, job = coroutineContext.job, findLifecycle = type == REQUEST_TYPE_ENQUEUE, - ).apply { assertActive() } + ) // Apply this image loader's defaults and other configuration to this request. val request = requestService.updateRequest(initialRequest) diff --git a/coil-core/src/commonMain/kotlin/coil3/request/RequestDelegate.kt b/coil-core/src/commonMain/kotlin/coil3/request/RequestDelegate.kt index 0e1696ad5a..b4d02fc1d8 100644 --- a/coil-core/src/commonMain/kotlin/coil3/request/RequestDelegate.kt +++ b/coil-core/src/commonMain/kotlin/coil3/request/RequestDelegate.kt @@ -1,14 +1,10 @@ package coil3.request import kotlin.jvm.JvmInline -import kotlinx.coroutines.CancellationException import kotlinx.coroutines.Job internal interface RequestDelegate { - /** Throw a [CancellationException] if this request should be cancelled before starting. */ - fun assertActive() {} - /** Register all lifecycle observers. */ fun start() {}