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
This commit is contained in:
topjohnwu
2026-10-08 10:35:49 -07:00
committed by John Wu
parent 5f1135036d
commit a271b9559e
@@ -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)