From 013efef29ea0c1f737414d98df7067d125b25629 Mon Sep 17 00:00:00 2001 From: Jean-Luc Makiola Date: Tue, 23 Jun 2026 11:05:26 +0200 Subject: [PATCH] fix(search): clear on reopen and centre messages above the keyboard MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The search ViewModel is activity-scoped and outlives the overlay, so a reopened search showed the previous query/results — reset the query when the screen re-enters (peeking a result keeps it, as the screen stays composed under the detail). Add imePadding so the idle/empty message re-centres in the area above the keyboard instead of staying centred on the full page behind it. Co-Authored-By: Claude Opus 4.8 (1M context) --- .../calendula/ui/search/SearchScreen.kt | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/de/jeanlucmakiola/calendula/ui/search/SearchScreen.kt b/app/src/main/java/de/jeanlucmakiola/calendula/ui/search/SearchScreen.kt index 737ca31..5309844 100644 --- a/app/src/main/java/de/jeanlucmakiola/calendula/ui/search/SearchScreen.kt +++ b/app/src/main/java/de/jeanlucmakiola/calendula/ui/search/SearchScreen.kt @@ -11,6 +11,7 @@ import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.imePadding import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.lazy.LazyColumn @@ -78,8 +79,12 @@ fun SearchScreen( val focusRequester = remember { FocusRequester() } val keyboard = LocalSoftwareKeyboardController.current - // Open straight into typing — request focus and raise the keyboard once. + // Each fresh open starts blank and straight into typing. The ViewModel is + // activity-scoped so it outlives the overlay; clearing on (re)enter is what + // resets a previous search. Peeking a result doesn't re-run this (the screen + // stays composed under the detail), so backing out keeps the query. LaunchedEffect(Unit) { + viewModel.setQuery("") focusRequester.requestFocus() keyboard?.show() } @@ -126,7 +131,15 @@ fun SearchScreen( ) }, ) { padding -> - Box(modifier = Modifier.fillMaxSize().padding(padding)) { + // imePadding shrinks the content by the keyboard, so the centered + // idle/empty message re-centres in the space above it (and the results + // list lifts clear of the keyboard too). + Box( + modifier = Modifier + .fillMaxSize() + .padding(padding) + .imePadding(), + ) { when (val s = state) { SearchUiState.Idle -> SearchMessage( icon = null,