mmin18 / RealtimeBlurView

A realtime blurring overlay for Android (like iOS UIVisualEffectView)
Other
3.17k stars 343 forks source link

DialogFragment views are ignored, the view behind the dialog is blurred and bleeds through #38

Open seth-gravy opened 5 years ago

seth-gravy commented 5 years ago

I opened up a DialogFragment and tried to blur a portion of it. Instead of seeing that portion blurred, I instead see through to a blurred version of what is behind the dialog.

I fixed it with a hack (note that all code is Kotlin):

class RealtimeBlurViewForDialogs(
    context: Context?,
    attrs: AttributeSet? = null,
    private val decorView: View?
): RealtimeBlurView(context, attrs) {
    override fun getActivityDecorView(): View = decorView ?: super.getActivityDecorView()
}

Usage inside my DialogFragment:

val blurView = RealtimeBlurViewForDialogs(context, null, dialog.window?.decorView).apply {
    id = View.generateViewId()
    setBlurRadius(50f)
    setOverlayColor(Color.TRANSPARENT)
}

// add blurView where you want in your View hierarchy

I think the underlying issue is that when we detect and set mDifferentRoot, we should use the new root as the DecorView instead of the initial root. By using the DecorView of the dialog instead of the parent Activity, which my hack does, the problem is resolved.

TianDehua commented 10 months ago

thanks, this resolve my problem, that Dialog blur effects always change!