Optimize for Android 12-, fix content backdrop doesn't have effects

This commit is contained in:
Kyant0 committed 2025-09-19 00:44:17 +08:00
1 parent 8821cdde60
commit b7aa21485f
3 files changed
+13 -10

No files matched your search

@@ -24,7 +24,6 @@ import androidx.compose.ui.node.requireGraphicsContext
import androidx.compose.ui.platform.InspectorInfo
import androidx.compose.ui.unit.Constraints
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.toIntSize
import com.kyant.backdrop.highlight.Highlight
import com.kyant.backdrop.highlight.HighlightElement
import com.kyant.backdrop.shadow.Shadow
@@ -188,19 +187,18 @@ private class ContentBackdropNode(
}
override fun ContentDrawScope.draw() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
if (!isCacheValid) {
observeReads { cacheDrawBlock() }
isCacheValid = true
}
}
onDrawBehind?.invoke(this)
graphicsLayer?.let { layer ->
layer.record(
density = this,
layoutDirection = layoutDirection,
size = size.toIntSize()
) {
val layer = graphicsLayer
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && layer != null) {
layer.record {
this@draw.drawContent()
}
@@ -214,6 +212,8 @@ private class ContentBackdropNode(
} else {
drawLayer(layer)
}
} else {
drawContent()
}
onDrawSurface?.invoke(this)
@@ -213,16 +213,18 @@ private class DrawBackdropNode(
}
override fun ContentDrawScope.draw() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
if (!isCacheValid) {
observeReads { cacheDrawBlock() }
isCacheValid = true
}
}
onDrawBehind?.invoke(this)
val layer = graphicsLayer
val recordBlock = recordBlock
if (layer != null && recordBlock != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && layer != null && recordBlock != null) {
layer.record(
density = this,
layoutDirection = layoutDirection,
@@ -230,6 +232,8 @@ private class DrawBackdropNode(
block = recordBlock
)
drawLayer(layer)
} else {
recordBlock?.invoke(this)
}
onDrawSurface?.invoke(this)
@@ -206,8 +206,7 @@ fun ControlCenterContent() {
.contentBackdrop(
{ ContinuousRoundedRectangle(40f.dp) },
highlight = glassHighlight,
shadow = null,
onDrawSurface = glassSurface
shadow = null
) {
refraction(12f.dp.toPx(), size.minDimension / 4f, true)
}