From 08af3486b8c18662bad83511792ab806af8626bb Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Thu, 3 Dec 2026 17:04:08 -0500 Subject: [PATCH] Settings search: open the result's row, scroll to it and flash it --- .../com/droiddeck/launcher/ui/SettingsJump.kt | 61 +++++++++++++++++++ .../droiddeck/launcher/ui/SettingsSearch.kt | 7 ++- .../droiddeck/launcher/ui/SettingsWidgets.kt | 8 +-- 3 files changed, 69 insertions(+), 7 deletions(-) create mode 100644 app/src/main/java/com/droiddeck/launcher/ui/SettingsJump.kt diff --git a/app/src/main/java/com/droiddeck/launcher/ui/SettingsJump.kt b/app/src/main/java/com/droiddeck/launcher/ui/SettingsJump.kt new file mode 100644 index 0000000000..1d98b78b7a --- /dev/null +++ b/app/src/main/java/com/droiddeck/launcher/ui/SettingsJump.kt @@ -0,0 +1,61 @@ +package com.droiddeck.launcher.ui + +import android.os.SystemClock +import androidx.compose.animation.core.Animatable +import androidx.compose.animation.core.tween +import androidx.compose.foundation.relocation.BringIntoViewRequester +import androidx.compose.foundation.relocation.bringIntoViewRequester +import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.SideEffect +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.staticCompositionLocalOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue +import androidx.compose.runtime.withFrameNanos +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.drawBehind + +/** The row a settings search result opens, so the page it lands on can scroll to it and flash it. */ +internal object SettingsJump { + class Target(val label: String, val at: Long = SystemClock.uptimeMillis()) + + var target: Target? by mutableStateOf(null) + + fun to(label: String) { target = Target(label) } +} + +private const val JUMP_WINDOW_MS = 5_000L + +/** False in the search results, whose rows carry the same labels as the rows they open. */ +internal val LocalSearchTargets = staticCompositionLocalOf { true } + +@Composable +internal fun Modifier.searchTarget(label: String): Modifier { + val pal = LocalPalette.current + val flash = remember { Animatable(0f) } + val reveal = remember { BringIntoViewRequester() } + var claimed by remember { mutableStateOf(null) } + val target = SettingsJump.target.takeIf { LocalSearchTargets.current } + if (target != null && target.label == label) SideEffect { + if (SettingsJump.target === target) { + SettingsJump.target = null + if (SystemClock.uptimeMillis() - target.at <= JUMP_WINDOW_MS) claimed = target + } + } + claimed?.let { mine -> + LaunchedEffect(mine) { + withFrameNanos { } + reveal.bringIntoView() + repeat(2) { + flash.animateTo(1f, tween(220)) + flash.animateTo(0f, tween(420)) + } + claimed = null + } + } + return bringIntoViewRequester(reveal).drawBehind { + if (flash.value > 0f) drawRect(pal.signal.copy(alpha = 0.28f * flash.value)) + } +} diff --git a/app/src/main/java/com/droiddeck/launcher/ui/SettingsSearch.kt b/app/src/main/java/com/droiddeck/launcher/ui/SettingsSearch.kt index e195b4ee8e..b76a5157f9 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/SettingsSearch.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/SettingsSearch.kt @@ -103,7 +103,7 @@ internal fun SettingsSearchResults(query: String, frost: Boolean, onOpen: (Setti Note(stringResource(R.string.settings_search_none, query.trim())) return } - Column { + androidx.compose.runtime.CompositionLocalProvider(LocalSearchTargets provides false) { Column { found.groupBy { it.place }.forEach { (place, entries) -> SettingsGroup(stringResource(place.title)) { entries.forEach { entry -> @@ -112,9 +112,10 @@ internal fun SettingsSearchResults(query: String, frost: Boolean, onOpen: (Setti val section = entry.section val tab = entry.tab if (section != null) { - ActionRow(title, within, stringResource(R.string.store_open), onClick = { onOpen(section) }) + ActionRow(title, within, stringResource(R.string.store_open), onClick = { SettingsJump.to(title); onOpen(section) }) } else if (tab != null) { ActionRow(title, within, stringResource(R.string.store_open), onClick = { + SettingsJump.to(title) if (tab == NavTabs.MORE) MoreTabs.editing = true if (tab == "downloads") DownloadsNav.showSettings = true RailRequest.key = tab @@ -125,5 +126,5 @@ internal fun SettingsSearchResults(query: String, frost: Boolean, onOpen: (Setti } } } - } + } } } diff --git a/app/src/main/java/com/droiddeck/launcher/ui/SettingsWidgets.kt b/app/src/main/java/com/droiddeck/launcher/ui/SettingsWidgets.kt index 5d09490e39..52ba78a7d6 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/SettingsWidgets.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/SettingsWidgets.kt @@ -536,7 +536,7 @@ fun SettingsRow(label: String, hint: String?, highlighted: Boolean = false, hint minLines = hintLines ?: 1, maxLines = hintLines ?: Int.MAX_VALUE, overflow = TextOverflow.Ellipsis) } if (compact && !stacked) Column( - modifier = Modifier.fillMaxWidth().background(bg).padding(horizontal = 10.dp, vertical = 6.dp), + modifier = Modifier.searchTarget(label).fillMaxWidth().background(bg).padding(horizontal = 10.dp, vertical = 6.dp), ) { Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(8.dp)) { Text(label, fontSize = 13.sp, lineHeight = 16.sp, fontWeight = FontWeight.SemiBold, color = colors.onBackground, @@ -545,7 +545,7 @@ fun SettingsRow(label: String, hint: String?, highlighted: Boolean = false, hint } if (hint != null || hintLines != null) hintText(11.sp) } else if (stacked || LocalNarrowPane.current) Column( - modifier = Modifier.fillMaxWidth().background(bg).padding( + modifier = Modifier.searchTarget(label).fillMaxWidth().background(bg).padding( horizontal = if (compact) 10.dp else 14.dp, vertical = if (tightControlSpacing) 2.dp else if (compact) 6.dp else 12.dp), ) { @@ -556,7 +556,7 @@ fun SettingsRow(label: String, hint: String?, highlighted: Boolean = false, hint Box(Modifier.padding(top = if (tightControlSpacing) 2.dp else if (compact) 6.dp else 8.dp)) { control() } } else Row( verticalAlignment = Alignment.CenterVertically, - modifier = Modifier.fillMaxWidth().background(bg).padding(horizontal = 14.dp, vertical = 11.dp), + modifier = Modifier.searchTarget(label).fillMaxWidth().background(bg).padding(horizontal = 14.dp, vertical = 11.dp), ) { Column(modifier = Modifier.weight(1f).padding(end = 12.dp)) { Text(label, fontSize = 15.sp, fontWeight = FontWeight.SemiBold, color = colors.onBackground) @@ -660,7 +660,7 @@ fun SliderRow( ) { val colors = MaterialTheme.colorScheme val pal = LocalPalette.current - Column(Modifier.fillMaxWidth()) { + Column(Modifier.searchTarget(label).fillMaxWidth()) { ValueSlider(value, range, step, enabled, label, format, modifier = modifier.padding(horizontal = 6.dp, vertical = 3.dp), onChange = onChange) if (hint != null) Text(hint, fontSize = 12.5.sp, color = colors.onSurfaceVariant,