From 63b37ef3f42841838cfeb8bf4200207825b2adab Mon Sep 17 00:00:00 2001 From: Ray <154766448+damontecres@users.noreply.github.com> Date: Sun, 8 Feb 2026 16:21:38 -0500 Subject: [PATCH] Fix glitchy nav drawer scrolling when opening (#848) ## Description The nav drawer would always glitch a little when it gained focus due it to trying to keep the selected page in view. #842 made this even worst. This PR fixes that issue by hoisting the list scroll state up higher which ensures it is remembered between recompositions. This change also eliminates the need for workarounds to try and scroll it programmatically which is also a tiny performance boost. ### Related issues Follow up to #842 ### Testing Emulator & nvidia shield ## Screenshots N/A ## AI or LLM usage None --- .../wholphin/ui/nav/ApplicationContent.kt | 3 ++ .../damontecres/wholphin/ui/nav/NavDrawer.kt | 35 ++----------------- 2 files changed, 6 insertions(+), 32 deletions(-) diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/nav/ApplicationContent.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/nav/ApplicationContent.kt index ff7643d8..0e3d5a43 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/nav/ApplicationContent.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/nav/ApplicationContent.kt @@ -6,6 +6,7 @@ import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.fillMaxHeight import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.saveable.rememberSerializable @@ -231,6 +232,7 @@ fun ApplicationContent( ) } } + val navDrawerListState = rememberLazyListState() NavDisplay( backStack = navigationManager.backStack, onBack = { navigationManager.goBack() }, @@ -257,6 +259,7 @@ fun ApplicationContent( user = user, server = server, drawerState = drawerState, + navDrawerListState = navDrawerListState, onClearBackdrop = viewModel::clearBackdrop, modifier = Modifier.fillMaxSize(), ) diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/nav/NavDrawer.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/nav/NavDrawer.kt index 0b9c8135..6eac3206 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/nav/NavDrawer.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/nav/NavDrawer.kt @@ -18,8 +18,8 @@ import androidx.compose.foundation.layout.offset import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.foundation.lazy.LazyListState import androidx.compose.foundation.lazy.itemsIndexed -import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.ArrowDropDown import androidx.compose.material.icons.filled.Home @@ -41,7 +41,6 @@ import androidx.compose.ui.focus.focusProperties import androidx.compose.ui.focus.focusRequester import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.vector.ImageVector -import androidx.compose.ui.platform.LocalConfiguration import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.platform.LocalView @@ -88,12 +87,10 @@ import com.github.damontecres.wholphin.ui.spacedByWithFooter import com.github.damontecres.wholphin.ui.theme.LocalTheme import com.github.damontecres.wholphin.ui.toServerString import com.github.damontecres.wholphin.ui.tryRequestFocus -import com.github.damontecres.wholphin.util.ExceptionHandler import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach -import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import org.jellyfin.sdk.api.client.ApiClient import org.jellyfin.sdk.api.client.extensions.imageApi @@ -272,6 +269,7 @@ fun NavDrawer( user: JellyfinUser, server: JellyfinServer, drawerState: DrawerState, + navDrawerListState: LazyListState, onClearBackdrop: () -> Unit, modifier: Modifier = Modifier, viewModel: NavDrawerViewModel = @@ -320,8 +318,6 @@ fun NavDrawer( visibilityThreshold = IntOffset.VisibilityThreshold, ), ) - val config = LocalConfiguration.current - val heightInPx = remember { with(density) { config.screenHeightDp.dp.roundToPx() } } ModalNavigationDrawer( modifier = modifier, @@ -329,28 +325,8 @@ fun NavDrawer( drawerContent = { drawerValue -> val isOpen = drawerValue.isOpen val spacedBy = 4.dp - val listState = rememberLazyListState() val searchFocusRequester = remember { FocusRequester() } - suspend fun scrollToSelected() { - val target = selectedIndex + 2 - try { - if (target !in - listState.firstVisibleItemIndex..