-
-
Notifications
You must be signed in to change notification settings - Fork 336
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
Using with Jetpack Compose #157
Comments
Not sure if I understand what problem you're having exactly. |
Hi, thank you for the reply. I'm trying to create a blurred effect in the TopBar of my app. The app is entirely written in Jetpack Compose. @Composable
fun TopBar() {
AndroidView(
modifier = Modifier
.fillMaxWidth()
.height(56.dp),
factory = { context ->
BlurView(context).apply {
this.setupWith(this) // <- Here
.setBlurAlgorithm(RenderScriptBlur(context))
.setBlurRadius(20f)
.setBlurAutoUpdate(true)
}
}
)
} If it's helpful, since it's a TopBar, the content behind is scrollable. |
If your composable is written within the Activity, just get a reference to it and do val decorView = activity.window.decorView
val rootView = decorView.findViewById<ViewGroup>(android.R.id.content) If you don't have a reference to the Activity, you can cast the You can also just pass the Activity reference to your |
I tried both with casting and passing the MainActivity to my TopBar, but in both cases the application crashes with this error:
My updated code looks like this: @Composable
fun TopBar(activity: MainActivity) {
val decorView = activity.window.decorView
val rootView = decorView.findViewById<ViewGroup>(android.R.id.content)
val windowBackground = decorView.background;
AndroidView(
modifier = Modifier
.fillMaxWidth()
.height(56.dp),
factory = { context ->
BlurView(context).apply {
this.setupWith(rootView)
.setFrameClearDrawable(windowBackground)
.setBlurAlgorithm(RenderScriptBlur(context))
.setBlurRadius(20f)
.setBlurAutoUpdate(true)
}
}
)
} |
Then I guess the BlurView is not compatible with Composable hierarchies. |
@LorenzoFerri If you are interested |
I tried that Modifier, but it doesn’t achieve what I need, blurring only the composable itself and not what's behind it. |
@LorenzoFerri |
I've spent some time trying to achieve the blurring effect in Compose using this library and anything else that I was able to find, but I haven't found any solution. So, currently, migrating my project to Compose is put on hold indefinitely. |
I haven't found a solution either. But I noticed that using @LorenzoFerri's code stops throwing an error if I don't use a Modifier in the AndroidView section however the blur itself is pretty weird and not the desired effect. So I wonder if it has something to do with that. I'd love to find a solution to this. |
It would be really great if BlurView can be used in Jetpack Compose :') |
Any updates? |
@SecretKeeper Star it if you'd like to help |
Unfortunately, it's probably some (un)lucky quirk of your particular setup, because there's a fundamental problem preventing it from working correctly. |
Version 2.0.2 should fix this problem, but I'm not sure it's going to be working in every scenario. |
Hi @Dimezis, sorry to comment on the closed issue, but I found this is relavent to my question, I am curious about what if the root view is composable? Basically I have a composable that is ready to be used, I just want its background to be blured, I tried to embed BlurView into AndroidView, but how to integrate composable in this case? Could you shed some lights, thanks!
|
@jianinz I'm not sure if I understand your problem.
Your setup looks fine, though I didn't test it. |
@Dimezis Thanks for your quick response! In the example here https://github.com/Dimezis/BlurView#how-to-use, BlurView will have any child view which will not be blured. In my case, the child view will be a composable, I wonder how to integrate that composable into BlurView? Should I just do something like:
|
If I use code below
I don't see the blured view, instead I see the mono background colored bottom bar, no blur effect takes into place |
Yes, although I think the order should be Box {
AndroidViewBasedCompose()
HomeBottomBar()
} And the Edit: |
Yeah, just tried changing order, in the end the blur view does not show up, is there any ways to include the bottom bar into its blurred content? |
As I said, the bottom bar composable has to have a transparent background. I don't know if it's adjustable though |
I set HomeBottomBar's background color as transparent and blur view as purple, unfortunately the result is just transparent HomeBottomBar |
Hi, I would like to use this library in a Jetpack Compose project however I'm not finding any success. Could you provide a simple
Composable
component that with anAndroidView
or aAndroidViewBinding
wrap your library? Thank youThe text was updated successfully, but these errors were encountered: