Cloudy

872

31

Jaewoong Eum

Added on December 21, 2024

Jetpack Compose blur effect library, which supports all Android versions.

Cloudy

Jetpack Compose blur effect library, which supports all Android versions.

Jaewoong Eum

README.md

Android Weekly Profile


☁️ Compose blur effect library, which falls back on to a CPU-based implementation to support older API levels.


The `blur` modifier supports only Android 12 and higher, and `RenderScript` APIs are deprecated starting in Android 12. Cloudy is the backport of the blur effect for Jetpack Compose.

Download

Version Catalog

If you're using Version Catalog, you can configure the dependency by adding it to your libs.versions.toml file as follows:

[versions]
#...
cloudy = "0.2.6"

[libraries]
#...
compose-cloudy = { module = "com.github.skydoves:cloudy", version.ref = "cloudy" }

Gradle

Add the dependency below to your module's build.gradle.kts file:

dependencies {
    implementation("com.github.skydoves:cloudy:0.2.6")
    
    // if you're using Version Catalog
    implementation(libs.compose.cloudy)
}

Usage

You can implement blur effect with Modifiy.cloudy() composable function as seen in the below:

Text(
  modifier = Modifier.cloudy(),
  text = "This text is blurred"
)

You can change the degree of the blur effect by changing the radius parameter of Modifier.cloudy() composable function.

Column(
  modifier = Modifier.cloudy(radius = 15)
) {
  Image(..)

  Text(
    modifier = Modifier
      .fillMaxWidth()
      .padding(8.dp),
    text = posterModel.name,
    fontSize = 40.sp,
    color = MaterialTheme.colors.onBackground,
    textAlign = TextAlign.Center
  )

  Text(
    modifier = Modifier
      .fillMaxWidth()
      .padding(8.dp),
    text = posterModel.description,
    color = MaterialTheme.colors.onBackground,
    textAlign = TextAlign.Center
  )
}

Observing Blurring Status

You can monitor the status of the blurring effect by using the onStateChanged parameter, which provides CloudyState. This allows you to observe and respond to changes in the blurring effect's state effectively.

GlideImage(
  modifier = Modifier
    .size(400.dp)
    .cloudy(
      radius = 25,
      onStateChanged = {
        // ..
      }
    ),
..

Maintaining Blurring Effect on Responsive Composable

The Modifier.cloudy captures the bitmap of the composable node under the hood. If you need to use the cloudy modifier as an item in lists or similar structures, you should provide the same graphic layer to ensure consistent rendering and performance.

val graphicsLayer = rememberGraphicsLayer()

LazyVerticalGrid(
  state = rememberLazyGridState(),
  columns = GridCells.Fixed(2)
) {
  itemsIndexed(key = { index, item -> item.id }, items = posters) { index, item ->
    HomePoster(
      poster = item,
      graphicsLayer = graphicsLayer
    )
  }
}

@Composable
private fun HomePoster(
  graphicsLayer: GraphicsLayer = rememberGraphicsLayer(),
  poster: Poster
) {

    ConstraintLayout {
      val (image, title, content) = createRefs()
      GlideImage(
        modifier = Modifier
          .cloudy(radius = 15, graphicsLayer = graphicsLayer)
          .aspectRatio(0.8f)
          .constrainAs(image) {
            centerHorizontallyTo(parent)
            top.linkTo(parent.top)
          }
          ..

Blur Effect with Network Images

You can easily implement blur effect with Landscapist, which is a Jetpack Compose image loading library that fetches and displays network images with Glide, Coil, and Fresco. For more information, see the Transformation section.

Find this repository useful? ❤

Support it by joining stargazers for this repository. ⭐
Also, follow me on GitHub for my next creations! 🤩

License

Designed and developed by 2022 skydoves (Jaewoong Eum)

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Related Content

kmPalette

A Compose multiplatform port for Androidx Palette. Generate a color palette from an image.
GitHubUpdated 2 days ago

Kaspresso

Kaspresso is a framework for native UI testing. Based on Espresso and UI Automator, it provides a wide range of additional useful features, such as flakiness control and faster execution of UI Automator commands.
GitHubUpdated 2 months ago

Silicone Calculator

🎨 Simple but attractive graphic a calculator built with Jetpack Compose
GitHubUpdated 3 months ago

Tivi

Tivi is a TV show tracking app that uses the latest Android libraries and tools, including Jetpack Compose.
GitHubUpdated 4 months ago

Localization

In-app language changing library
GitHubUpdated 33 months ago

We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.