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 ce8b3527f..b095b420a 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 7a6e157b7..aca0ebcb3 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 0e1696ad5..b4d02fc1d 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() {}