Fix scrollbar not showing when animator duration scale animation is turned off (mihonapp/mihon#2398)

(cherry picked from commit 09ec9fc8c54e126692ae68ff260058f3be46a5dd)
This commit is contained in:
anirudhn 2025-11-01 07:34:07 -07:00 committed by Cuong-Tran
parent 8ec37f3807
commit aca83212c3
No known key found for this signature in database
GPG key ID: 94EFFE320FE7A47C
2 changed files with 11 additions and 9 deletions

View file

@ -47,6 +47,7 @@ import androidx.compose.ui.util.fastForEach
import androidx.compose.ui.util.fastLastOrNull import androidx.compose.ui.util.fastLastOrNull
import androidx.compose.ui.util.fastMaxBy import androidx.compose.ui.util.fastMaxBy
import kotlinx.coroutines.channels.BufferOverflow import kotlinx.coroutines.channels.BufferOverflow
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.sample import kotlinx.coroutines.flow.sample
@ -177,7 +178,8 @@ fun VerticalFastScroller(
.collectLatest { .collectLatest {
if (thumbAllowed()) { if (thumbAllowed()) {
alpha.snapTo(1f) alpha.snapTo(1f)
alpha.animateTo(0f, animationSpec = FadeOutAnimationSpec) delay(ScrollBarVisibilityDurationMillis)
alpha.animateTo(0f, animationSpec = ImmediateFadeOutAnimationSpec)
} else { } else {
alpha.animateTo(0f, animationSpec = ImmediateFadeOutAnimationSpec) alpha.animateTo(0f, animationSpec = ImmediateFadeOutAnimationSpec)
} }
@ -366,7 +368,8 @@ fun VerticalGridFastScroller(
.collectLatest { .collectLatest {
if (thumbAllowed()) { if (thumbAllowed()) {
alpha.snapTo(1f) alpha.snapTo(1f)
alpha.animateTo(0f, animationSpec = FadeOutAnimationSpec) delay(ScrollBarVisibilityDurationMillis)
alpha.animateTo(0f, animationSpec = ImmediateFadeOutAnimationSpec)
} else { } else {
alpha.animateTo(0f, animationSpec = ImmediateFadeOutAnimationSpec) alpha.animateTo(0f, animationSpec = ImmediateFadeOutAnimationSpec)
} }
@ -460,10 +463,7 @@ object Scroller {
private val ThumbLength = 48.dp private val ThumbLength = 48.dp
private val ThumbThickness = 12.dp private val ThumbThickness = 12.dp
private val ThumbShape = RoundedCornerShape(ThumbThickness / 2) private val ThumbShape = RoundedCornerShape(ThumbThickness / 2)
private val FadeOutAnimationSpec = tween<Float>( private val ScrollBarVisibilityDurationMillis = 2000L
durationMillis = ViewConfiguration.getScrollBarFadeDuration(),
delayMillis = 2000,
)
private val ImmediateFadeOutAnimationSpec = tween<Float>( private val ImmediateFadeOutAnimationSpec = tween<Float>(
durationMillis = ViewConfiguration.getScrollBarFadeDuration(), durationMillis = ViewConfiguration.getScrollBarFadeDuration(),
) )

View file

@ -64,6 +64,7 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.util.fastFirstOrNull import androidx.compose.ui.util.fastFirstOrNull
import androidx.compose.ui.util.fastSumBy import androidx.compose.ui.util.fastSumBy
import kotlinx.coroutines.channels.BufferOverflow import kotlinx.coroutines.channels.BufferOverflow
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.sample import kotlinx.coroutines.flow.sample
@ -218,7 +219,8 @@ private fun Modifier.drawScrollbar(
.sample(100) .sample(100)
.collectLatest { .collectLatest {
alpha.snapTo(1f) alpha.snapTo(1f)
alpha.animateTo(0f, animationSpec = FadeOutAnimationSpec) delay(ScrollBarVisibilityDurationMillis)
alpha.animateTo(0f, animationSpec = ImmediateFadeOutAnimationSpec)
} }
} }
@ -241,9 +243,9 @@ private fun Modifier.drawScrollbar(
} }
} }
private val FadeOutAnimationSpec = tween<Float>( private val ScrollBarVisibilityDurationMillis = ViewConfiguration.getScrollDefaultDelay().toLong()
private val ImmediateFadeOutAnimationSpec = tween<Float>(
durationMillis = ViewConfiguration.getScrollBarFadeDuration(), durationMillis = ViewConfiguration.getScrollBarFadeDuration(),
delayMillis = ViewConfiguration.getScrollDefaultDelay(),
) )
@Preview(widthDp = 400, heightDp = 400, showBackground = true) @Preview(widthDp = 400, heightDp = 400, showBackground = true)