From 85224988af726eddf854b014ff457bf92fb79560 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Fri, 9 Oct 2026 14:29:28 +0200 Subject: [PATCH] Room select: address review remarks - Scroll the list to the top using a LaunchedEffect instead of recreating the LazyListState on each search query change. - Use isBlank to check the search query, to match the logic of RoomSelectSearchDataSource. Co-Authored-By: Claude Opus 5.5 (1M context) --- .../libraries/roomselect/impl/RoomSelectView.kt | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/libraries/roomselect/impl/src/main/kotlin/io/element/android/libraries/roomselect/impl/RoomSelectView.kt b/libraries/roomselect/impl/src/main/kotlin/io/element/android/libraries/roomselect/impl/RoomSelectView.kt index 4c5ad390e7..dcae5b9f87 100644 --- a/libraries/roomselect/impl/src/main/kotlin/io/element/android/libraries/roomselect/impl/RoomSelectView.kt +++ b/libraries/roomselect/impl/src/main/kotlin/io/element/android/libraries/roomselect/impl/RoomSelectView.kt @@ -144,15 +144,19 @@ fun RoomSelectView( ) val searchQuery = state.searchQuery.text.toString() - // Use a new list state when the selected account or the search query changes, so that the list of rooms is scrolled to the top - val lazyListState = key(state.selectedAccount.userId, searchQuery) { rememberLazyListState() } + // Use a new list state when the selected account changes, so that the list of rooms is scrolled to the top + val lazyListState = key(state.selectedAccount.userId) { rememberLazyListState() } + // Scroll the list of rooms to the top when the search query changes + LaunchedEffect(lazyListState, searchQuery) { + lazyListState.scrollToItem(0) + } // Hide the account switch section when the room list is scrolled up, and show it again as soon as it is scrolled down. // Use a new state when the selected account changes, so that the section is fully displayed again. val accountSwitchScrollBehavior = key(state.selectedAccount.userId) { TopAppBarDefaults.enterAlwaysScrollBehavior(rememberTopAppBarState()) } // Collapse the account switch section when the user starts searching. It can be displayed again by scrolling down. - val isSearching = searchQuery.isNotEmpty() + val isSearching = searchQuery.isNotBlank() LaunchedEffect(isSearching) { if (isSearching) { val topAppBarState = accountSwitchScrollBehavior.state @@ -246,7 +250,7 @@ fun RoomSelectView( ) { if (state.resultState.results.isNotEmpty()) { item { - val headerText = if (searchQuery.isEmpty()) { + val headerText = if (searchQuery.isBlank()) { stringResource(CommonStrings.common_header_rooms) } else { stringResource(CommonStrings.common_results_for, searchQuery)