Fix Discord launcher layout and controller navigation (#596)

This commit is contained in:
Kurt Himebauch authored and GitHub committed 2026-10-11 20:08:59 -04:00
1 parent 8f5ccbf23f
commit b1690852e9
20 files changed
+278 -75

No files matched your search

@@ -163,6 +163,7 @@ class MainActivity : ComponentActivity() {
private var orientation by mutableStateOf(android.content.pm.ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE)
private var launcherFullscreen by mutableStateOf(true)
private var animationsEnabled by mutableStateOf(true)
private var gameStoresEnabled by mutableStateOf(true)
private var gameStoresSpeedTier by mutableStateOf("fast")
private var storesOpenTab by mutableStateOf(SessionPrefs.STORES_OPEN_LIBRARY)
/** A page a notification asked for ("stores:downloads", "app:<id>"), until the front end has gone there. */
@@ -534,6 +535,7 @@ class MainActivity : ComponentActivity() {
requestedOrientation = orientation
launcherFullscreen = SessionPrefs.launcherFullscreen(this)
animationsEnabled = SessionPrefs.animationsEnabled(this)
gameStoresEnabled = SessionPrefs.gameStoresEnabled(this)
gameStoresSpeedTier = SessionPrefs.gameStoresSpeedTier(this)
storesOpenTab = SessionPrefs.storesOpenTab(this)
storesShowMature = SessionPrefs.storesShowMature(this)
@@ -587,6 +589,7 @@ class MainActivity : ComponentActivity() {
orientation = orientation,
launcherFullscreen = launcherFullscreen,
animationsEnabled = animationsEnabled,
gameStoresEnabled = gameStoresEnabled,
gameStoresSpeedTier = gameStoresSpeedTier,
storesOpenTab = storesOpenTab,
navigate = navRequest,
@@ -727,6 +730,7 @@ class MainActivity : ComponentActivity() {
offline = OfflineMode.enabled(this)
},
onPageBack = { showPerformance = false; showComponents = false; showMapping = false },
onGameStoresEnabled = { on -> SessionPrefs.setGameStoresEnabled(this, on); gameStoresEnabled = on },
onTheme = { id -> SessionPrefs.setTheme(this, id); theme = id },
onLanguage = { tag ->
if (tag != com.droiddeck.launcher.core.AppLanguage.chosen(this)) {
@@ -71,6 +71,12 @@ object SessionPrefs {
prefs(context).edit().putBoolean("animations", on).apply()
}
fun gameStoresEnabled(context: Context): Boolean = prefs(context).getBoolean("gameStoresEnabled", true)
fun setGameStoresEnabled(context: Context, on: Boolean) {
prefs(context).edit().putBoolean("gameStoresEnabled", on).apply()
}
/** The store download engine's speed tier (stores/download/StoreDownloadTier ids); Fast unless chosen otherwise. */
fun gameStoresSpeedTier(context: Context): String = prefs(context).getString("gameStoresSpeedTier", "fast") ?: "fast"
@@ -739,7 +739,15 @@ fun ComponentsPage(
Column(Modifier.fillMaxSize()) {
// The in-use bar keeps its place; only its words change.
AnimatedContent(l, transitionSpec = { fadeIn(Motion.tw(240)) togetherWith fadeOut(Motion.tw(160)) }, label = "inUse") { k -> bar(k) }
Column(Modifier.weight(1f).fillMaxWidth().verticalScroll(rememberScrollState()).padding(top = 12.dp, bottom = 16.dp)) {
val detailScroll = androidx.compose.runtime.key(l) { rememberScrollState() }
Column(Modifier.weight(1f).fillMaxWidth().verticalScroll(detailScroll).padding(top = 12.dp, bottom = 16.dp)) {
// Shared performance settings stay visible before the downloadable catalog.
if (l == PROTON_TAB) {
if (!protons.runtimeReady) EmptyLine(stringResource(R.string.content_needs_runtime))
if (protons.sessionRunning) EmptyLine(stringResource(R.string.proton_stop_first))
SettingsGroup(stringResource(R.string.comp_for_every_proton)) { protonOptions() }
Spacer(Modifier.height(12.dp))
}
val slide: @Composable (@Composable (String) -> Unit) -> Unit = { body ->
AnimatedContent(
l,
@@ -777,10 +785,6 @@ fun ComponentsPage(
}
}
if (l == PROTON_TAB) {
Spacer(Modifier.height(10.dp))
if (!protons.runtimeReady) EmptyLine(stringResource(R.string.content_needs_runtime))
if (protons.sessionRunning) EmptyLine(stringResource(R.string.proton_stop_first))
SettingsGroup(stringResource(R.string.comp_for_every_proton)) { protonOptions() }
Spacer(Modifier.height(12.dp))
Note(stringResource(R.string.comp_about_text))
}
@@ -815,41 +819,37 @@ fun ComponentsPage(
if (narrow) Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.padding(top = 6.dp)) { DeviceChip(gpu) }
Spacer(Modifier.height(14.dp))
if (games.isNotEmpty()) {
SettingsGroup(stringResource(R.string.comp_profile_configure)) {
SettingsRow(
stringResource(R.string.comp_profile),
if (selectedGame == null) {
stringResource(R.string.comp_scope_general_detail)
} else {
stringResource(R.string.comp_profile_game_detail, selectedGame.name)
},
) {
Box {
ValueChip(
selectedGame?.name ?: stringResource(R.string.comp_scope_general),
scopeMenu,
modifier = Modifier.widthIn(max = 320.dp).heightIn(min = 44.dp),
) { scopeMenu = !scopeMenu }
AnchoredMenu(
scopeMenu,
onDismiss = { scopeMenu = false },
title = stringResource(R.string.comp_profile_configure),
) { first ->
MenuItem(
stringResource(R.string.comp_scope_general),
checked = selectedGame == null,
detail = stringResource(R.string.comp_scope_general_detail),
focusRequester = first,
) {
selectedGameKey = null
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(12.dp),
modifier = Modifier.fillMaxWidth().padding(bottom = 10.dp),
) {
Text(stringResource(R.string.comp_profile), fontSize = 14.sp, color = colors.onSurfaceVariant)
Box(Modifier.weight(1f, fill = false)) {
ValueChip(
selectedGame?.name ?: stringResource(R.string.comp_scope_general),
scopeMenu,
modifier = Modifier.widthIn(max = 320.dp).heightIn(min = 44.dp),
) { scopeMenu = !scopeMenu }
AnchoredMenu(
scopeMenu,
onDismiss = { scopeMenu = false },
title = stringResource(R.string.comp_profile_configure),
) { first ->
MenuItem(
stringResource(R.string.comp_scope_general),
checked = selectedGame == null,
detail = stringResource(R.string.comp_scope_general_detail),
focusRequester = first,
) {
selectedGameKey = null
scopeMenu = false
}
games.sortedBy { it.name.lowercase() }.forEach { game ->
MenuItem(game.name, checked = selectedGameKey == game.profileKey) {
selectedGameKey = game.profileKey
scopeMenu = false
}
games.sortedBy { it.name.lowercase() }.forEach { game ->
MenuItem(game.name, checked = selectedGameKey == game.profileKey) {
selectedGameKey = game.profileKey
scopeMenu = false
}
}
}
}
}
@@ -3,6 +3,7 @@ package com.droiddeck.launcher.ui
import com.droiddeck.launcher.R
import androidx.compose.ui.res.stringResource
import androidx.activity.compose.BackHandler
import androidx.compose.foundation.focusGroup
import androidx.compose.foundation.background
import androidx.compose.foundation.hoverable
import androidx.compose.foundation.interaction.MutableInteractionSource
@@ -42,6 +43,11 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.onFocusChanged
import androidx.compose.ui.input.InputMode
import androidx.compose.ui.platform.LocalInputModeManager
import androidx.compose.runtime.snapshotFlow
import kotlinx.coroutines.flow.first
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.font.FontWeight
@@ -84,11 +90,19 @@ fun DriverPage(
// D-pad: up from the first driver lands on refresh; the page opens with the driver in use focused.
val refreshFocus = remember { FocusRequester() }
val selectedFocus = remember { FocusRequester() }
LaunchedEffect(Unit) { runCatching { selectedFocus.requestFocus() } }
val inputMode = LocalInputModeManager.current
var pageFocused by remember { mutableStateOf(false) }
LaunchedEffect(inputMode.inputMode) {
if (inputMode.inputMode != InputMode.Keyboard) return@LaunchedEffect
// The chooser holds controller focus until its closing animation finishes.
snapshotFlow { Steps.step }.first { it == null }
focusWithinFrames({ pageFocused }) { selectedFocus }
}
val refreshSrc = remember { MutableInteractionSource() }
val refreshHot = refreshSrc.collectIsFocusedAsState().value || refreshSrc.collectIsHoveredAsState().value
SettingsPage(
host, title = title, onBack = onBack, lede = "$hint\n$status",
modifier = Modifier.onFocusChanged { pageFocused = it.hasFocus }.focusGroup(),
action = {
Box(
contentAlignment = Alignment.Center,
@@ -175,7 +175,7 @@ internal fun FocusGlideHost(modifier: Modifier = Modifier, content: @Composable
val alpha = remember { Animatable(0f) }
val scope = rememberCoroutineScope()
// An edge each, the corner, and a droplet carrying all of them.
val jobs = remember { arrayOfNulls<Job>(6) }
val jobs = remember { arrayOfNulls<Job>(7) }
val cur = glide.current
var lastColor by remember { mutableStateOf(Color.Transparent) }
if (cur != null) lastColor = cur.color
@@ -191,8 +191,11 @@ internal fun FocusGlideHost(modifier: Modifier = Modifier, content: @Composable
var lastMove = 0L
fun go(i: Int, v: Float, spec: AnimationSpec<Float>, wait: Long) {
// A drop cut short by another move turns back into an outline on the way.
if (jobs[5]?.isActive == true || solid.targetValue > 0f) scope.launch { solid.animateTo(0f, Motion.tw(120)) }
jobs[5]?.cancel()
if (jobs[5]?.isActive == true || solid.targetValue > 0f) {
jobs[5]?.cancel()
jobs[6]?.cancel()
jobs[6] = scope.launch { solid.animateTo(0f, Motion.tw(120)) }
}
// Picks up the speed it is going at: restarting from rest on every step of a held
// direction is what made it stutter.
val speed = edges[i].velocity
@@ -270,6 +273,8 @@ internal fun FocusGlideHost(modifier: Modifier = Modifier, content: @Composable
// Focus passing between two controls can let go of one a moment before the next
// takes it: wait a beat, so that reads as a move and not a fade out and back in.
delay(60)
jobs.forEach { it?.cancel() }
solid.snapTo(0f)
scope.launch { alpha.animateTo(0f, Motion.tw(140)) }
shown = null
return@collectLatest
@@ -106,14 +106,14 @@ internal fun SideRail(
modifier = modifier.width(if (iconOnly) 64.dp else 92.dp).background(colors.surface).padding(vertical = if (compact) 8.dp else 12.dp),
) {
// Every section on screen at once: items shrink (to 44dp, still a touch target) before the rail scrolls.
val count = 7 + (if (s.isHomeApp) 1 else 0)
val count = 6 + (if (s.gameStoresEnabled) 1 else 0) + (if (s.isHomeApp) 1 else 0)
BoxWithConstraints(Modifier.weight(1f).fillMaxWidth()) {
val fit = (maxHeight / count - 4.dp).coerceIn(44.dp, if (iconOnly) 48.dp else if (compact) 52.dp else 60.dp)
// A hop in flight moves the selection ahead of the page it is bringing.
val shown = Hops.railPreview ?: selected
val keys = buildList {
add("steam"); add("games")
add("stores")
if (s.gameStoresEnabled) add("stores")
add("desktop")
add("components")
if (s.isHomeApp) add("android-apps")
@@ -145,7 +145,7 @@ internal fun SideRail(
// The game stores, right under Games: what they install lands there. Its badge counts
// the downloads in flight, so a download started here is never out of sight.
// A section switched on in Setup comes in as the rail's own entrance; off, it folds away.
RailItem(stringResource(R.string.rail_stores), Icons.Outlined.LocalMall, "stores", shown == "stores", compact, iconOnly, fit, count = s.storeDownloadsActive, place = place, onFocus = { onFocusSelect("stores") }) { onSelect("stores") }
if (s.gameStoresEnabled) RailItem(stringResource(R.string.rail_stores), Icons.Outlined.LocalMall, "stores", shown == "stores", compact, iconOnly, fit, count = s.storeDownloadsActive, place = place, onFocus = { onFocusSelect("stores") }) { onSelect("stores") }
RailItem(stringResource(R.string.rail_desktop), Icons.Outlined.DesktopWindows, "desktop", shown == "desktop", compact, iconOnly, fit, place = place, onFocus = { onFocusSelect("desktop") }) { onSelect("desktop") }
RailItem(stringResource(R.string.rail_components), Icons.Outlined.Layers, "components", shown == "components", compact, iconOnly, fit, place = place, onFocus = { onFocusSelect("components") }) { onSelect("components") }
// Home mode's extra section goes last, so it shifts nothing above it.
@@ -134,6 +134,7 @@ class FrontEndState(
val orientation: Int = android.content.pm.ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE,
val launcherFullscreen: Boolean = true,
val animationsEnabled: Boolean = true,
val gameStoresEnabled: Boolean = true,
/** Setup › Stores: the download engine's speed tier (stores/download/StoreDownloadTier ids). */
val gameStoresSpeedTier: String = "fast",
/** Setup › Stores: the tab a signed-in store opens on (SessionPrefs.STORES_OPEN_LIBRARY / STORE). */
@@ -212,6 +213,7 @@ class FrontEndActions(
val onOrientation: (Int) -> Unit = {},
val onLauncherFullscreen: (Boolean) -> Unit = {},
val onAnimationsEnabled: (Boolean) -> Unit = {},
val onGameStoresEnabled: (Boolean) -> Unit = {},
val onGameStoresSpeedTier: (String) -> Unit = {},
val onStoresOpenTab: (String) -> Unit = {},
val onNavigated: () -> Unit = {},
@@ -339,6 +341,8 @@ internal class FrontFocus {
/** Down from this button goes to the first tile of the page's grid, when there is one. */
@Composable
internal fun Modifier.downToFirstTile(): Modifier {
// Sheet rows walk their settings; Desktop's dock stays composed behind the sheet.
if (LocalSheetBeat.current != null) return this
val ff = LocalFrontFocus.current ?: return this
return this.focusProperties { down = if (ff.firstTileAttached > 0) ff.firstTile else FocusRequester.Default }
}
@@ -499,6 +503,7 @@ private fun FrontEndScreenBody(s: FrontEndState, a: FrontEndActions, page: (@Com
}
val inputModeManager = LocalInputModeManager.current
val window = LocalWindowInfo.current
val androidContext = androidx.compose.ui.platform.LocalContext.current
var anyFocused by remember { mutableStateOf(false) }
Box(
modifier = Modifier.fillMaxSize().background(colors.background)
@@ -530,7 +535,15 @@ private fun FrontEndScreenBody(s: FrontEndState, a: FrontEndActions, page: (@Com
if (processSettingsPageVisible) return@LaunchedEffect
// Past the old page's exit (170ms), then the first frame the new page takes focus.
kotlinx.coroutines.delay(Motion.ms(PAGE_EXIT_MS).toLong())
if (anyFocused || inputModeManager.inputMode != InputMode.Keyboard) return@LaunchedEffect
if (inputModeManager.inputMode != InputMode.Keyboard) return@LaunchedEffect
if (s.pageKey == "performance") {
val back = "back:${androidContext.getString(R.string.mode_back)}"
focusWithinFrames({ frontFocus.last == back && anyFocused && frontFocus.focusedRail == null }) {
frontFocus.items[back] ?: FocusRequester.Default
}
return@LaunchedEffect
}
if (anyFocused) return@LaunchedEffect
focusWithinFrames({ anyFocused }) { if (frontFocus.primaryAttached > 0) frontFocus.primary else frontFocus.railFor(railSelection) }
}
// A rail item picked with a controller moves on into its page, once the page is in.
@@ -366,6 +366,7 @@ internal fun SetupPanel(
ToggleRow(host, "launcher-animations", stringResource(R.string.setup_animations), null,
s.animationsEnabled, onChange = a.onAnimationsEnabled)
LanguageRow(host, s.language, a.onLanguage)
ToggleRow(host, "show-stores", stringResource(R.string.setup_stores), null, s.gameStoresEnabled, onChange = a.onGameStoresEnabled)
}
}
val device: @Composable () -> Unit = {
@@ -37,10 +37,14 @@ import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.widthIn
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.horizontalScroll
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Close
import androidx.compose.material.icons.filled.KeyboardArrowUp
import androidx.compose.ui.platform.testTag
import kotlinx.coroutines.Job
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
@@ -126,12 +130,12 @@ internal object SheetTab {
/**
* Where the open sheet's top edge sits in a pane [paneH] tall (px), for a button [buttonH] tall
* riding it: 82dp down a 360dp pane, the same share of any other, and never so high that the
* riding it: 60dp down a 360dp pane, the same share of any other, and never so high that the
* button's top comes closer than [minAbove] to the pane's. [ride] is how far below the edge the
* button's centre sits.
*/
internal fun sheetTop(paneH: Float, buttonH: Float, minAbove: Float, ride: Float): Float =
maxOf(paneH * 82f / 360f, minAbove + buttonH / 2f - ride)
maxOf(paneH * 60f / 360f, minAbove + buttonH / 2f - ride)
/** A finger's hold on the sheet: where it started (0 rest, 1 open), where it is, whether it has it. */
private class SheetDrag {
@@ -228,6 +232,7 @@ internal fun LiftHero(
// Set as a finger's drag lets go: the sheet is already where it is going.
var dragSettled by remember { mutableStateOf(false) }
val scope = androidx.compose.runtime.rememberCoroutineScope()
var dragJob by remember { mutableStateOf<Job?>(null) }
val onOpenNow = rememberUpdatedState(onOpen)
val pull = remember { Animatable(0f) }
val sink = remember { Animatable(0f) }
@@ -273,6 +278,7 @@ internal fun LiftHero(
onDispose { lifecycle.removeObserver(obs) }
}
LaunchedEffect(open, launching) {
if (!dragSettled) { dragJob?.cancel(); dragJob = null }
if (dragSettled) {
// A finger brought it here and has already animated it: only what opening needs.
dragSettled = false
@@ -378,6 +384,8 @@ internal fun LiftHero(
}
/** A finger takes the sheet where it is: up from rest, or down from open. */
fun beginDrag() {
dragJob?.cancel(); dragJob = null
dragSettled = false
drag.engaged = true
drag.from = if (open) 1f else 0f
drag.progress = drag.from
@@ -401,7 +409,8 @@ internal fun LiftHero(
else -> drag.progress > 0.3f
}
dragSettled = true
scope.launch {
dragJob?.cancel()
dragJob = scope.launch {
val to = if (opens) 1f else 0f
coroutineScope {
launch { lift.animateTo(to, Motion.sp(if (opens) 0.7f else 1f, 380f)) }
@@ -554,7 +563,7 @@ internal fun LiftHero(
.offset { IntOffset(chipsX.roundToInt(), chipsY.roundToInt()) }
// Over the rows, whatever they scroll under them.
.zIndex(1f)
.width(with(density) { (sheetW - chipsX - 16.dp.toPx()).coerceAtLeast(0f).toDp() })
.width(with(density) { (sheetW - chipsX - 64.dp.toPx()).coerceAtLeast(0f).toDp() })
.graphicsLayer { val v = pieces[0].value; alpha = v; translationY = (1f - v) * 6.dp.toPx() }
// Up from the chips folds the sheet (a finger drags it down, see the hero's drag).
.onPreviewKeyEvent { e ->
@@ -596,6 +605,18 @@ internal fun LiftHero(
}
}
}
val closeSource = remember { MutableInteractionSource() }
val closeHot = rememberHot(closeSource)
Box(
contentAlignment = Alignment.Center,
modifier = Modifier
.offset { IntOffset((sheetW - 52.dp.toPx()).roundToInt(), chipsY.roundToInt()) }
.zIndex(1f).size(44.dp).testTag("sheet-close")
.clip(CircleShape).glideBorder(closeHot, CircleShape, pal.signal)
.hoverable(closeSource)
.clickable(interactionSource = closeSource, indication = LocalIndication.current, enabled = open && !launching, role = Role.Button) { close() }
.controllerConfirm(enabled = open && !launching) { close() },
) { Icon(Icons.Filled.Close, stringResource(R.string.common_close), tint = colors.onSurfaceVariant, modifier = Modifier.size(20.dp)) }
}
}
@@ -643,15 +664,15 @@ internal fun LiftHero(
// A lip a pad can reach stays composed (unseen at rest) so Down always has it to land on.
if (r0 != null && (lipShow.value > 0.01f || pull.value > 0.5f || (!downOpens && !open && !shown))) {
var handleW by remember { mutableStateOf(0f) }
val lipH = 22.dp + pull.value.dp
val lipH = 32.dp + pull.value.dp
val lift = { if (!open) open = true }
Box(
Modifier
.offset { IntOffset((r0.center.x - handleW / 2f).roundToInt(), (r0.bottom + raise * ride.value + (lipShow.value - 1f) * 8.dp.toPx()).roundToInt()) }
.onSizeChanged { handleW = it.width.toFloat() }
.graphicsLayer { alpha = lipShow.value * (1f - lipGone.value) }
// 44dp to touch; the tab itself is the top 22.
.heightIn(min = 44.dp)
// 44dp to touch, with a 32dp visible handle.
.heightIn(min = 44.dp).testTag("sheet-open")
.semantics { contentDescription = settingsLabel }
.then(
if (downOpens) Modifier.focusProperties { canFocus = false }
@@ -698,7 +719,7 @@ private fun Handle(height: Dp) {
.drawBorderSidesAndFoot(pal.line, 12.dp)
.padding(start = 14.dp, end = 10.dp),
) {
Text(stringResource(R.string.drawer_page_settings), fontSize = 12.sp, fontWeight = FontWeight.SemiBold, color = colors.onSurfaceVariant, maxLines = 1)
Text(stringResource(R.string.drawer_page_settings), fontSize = 14.sp, fontWeight = FontWeight.SemiBold, color = colors.onSurfaceVariant, maxLines = 1)
Icon(
Icons.Filled.KeyboardArrowUp, null, tint = colors.onSurfaceVariant,
modifier = Modifier.size(16.dp).graphicsLayer { translationY = if (still) 0f else -3.dp.toPx() * lift },
@@ -474,7 +474,7 @@ internal fun ProtonOptions(
onSyncBackend: (String) -> Unit, onFexPreset: (String) -> Unit, onForceSsbs: (Boolean) -> Unit,
) {
val host = rememberMenuHost()
SettingsRow(stringResource(R.string.sync_backend_title), stringResource(R.string.sync_backend_hint)) {
SettingsRow(stringResource(R.string.sync_backend_title), stringResource(R.string.sync_backend_hint), stacked = true) {
SegmentedTabs(
listOf(
SessionPrefs.SYNC_NTSYNC to stringResource(R.string.sync_backend_ntsync),
@@ -443,7 +443,7 @@ fun SettingsGroup(title: String, compact: Boolean = false, content: @Composable
* under it stay put.
*/
@Composable
fun SettingsRow(label: String, hint: String?, highlighted: Boolean = false, hintLines: Int? = null, control: @Composable () -> Unit) {
fun SettingsRow(label: String, hint: String?, highlighted: Boolean = false, hintLines: Int? = null, stacked: Boolean = false, control: @Composable () -> Unit) {
val colors = MaterialTheme.colorScheme
val pal = LocalPalette.current
val bg by animateColorAsState(if (highlighted) pal.signal.copy(alpha = 0.10f) else Color.Transparent, Motion.tw(200), label = "rowBg")
@@ -452,7 +452,7 @@ fun SettingsRow(label: String, hint: String?, highlighted: Boolean = false, hint
minLines = hintLines ?: 1, maxLines = hintLines ?: Int.MAX_VALUE, overflow = TextOverflow.Ellipsis)
}
// A narrow page stacks the control under its label, so neither squeezes the other.
if (LocalNarrowPane.current) Column(
if (stacked || LocalNarrowPane.current) Column(
modifier = Modifier.fillMaxWidth().background(bg).padding(start = 14.dp, end = 14.dp, top = 11.dp, bottom = 12.dp),
) {
Text(label, fontSize = 15.sp, fontWeight = FontWeight.SemiBold, color = colors.onBackground)
@@ -67,7 +67,7 @@ internal fun BoxScope.ChipGlide(
val crossEnd = remember { mutableStateOf(0f) }
val was = remember { intArrayOf(-1) }
val vertical = axis == GlideAxis.Vertical
LaunchedEffect(index, at) {
LaunchedEffect(index, at, Motion.scale) {
val b = at ?: return@LaunchedEffect
val s = if (vertical) b.top else b.left
val e = if (vertical) b.bottom else b.right
@@ -88,6 +88,8 @@ internal fun BoxScope.ChipGlide(
l.join(); r.join()
pinch.animateTo(0f, Motion.sp(0.6f, 500f))
} else {
// An adjacent move can interrupt a long hop while it is still pinched.
launch { pinch.animateTo(0f, Motion.sp(0.6f, 500f)) }
val forward = index > from
val (lead, trail) = if (forward) end to start else start to end
val leadTo = if (forward) e else s
@@ -7,6 +7,8 @@ import androidx.compose.foundation.LocalIndication
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.focusGroup
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.foundation.hoverable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Arrangement
@@ -133,7 +135,7 @@ internal enum class StepSide {
}
/** The choices' side of a [StepOut]: each piece fades in on its own beat, and [first] takes focus. */
internal class StepOutScope(private val items: List<Animatable<Float, AnimationVector1D>>, val first: FocusRequester, val open: Boolean) {
internal class StepOutScope(private val items: List<Animatable<Float, AnimationVector1D>>, val first: FocusRequester, val open: Boolean, val maxHeight: Dp) {
/** Piece [i] (0 first) of the box: it fades and rises in after the box has stepped out. */
fun Modifier.stepItem(i: Int): Modifier = graphicsLayer {
val v = items[i.coerceIn(0, items.lastIndex)].value
@@ -185,6 +187,9 @@ internal fun StepOut(
BoxWithConstraints(Modifier.fillMaxSize()) {
val hostWidth = constraints.maxWidth.toFloat()
val hostHeight = constraints.maxHeight.toFloat()
val availableHeight = with(density) {
maxOf(hostHeight - pill.bottom - pull, pill.top - pull).coerceAtLeast(44.dp.toPx()).toDp()
}
// No room under the control (a row near the foot of the screen): it steps out upward
// instead, the same outline mirrored about the control.
val up = measured?.let { pill.bottom + pull + it.height > hostHeight && pill.top - pull - it.height >= 0f } ?: false
@@ -265,13 +270,15 @@ internal fun StepOut(
modifier = Modifier
.offset { IntOffset(x.roundToInt(), (if (up) pill.top - pull - (measured?.height ?: 0) else pill.bottom + pull).roundToInt()) }
.widthIn(min = with(density) { pill.width.toDp() }, max = with(density) { maxW.toDp() })
.heightIn(max = availableHeight)
.onSizeChanged { if (measured != it) measured = it }
.controllerBack(onDismiss)
// A pad stays in the box until it is answered or folded, as it did in Stop's dialog.
.focusProperties { exit = { FocusRequester.Cancel } }
.focusGroup()
.verticalScroll(rememberScrollState())
.padding(start = 14.dp, end = 14.dp, top = 12.dp, bottom = 12.dp),
) { StepOutScope(pieces, first, open).content() }
) { StepOutScope(pieces, first, open, availableHeight).content() }
}
}
@@ -0,0 +1,7 @@
package com.droiddeck.launcher.ui
/** Vertical controller moves keep the same column, including across lazy item boundaries. */
internal fun storeGridNeighbor(index: Int, count: Int, columns: Int, direction: Int): Int? {
if (index !in 0 until count || columns < 1 || direction !in listOf(-1, 1)) return null
return (index + columns * direction).takeIf { it in 0 until count }
}
@@ -505,11 +505,11 @@ internal fun storesSettingsStep(at: Rect, s: androidx.compose.runtime.State<Fron
) {
StepTitle(stringResource(R.string.stores_settings_eyebrow))
Column(
Modifier.stepItem(1).fillMaxWidth().heightIn(max = 340.dp).verticalScroll(rememberScrollState()),
Modifier.stepItem(1).fillMaxWidth().heightIn(max = minOf(340.dp, (maxHeight - 64.dp).coerceAtLeast(44.dp))).verticalScroll(rememberScrollState()),
verticalArrangement = Arrangement.spacedBy(6.dp),
) {
val st = s.value
SettingsRow(stringResource(R.string.setup_stores_open_on), null) {
SettingsRow(stringResource(R.string.setup_stores_open_on), null, stacked = true) {
SegmentedTabs(
listOf(SessionPrefs.STORES_OPEN_LIBRARY to stringResource(R.string.stores_tab_library), SessionPrefs.STORES_OPEN_STORE to stringResource(R.string.stores_tab_store)),
st.storesOpenTab,
@@ -32,6 +32,10 @@ import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import androidx.compose.ui.layout.boundsInWindow
import androidx.compose.ui.layout.onGloballyPositioned
import android.view.KeyEvent
import androidx.compose.ui.input.key.onPreviewKeyEvent
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.layout.onSizeChanged
import androidx.compose.ui.draw.drawWithContent
import androidx.compose.ui.draw.drawBehind
@@ -718,23 +722,23 @@ private fun SignInCard(store: Store, height: Dp) {
val shape = RoundedCornerShape(20.dp)
val blank = WallCapsule(Brush.linearGradient(listOf(c.fill, colors.background)), edge = c.dot.copy(alpha = 0.22f))
val ground = SolidColor(c.fill)
Box(Modifier.fillMaxWidth().height(height.coerceAtLeast(320.dp)).clip(shape).background(colors.background).border(1.dp, pal.line, shape)) {
Box(Modifier.fillMaxWidth().heightIn(min = height.coerceAtLeast(0.dp)).clip(shape).background(colors.background).border(1.dp, pal.line, shape)) {
// The storefront arrives a moment after the page: its wall fades in over the blank one.
androidx.compose.animation.Crossfade(art, animationSpec = Motion.tw(600), label = "signInWall") { tiles ->
androidx.compose.animation.Crossfade(art, animationSpec = Motion.tw(600), label = "signInWall", modifier = Modifier.matchParentSize()) { tiles ->
TiltedWall(tiles.size, if (tiles.isEmpty()) 75_000 else 50_000) { i -> if (tiles.isEmpty()) blank else WallCapsule(ground, tiles[i]) }
}
// The wall gives way to the words: dark at the left and the foot, and the store's glow under them.
Box(
Modifier.fillMaxSize().background(
Modifier.matchParentSize().background(
Brush.horizontalGradient(
0f to colors.background.copy(alpha = 0.97f), 0.45f to colors.background.copy(alpha = 0.9f),
0.78f to colors.background.copy(alpha = 0.35f), 1f to colors.background.copy(alpha = 0.15f),
),
),
)
Box(Modifier.fillMaxSize().background(Brush.verticalGradient(0.5f to Color.Transparent, 1f to colors.background.copy(alpha = 0.92f))))
Box(Modifier.matchParentSize().background(Brush.verticalGradient(0.5f to Color.Transparent, 1f to colors.background.copy(alpha = 0.92f))))
Box(
Modifier.fillMaxSize().drawBehind {
Modifier.matchParentSize().drawBehind {
drawRect(Brush.radialGradient(listOf(c.dot.copy(alpha = 0.22f), Color.Transparent), center = Offset(size.width * 0.16f, size.height * 0.9f), radius = size.height * 0.75f))
},
)
@@ -823,13 +827,50 @@ private fun Storefront(
// A lazy item can be recomposed or prefetched out of order; the first grid card is identified
// by its key, rather than whichever happens to compose first.
var firstPlaced = false
var columns by remember { mutableIntStateOf(1) }
val density = androidx.compose.ui.platform.LocalDensity.current
val focus = LocalFrontFocus.current
val scope = rememberCoroutineScope()
val headerItems = 1 + (if (StoresState.status[store] != null) 1 else 0) + (if (StoresState.problems[store] != null) 1 else 0)
val card: @Composable (CatalogItem) -> Unit = { item ->
val first = if (showGrid) item.key == visible.firstOrNull()?.key else !firstPlaced
firstPlaced = true
GameCard(item, store, s, a, installedKeys, onOpen, first)
val navigation = if (!showGrid || focus == null) Modifier else Modifier.onPreviewKeyEvent { event ->
val key = event.nativeKeyEvent
val direction = when (key.keyCode) {
KeyEvent.KEYCODE_DPAD_DOWN -> 1
KeyEvent.KEYCODE_DPAD_UP -> -1
else -> 0
}
val index = visible.indexOfFirst { it.key == item.key }
val next = storeGridNeighbor(index, visible.size, columns, direction)
when {
direction == 0 || index < 0 -> false
next == null -> direction > 0 // The last row stays in its column; Up can reach the header.
else -> {
if (key.action == KeyEvent.ACTION_DOWN) {
val target = "card:${visible[next].key}"
val targetIndex = headerItems + next
// Prefetched cards can accept focus without being on screen.
val visibleTarget = grid.layoutInfo.visibleItemsInfo.any { it.index == targetIndex }
if (!visibleTarget || (focus.attached[target] ?: 0) == 0 ||
runCatching { focus.items.getValue(target).requestFocus() }.isFailure) scope.launch {
grid.scrollToItem(targetIndex)
focusWithinFrames({ focus.last == target }) { focus.items[target] ?: androidx.compose.ui.focus.FocusRequester.Default }
}
}
true
}
}
}
GameCard(item, store, s, a, installedKeys, onOpen, first, navigation)
}
LazyVerticalGrid(
columns = GridCells.Adaptive(CardWidth), state = grid, modifier = Modifier.fillMaxSize(),
columns = GridCells.Adaptive(CardWidth), state = grid, modifier = Modifier.fillMaxSize().focusGroup().onSizeChanged {
val gap = with(density) { 10.dp.roundToPx() }
val minimum = with(density) { CardWidth.roundToPx() }
columns = ((it.width + gap) / (minimum + gap)).toInt().coerceAtLeast(1)
},
horizontalArrangement = Arrangement.spacedBy(10.dp), verticalArrangement = Arrangement.spacedBy(10.dp),
contentPadding = PaddingValues(top = 4.dp, bottom = 16.dp),
) {
@@ -1066,7 +1107,7 @@ private val CardWidth = 112.dp
* on the store. Tapping the card itself opens the game's page.
*/
@Composable
private fun GameCard(item: CatalogItem, store: Store, s: FrontEndState, a: FrontEndActions, installedKeys: Set<String>, onOpen: (String) -> Unit, first: Boolean = false) {
private fun GameCard(item: CatalogItem, store: Store, s: FrontEndState, a: FrontEndActions, installedKeys: Set<String>, onOpen: (String) -> Unit, first: Boolean = false, navigation: Modifier = Modifier) {
val ctx = LocalContext.current
val colors = MaterialTheme.colorScheme
val pal = LocalPalette.current
@@ -1095,7 +1136,7 @@ private fun GameCard(item: CatalogItem, store: Store, s: FrontEndState, a: Front
if (b.bottom > -ahead && b.top < screen + ahead && b.width > 0f) com.droiddeck.launcher.stores.StoreSizes.request(ctx, item)
}
}
.paneItem("card:${item.key}").then(if (first) Modifier.firstTile() else Modifier).graphicsLayer { scaleX = scale; scaleY = scale }
.then(navigation).paneItem("card:${item.key}").then(if (first) Modifier.firstTile() else Modifier).graphicsLayer { scaleX = scale; scaleY = scale }
.clip(RoundedCornerShape(10.dp)).glideBorder(hot, RoundedCornerShape(10.dp), pal.signal, pal.line)
.hoverable(src).clickable(interactionSource = src, indication = LocalIndication.current, onClick = open).controllerConfirm(onClick = open),
) {
@@ -42,7 +42,7 @@ object Themes {
PAPER, R.string.theme_paper, R.string.theme_paper_detail,
background = Color(0xFF000000), surface = Color(0xFF0F0F10), surfaceVariant = Color(0xFF191A1C), line = Color(0xFF262729), line2 = Color(0xFF343638),
onBackground = Color(0xFFF9F9F9), onSurfaceVariant = Color(0xFF8E9196),
primary = Color(0xFFF9F9F9), primary2 = Color(0xFFD9DADD), onPrimary = Color(0xFF000000), signal = Color(0xFF136CE0),
primary = Color(0xFFF9F9F9), primary2 = Color(0xFFD9DADD), onPrimary = Color(0xFF000000), signal = Color(0xFFF9F9F9),
good = Color(0xFF4CD37F),
),
Palette(