diff --git a/app/src/main/kotlin/it/vfsfitvnm/vimusic/ui/components/themed/ScrollToTop.kt b/app/src/main/kotlin/it/vfsfitvnm/vimusic/ui/components/themed/ScrollToTop.kt index a2dd671..5735aaa 100644 --- a/app/src/main/kotlin/it/vfsfitvnm/vimusic/ui/components/themed/ScrollToTop.kt +++ b/app/src/main/kotlin/it/vfsfitvnm/vimusic/ui/components/themed/ScrollToTop.kt @@ -9,7 +9,6 @@ import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.lazy.LazyListState -import androidx.compose.foundation.lazy.grid.LazyGridState import androidx.compose.runtime.Composable import androidx.compose.runtime.derivedStateOf import androidx.compose.runtime.getValue @@ -24,6 +23,7 @@ import androidx.compose.ui.unit.dp import it.vfsfitvnm.vimusic.LocalPlayerAwarePaddingValues import it.vfsfitvnm.vimusic.R import it.vfsfitvnm.vimusic.ui.styling.LocalAppearance +import it.vfsfitvnm.vimusic.utils.smoothScrollToTop import kotlinx.coroutines.launch @Composable @@ -39,25 +39,7 @@ fun ScrollToTop( ScrollToTop( isVisible = showScrollTopButton, - onClick = { lazyListState.animateScrollToItem(0) }, - modifier = modifier - ) -} - -@Composable -fun ScrollToTop( - lazyGridState: LazyGridState, - modifier: Modifier = Modifier, -) { - val showScrollTopButton by remember { - derivedStateOf { - lazyGridState.firstVisibleItemIndex > lazyGridState.layoutInfo.visibleItemsInfo.size - } - } - - ScrollToTop( - isVisible = showScrollTopButton, - onClick = { lazyGridState.animateScrollToItem(0) }, + onClick = lazyListState::smoothScrollToTop, modifier = modifier ) } diff --git a/app/src/main/kotlin/it/vfsfitvnm/vimusic/ui/screens/player/PlayerBottomSheet.kt b/app/src/main/kotlin/it/vfsfitvnm/vimusic/ui/screens/player/PlayerBottomSheet.kt index 04220bb..d6d077b 100644 --- a/app/src/main/kotlin/it/vfsfitvnm/vimusic/ui/screens/player/PlayerBottomSheet.kt +++ b/app/src/main/kotlin/it/vfsfitvnm/vimusic/ui/screens/player/PlayerBottomSheet.kt @@ -64,6 +64,7 @@ import it.vfsfitvnm.vimusic.utils.rememberMediaItemIndex import it.vfsfitvnm.vimusic.utils.rememberShouldBePlaying import it.vfsfitvnm.vimusic.utils.rememberWindows import it.vfsfitvnm.vimusic.utils.shuffleQueue +import it.vfsfitvnm.vimusic.utils.smoothScrollToTop import kotlinx.coroutines.launch @ExperimentalFoundationApi @@ -285,7 +286,7 @@ fun PlayerBottomSheet( .padding(end = 2.dp) .clickable { reorderingState.coroutineScope.launch { - reorderingState.lazyListState.animateScrollToItem(0) + reorderingState.lazyListState.smoothScrollToTop() }.invokeOnCompletion { binder.player.shuffleQueue() } diff --git a/app/src/main/kotlin/it/vfsfitvnm/vimusic/utils/LazyListState.kt b/app/src/main/kotlin/it/vfsfitvnm/vimusic/utils/LazyListState.kt new file mode 100644 index 0000000..ccd3aec --- /dev/null +++ b/app/src/main/kotlin/it/vfsfitvnm/vimusic/utils/LazyListState.kt @@ -0,0 +1,10 @@ +package it.vfsfitvnm.vimusic.utils + +import androidx.compose.foundation.lazy.LazyListState + +suspend fun LazyListState.smoothScrollToTop() { + if (firstVisibleItemIndex > layoutInfo.visibleItemsInfo.size) { + scrollToItem(layoutInfo.visibleItemsInfo.size) + } + animateScrollToItem(0) +}