Dimezis / BlurView

Dynamic iOS-like blur of underlying Views for Android
Apache License 2.0
3.45k stars 327 forks source link

Ripple in views near BlurView doesnt render (at least in Android 13) #185

Open hugomc92 opened 1 year ago

hugomc92 commented 1 year ago

Please include: 1) Library version

2.0.2

2) Device and OS version

OnePlus 6 Android 13 CherishOS (https://forum.xda-developers.com/t/rom-official-13-0-cherish-os-aosp-oneplus-6-6t-v4-0-4-sept-2022.4485817/)

3) Detailed steps to reproduce the issue -

If you set a BlurView, every view with ripple near it doesnt show ripple.

Even when activities and aplication is hardware accelerated, at the moment the blurview is shown the ripple near it stop to work.

4) XML layout and code for BlurView setup

<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/rootLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:fitsSystemWindows="false">

    <eightbitlab.com.blurview.BlurView
        android:id="@+id/titleBlurView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:elevation="8dp"
        app:blurOverlayColor="@color/colorOverlay"
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:clickable="false">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:text="@string/my_packs"
            android:textSize="18sp"
            android:textStyle="bold"
            android:textColor="@color/colorPrimary"
            android:padding="16dp"
            android:layout_marginTop="24dp"/>
    </eightbitlab.com.blurview.BlurView>

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/boughtPacksList"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:nestedScrollingEnabled="false"
        app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
        android:paddingTop="78dp"
        android:paddingBottom="56dp"
        android:clipToPadding="false"
        android:layoutAnimation="@anim/layout_animation_fall_down"/>
</FrameLayout>

The ripple in the recycler items are set with

<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:clickable="true"
    android:focusable="true"
    android:foreground="?attr/selectableItemBackgroundBorderless">

   ... 

</androidx.constraintlayout.widget.ConstraintLayout>

I setup the blur as this

BlurUtils.setupBlur(titleBlurView, boughtPacksList, activity)

fun setupBlur(blurView: BlurView?, rootLayout: ViewGroup?, activity: Activity?, blurRadius: Float = 25f) {
  if(blurView != null) {
    blurView.setBlurEnabled(false)
    blurView.setBlurEnabled(true)

    val blurAlgorithm: BlurAlgorithm = if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) RenderEffectBlur() else RenderScriptBlur(blurView.context)

    rootLayout?.let {
    blurView.setupWith(rootLayout, blurAlgorithm)
      ?.setFrameClearDrawable(activity?.window?.decorView?.background)
      ?.setBlurRadius(blurRadius)
      ?.setBlurAutoUpdate(true)
    }
  }
}

5) Stacktrace in case of a crash

Not a crash really but this log is showed.

The RippleDrawable.STYLE_PATTERNED animation is not supported for a non-hardware accelerated Canvas. Skipping animation.
hugomc92 commented 1 year ago

Any news on this?

Dimezis commented 1 year ago

@hugomc92 It indeed seems to be the case, but I'm afraid there's nothing reasonable I can do to fix it.

I'm not sure what they changed internally so it stopped working, because they shouldn't stop the ripple on the Render thread and system canvas just because someone requests drawing on a different unrelated software Canvas. They could just skip drawing on that software Canvas only.

The only fix I imagine is to move to a hardware-accelerated Canvas for view snapshotting, but because it forces a quite different rendering approach, I couldn't squeeze a reasonable performance for real-time blur from it. And I tried it implementing it a couple of times already.

So most likely this won't ever be fixed, unless one day I find some brilliant way of doing the same thing on a hardware canvas

asierpn commented 8 months ago

We had the same warning in our app only in Android 13 emulators and it went away after removing android:hardwareAccelerated="false" from the manifest.