Giter Site home page Giter Site logo

rockystevejobs / cloudy Goto Github PK

View Code? Open in Web Editor NEW

This project forked from skydoves/cloudy

0.0 1.0 0.0 6.04 MB

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

License: Apache License 2.0

C++ 22.52% Kotlin 76.22% CMake 1.25%

cloudy's Introduction

Cloudy


License API Build Status Profile


☁️ Jetpack Compose blur process library, which supports all Android versions.


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

Maven Central

Gradle

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

dependencies {
    implementation "com.github.skydoves:cloudy:0.1.0"
}

Usage

You can implement blur effect with Cloudy composable function as seen in the below:

Cloudy {
    Text(text = "This text is blurred")
}

You can change the degree of the blur effect by changing the radius parameter of Cloudy composable function. You can only set between 0..25 integer values.

Cloudy(radius = 15) {
    Column {
        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
        )
    }
}

Blur Effects Depending on States

If you need to load your network image or do something heavy business logic first, you should re-execute the blur effect depending on your state. Basically, you can re-execute the blur calculation by changing the radius value, but you can also re-execute the blurring process by giving the key1 parameter to trigger internal processes.

var glideState by rememberGlideImageState()
Cloudy(
  radius = 15,
  key1 = glideState, // re-execute the blurring process whenever the state value is changed.
) {
  GlideImage(
    modifier = Modifier.size(400.dp),
    imageModel = { poster.image },
    onImageStateChanged = { glideState = it }
  )
}

You can also utilize the key2 parameter to trigger the blurring process.

Accumulate Blur Radius

You can accumulate the blur radius and keep adding the degree of blur effect whenever you change the radius parameter by giving the allowAccumulate condition. For example, if you want to accumulate the degree of blur gradually, you can set the condition of the allowAccumulate parameter depending on your states like the below:

var animationPlayed by remember { mutableStateOf(false) }
val radius by animateIntAsState(
  targetValue = if (animationPlayed) 10 else 0,
  animationSpec = tween(
    durationMillis = 3000,
    delayMillis = 100,
    easing = LinearOutSlowInEasing
  )
)

// Accumulate the degree of blur gradually for the network image.
var glideState by rememberGlideImageState()
Cloudy(
  radius = radius,
  key1 = glideState,
  allowAccumulate = { it is CloudyState.Success && glideState is GlideImageState.Success }
) {
  GlideImage(
    modifier = Modifier.size(400.dp),
    imageModel = { poster.image },
    onImageStateChanged = { glideState = it }
  )
}

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.

cloudy's People

Contributors

skydoves avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.