Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement enabled feature #40

Merged
merged 1 commit into from
Sep 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
Loading