From dc6844e17e322bb18183abddae92c15f20aa1802 Mon Sep 17 00:00:00 2001 From: skydoves Date: Sun, 15 Sep 2024 14:08:51 +0900 Subject: [PATCH] Implement enabled feature --- cloudy/api/cloudy.api | 2 +- .../main/kotlin/com/skydoves/cloudy/CloudyModifierNode.kt | 6 ++++++ cloudy/src/main/kotlin/com/skydoves/cloudy/CloudyState.kt | 5 +++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/cloudy/api/cloudy.api b/cloudy/api/cloudy.api index 12b6e49..8cdcd6c 100644 --- a/cloudy/api/cloudy.api +++ b/cloudy/api/cloudy.api @@ -1,5 +1,5 @@ public final class com/skydoves/cloudy/CloudyModifierNodeKt { - public static final fun cloudy (Landroidx/compose/ui/Modifier;ILandroidx/compose/ui/graphics/layer/GraphicsLayer;Lkotlin/jvm/functions/Function1;Landroidx/compose/runtime/Composer;II)Landroidx/compose/ui/Modifier; + public static final fun cloudy (Landroidx/compose/ui/Modifier;IZLandroidx/compose/ui/graphics/layer/GraphicsLayer;Lkotlin/jvm/functions/Function1;Landroidx/compose/runtime/Composer;II)Landroidx/compose/ui/Modifier; } public abstract interface class com/skydoves/cloudy/CloudyState { diff --git a/cloudy/src/main/kotlin/com/skydoves/cloudy/CloudyModifierNode.kt b/cloudy/src/main/kotlin/com/skydoves/cloudy/CloudyModifierNode.kt index d3a62a0..136ddad 100644 --- a/cloudy/src/main/kotlin/com/skydoves/cloudy/CloudyModifierNode.kt +++ b/cloudy/src/main/kotlin/com/skydoves/cloudy/CloudyModifierNode.kt @@ -46,6 +46,7 @@ import kotlinx.coroutines.runBlocking * History: The [blur] modifier supports only Android 12 and higher, and [RenderScript] was also deprecated. * * @param radius Radius of the blur along both the x and y axis. + * @param enabled Enabling the blur effects. * @param graphicsLayer The graphic layer that records the original content and get the bitmap information. * This parameter should be used when you need to remain with the same graphic layer for the dynamically * updated Composable functions, such as Lazy Lists. @@ -54,9 +55,14 @@ import kotlinx.coroutines.runBlocking @Composable public fun Modifier.cloudy( radius: Int = 10, + enabled: Boolean = true, graphicsLayer: GraphicsLayer = rememberGraphicsLayer(), onStateChanged: (CloudyState) -> Unit = {} ): Modifier { + if (!enabled) { + return this + } + // This local inspection preview only works over Android 12. if (LocalInspectionMode.current) { return this.blur(radius = radius.dp) diff --git a/cloudy/src/main/kotlin/com/skydoves/cloudy/CloudyState.kt b/cloudy/src/main/kotlin/com/skydoves/cloudy/CloudyState.kt index fd59c90..a187137 100644 --- a/cloudy/src/main/kotlin/com/skydoves/cloudy/CloudyState.kt +++ b/cloudy/src/main/kotlin/com/skydoves/cloudy/CloudyState.kt @@ -16,6 +16,7 @@ package com.skydoves.cloudy import android.graphics.Bitmap +import androidx.compose.runtime.Immutable import androidx.compose.runtime.Stable /** Represents the state of [cloudy] composable function. */ @@ -23,14 +24,18 @@ import androidx.compose.runtime.Stable public sealed interface CloudyState { /** Represents the state of [cloudy] process doesn't started. */ + @Stable public data object Nothing : CloudyState /** Represents the state of [cloudy] process is ongoing. */ + @Stable public data object Loading : CloudyState /** Represents the state of [cloudy] process is successful. */ + @Immutable public data class Success(public val bitmap: Bitmap?) : CloudyState /** Represents the state of [cloudy] process is failed. */ + @Immutable public data class Error(val throwable: Throwable) : CloudyState }