From 690ab3fd6ac66b42aae364df59a9848cb1ddc2ed Mon Sep 17 00:00:00 2001 From: Chris Banes Date: Mon, 6 Jan 2025 15:16:13 +0000 Subject: [PATCH] Small tidy ups ready for release (#463) --- haze/api/api.txt | 1 - .../kotlin/dev/chrisbanes/haze/Bitmask.kt | 2 +- .../kotlin/dev/chrisbanes/haze/Haze.kt | 39 ++++++++----------- .../kotlin/dev/chrisbanes/haze/HazeChild.kt | 7 ++++ .../dev/chrisbanes/haze/HazeSourceNode.kt | 4 +- 5 files changed, 27 insertions(+), 26 deletions(-) diff --git a/haze/api/api.txt b/haze/api/api.txt index 2b775aed..b81652ab 100644 --- a/haze/api/api.txt +++ b/haze/api/api.txt @@ -30,7 +30,6 @@ package dev.chrisbanes.haze { method public boolean blurEnabled(); method public float getBlurRadius(); method public dev.chrisbanes.haze.HazeStyle style(long backgroundColor, optional dev.chrisbanes.haze.HazeTint tint, optional float blurRadius, optional float noiseFactor); - method @Deprecated public dev.chrisbanes.haze.HazeStyle style(optional long backgroundColor, long tint, optional float blurRadius, optional float noiseFactor); method public dev.chrisbanes.haze.HazeTint tint(long color); property public final float blurRadius; field public static final dev.chrisbanes.haze.HazeDefaults INSTANCE; diff --git a/haze/src/commonMain/kotlin/dev/chrisbanes/haze/Bitmask.kt b/haze/src/commonMain/kotlin/dev/chrisbanes/haze/Bitmask.kt index c49e1b10..ceb298a9 100644 --- a/haze/src/commonMain/kotlin/dev/chrisbanes/haze/Bitmask.kt +++ b/haze/src/commonMain/kotlin/dev/chrisbanes/haze/Bitmask.kt @@ -6,7 +6,7 @@ package dev.chrisbanes.haze import kotlin.jvm.JvmInline @JvmInline -internal value class Bitmask(internal val value: Int = 0) { +internal value class Bitmask(private val value: Int = 0) { operator fun plus(flag: Int): Bitmask = Bitmask(value or flag) operator fun minus(flag: Int): Bitmask = Bitmask(value and flag.inv()) operator fun contains(flag: Int): Boolean = (flag and value) == flag diff --git a/haze/src/commonMain/kotlin/dev/chrisbanes/haze/Haze.kt b/haze/src/commonMain/kotlin/dev/chrisbanes/haze/Haze.kt index de58c92c..a4793e77 100644 --- a/haze/src/commonMain/kotlin/dev/chrisbanes/haze/Haze.kt +++ b/haze/src/commonMain/kotlin/dev/chrisbanes/haze/Haze.kt @@ -24,11 +24,17 @@ import androidx.compose.ui.unit.dp @Stable class HazeState { - - @Suppress("PropertyName") - internal val _areas = mutableStateListOf() + private val _areas = mutableStateListOf() val areas: List get() = _areas.toList() + internal fun addArea(area: HazeArea) { + _areas += area + } + + internal fun removeArea(area: HazeArea) { + _areas -= area + } + @Deprecated("Inspect areas instead") var positionOnScreen: Offset get() = areas.firstOrNull()?.positionOnScreen ?: Offset.Unspecified @@ -76,14 +82,14 @@ class HazeArea { internal var contentDrawing = false - override fun toString(): String { - return "HazeArea(" + - "positionOnScreen=$positionOnScreen, " + - "size=$size, " + - "zIndex=$zIndex, " + - "contentLayer=$contentLayer, " + - "contentDrawing=$contentDrawing" + - ")" + override fun toString(): String = buildString { + append("HazeArea(") + append("positionOnScreen=$positionOnScreen, ") + append("size=$size, ") + append("zIndex=$zIndex, ") + append("contentLayer=$contentLayer, ") + append("contentDrawing=$contentDrawing") + append(")") } } @@ -137,17 +143,6 @@ object HazeDefaults { else -> color }.let(::HazeTint) - @Deprecated( - "Migrate to HazeTint for tint", - ReplaceWith("HazeStyle(backgroundColor, HazeTint(tint), blurRadius, noiseFactor)"), - ) - fun style( - backgroundColor: Color = Color.Unspecified, - tint: Color, - blurRadius: Dp = this.blurRadius, - noiseFactor: Float = this.noiseFactor, - ): HazeStyle = HazeStyle(backgroundColor, tint(backgroundColor), blurRadius, noiseFactor) - /** * Default [HazeStyle] for usage with [Modifier.hazeSource]. * diff --git a/haze/src/commonMain/kotlin/dev/chrisbanes/haze/HazeChild.kt b/haze/src/commonMain/kotlin/dev/chrisbanes/haze/HazeChild.kt index b8f1bc92..4f62abfa 100644 --- a/haze/src/commonMain/kotlin/dev/chrisbanes/haze/HazeChild.kt +++ b/haze/src/commonMain/kotlin/dev/chrisbanes/haze/HazeChild.kt @@ -154,6 +154,13 @@ interface HazeEffectScope { @ExperimentalHazeApi var inputScale: HazeInputScale + /** + * A block which controls whether this [hazeEffect] should draw the given [HazeArea]. + * + * When null, the default behavior is that this effect will only draw areas with a + * [HazeArea.zIndex] less than [ModifierLocalCurrentHazeZIndex]. + */ + @ExperimentalHazeApi var canDrawArea: ((HazeArea) -> Boolean)? } diff --git a/haze/src/commonMain/kotlin/dev/chrisbanes/haze/HazeSourceNode.kt b/haze/src/commonMain/kotlin/dev/chrisbanes/haze/HazeSourceNode.kt index af3793c3..2d986214 100644 --- a/haze/src/commonMain/kotlin/dev/chrisbanes/haze/HazeSourceNode.kt +++ b/haze/src/commonMain/kotlin/dev/chrisbanes/haze/HazeSourceNode.kt @@ -76,7 +76,7 @@ class HazeSourceNode( override fun onAttach() { log(TAG) { "onAttach. Adding HazeArea: $area" } - state._areas.add(area) + state.addArea(area) onObservedReadsChanged() } @@ -162,7 +162,7 @@ class HazeSourceNode( override fun onDetach() { log(TAG) { "onDetach. Removing HazeArea: $area" } area.reset() - state._areas.remove(area) + state.removeArea(area) } override fun onReset() {