mirror of
https://github.com/twinksoftware/Gearslip.git
synced 2026-11-10 16:02:25 +01:00
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:
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))
|
||||
}
|
||||
|
||||
/**
|
||||
* 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. */
|
||||
fun home() {
|
||||
stack.clear()
|
||||
|
||||
@@ -259,10 +259,14 @@ fun MediaScreen(app: MediaApp, onExit: () -> Unit) {
|
||||
@Composable
|
||||
private fun AppIdentity(app: MediaApp, onExit: () -> Unit, modifier: Modifier = Modifier) {
|
||||
val icon = remember(app) { findEntry(app.component.flattenToString())?.icon }
|
||||
val navigator = LocalCarNavigator.current
|
||||
Row(modifier, verticalAlignment = Alignment.CenterVertically) {
|
||||
// The same back button as every other screen's header, in the same place.
|
||||
GsIconButton(Icons.Filled.ArrowBack, stringResource(R.string.back), onExit)
|
||||
Spacer(Modifier.width(12.dp))
|
||||
// Shown on the same terms as every other screen's header: only when it leads somewhere
|
||||
// the nav bar doesn't.
|
||||
if (navigator.backLeadsSomewhere) {
|
||||
GsIconButton(Icons.Filled.ArrowBack, stringResource(R.string.back), onExit)
|
||||
Spacer(Modifier.width(12.dp))
|
||||
}
|
||||
icon?.let {
|
||||
Image(it, null, Modifier.size(26.dp).clip(RoundedCornerShape(7.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)) {
|
||||
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))) }
|
||||
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
|
||||
|
||||
/**
|
||||
* The top of every screen reached from Home: a back button in the current theme, the title, and
|
||||
* room on the right for the screen's own controls. A car touchscreen has no hardware back button,
|
||||
* so this is the way out of a screen.
|
||||
* The top of every screen reached from Home: the title, room on the right for the screen's own
|
||||
* controls, and a back button when the screen under this one is more than Home or the app grid -
|
||||
* those the nav bar already reaches, so a back button there only repeated it.
|
||||
*/
|
||||
@Composable
|
||||
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,
|
||||
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(
|
||||
title,
|
||||
style = MaterialTheme.typography.headlineSmall,
|
||||
|
||||
Reference in new issue
Block a user