From 3072296919089546016de10c274de1a10b0b7234 Mon Sep 17 00:00:00 2001 From: Ivan Iskandar <12537387+ivaniskandar@users.noreply.github.com> Date: Fri, 1 Jul 2022 21:37:58 +0700 Subject: [PATCH] MangaScreen: Hide scroller when appbar is expanded (#7426) --- .../presentation/components/VerticalFastScroller.kt | 12 ++++++++++-- .../java/eu/kanade/presentation/manga/MangaScreen.kt | 1 + 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/eu/kanade/presentation/components/VerticalFastScroller.kt b/app/src/main/java/eu/kanade/presentation/components/VerticalFastScroller.kt index b46d85c65..009219afb 100644 --- a/app/src/main/java/eu/kanade/presentation/components/VerticalFastScroller.kt +++ b/app/src/main/java/eu/kanade/presentation/components/VerticalFastScroller.kt @@ -47,6 +47,7 @@ import kotlin.math.roundToInt fun VerticalFastScroller( listState: LazyListState, modifier: Modifier = Modifier, + thumbAllowed: () -> Boolean = { true }, thumbColor: Color = MaterialTheme.colorScheme.primary, topContentPadding: Dp = Dp.Hairline, endContentPadding: Dp = Dp.Hairline, @@ -106,8 +107,12 @@ fun VerticalFastScroller( val isThumbVisible = alpha.value > 0f LaunchedEffect(scrolled, alpha) { scrolled.collectLatest { - alpha.snapTo(1f) - alpha.animateTo(0f, animationSpec = FadeOutAnimationSpec) + if (thumbAllowed()) { + alpha.snapTo(1f) + alpha.animateTo(0f, animationSpec = FadeOutAnimationSpec) + } else { + alpha.animateTo(0f, animationSpec = ImmediateFadeOutAnimationSpec) + } } } @@ -187,6 +192,9 @@ private val FadeOutAnimationSpec = tween( durationMillis = ViewConfiguration.getScrollBarFadeDuration(), delayMillis = 2000, ) +private val ImmediateFadeOutAnimationSpec = tween( + durationMillis = ViewConfiguration.getScrollBarFadeDuration(), +) private val LazyListItemInfo.top: Int get() = offset diff --git a/app/src/main/java/eu/kanade/presentation/manga/MangaScreen.kt b/app/src/main/java/eu/kanade/presentation/manga/MangaScreen.kt index d52c9e370..62432606d 100644 --- a/app/src/main/java/eu/kanade/presentation/manga/MangaScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/manga/MangaScreen.kt @@ -353,6 +353,7 @@ private fun MangaScreenSmallImpl( WindowInsets.navigationBars.only(WindowInsetsSides.Bottom).asPaddingValues() VerticalFastScroller( listState = chapterListState, + thumbAllowed = { scrollBehavior.state.offset == scrollBehavior.state.offsetLimit }, topContentPadding = withNavBarContentPadding.calculateTopPadding(), endContentPadding = withNavBarContentPadding.calculateEndPadding(LocalLayoutDirection.current), ) {