feat(ui): tabs that do not fit a narrow page open as a dropdown (#3640)

* feat(ui): tabs that do not fit a narrow page open as a dropdown

In portrait or on a narrow page, a row of section pills that would scroll
sideways becomes one chip naming the shown section, which opens the list of
sections, as the second screen's picker does. Covers the sheets' pills
(Steam, desktop, glasses, Settings and the others on SheetChips), TabStrip,
the game page's tabs and the Stores chips.

* fix(stores): the compact store picker takes controller focus, survives a hidden store and keeps the signed-out status

* fix(ui): picking the shown tab from the tab menu still activates it
This commit is contained in:
Kurt Himebauch authored and GitHub committed 2026-12-03 13:49:09 -05:00
1 parent 7138f95c90
commit 18d735b4c4
5 files changed
+129 -3

No files matched your search

@@ -415,6 +415,10 @@ private fun GameTabBar(
if (bumpers) TabBarBumper("LB", stringResource(R.string.widgets_prev_tab), leading = true) { onSelect((selected + tabs.size - 1) % tabs.size) }
androidx.compose.foundation.layout.BoxWithConstraints(Modifier.weight(1f).clip(if (bumpers) RoundedCornerShape(BumperFlat) else CircleShape).onSizeChanged { viewport = it.width }) {
val share = maxWidth / tabs.size.coerceAtLeast(1)
if (tabsAsMenu(maxWidth, tabs.size)) {
TabMenu(tabs, selected, onSelect, focus = focusRequesters)
return@BoxWithConstraints
}
Box(Modifier.horizontalScroll(scroll)) {
spans.getOrNull(selected)?.takeIf { tabHeight > 0 }?.let { span ->
TabHighlight(span, tabHeight, flatStart = bumpers && selected == 0, flatEnd = bumpers && selected == tabs.lastIndex)
@@ -711,6 +711,10 @@ internal fun SheetChips(
Modifier.fillMaxWidth().onFocusChanged { within = it.hasFocus },
contentAlignment = Alignment.CenterStart,
) {
if (tabsAsMenu(maxWidth, labels.size)) {
TabMenu(labels, selected, onPick, focus = chips)
return@BoxWithConstraints
}
val equal = !width.isSpecified && maxWidth / labels.size.coerceAtLeast(1) >= 96.dp
val least = if (width.isSpecified) maxOf(width, 64.dp) else 64.dp
val scroll = rememberScrollState()
@@ -212,7 +212,8 @@ internal fun TabStrip(
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(6.dp), modifier = modifier) {
if (bumpers) BumperKey("LB", stringResource(R.string.widgets_prev_tab)) { onSelect((selected + tabs.size - 1) % tabs.size) }
// Centred, the bumpers sit at the edges and the tabs in the middle, as in the bottom bar.
Box(if (centered) Modifier.weight(1f) else Modifier.weight(1f, fill = false), contentAlignment = Alignment.Center) { Row(
Box(if (centered) Modifier.weight(1f) else Modifier.weight(1f, fill = false), contentAlignment = Alignment.Center) { androidx.compose.foundation.layout.BoxWithConstraints {
if (tabsAsMenu(maxWidth, tabs.size)) TabMenu(tabs, selected, onSelect, focus = focusRequesters) else Row(
modifier = Modifier.clip(shape).background(colors.surfaceVariant).border(1.dp, pal.line2, shape)
.horizontalScroll(scroll).selectableGroup().padding(3.dp),
) {
@@ -239,7 +240,7 @@ internal fun TabStrip(
.padding(horizontal = tabPadding, vertical = if (compact) 6.dp else 12.dp),
)
}
} }
} } }
if (bumpers) BumperKey("RB", stringResource(R.string.widgets_next_tab)) { onSelect((selected + 1) % tabs.size) }
}
}
@@ -470,7 +470,21 @@ private fun StoreChips(
val tabScroll = rememberScrollState()
Box(Modifier.fillMaxWidth()) {
Row(horizontalArrangement = Arrangement.spacedBy(gap), verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxWidth()) {
Box(Modifier.weight(1f).edgeFade(tabScroll).horizontalScroll(tabScroll)) {
val shown = tabs.filter { it.shown }.map { it.store }
androidx.compose.foundation.layout.BoxWithConstraints(Modifier.weight(1f)) {
if (tabsAsMenu(maxWidth, shown.size)) TabMenu(
shown.map { it.shortLabel }, shown.indexOfFirst { it.id == selected }, { onStore(shown[it]) },
chipModifier = shown.fold(Modifier as Modifier) { m, st -> key(st) { m.paneItem("storechip:${st.id}") } },
descriptions = shown.map { st ->
val signedIn = StoresState.isSignedIn(st) && StoresState.expired[st] != true
st.label + if (signedIn || !StoresState.accountsLoaded) "" else " " + stringResource(R.string.stores_chip_signed_out)
},
leading = { i, inList ->
val signedIn = StoresState.isSignedIn(shown[i]) && StoresState.expired[shown[i]] != true
if (inList) Box(Modifier.size(12.dp).background(sourceColours(shown[i].id).dot.copy(alpha = if (signedIn) 1f else 0.35f), CircleShape))
else StoreDot(shown[i], signedIn)
},
) else Box(Modifier.edgeFade(tabScroll).horizontalScroll(tabScroll)) {
Row(horizontalArrangement = Arrangement.spacedBy(gap), verticalAlignment = Alignment.CenterVertically, modifier = Modifier.focusGroup()) {
for (tab in tabs) {
val store = tab.store
@@ -492,6 +506,7 @@ private fun StoreChips(
}
ChipGlide(keys.indexOf(highlighted), bounds[highlighted], tint, visible = fillShown)
}
}
var cogAt by remember { mutableStateOf<Rect?>(null) }
Box(Modifier.onGloballyPositioned { cogAt = it.boundsInRoot() }) {
IconChip(Icons.Filled.Settings, stringResource(R.string.stores_settings)) { onSettings(cogAt) }
@@ -0,0 +1,102 @@
package com.droiddeck.launcher.ui
import androidx.compose.foundation.LocalIndication
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.hoverable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.interaction.collectIsFocusedAsState
import androidx.compose.foundation.interaction.collectIsHoveredAsState
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.ExpandLess
import androidx.compose.material.icons.outlined.ExpandMore
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
private val TAB_MENU_BELOW = 600.dp
private val TAB_MIN_WIDTH = 96.dp
/** Whether [count] tabs in [width] become a [TabMenu]: on a narrow page, when they would not fit side by side. */
internal fun tabsAsMenu(width: Dp, count: Int): Boolean =
count > 2 && width < TAB_MENU_BELOW && width / count < TAB_MIN_WIDTH
/**
* Tabs as one chip naming the shown tab, which opens the list of them, as the second screen's
* picker does. Each of [focus] lands on the chip, so callers that focus a tab still reach it.
*/
@Composable
internal fun TabMenu(
labels: List<String>, selected: Int, onPick: (Int) -> Unit,
modifier: Modifier = Modifier, focus: List<FocusRequester>? = null,
chipModifier: Modifier = Modifier, descriptions: List<String>? = null,
leading: (@Composable (index: Int, inList: Boolean) -> Unit)? = null,
) {
val colors = MaterialTheme.colorScheme
val pal = LocalPalette.current
var open by remember { mutableStateOf(false) }
val source = remember { MutableInteractionSource() }
val hot = source.collectIsFocusedAsState().value || source.collectIsHoveredAsState().value
val shape = RoundedCornerShape(22.dp)
val label = labels.getOrNull(selected).orEmpty()
val description = descriptions?.getOrNull(selected) ?: label
val toggle = { open = !open }
Box(modifier) {
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(8.dp),
modifier = focus.orEmpty().fold(chipModifier.height(44.dp)) { m, r -> m.focusRequester(r) }
.testTag("tab-menu")
.semantics { contentDescription = description }
.clip(shape).background(if (hot || open) pal.signal.copy(alpha = 0.14f) else colors.surfaceVariant)
.glideBorder(hot || open, shape, pal.signal, pal.line2)
.hoverable(source)
.clickable(role = Role.Button, interactionSource = source, indication = LocalIndication.current, onClick = toggle)
.controllerConfirm(onClick = toggle)
.padding(start = 14.dp, end = 10.dp),
) {
if (selected in labels.indices) leading?.invoke(selected, false)
Text(label, fontSize = 14.sp, fontWeight = FontWeight.Bold, color = colors.onBackground, maxLines = 1,
overflow = TextOverflow.Ellipsis, modifier = Modifier.weight(1f, fill = false))
Icon(if (open) Icons.Outlined.ExpandLess else Icons.Outlined.ExpandMore, contentDescription = null,
tint = colors.onSurfaceVariant, modifier = Modifier.size(20.dp))
}
AnchoredMenu(open, { open = false }, compact = true, minWidth = 200.dp) { first ->
labels.forEachIndexed { i, item ->
MenuItem(
item, checked = i == selected,
leading = leading?.let { { it(i, true) } },
focusRequester = first.takeIf { i == selected || (i == 0 && selected !in labels.indices) },
modifier = Modifier.testTag("tab-menu:$i")
.then(descriptions?.getOrNull(i)?.let { d -> Modifier.semantics { contentDescription = d } } ?: Modifier),
) { open = false; onPick(i) }
}
}
}
}