Skip to content

Commit

Permalink
Fix Android Studio previews not rendering. (#2338)
Browse files Browse the repository at this point in the history
  • Loading branch information
colinrtwhite authored Jun 26, 2024
1 parent e0c93d9 commit f7c2622
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,12 @@ class AsyncImagePainter internal constructor(
if (previewHandler != null) {
// If we're in inspection mode use the preview renderer.
_input.mapLatest {
previewHandler.handle(it.imageLoader, it.request)
previewHandler.handle(it.imageLoader, updateRequest(it.request, isPreview = true))
}
} else {
// Else, execute the request as normal.
_input.mapLatest {
it.imageLoader.execute(updateRequest(it.request)).toState()
it.imageLoader.execute(updateRequest(it.request, isPreview = false)).toState()
}
}.collect(::updateState)
}
Expand All @@ -265,7 +265,7 @@ class AsyncImagePainter internal constructor(
}

/** Update the [request] to work with [AsyncImagePainter]. */
private fun updateRequest(request: ImageRequest): ImageRequest {
private fun updateRequest(request: ImageRequest, isPreview: Boolean): ImageRequest {
// Connect the size resolver to the draw scope if necessary.
val sizeResolver = request.sizeResolver
if (sizeResolver is DrawScopeSizeResolver) {
Expand All @@ -292,6 +292,9 @@ class AsyncImagePainter internal constructor(
// AsyncImagePainter scales the image to fit the canvas size at draw time.
precision(Precision.INEXACT)
}
if (isPreview) {
dispatcher(Dispatchers.Unconfined)
}
applyGlobalLifecycle()
}
.build()
Expand Down

0 comments on commit f7c2622

Please sign in to comment.