ui: try band-aiding bottom sheet flickering

Use an assumed peekHeight close to the real one and reduce the
jumpiness that appears in some cases.

Resolves #631.
This commit is contained in:
Alexander Capehart 2024-07-04 11:42:45 -06:00
parent 27fb1d1823
commit e035d81ee0
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
4 changed files with 23 additions and 1 deletions

View file

@ -12,6 +12,7 @@
#### What's Fixed
- Music loader no longer spawns thousands of threads when scanning
- Excessive CPU no longer spent showing music loading process
- Fixed playback sheet flickering on warm start
## 3.5.1

View file

@ -28,8 +28,10 @@ import androidx.coordinatorlayout.widget.CoordinatorLayout
import com.google.android.material.R as MR
import com.google.android.material.shape.MaterialShapeDrawable
import com.google.android.material.shape.ShapeAppearanceModel
import org.oxycblt.auxio.R
import org.oxycblt.auxio.ui.BaseBottomSheetBehavior
import org.oxycblt.auxio.util.getAttrColorCompat
import org.oxycblt.auxio.util.getDimenPixels
import org.oxycblt.auxio.util.replaceSystemBarInsetsCompat
import org.oxycblt.auxio.util.systemBarInsetsCompat
@ -55,6 +57,9 @@ class PlaybackBottomSheetBehavior<V : View>(context: Context, attributeSet: Attr
isHideable = true
}
override fun getIdealBarHeight(context: Context) =
context.getDimenPixels(R.dimen.size_touchable_large)
// Hack around issue where the playback sheet will try to intercept nested scrolling events
// before the queue sheet.
override fun onInterceptTouchEvent(parent: CoordinatorLayout, child: V, event: MotionEvent) =

View file

@ -49,6 +49,9 @@ class QueueBottomSheetBehavior<V : View>(context: Context, attributeSet: Attribu
isHideable = false
}
override fun getIdealBarHeight(context: Context) =
context.getDimenPixels(R.dimen.size_touchable_large)
override fun layoutDependsOn(parent: CoordinatorLayout, child: V, dependency: View) =
dependency.id == R.id.playback_bar_fragment

View file

@ -27,7 +27,9 @@ import android.view.WindowInsets
import androidx.coordinatorlayout.widget.CoordinatorLayout
import com.google.android.material.R as MR
import com.google.android.material.bottomsheet.BackportBottomSheetBehavior
import org.oxycblt.auxio.R
import org.oxycblt.auxio.util.getDimen
import org.oxycblt.auxio.util.getDimenPixels
import org.oxycblt.auxio.util.logD
import org.oxycblt.auxio.util.systemGestureInsetsCompat
@ -42,6 +44,7 @@ import org.oxycblt.auxio.util.systemGestureInsetsCompat
abstract class BaseBottomSheetBehavior<V : View>(context: Context, attributeSet: AttributeSet?) :
BackportBottomSheetBehavior<V>(context, attributeSet) {
private var initalized = false
private val idealBottomGestureInsets = context.getDimenPixels(R.dimen.spacing_medium)
init {
// Disable isFitToContents to make the bottom sheet expand to the top of the screen and
@ -57,6 +60,9 @@ abstract class BaseBottomSheetBehavior<V : View>(context: Context, attributeSet:
*/
abstract fun createBackground(context: Context): Drawable
/** Get the ideal bar height to use before the bar is properly measured. */
abstract fun getIdealBarHeight(context: Context): Int
/**
* Called when window insets are being applied to the [View] this [BaseBottomSheetBehavior] is
* linked to.
@ -70,7 +76,13 @@ abstract class BaseBottomSheetBehavior<V : View>(context: Context, attributeSet:
// All sheet behaviors derive their peek height from the size of the "bar" (i.e the
// first child) plus the gesture insets.
val gestures = insets.systemGestureInsetsCompat
peekHeight = (child as ViewGroup).getChildAt(0).height + gestures.bottom
val bar = (child as ViewGroup).getChildAt(0)
peekHeight =
if (bar.measuredHeight > 0) {
bar.measuredHeight + gestures.bottom
} else {
getIdealBarHeight(child.context) + gestures.bottom
}
return insets
}
@ -93,6 +105,7 @@ abstract class BaseBottomSheetBehavior<V : View>(context: Context, attributeSet:
setOnApplyWindowInsetsListener(::applyWindowInsets)
}
initalized = true
peekHeight = getIdealBarHeight(child.context) + idealBottomGestureInsets
}
// Sometimes CoordinatorLayout doesn't dispatch window insets to us, likely due to how
// much we overload it. Ensure that we get them.