Skip to content

Commit

Permalink
Fold RequestDelegate.assertActive into RequestDelegate.start. (#2683)
Browse files Browse the repository at this point in the history
  • Loading branch information
colinrtwhite authored Nov 14, 2024
1 parent c16f19b commit f93ac43
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion coil-core/src/commonMain/kotlin/coil3/RealImageLoader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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() {}

Expand Down

0 comments on commit f93ac43

Please sign in to comment.