feat: Add isScrollingUp support for ScrollState

This commit is contained in:
Ushie 2024-07-03 02:45:45 +03:00
parent 9883dcd0a7
commit d987ac6c7a
No known key found for this signature in database
GPG Key ID: B3AAD18842E34632
2 changed files with 17 additions and 3 deletions

View File

@ -3,7 +3,6 @@ package app.revanced.manager.ui.screen
import android.content.pm.PackageInfo import android.content.pm.PackageInfo
import androidx.annotation.StringRes import androidx.annotation.StringRes
import androidx.compose.foundation.clickable import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
@ -28,6 +27,7 @@ import androidx.lifecycle.compose.collectAsStateWithLifecycle
import app.revanced.manager.R import app.revanced.manager.R
import app.revanced.manager.ui.component.AppInfo import app.revanced.manager.ui.component.AppInfo
import app.revanced.manager.ui.component.AppTopBar import app.revanced.manager.ui.component.AppTopBar
import app.revanced.manager.ui.component.ColumnWithScrollbar
import app.revanced.manager.ui.destination.SelectedAppInfoDestination import app.revanced.manager.ui.destination.SelectedAppInfoDestination
import app.revanced.manager.ui.model.BundleInfo.Extensions.bundleInfoFlow import app.revanced.manager.ui.model.BundleInfo.Extensions.bundleInfoFlow
import app.revanced.manager.ui.model.SelectedApp import app.revanced.manager.ui.model.SelectedApp
@ -175,7 +175,7 @@ private fun SelectedAppInfoScreen(
) )
} }
) { paddingValues -> ) { paddingValues ->
Column( ColumnWithScrollbar(
modifier = Modifier modifier = Modifier
.fillMaxSize() .fillMaxSize()
.padding(paddingValues) .padding(paddingValues)

View File

@ -11,6 +11,7 @@ import android.os.Build
import android.util.Log import android.util.Log
import android.widget.Toast import android.widget.Toast
import androidx.annotation.StringRes import androidx.annotation.StringRes
import androidx.compose.foundation.ScrollState
import androidx.compose.foundation.lazy.LazyListState import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.State import androidx.compose.runtime.State
@ -194,4 +195,17 @@ fun LazyListState.isScrollingUp(): State<Boolean> {
} }
} }
val LazyListState.isScrollingUp: Boolean @Composable get() = this.isScrollingUp().value @Composable
fun ScrollState.isScrollingUp(): State<Boolean> {
return remember(this) {
var previousScrollOffset by mutableIntStateOf(value)
derivedStateOf {
(previousScrollOffset >= value).also {
previousScrollOffset = value
}
}
}
}
val LazyListState.isScrollingUp: Boolean @Composable get() = this.isScrollingUp().value
val ScrollState.isScrollingUp: Boolean @Composable get() = this.isScrollingUp().value