playback: fix stepper in carousel

This commit is contained in:
Alexander Capehart
2026-05-24 22:07:41 -06:00
parent 3b47395f7f
commit 9d77a2a41e
@@ -20,10 +20,13 @@ package org.oxycblt.auxio.playback.ui.swiper
import android.graphics.RectF import android.graphics.RectF
import android.view.View import android.view.View
import androidx.core.view.isInvisible
import androidx.viewpager2.widget.ViewPager2 import androidx.viewpager2.widget.ViewPager2
import com.google.android.material.carousel.MaskableFrameLayout import com.google.android.material.carousel.MaskableFrameLayout
class CarouselTransformer : ViewPager2.PageTransformer { class CarouselTransformer : ViewPager2.PageTransformer {
private val hiddenRect = RectF()
override fun transformPage(page: View, position: Float) { override fun transformPage(page: View, position: Float) {
// drafted by codex mostly due to the insane complexity of abusing a viewpager2 // drafted by codex mostly due to the insane complexity of abusing a viewpager2
// into a m3 carousel like thing // into a m3 carousel like thing
@@ -32,6 +35,11 @@ class CarouselTransformer : ViewPager2.PageTransformer {
val width = page.width.toFloat() val width = page.width.toFloat()
val height = page.height.toFloat() val height = page.height.toFloat()
if (width <= 0f || height <= 0f) {
//
return
}
// pin the page // pin the page
// normally the page's layout is controlled by linearlayoutmanager which we dont // normally the page's layout is controlled by linearlayoutmanager which we dont
// like since it means we cant arrange them in the carousel // like since it means we cant arrange them in the carousel
@@ -39,6 +47,12 @@ class CarouselTransformer : ViewPager2.PageTransformer {
// we want to create our effect // we want to create our effect
page.translationX = -position * width page.translationX = -position * width
// Make sure despite the pinning offscreen pages are noninteractable
// Otherwise funky android touch logic kicks in and breaks the playback stepper
page.isInvisible = position <= -1f || position >= 1f
page.alpha = 1f
val p = val p =
when { when {
// prev page, just abs // prev page, just abs