MangaScreen: Hide scroller when appbar is expanded (#7426)

This commit is contained in:
Ivan Iskandar 2022-07-01 21:37:58 +07:00 committed by GitHub
parent 1f10b79ee8
commit 3072296919
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 2 deletions

View file

@ -47,6 +47,7 @@ import kotlin.math.roundToInt
fun VerticalFastScroller( fun VerticalFastScroller(
listState: LazyListState, listState: LazyListState,
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
thumbAllowed: () -> Boolean = { true },
thumbColor: Color = MaterialTheme.colorScheme.primary, thumbColor: Color = MaterialTheme.colorScheme.primary,
topContentPadding: Dp = Dp.Hairline, topContentPadding: Dp = Dp.Hairline,
endContentPadding: Dp = Dp.Hairline, endContentPadding: Dp = Dp.Hairline,
@ -106,8 +107,12 @@ fun VerticalFastScroller(
val isThumbVisible = alpha.value > 0f val isThumbVisible = alpha.value > 0f
LaunchedEffect(scrolled, alpha) { LaunchedEffect(scrolled, alpha) {
scrolled.collectLatest { scrolled.collectLatest {
if (thumbAllowed()) {
alpha.snapTo(1f) alpha.snapTo(1f)
alpha.animateTo(0f, animationSpec = FadeOutAnimationSpec) alpha.animateTo(0f, animationSpec = FadeOutAnimationSpec)
} else {
alpha.animateTo(0f, animationSpec = ImmediateFadeOutAnimationSpec)
}
} }
} }
@ -187,6 +192,9 @@ private val FadeOutAnimationSpec = tween<Float>(
durationMillis = ViewConfiguration.getScrollBarFadeDuration(), durationMillis = ViewConfiguration.getScrollBarFadeDuration(),
delayMillis = 2000, delayMillis = 2000,
) )
private val ImmediateFadeOutAnimationSpec = tween<Float>(
durationMillis = ViewConfiguration.getScrollBarFadeDuration(),
)
private val LazyListItemInfo.top: Int private val LazyListItemInfo.top: Int
get() = offset get() = offset

View file

@ -353,6 +353,7 @@ private fun MangaScreenSmallImpl(
WindowInsets.navigationBars.only(WindowInsetsSides.Bottom).asPaddingValues() WindowInsets.navigationBars.only(WindowInsetsSides.Bottom).asPaddingValues()
VerticalFastScroller( VerticalFastScroller(
listState = chapterListState, listState = chapterListState,
thumbAllowed = { scrollBehavior.state.offset == scrollBehavior.state.offsetLimit },
topContentPadding = withNavBarContentPadding.calculateTopPadding(), topContentPadding = withNavBarContentPadding.calculateTopPadding(),
endContentPadding = withNavBarContentPadding.calculateEndPadding(LocalLayoutDirection.current), endContentPadding = withNavBarContentPadding.calculateEndPadding(LocalLayoutDirection.current),
) { ) {