App screens drop the back button when it would only lead to Home or the app grid, which the nav bar already does

This commit is contained in:
Seb3thehacker committed 2026-11-06 12:04:28 -08:00
1 parent be92ff0b3d
commit 6d32fe2bd3
4 files changed
+20 -8

No files matched your search

@@ -83,6 +83,14 @@ class CarNavigator(startId: String) {
stack.add(Crumb(screen, label, labelRes)) stack.add(Crumb(screen, label, labelRes))
} }
/**
* Whether a back button on this screen leads anywhere the nav bar doesn't: false when the
* screen under it is Home or the app grid, which the nav bar's own buttons already reach.
* Android Auto shows no back button on an app's first screen for the same reason.
*/
val backLeadsSomewhere: Boolean
get() = stack.size >= 2 && stack[stack.size - 2].screen.let { it != CarScreen.Home && it != CarScreen.Apps }
/** The one way back to a clean slate: resets the whole trail to just Home. */ /** The one way back to a clean slate: resets the whole trail to just Home. */
fun home() { fun home() {
stack.clear() stack.clear()
@@ -259,10 +259,14 @@ fun MediaScreen(app: MediaApp, onExit: () -> Unit) {
@Composable @Composable
private fun AppIdentity(app: MediaApp, onExit: () -> Unit, modifier: Modifier = Modifier) { private fun AppIdentity(app: MediaApp, onExit: () -> Unit, modifier: Modifier = Modifier) {
val icon = remember(app) { findEntry(app.component.flattenToString())?.icon } val icon = remember(app) { findEntry(app.component.flattenToString())?.icon }
val navigator = LocalCarNavigator.current
Row(modifier, verticalAlignment = Alignment.CenterVertically) { Row(modifier, verticalAlignment = Alignment.CenterVertically) {
// The same back button as every other screen's header, in the same place. // Shown on the same terms as every other screen's header: only when it leads somewhere
GsIconButton(Icons.Filled.ArrowBack, stringResource(R.string.back), onExit) // the nav bar doesn't.
Spacer(Modifier.width(12.dp)) if (navigator.backLeadsSomewhere) {
GsIconButton(Icons.Filled.ArrowBack, stringResource(R.string.back), onExit)
Spacer(Modifier.width(12.dp))
}
icon?.let { icon?.let {
Image(it, null, Modifier.size(26.dp).clip(RoundedCornerShape(7.dp))) Image(it, null, Modifier.size(26.dp).clip(RoundedCornerShape(7.dp)))
Spacer(Modifier.width(10.dp)) Spacer(Modifier.width(10.dp))
@@ -72,7 +72,7 @@ fun MessagesScreen(packageName: String) {
Column(Modifier.fillMaxSize().padding(start = 16.dp, end = 16.dp, top = 16.dp), verticalArrangement = Arrangement.spacedBy(16.dp)) { Column(Modifier.fillMaxSize().padding(start = 16.dp, end = 16.dp, top = 16.dp), verticalArrangement = Arrangement.spacedBy(16.dp)) {
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(12.dp)) { Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(12.dp)) {
GsIconButton(Icons.AutoMirrored.Filled.ArrowBack, stringResource(R.string.back), navigator::back) if (navigator.backLeadsSomewhere) GsIconButton(Icons.AutoMirrored.Filled.ArrowBack, stringResource(R.string.back), navigator::back)
entry?.icon?.let { Image(it, contentDescription = null, modifier = Modifier.size(36.dp).clip(RoundedCornerShape(8.dp))) } entry?.icon?.let { Image(it, contentDescription = null, modifier = Modifier.size(36.dp).clip(RoundedCornerShape(8.dp))) }
Text(label, style = MaterialTheme.typography.headlineSmall, fontWeight = FontWeight.Bold) Text(label, style = MaterialTheme.typography.headlineSmall, fontWeight = FontWeight.Bold)
} }
@@ -19,9 +19,9 @@ import androidx.compose.ui.unit.dp
import app.seb3thehacker.gearslip.car.theme.GsIconButton import app.seb3thehacker.gearslip.car.theme.GsIconButton
/** /**
* The top of every screen reached from Home: a back button in the current theme, the title, and * The top of every screen reached from Home: the title, room on the right for the screen's own
* room on the right for the screen's own controls. A car touchscreen has no hardware back button, * controls, and a back button when the screen under this one is more than Home or the app grid -
* so this is the way out of a screen. * those the nav bar already reaches, so a back button there only repeated it.
*/ */
@Composable @Composable
fun ScreenHeader(title: String, modifier: Modifier = Modifier, trailing: @Composable RowScope.() -> Unit = {}) { fun ScreenHeader(title: String, modifier: Modifier = Modifier, trailing: @Composable RowScope.() -> Unit = {}) {
@@ -31,7 +31,7 @@ fun ScreenHeader(title: String, modifier: Modifier = Modifier, trailing: @Compos
verticalAlignment = Alignment.CenterVertically, verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(12.dp), horizontalArrangement = Arrangement.spacedBy(12.dp),
) { ) {
GsIconButton(Icons.AutoMirrored.Filled.ArrowBack, stringResource(R.string.back), navigator::back) if (navigator.backLeadsSomewhere) GsIconButton(Icons.AutoMirrored.Filled.ArrowBack, stringResource(R.string.back), navigator::back)
Text( Text(
title, title,
style = MaterialTheme.typography.headlineSmall, style = MaterialTheme.typography.headlineSmall,