From 96e6d90d0fdbde688312a2a205c051b3eac9ac00 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Thu, 8 Oct 2026 12:26:29 +0000 Subject: [PATCH] app: refine FAB slot in navigation rail M3 specifies that a FAB nested in a navigation rail rests at elevation level 0. Use the library's zero elevation for the FAB in the rail header; the FAB floating above the bottom bar keeps its default elevation. The rail header reserves a 56dp slot so the rail items do not jump when the FAB shows or hides. Without root, neither the Modules nor the Superuser tab exists and the FAB never shows, so skip the slot and let the rail items start at the top. Assisted-by: Claude Opus 5.5 --- .../main/java/com/topjohnwu/magisk/ui/MainScreen.kt | 11 ++++++++++- 1 file changed, 10 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 390a23974..888cc56fb 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 @@ -18,6 +18,7 @@ import androidx.compose.foundation.pager.rememberPagerState import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Add import androidx.compose.material3.FloatingActionButton +import androidx.compose.material3.FloatingActionButtonDefaults import androidx.compose.material3.Icon import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text @@ -105,6 +106,7 @@ fun MainScreen( val isBar = navType == NavigationSuiteType.ShortNavigationBarCompact || navType == NavigationSuiteType.ShortNavigationBarMedium val showFab = (isModulesTab && moduleFabAction != null) || (isSuperuserTab && superuserFabAction != null) + val hasFabTab = Tab.MODULES in visibleTabs || Tab.SUPERUSER in visibleTabs // The explicit focus wiring below assumes the FAB sits above a bottom bar, so only apply // it in bar mode. With a rail, the default 2D focus search works as is. @@ -143,7 +145,11 @@ fun MainScreen( primaryActionContent = { // In the rail header, keep the FAB slot even when the FAB is hidden so the rail // items don't jump on tab switches, and center the FAB in the collapsed rail. - Box(if (isBar) Modifier else Modifier.padding(start = 20.dp).heightIn(min = 56.dp)) { + // Skip the slot if no tab has a FAB (no root). + Box( + if (isBar || !hasFabTab) Modifier + else Modifier.padding(start = 20.dp).heightIn(min = 56.dp) + ) { AnimatedVisibility( visible = showFab, enter = scaleIn() + fadeIn(), @@ -167,6 +173,9 @@ fun MainScreen( } else Modifier, containerColor = MaterialTheme.colorScheme.primaryContainer, contentColor = MaterialTheme.colorScheme.onPrimaryContainer, + // M3: a FAB nested in the navigation rail has no elevation + elevation = if (isBar) FloatingActionButtonDefaults.elevation() + else FloatingActionButtonDefaults.bottomAppBarFabElevation(), ) { Icon( imageVector = Icons.Default.Add,