From 98867a2407bb35f57ec17f898c54f6d17a0f14af Mon Sep 17 00:00:00 2001 From: OneWay Date: Wed, 28 Oct 2026 00:02:34 +0800 Subject: [PATCH] fix(history): keep history actions visible while scrolling --- .../ui/main/components/SearchHistoryList.kt | 90 ++++++++++--------- 1 file changed, 48 insertions(+), 42 deletions(-) diff --git a/app/src/main/java/com/example/research/ui/main/components/SearchHistoryList.kt b/app/src/main/java/com/example/research/ui/main/components/SearchHistoryList.kt index 8b01329..f0925df 100644 --- a/app/src/main/java/com/example/research/ui/main/components/SearchHistoryList.kt +++ b/app/src/main/java/com/example/research/ui/main/components/SearchHistoryList.kt @@ -4,9 +4,12 @@ import androidx.compose.foundation.background import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.width @@ -42,52 +45,55 @@ fun SearchHistoryList( listState: LazyListState = rememberLazyListState(), contentPadding: PaddingValues = PaddingValues(), ) { - LazyColumn( - modifier = modifier - .appTestTag("search_history"), - state = listState, - contentPadding = contentPadding, - verticalArrangement = Arrangement.spacedBy(4.dp) - ) { - item(key = "history_header", contentType = "history_header") { - Row( + Column(modifier = modifier) { + Row( + modifier = Modifier + .fillMaxWidth() + .padding(vertical = Spacing.listItemVertical), + verticalAlignment = Alignment.CenterVertically + ) { + Text( + text = stringResource(R.string.recent_searches), + style = MaterialTheme.typography.titleSmall, + color = MaterialTheme.colorScheme.onSurfaceVariant, + modifier = Modifier.weight(1f) + ) + Text( + text = stringResource(R.string.clear_search_history), + style = MaterialTheme.typography.titleSmall, + color = MaterialTheme.colorScheme.primary, + softWrap = false, modifier = Modifier - .fillMaxWidth() - .padding(vertical = Spacing.listItemVertical), - verticalAlignment = Alignment.CenterVertically - ) { - Text( - text = stringResource(R.string.recent_searches), - style = MaterialTheme.typography.titleSmall, - color = MaterialTheme.colorScheme.onSurfaceVariant, - modifier = Modifier.weight(1f) - ) - Text( - text = stringResource(R.string.clear_search_history), - style = MaterialTheme.typography.titleSmall, - color = MaterialTheme.colorScheme.primary, - softWrap = false, - modifier = Modifier - .padding(end = 18.dp) - .clip(CircleShape) - .background(MaterialTheme.colorScheme.surfaceContainerHighest) - .appTestTag("clear_history") - .clickable { onClearAll() } - .padding(horizontal = 12.dp, vertical = 6.dp) + .padding(end = 18.dp) + .clip(CircleShape) + .background(MaterialTheme.colorScheme.surfaceContainerHighest) + .appTestTag("clear_history") + .clickable { onClearAll() } + .padding(horizontal = 12.dp, vertical = 6.dp) + ) + } + Spacer(modifier = Modifier.height(4.dp)) + LazyColumn( + modifier = Modifier + .fillMaxWidth() + .weight(1f, fill = false) + .appTestTag("search_history"), + state = listState, + contentPadding = contentPadding, + verticalArrangement = Arrangement.spacedBy(4.dp) + ) { + items( + items = history, + key = { it }, + contentType = { "history_entry" } + ) { entry -> + SearchHistoryItem( + entry = entry, + onEntryClick = onEntryClick, + onEntryRemove = onEntryRemove ) } } - items( - items = history, - key = { it }, - contentType = { "history_entry" } - ) { entry -> - SearchHistoryItem( - entry = entry, - onEntryClick = onEntryClick, - onEntryRemove = onEntryRemove - ) - } } }