mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-03 16:10:00 +00:00
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) <noreply@anthropic.com>
This commit is contained in:
+8
-4
@@ -144,15 +144,19 @@ fun RoomSelectView(
|
|||||||
)
|
)
|
||||||
|
|
||||||
val searchQuery = state.searchQuery.text.toString()
|
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
|
// 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, searchQuery) { rememberLazyListState() }
|
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.
|
// 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.
|
// Use a new state when the selected account changes, so that the section is fully displayed again.
|
||||||
val accountSwitchScrollBehavior = key(state.selectedAccount.userId) {
|
val accountSwitchScrollBehavior = key(state.selectedAccount.userId) {
|
||||||
TopAppBarDefaults.enterAlwaysScrollBehavior(rememberTopAppBarState())
|
TopAppBarDefaults.enterAlwaysScrollBehavior(rememberTopAppBarState())
|
||||||
}
|
}
|
||||||
// Collapse the account switch section when the user starts searching. It can be displayed again by scrolling down.
|
// 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) {
|
LaunchedEffect(isSearching) {
|
||||||
if (isSearching) {
|
if (isSearching) {
|
||||||
val topAppBarState = accountSwitchScrollBehavior.state
|
val topAppBarState = accountSwitchScrollBehavior.state
|
||||||
@@ -246,7 +250,7 @@ fun RoomSelectView(
|
|||||||
) {
|
) {
|
||||||
if (state.resultState.results.isNotEmpty()) {
|
if (state.resultState.results.isNotEmpty()) {
|
||||||
item {
|
item {
|
||||||
val headerText = if (searchQuery.isEmpty()) {
|
val headerText = if (searchQuery.isBlank()) {
|
||||||
stringResource(CommonStrings.common_header_rooms)
|
stringResource(CommonStrings.common_header_rooms)
|
||||||
} else {
|
} else {
|
||||||
stringResource(CommonStrings.common_results_for, searchQuery)
|
stringResource(CommonStrings.common_results_for, searchQuery)
|
||||||
|
|||||||
Reference in New Issue
Block a user