diff --git a/haze/src/androidMain/kotlin/dev/chrisbanes/haze/HazeNode.android.kt b/haze/src/androidMain/kotlin/dev/chrisbanes/haze/HazeNode.android.kt index b8b372eb..34250f52 100644 --- a/haze/src/androidMain/kotlin/dev/chrisbanes/haze/HazeNode.android.kt +++ b/haze/src/androidMain/kotlin/dev/chrisbanes/haze/HazeNode.android.kt @@ -60,8 +60,8 @@ private val noiseTextureCache = lruCache(3) context(CompositionLocalConsumerModifierNode) private fun getNoiseTexture(noiseFactor: Float): Bitmap { - val cacheKey = (noiseFactor * 255).roundToInt() - val cached = noiseTextureCache[cacheKey] + val noiseAlphaInt = (noiseFactor * 255).roundToInt().coerceIn(0, 255) + val cached = noiseTextureCache[noiseAlphaInt] if (cached != null && !cached.isRecycled) { return cached } @@ -69,8 +69,8 @@ private fun getNoiseTexture(noiseFactor: Float): Bitmap { // We draw the noise with the given opacity val resources = currentValueOf(LocalContext).resources return BitmapFactory.decodeResource(resources, R.drawable.haze_noise) - .withAlpha(noiseFactor) - .also { noiseTextureCache.put(cacheKey, it) } + .withAlpha(noiseAlphaInt) + .also { noiseTextureCache.put(noiseAlphaInt, it) } } context(CompositionLocalConsumerModifierNode) @@ -155,9 +155,9 @@ private fun AndroidRenderEffect.withTint( * There might be a better way to do this via a [BlendMode], but none of the results looked as * good. */ -private fun Bitmap.withAlpha(alpha: Float): Bitmap { +private fun Bitmap.withAlpha(alpha: Int): Bitmap { val paint = android.graphics.Paint().apply { - this.alpha = (alpha * 255).roundToInt().coerceIn(0, 255) + this.alpha = alpha } return Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888).also { diff --git a/haze/src/commonMain/kotlin/dev/chrisbanes/haze/HazeChildNode.kt b/haze/src/commonMain/kotlin/dev/chrisbanes/haze/HazeChildNode.kt index fc252117..20ae24e5 100644 --- a/haze/src/commonMain/kotlin/dev/chrisbanes/haze/HazeChildNode.kt +++ b/haze/src/commonMain/kotlin/dev/chrisbanes/haze/HazeChildNode.kt @@ -135,7 +135,7 @@ class HazeChildNode( else -> Offset.Zero } - override var blurRadius: Dp = HazeDefaults.blurRadius + override var blurRadius: Dp = Dp.Unspecified set(value) { if (value != field) { log(TAG) { "blurRadius changed. Current: $field. New: $value" } @@ -144,7 +144,7 @@ class HazeChildNode( } } - override var noiseFactor: Float = HazeDefaults.noiseFactor + override var noiseFactor: Float = -1f set(value) { if (value != field) { log(TAG) { "noiseFactor changed. Current: $field. New: $value" }