https://kotlinlang.org logo
#compose-android
Title
# compose-android
s

Sergio Moral

03/14/2024, 12:35 PM
Hi! Does anyone know if it is possible to create a
Modifier
extension to add blur effect that is compatible with all Android versions?
Modifier.blur()
is compatible with Android 12 and above and I was trying to encapsulate all the compatible logic in one extension function. I have tried to use graphics layer and adding a
BlurEffect
to
renderEffect
but with no luck in my Android 10. Any ideas? This is the code I have tried at this moment.
Copy code
@Composable 
fun Modifier.compatBlur ( radius: Float
: Modifier = 
if(Build.VERSION.SDK_INT <= Build. VERSION_CODES.S)
 graphicslayer {
   if (radius > 0f)
   renderEffect = BlurEffect(radius,radius)
}
else this.blur(radius.dp)
j

jw

03/14/2024, 12:37 PM
s

Stylianos Gakis

03/14/2024, 12:40 PM
Does haze work for older versions? https://kotlinlang.slack.com/archives/CJLTWPH7S/p1651845634528419 Read more here 😄
❤️ 2
j

jw

03/14/2024, 12:42 PM
It falls back to scrim, I think
Better than nothing
👍 1