|
| 1 | + |
| 2 | +# Shaded |
| 3 | + |
| 4 | +Shaded is a jetpack compose library for Android allowing blurring on lower Android versions |
| 5 | + |
| 6 | + |
| 7 | +## Screenshots |
| 8 | + |
| 9 | +<img width="357" height="720" alt="Unbounded Blur Comparison" src="https://github.com/user-attachments/assets/864e02f6-a22b-4e33-8e1b-a4dc4a5ef5d7" /> |
| 10 | +<img width="355" height="720" alt="Bounded Blur Comparison" src="https://github.com/user-attachments/assets/b1596273-588c-4aaa-9de7-5dc3779ba58e" /> |
| 11 | + |
| 12 | +# Installation |
| 13 | + |
| 14 | +## Method 1: Direct Dependency |
| 15 | + |
| 16 | +### Step 1: Add JitPack Repository |
| 17 | + |
| 18 | +Add the JitPack repository to your **root** `settings.gradle` file: |
| 19 | + |
| 20 | +```kotlin |
| 21 | +dependencyResolutionManagement { |
| 22 | + repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) |
| 23 | + repositories { |
| 24 | + mavenCentral() |
| 25 | + maven { url = uri("https://jitpack.io") } |
| 26 | + } |
| 27 | +} |
| 28 | +``` |
| 29 | + |
| 30 | +### Step 2: Add Dependency |
| 31 | + |
| 32 | +Add the dependency to your **module** `build.gradle.kts`: |
| 33 | + |
| 34 | +```kotlin |
| 35 | +dependencies { |
| 36 | + implementation("com.github.mohamedd-hassan:Shaded:0.2.3-alpha") |
| 37 | +} |
| 38 | +``` |
| 39 | + |
| 40 | +--- |
| 41 | + |
| 42 | +## Method 2: Version Catalog (Recommended) |
| 43 | + |
| 44 | +### Step 1: Add to Version Catalog |
| 45 | + |
| 46 | +Add the dependency to your `libs.versions.toml`: |
| 47 | + |
| 48 | +```toml |
| 49 | +[versions] |
| 50 | +shaded = "0.2.3-alpha" |
| 51 | + |
| 52 | +[libraries] |
| 53 | +sifr-shaded = { module = "com.github.mohamedd-hassan:Shaded", version.ref = "shaded" } |
| 54 | +``` |
| 55 | + |
| 56 | +### Step 2: Add to Build Script |
| 57 | + |
| 58 | +Add it to your **module** `build.gradle.kts`: |
| 59 | + |
| 60 | +```kotlin |
| 61 | +dependencies { |
| 62 | + implementation(libs.sifr.shaded) |
| 63 | +} |
| 64 | +``` |
| 65 | +## Features |
| 66 | + |
| 67 | +- Blurring composables on low Android versions (API 24+) |
| 68 | +- Unbounded and Bounded blurring just like native blurring |
| 69 | +- If on Android 12 and above it automatically uses native blur for performance |
| 70 | +- High performance while keeping the same look and effect |
| 71 | + |
| 72 | + |
| 73 | +## Roadmap |
| 74 | + |
| 75 | +[ ] Better OpenGL context management for improved performance |
| 76 | + |
| 77 | +[ ] Vulkan support for reduced |
| 78 | + |
| 79 | +[ ] Hardware Accelerated composable support |
| 80 | + |
| 81 | +[ ] Support for custom shader integrations |
| 82 | + |
| 83 | +[ ] Better interoperability with the Android renderer for improved performance |
| 84 | + |
| 85 | +## Usage/Examples |
| 86 | + |
| 87 | +You would use it just like the normal blur modifier that comes with androidx |
| 88 | + |
| 89 | +``` |
| 90 | +@Composable |
| 91 | +fun BlurSample() { |
| 92 | + Box( |
| 93 | + modifier = Modifier |
| 94 | + .size(200.dp, 100.dp) |
| 95 | + .background( |
| 96 | + brush = Brush.horizontalGradient( |
| 97 | + colors = listOf( |
| 98 | + Color.Blue, |
| 99 | + Color.Cyan, |
| 100 | + Color.Magenta |
| 101 | + ) |
| 102 | + ), |
| 103 | + shape = RoundedCornerShape(16.dp) |
| 104 | + ) |
| 105 | + // Here we pass the radius as Float instead. it gives the same effect as the native one (30F will look the same here and in the native modifier) |
| 106 | + .blur( |
| 107 | + radius = 30F, |
| 108 | + edgeTreatment = BlurEdgeTreatment.UNBOUNDED |
| 109 | + ), |
| 110 | + contentAlignment = Alignment.Center |
| 111 | + ) { |
| 112 | + BasicText( |
| 113 | + text = "Test Content", |
| 114 | + color = { Color.White }, |
| 115 | + style = TextStyle( |
| 116 | + fontWeight = FontWeight.Bold, |
| 117 | + fontSize = 24.sp |
| 118 | + ) |
| 119 | + ) |
| 120 | + } |
| 121 | +} |
| 122 | +``` |
| 123 | +here while using it with coil we had to disable hardware bitmaps because the library currently does not support hardware accelerated composables |
| 124 | + |
| 125 | +``` |
| 126 | +@Composable |
| 127 | +fun CoilBlurSample(){ |
| 128 | + val context = LocalContext.current |
| 129 | + AsyncImage( |
| 130 | + model = ImageRequest |
| 131 | + .Builder(context) |
| 132 | + // Here for example we turn coil hardware acceleration off so the blur can be applied on old APIS |
| 133 | + .allowHardware(false) |
| 134 | + .data("IMAGE DATA") |
| 135 | + .build() |
| 136 | + , |
| 137 | + contentDescription = null, |
| 138 | + modifier = Modifier |
| 139 | + .fillMaxWidth() |
| 140 | + .blur( |
| 141 | + 5f, |
| 142 | + BlurEdgeTreatment.UNBOUNDED |
| 143 | + ) |
| 144 | + ) |
| 145 | +} |
| 146 | +``` |
| 147 | + |
0 commit comments