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

This commit is contained in:
anirudhn
2025-11-01 07:34:07 -07:00
committed by GitHub
parent 87c6f34a55
commit 09ec9fc8c5
3 changed files with 12 additions and 9 deletions

View File

@@ -33,6 +33,7 @@ The format is a modified version of [Keep a Changelog](https://keepachangelog.co
- Fix migration "Attempt to invoke virtual method" crash ([@AntsyLich](https://github.com/AntsyLich)) ([#2632](https://github.com/mihonapp/mihon/pull/2632)) - Fix migration "Attempt to invoke virtual method" crash ([@AntsyLich](https://github.com/AntsyLich)) ([#2632](https://github.com/mihonapp/mihon/pull/2632))
- Fix reader "Unable to edit key" error ([@AntsyLich](https://github.com/AntsyLich)) ([#2634](https://github.com/mihonapp/mihon/pull/2634)) - Fix reader "Unable to edit key" error ([@AntsyLich](https://github.com/AntsyLich)) ([#2634](https://github.com/mihonapp/mihon/pull/2634))
- Fix extension download stuck in pending state in some cases ([@c2y5](https://github.com/c2y5)) ([#2483](https://github.com/mihonapp/mihon/pull/2483)) - Fix extension download stuck in pending state in some cases ([@c2y5](https://github.com/c2y5)) ([#2483](https://github.com/mihonapp/mihon/pull/2483))
- Fix scrollbar not showing when animator duration scale animation is turned off ([@anirudhsnayak](https://github.com/anirudhsnayak)) ([#2398](https://github.com/mihonapp/mihon/pull/2398))
### Improved ### Improved
- Auto refresh extension list whenever a repository is added or removed ([@c2y5](https://github.com/c2y5)) ([#2483](https://github.com/mihonapp/mihon/pull/2483)) - Auto refresh extension list whenever a repository is added or removed ([@c2y5](https://github.com/c2y5)) ([#2483](https://github.com/mihonapp/mihon/pull/2483))

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)