From b1c6076bbbc3cc46d45f35924070cb11be44ff90 Mon Sep 17 00:00:00 2001 From: Sam Judd Date: Sun, 1 Oct 2023 19:19:00 -0700 Subject: [PATCH] Avoid drawing placeholder when it shouldn't be used --- .../glide/integration/compose/GlideModifier.kt | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/integration/compose/src/main/java/com/bumptech/glide/integration/compose/GlideModifier.kt b/integration/compose/src/main/java/com/bumptech/glide/integration/compose/GlideModifier.kt index a193f844b8..1d43a7496d 100644 --- a/integration/compose/src/main/java/com/bumptech/glide/integration/compose/GlideModifier.kt +++ b/integration/compose/src/main/java/com/bumptech/glide/integration/compose/GlideModifier.kt @@ -332,10 +332,15 @@ internal class GlideNode : DrawModifierNode, LayoutModifierNode, SemanticsModifi override fun ContentDrawScope.draw() { if (draw) { val drawPlaceholder = transition.drawPlaceholder ?: DoNotTransition.drawPlaceholder - placeholder?.let { painter -> - drawContext.canvas.withSave { - placeholderPositionAndSize = drawOne(painter, placeholderPositionAndSize) { size -> - drawPlaceholder.invoke(this, painter, size, alpha, colorFilter) + // If we're only showing the placeholder, it should just be drawn as the primary image. + // If we've loaded a full image and we have a placeholder, then we should try to draw both so + // that the transition can decide what to do. + if (placeholder != primary && transition != DoNotTransition) { + placeholder?.let { painter -> + drawContext.canvas.withSave { + placeholderPositionAndSize = drawOne(painter, placeholderPositionAndSize) { size -> + drawPlaceholder.invoke(this, painter, size, alpha, colorFilter) + } } } }