From 5e21587c880d26cdc40bea106ddfdd1a5b3cc65f Mon Sep 17 00:00:00 2001 From: LeanBitLab Date: Sun, 15 Nov 2026 14:17:09 +0530 Subject: [PATCH 1/2] fix(settings): hide section headers from search results and keep the jump highlight readable The fine-tune section headers (Swipe gestures, Prediction details, ...) did nothing when clicked in the search results, and the settings inside them are listed anyway. The highlight after a long press used a solid primaryContainer behind texts that keep the onSurface color, which was unreadable in some themes; it is a tint of the primary color now. --- .../main/java/helium314/keyboard/settings/SearchScreen.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/helium314/keyboard/settings/SearchScreen.kt b/app/src/main/java/helium314/keyboard/settings/SearchScreen.kt index 92786f52c..ab24ea1b4 100644 --- a/app/src/main/java/helium314/keyboard/settings/SearchScreen.kt +++ b/app/src/main/java/helium314/keyboard/settings/SearchScreen.kt @@ -180,7 +180,8 @@ fun SearchSettingsScreen( keys.forEach { key -> androidx.compose.runtime.key(key) { val highlight by animateColorAsState( - if (key == highlightKey) MaterialTheme.colorScheme.primaryContainer + // a tint, not a solid color: the texts keep their contrast in light and dark themes + if (key == highlightKey) MaterialTheme.colorScheme.primary.copy(alpha = 0.22f) else androidx.compose.ui.graphics.Color.Transparent, label = "jump highlight" ) @@ -207,6 +208,8 @@ fun SearchSettingsScreen( if (index > customCount) return@filter false } if (key == "add_custom_layout") return@filter false + // fine-tune section headers do nothing in the results (the settings inside are listed themselves) + if (key.startsWith(FINE_TUNE_SECTION_PREFIX)) return@filter false when (helium314.keyboard.latin.BuildConfig.FLAVOR) { "offline" -> { val isOldAndroid = android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.O From 429d06b2424187c874dd869ca55f8b9c5592db4e Mon Sep 17 00:00:00 2001 From: LeanBitLab Date: Sun, 15 Nov 2026 14:43:03 +0530 Subject: [PATCH 2/2] perf(settings): compose the settings of a screen lazily, one row per setting A card was one list item, so opening a large screen (toolbar, advanced, appearance) composed every setting of it in a single frame. Each setting is its own lazy row now, drawn as one card as before; the jump to a setting scrolls to its row. --- .../keyboard/settings/SearchScreen.kt | 71 +++++++++++-------- 1 file changed, 42 insertions(+), 29 deletions(-) diff --git a/app/src/main/java/helium314/keyboard/settings/SearchScreen.kt b/app/src/main/java/helium314/keyboard/settings/SearchScreen.kt index ab24ea1b4..642a8bcb7 100644 --- a/app/src/main/java/helium314/keyboard/settings/SearchScreen.kt +++ b/app/src/main/java/helium314/keyboard/settings/SearchScreen.kt @@ -112,6 +112,9 @@ fun SearchSettingsScreen( } result.filter { it.second.isNotEmpty() } } + // one lazy row per setting (a whole card as one item composed every setting of the screen at once, + // which is what made opening a large screen slow); the rows of a group are drawn as one card + val rows = remember(groups) { settingRows(groups) } // jump from a long press in the search results (see SettingsJump): show the setting // here, opening its fine-tune section if needed, scroll to it and highlight it @@ -140,9 +143,8 @@ fun SearchSettingsScreen( } LaunchedEffect(scrollKey) { val target = scrollKey ?: return@LaunchedEffect - val index = groups.indexOfFirst { target in it.second } + val index = rows.indexOfFirst { it.key == target } if (index >= 0) { - // to the card with the setting, then the setting itself is brought into view (see below) listState.animateScrollToItem(index + if (headerContent != null) 1 else 0) highlightKey = target delay(2500) @@ -163,35 +165,33 @@ fun SearchSettingsScreen( headerContent() } } - items(groups, key = { (titleRes, keys) -> "${titleRes}_${keys.hashCode()}" }) { (titleRes, keys) -> - androidx.compose.material3.Card( - modifier = Modifier + items(rows, key = { it.id }) { row -> + val shape = androidx.compose.foundation.shape.RoundedCornerShape( + topStart = if (row.first) 12.dp else 0.dp, topEnd = if (row.first) 12.dp else 0.dp, + bottomStart = if (row.last) 12.dp else 0.dp, bottomEnd = if (row.last) 12.dp else 0.dp + ) + Box( + Modifier .fillMaxWidth() - .padding(horizontal = 16.dp, vertical = 8.dp), - colors = androidx.compose.material3.CardDefaults.cardColors( - containerColor = MaterialTheme.colorScheme.surfaceContainer - ) + .padding(start = 16.dp, end = 16.dp, top = if (row.first) 8.dp else 0.dp, bottom = if (row.last) 8.dp else 0.dp) + .clip(shape) + .background(MaterialTheme.colorScheme.surfaceContainer) ) { - Column { - if (titleRes != null) { - PreferenceCategory(stringResource(titleRes)) - } - - keys.forEach { key -> - androidx.compose.runtime.key(key) { - val highlight by animateColorAsState( - // a tint, not a solid color: the texts keep their contrast in light and dark themes - if (key == highlightKey) MaterialTheme.colorScheme.primary.copy(alpha = 0.22f) - else androidx.compose.ui.graphics.Color.Transparent, - label = "jump highlight" - ) - // a setting further down in a large card is not on screen after scrolling to the card - val bringIntoView = remember { BringIntoViewRequester() } - LaunchedEffect(highlightKey) { if (key == highlightKey) bringIntoView.bringIntoView() } - Box(Modifier.bringIntoViewRequester(bringIntoView).background(highlight)) { - SettingsActivity.settingsContainer[key]?.Preference() - } - } + if (row.key == null) { + PreferenceCategory(stringResource(row.titleRes!!)) + } else { + val key = row.key + val highlight by animateColorAsState( + // a tint, not a solid color: the texts keep their contrast in light and dark themes + if (key == highlightKey) MaterialTheme.colorScheme.primary.copy(alpha = 0.22f) + else androidx.compose.ui.graphics.Color.Transparent, + label = "jump highlight" + ) + // a setting further down in a large card is not on screen after scrolling to it + val bringIntoView = remember { BringIntoViewRequester() } + LaunchedEffect(highlightKey) { if (key == highlightKey) bringIntoView.bringIntoView() } + Box(Modifier.bringIntoViewRequester(bringIntoView).background(highlight)) { + SettingsActivity.settingsContainer[key]?.Preference() } } } @@ -228,6 +228,19 @@ fun SearchSettingsScreen( ) } +/** A row of a settings screen: the title of a category ([key] is null) or a setting; first and last row of a card */ +private data class SettingRow(val id: String, val titleRes: Int?, val key: String?, val first: Boolean = false, val last: Boolean = false) + +private fun settingRows(groups: List>>): List = buildList { + groups.forEachIndexed { index, (titleRes, keys) -> + val group = buildList { + if (titleRes != null) add(SettingRow("title_${index}_$titleRes", titleRes, null)) + keys.forEach { add(SettingRow("${index}_$it", null, it)) } + } + group.forEachIndexed { i, row -> add(row.copy(first = i == 0, last = i == group.lastIndex)) } + } +} + /** A search result: a long press opens the screen of the setting and shows it there */ @Composable private fun SearchResult(setting: Setting) {