Sample updates to scrollbars

This commit is contained in:
arkon 2023-03-29 23:19:52 -04:00
parent 7a1b599462
commit bc0b9e536a
2 changed files with 26 additions and 18 deletions

View File

@ -48,6 +48,7 @@ import androidx.compose.ui.util.fastMaxBy
import kotlinx.coroutines.channels.BufferOverflow import kotlinx.coroutines.channels.BufferOverflow
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 tachiyomi.presentation.core.components.Scroller.STICKY_HEADER_KEY_PREFIX import tachiyomi.presentation.core.components.Scroller.STICKY_HEADER_KEY_PREFIX
import kotlin.math.abs import kotlin.math.abs
import kotlin.math.max import kotlin.math.max
@ -124,7 +125,9 @@ fun VerticalFastScroller(
val alpha = remember { Animatable(0f) } val alpha = remember { Animatable(0f) }
val isThumbVisible = alpha.value > 0f val isThumbVisible = alpha.value > 0f
LaunchedEffect(scrolled, alpha) { LaunchedEffect(scrolled, alpha) {
scrolled.collectLatest { scrolled
.sample(100)
.collectLatest {
if (thumbAllowed()) { if (thumbAllowed()) {
alpha.snapTo(1f) alpha.snapTo(1f)
alpha.animateTo(0f, animationSpec = FadeOutAnimationSpec) alpha.animateTo(0f, animationSpec = FadeOutAnimationSpec)
@ -304,7 +307,9 @@ fun VerticalGridFastScroller(
val alpha = remember { Animatable(0f) } val alpha = remember { Animatable(0f) }
val isThumbVisible = alpha.value > 0f val isThumbVisible = alpha.value > 0f
LaunchedEffect(scrolled, alpha) { LaunchedEffect(scrolled, alpha) {
scrolled.collectLatest { scrolled
.sample(100)
.collectLatest {
if (thumbAllowed()) { if (thumbAllowed()) {
alpha.snapTo(1f) alpha.snapTo(1f)
alpha.animateTo(0f, animationSpec = FadeOutAnimationSpec) alpha.animateTo(0f, animationSpec = FadeOutAnimationSpec)

View File

@ -67,6 +67,7 @@ import androidx.compose.ui.util.fastSumBy
import kotlinx.coroutines.channels.BufferOverflow import kotlinx.coroutines.channels.BufferOverflow
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 tachiyomi.presentation.core.components.Scroller.STICKY_HEADER_KEY_PREFIX import tachiyomi.presentation.core.components.Scroller.STICKY_HEADER_KEY_PREFIX
/** /**
@ -206,7 +207,9 @@ private fun Modifier.drawScrollbar(
val alpha = remember { Animatable(0f) } val alpha = remember { Animatable(0f) }
LaunchedEffect(scrolled, alpha) { LaunchedEffect(scrolled, alpha) {
scrolled.collectLatest { scrolled
.sample(100)
.collectLatest {
alpha.snapTo(1f) alpha.snapTo(1f)
alpha.animateTo(0f, animationSpec = FadeOutAnimationSpec) alpha.animateTo(0f, animationSpec = FadeOutAnimationSpec)
} }