mirror of
https://github.com/ReVanced/revanced-manager.git
synced 2024-11-10 01:01:56 +01:00
feat: Add sensitivity to isScrollingUp
This commit is contained in:
parent
d987ac6c7a
commit
e3bd8a8b22
1 changed files with 12 additions and 2 deletions
|
@ -176,6 +176,9 @@ fun String.relativeTime(context: Context): String {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
const val isScrollingUpSensitivity = 10
|
||||
|
||||
@Composable
|
||||
fun LazyListState.isScrollingUp(): State<Boolean> {
|
||||
return remember(this) {
|
||||
|
@ -183,10 +186,16 @@ fun LazyListState.isScrollingUp(): State<Boolean> {
|
|||
var previousScrollOffset by mutableIntStateOf(firstVisibleItemScrollOffset)
|
||||
|
||||
derivedStateOf {
|
||||
if (previousIndex != firstVisibleItemIndex) {
|
||||
val indexChanged = previousIndex != firstVisibleItemIndex
|
||||
val offsetChanged =
|
||||
kotlin.math.abs(previousScrollOffset - firstVisibleItemScrollOffset) > isScrollingUpSensitivity
|
||||
|
||||
if (indexChanged) {
|
||||
previousIndex > firstVisibleItemIndex
|
||||
} else if (offsetChanged) {
|
||||
previousScrollOffset > firstVisibleItemScrollOffset
|
||||
} else {
|
||||
previousScrollOffset >= firstVisibleItemScrollOffset
|
||||
true
|
||||
}.also {
|
||||
previousIndex = firstVisibleItemIndex
|
||||
previousScrollOffset = firstVisibleItemScrollOffset
|
||||
|
@ -195,6 +204,7 @@ fun LazyListState.isScrollingUp(): State<Boolean> {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO: support sensitivity
|
||||
@Composable
|
||||
fun ScrollState.isScrollingUp(): State<Boolean> {
|
||||
return remember(this) {
|
||||
|
|
Loading…
Reference in a new issue