Skip to content

Commit

Permalink
Implement enabled feature
Browse files Browse the repository at this point in the history
  • Loading branch information
skydoves committed Sep 15, 2024
1 parent c33d924 commit dc6844e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cloudy/api/cloudy.api
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions cloudy/src/main/kotlin/com/skydoves/cloudy/CloudyState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,26 @@
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. */
@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
}

0 comments on commit dc6844e

Please sign in to comment.