From a271b9559e4948ff7d46ed033ba2985b8d20dca2 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Thu, 8 Oct 2026 12:27:48 +0000 Subject: [PATCH] app: use bar when navigation rail does not fit The navigation suite switches to a rail once the window is at least 480dp tall, but the collapsed rail with the FAB header needs about 476dp of its own height for all five destinations plus the 44dp bottom space. In short freeform windows on desktop the last rail item was clipped by the window edge. The rail cannot scroll and its spacing is fixed, so fall back to the short navigation bar when the height left for the rail after system bars is below 520dp, the same switch the library already makes for windows under 480dp. Assisted-by: Claude Opus 5.5 --- .../java/com/topjohnwu/magisk/ui/MainScreen.kt | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/app/apk/src/main/java/com/topjohnwu/magisk/ui/MainScreen.kt b/app/apk/src/main/java/com/topjohnwu/magisk/ui/MainScreen.kt index 888cc56fb..edb4c8d24 100644 --- a/app/apk/src/main/java/com/topjohnwu/magisk/ui/MainScreen.kt +++ b/app/apk/src/main/java/com/topjohnwu/magisk/ui/MainScreen.kt @@ -9,10 +9,12 @@ import androidx.compose.animation.scaleIn import androidx.compose.animation.scaleOut import androidx.compose.foundation.focusGroup import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.WindowInsets import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.heightIn import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size +import androidx.compose.foundation.layout.systemBars import androidx.compose.foundation.pager.HorizontalPager import androidx.compose.foundation.pager.rememberPagerState import androidx.compose.material.icons.Icons @@ -40,6 +42,8 @@ import androidx.compose.ui.focus.FocusRequester import androidx.compose.ui.focus.focusProperties import androidx.compose.ui.focus.focusRequester import androidx.compose.ui.graphics.vector.ImageVector +import androidx.compose.ui.platform.LocalDensity +import androidx.compose.ui.platform.LocalWindowInfo import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.vectorResource import androidx.compose.ui.unit.dp @@ -102,7 +106,16 @@ fun MainScreen( val isModulesTab = visibleTabs.getOrNull(pagerState.currentPage) == Tab.MODULES val isSuperuserTab = visibleTabs.getOrNull(pagerState.currentPage) == Tab.SUPERUSER - val navType = NavigationSuiteScaffoldDefaults.navigationSuiteType(currentWindowAdaptiveInfo()) + // The collapsed rail needs 520dp (44dp top space, 96dp FAB header, 5 items, 44dp bottom) to + // show every item. In shorter windows use the bar, like the library does below 480dp. + val systemBars = WindowInsets.systemBars + val railHeight = LocalWindowInfo.current.containerDpSize.height - + with(LocalDensity.current) { (systemBars.getTop(this) + systemBars.getBottom(this)).toDp() } + val navType = NavigationSuiteScaffoldDefaults.navigationSuiteType(currentWindowAdaptiveInfo()).let { + if (it == NavigationSuiteType.WideNavigationRailCollapsed && railHeight < 520.dp) { + NavigationSuiteType.ShortNavigationBarMedium + } else it + } val isBar = navType == NavigationSuiteType.ShortNavigationBarCompact || navType == NavigationSuiteType.ShortNavigationBarMedium val showFab = (isModulesTab && moduleFabAction != null) || (isSuperuserTab && superuserFabAction != null)