Skip to content

Commit

Permalink
Small tidy ups ready for release (#463)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbanes authored Jan 6, 2025
1 parent ad507f0 commit 690ab3f
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 26 deletions.
1 change: 0 additions & 1 deletion haze/api/api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion haze/src/commonMain/kotlin/dev/chrisbanes/haze/Bitmask.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
39 changes: 17 additions & 22 deletions haze/src/commonMain/kotlin/dev/chrisbanes/haze/Haze.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,17 @@ import androidx.compose.ui.unit.dp

@Stable
class HazeState {

@Suppress("PropertyName")
internal val _areas = mutableStateListOf<HazeArea>()
private val _areas = mutableStateListOf<HazeArea>()
val areas: List<HazeArea> 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
Expand Down Expand Up @@ -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(")")
}
}

Expand Down Expand Up @@ -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].
*
Expand Down
7 changes: 7 additions & 0 deletions haze/src/commonMain/kotlin/dev/chrisbanes/haze/HazeChild.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)?
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class HazeSourceNode(

override fun onAttach() {
log(TAG) { "onAttach. Adding HazeArea: $area" }
state._areas.add(area)
state.addArea(area)
onObservedReadsChanged()
}

Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 690ab3f

Please sign in to comment.