From bc0b9e536a2c4a7059809dd8c1f31b0dce7f10bd Mon Sep 17 00:00:00 2001 From: arkon Date: Wed, 29 Mar 2023 23:19:52 -0400 Subject: [PATCH] Sample updates to scrollbars --- .../core/components/VerticalFastScroller.kt | 33 +++++++++++-------- .../presentation/core/util/Scrollbar.kt | 11 ++++--- 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/presentation-core/src/main/java/tachiyomi/presentation/core/components/VerticalFastScroller.kt b/presentation-core/src/main/java/tachiyomi/presentation/core/components/VerticalFastScroller.kt index 92fcd0ca3..b7d769f35 100644 --- a/presentation-core/src/main/java/tachiyomi/presentation/core/components/VerticalFastScroller.kt +++ b/presentation-core/src/main/java/tachiyomi/presentation/core/components/VerticalFastScroller.kt @@ -48,6 +48,7 @@ import androidx.compose.ui.util.fastMaxBy import kotlinx.coroutines.channels.BufferOverflow import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.collectLatest +import kotlinx.coroutines.flow.sample import tachiyomi.presentation.core.components.Scroller.STICKY_HEADER_KEY_PREFIX import kotlin.math.abs import kotlin.math.max @@ -124,14 +125,16 @@ fun VerticalFastScroller( val alpha = remember { Animatable(0f) } val isThumbVisible = alpha.value > 0f LaunchedEffect(scrolled, alpha) { - scrolled.collectLatest { - if (thumbAllowed()) { - alpha.snapTo(1f) - alpha.animateTo(0f, animationSpec = FadeOutAnimationSpec) - } else { - alpha.animateTo(0f, animationSpec = ImmediateFadeOutAnimationSpec) + scrolled + .sample(100) + .collectLatest { + if (thumbAllowed()) { + alpha.snapTo(1f) + alpha.animateTo(0f, animationSpec = FadeOutAnimationSpec) + } else { + alpha.animateTo(0f, animationSpec = ImmediateFadeOutAnimationSpec) + } } - } } Box( @@ -304,14 +307,16 @@ fun VerticalGridFastScroller( val alpha = remember { Animatable(0f) } val isThumbVisible = alpha.value > 0f LaunchedEffect(scrolled, alpha) { - scrolled.collectLatest { - if (thumbAllowed()) { - alpha.snapTo(1f) - alpha.animateTo(0f, animationSpec = FadeOutAnimationSpec) - } else { - alpha.animateTo(0f, animationSpec = ImmediateFadeOutAnimationSpec) + scrolled + .sample(100) + .collectLatest { + if (thumbAllowed()) { + alpha.snapTo(1f) + alpha.animateTo(0f, animationSpec = FadeOutAnimationSpec) + } else { + alpha.animateTo(0f, animationSpec = ImmediateFadeOutAnimationSpec) + } } - } } Box( diff --git a/presentation-core/src/main/java/tachiyomi/presentation/core/util/Scrollbar.kt b/presentation-core/src/main/java/tachiyomi/presentation/core/util/Scrollbar.kt index 55552d78c..b842952e8 100644 --- a/presentation-core/src/main/java/tachiyomi/presentation/core/util/Scrollbar.kt +++ b/presentation-core/src/main/java/tachiyomi/presentation/core/util/Scrollbar.kt @@ -67,6 +67,7 @@ import androidx.compose.ui.util.fastSumBy import kotlinx.coroutines.channels.BufferOverflow import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.collectLatest +import kotlinx.coroutines.flow.sample import tachiyomi.presentation.core.components.Scroller.STICKY_HEADER_KEY_PREFIX /** @@ -206,10 +207,12 @@ private fun Modifier.drawScrollbar( val alpha = remember { Animatable(0f) } LaunchedEffect(scrolled, alpha) { - scrolled.collectLatest { - alpha.snapTo(1f) - alpha.animateTo(0f, animationSpec = FadeOutAnimationSpec) - } + scrolled + .sample(100) + .collectLatest { + alpha.snapTo(1f) + alpha.animateTo(0f, animationSpec = FadeOutAnimationSpec) + } } val isLtr = LocalLayoutDirection.current == LayoutDirection.Ltr