Skip to content

Commit f07662c

Browse files
Menu: color back button with secondaryContainer for differentiation (#2245)
The auto-injected previous-menu item rendered identically to other ring entries because both used primaryContainer. Add an isBackButton flag on MenuItem, default false, set true only on the BaseMenu-injected back item. RegularMenuItem flips its circle background and foreground tint to secondaryContainer / onSecondaryContainer when the flag is set, so users can pick the back action out at a glance without changing position or size. Co-authored-by: Owen McGirr <o.a.mcgirr@gmail.com>
1 parent aa9e8de commit f07662c

2 files changed

Lines changed: 17 additions & 5 deletions

File tree

app/src/main/java/com/enaboapps/switchify/service/menu/MenuItem.kt

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ class MenuItem(
6767
val closeOnSelect: Boolean = true,
6868
var isLinkToMenu: Boolean = false,
6969
var isMenuHierarchyManipulator: Boolean = false,
70+
val isBackButton: Boolean = false,
7071
private val action: () -> Unit
7172
) {
7273
/**
@@ -112,6 +113,7 @@ class MenuItem(
112113
isMenuHierarchyManipulator = isMenuHierarchyManipulator,
113114
isSmall = isSmall,
114115
isLinkToMenu = isLinkToMenu,
116+
isBackButton = isBackButton,
115117
menuSize = menuSize,
116118
onClick = { select() }
117119
)
@@ -185,6 +187,7 @@ private fun MenuItemContent(
185187
isMenuHierarchyManipulator: Boolean,
186188
isSmall: Boolean,
187189
isLinkToMenu: Boolean,
190+
isBackButton: Boolean,
188191
menuSize: MenuItemSize,
189192
onClick: () -> Unit
190193
) {
@@ -211,6 +214,7 @@ private fun MenuItemContent(
211214
showLabelAsDescription = showLabelAsDescription,
212215
menuSize = menuSize,
213216
isLinkToMenu = isLinkToMenu,
217+
isBackButton = isBackButton,
214218
onClick = onClick
215219
)
216220
}
@@ -260,11 +264,18 @@ private fun RegularMenuItem(
260264
showLabelAsDescription: Boolean,
261265
menuSize: MenuItemSize,
262266
isLinkToMenu: Boolean,
267+
isBackButton: Boolean,
263268
onClick: () -> Unit
264269
) {
265270
// Ring item: icon (or short text stand-in for label-only items) inside a
266271
// coloured circle, full label stacked underneath. Every item gets the same
267-
// circle background for visual consistency across the ring.
272+
// circle background for visual consistency across the ring — except the
273+
// back button, which uses the secondary container so users can pick it
274+
// out at a glance.
275+
val circleColor = if (isBackButton) MaterialTheme.colorScheme.secondaryContainer
276+
else MaterialTheme.colorScheme.primaryContainer
277+
val iconTint = if (isBackButton) MaterialTheme.colorScheme.onSecondaryContainer
278+
else MaterialTheme.colorScheme.onPrimaryContainer
268279
Column(
269280
modifier = Modifier
270281
.fillMaxSize()
@@ -280,7 +291,7 @@ private fun RegularMenuItem(
280291
modifier = Modifier
281292
.size(menuSize.containerCircleSize)
282293
.clip(CircleShape)
283-
.background(MaterialTheme.colorScheme.primaryContainer),
294+
.background(circleColor),
284295
contentAlignment = Alignment.Center
285296
) {
286297
// `circleText` overrides the icon: callers set it on items whose
@@ -298,7 +309,7 @@ private fun RegularMenuItem(
298309
)
299310
Text(
300311
text = circleText,
301-
color = MaterialTheme.colorScheme.onPrimaryContainer,
312+
color = iconTint,
302313
fontSize = effectiveFontSize,
303314
textAlign = TextAlign.Center,
304315
maxLines = 1
@@ -308,7 +319,7 @@ private fun RegularMenuItem(
308319
painter = painterResource(id = drawableId),
309320
contentDescription = labelResource?.let { Resources.getString(it) },
310321
modifier = Modifier.size(menuSize.iconSize),
311-
tint = MaterialTheme.colorScheme.onPrimaryContainer
322+
tint = iconTint
312323
)
313324
} else if (text != null) {
314325
// Cap the in-circle letter so the user's system font scale
@@ -326,7 +337,7 @@ private fun RegularMenuItem(
326337
}
327338
Text(
328339
text = circleInitials(text),
329-
color = MaterialTheme.colorScheme.onPrimaryContainer,
340+
color = iconTint,
330341
fontSize = effectiveFontSize,
331342
textAlign = TextAlign.Center,
332343
maxLines = 1

app/src/main/java/com/enaboapps/switchify/service/menu/menus/BaseMenu.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ open class BaseMenu(
6060
labelResource = R.string.menu_item_previous_menu,
6161
descriptionResource = R.string.menu_item_previous_menu_description,
6262
isLinkToMenu = true,
63+
isBackButton = true,
6364
action = { MenuManager.getInstance().menuHierarchy?.popMenu() }
6465
)
6566
listOf(previousMenuItem) + orderedItems

0 commit comments

Comments
 (0)