From c58c9ae6b3cb40c1d0701cc689029a7b5e99639c Mon Sep 17 00:00:00 2001 From: Kyant0 Date: Sat, 27 Sep 2025 17:47:33 +0800 Subject: [PATCH] Fix content layer doesn't draw --- .../kyant/backdrop/DrawBackdropModifier.kt | 19 +++++-------------- .../java/com/kyant/backdrop/MutableDensity.kt | 15 --------------- 2 files changed, 5 insertions(+), 29 deletions(-) delete mode 100644 backdrop/src/main/java/com/kyant/backdrop/MutableDensity.kt diff --git a/backdrop/src/main/java/com/kyant/backdrop/DrawBackdropModifier.kt b/backdrop/src/main/java/com/kyant/backdrop/DrawBackdropModifier.kt index e76e687..db29ce3 100644 --- a/backdrop/src/main/java/com/kyant/backdrop/DrawBackdropModifier.kt +++ b/backdrop/src/main/java/com/kyant/backdrop/DrawBackdropModifier.kt @@ -25,6 +25,7 @@ import androidx.compose.ui.node.ModifierNodeElement import androidx.compose.ui.node.ObserverModifierNode import androidx.compose.ui.node.invalidateDraw import androidx.compose.ui.node.observeReads +import androidx.compose.ui.node.requireDensity import androidx.compose.ui.node.requireGraphicsContext import androidx.compose.ui.platform.InspectorInfo import androidx.compose.ui.unit.Constraints @@ -222,7 +223,6 @@ private class DrawBackdropNode( override val shouldAutoInvalidate: Boolean = false - private val mutableDensity = MutableDensity() private val effectScope = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { object : BackdropEffectScopeImpl() { @@ -247,7 +247,7 @@ private class DrawBackdropNode( onDrawBackdrop { with(backdrop) { drawBackdrop( - density = mutableDensity, + density = this@onDrawBackdrop, coordinates = layoutCoordinates, layerBlock = layerBlock ) @@ -258,7 +258,7 @@ private class DrawBackdropNode( val layer = backdropGraphicsLayer if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && layer != null) { layer.record( - density = mutableDensity, + density = requireDensity(), layoutDirection = layoutDirection, size = size.toIntSize(), block = recordBackdropBlock @@ -271,11 +271,7 @@ private class DrawBackdropNode( private val drawContentLayer: ContentDrawScope.() -> Unit = draw@{ val contentLayer = contentGraphicsLayer if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && contentLayer != null) { - contentLayer.record( - density = mutableDensity, - layoutDirection = layoutDirection, - size = size.toIntSize() - ) { this@draw.onDrawContent() } + contentLayer.record { this@draw.onDrawContent() } drawLayer(contentLayer) } } @@ -291,7 +287,6 @@ private class DrawBackdropNode( } override fun ContentDrawScope.draw() { - mutableDensity.update(this) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { if (effectScope != null && effectScope.update(this)) { updateEffects() @@ -305,11 +300,7 @@ private class DrawBackdropNode( if (drawContent) drawContent() onDrawFront?.invoke(this) - exportedBackdrop?.graphicsLayer?.record( - density = mutableDensity, - layoutDirection = layoutDirection, - size = size.toIntSize() - ) { + exportedBackdrop?.graphicsLayer?.record { onDrawBehind?.invoke(this) drawBackdropLayer() onDrawSurface?.invoke(this) diff --git a/backdrop/src/main/java/com/kyant/backdrop/MutableDensity.kt b/backdrop/src/main/java/com/kyant/backdrop/MutableDensity.kt deleted file mode 100644 index 85478c7..0000000 --- a/backdrop/src/main/java/com/kyant/backdrop/MutableDensity.kt +++ /dev/null @@ -1,15 +0,0 @@ -package com.kyant.backdrop - -import androidx.compose.ui.unit.Density - -internal class MutableDensity : Density { - - override var density: Float = 1f - - override var fontScale: Float = 1f - - fun update(density: Density) { - this.density = density.density - fontScale = density.fontScale - } -}