mirror of
https://github.com/element-hq/element-x-ios.git
synced 2025-03-10 21:39:12 +00:00
Fix room list search bar focus glitches (#2112)
* Fixes #2112 - Room list search bar focus glitches * Address PR comments
This commit is contained in:
parent
d245a4f158
commit
f717c7dba4
@ -100,6 +100,11 @@ struct HomeScreenViewState: BindableState {
|
||||
HomeScreenRoom.placeholder()
|
||||
}
|
||||
}
|
||||
|
||||
// Used to hide all the rooms when the search field is focused and the query is empty
|
||||
var shouldHideRoomList: Bool {
|
||||
bindings.isSearchFieldFocused && bindings.searchQuery.isEmpty
|
||||
}
|
||||
}
|
||||
|
||||
struct HomeScreenViewStateBindings {
|
||||
|
@ -109,7 +109,7 @@ class HomeScreenViewModel: HomeScreenViewModelType, HomeScreenViewModelProtocol
|
||||
// Don't capture the values here as combine behaves incorrectly and `isSearchFieldFocused` is sometimes
|
||||
// turning to true after cancelling the search. Read them directly from the state in the updateFilter
|
||||
// method instead on the next run loop to make sure they're up to date.
|
||||
DispatchQueue.main.async {
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.05) {
|
||||
self.updateFilter()
|
||||
}
|
||||
}
|
||||
@ -170,12 +170,14 @@ class HomeScreenViewModel: HomeScreenViewModelType, HomeScreenViewModelProtocol
|
||||
// MARK: - Private
|
||||
|
||||
private func updateFilter() {
|
||||
if !state.bindings.isSearchFieldFocused {
|
||||
roomSummaryProvider?.setFilter(.all)
|
||||
} else if state.bindings.searchQuery.isEmpty {
|
||||
if state.shouldHideRoomList {
|
||||
roomSummaryProvider?.setFilter(.none)
|
||||
} else {
|
||||
roomSummaryProvider?.setFilter(.normalizedMatchRoomName(state.bindings.searchQuery))
|
||||
if state.bindings.isSearchFieldFocused {
|
||||
roomSummaryProvider?.setFilter(.normalizedMatchRoomName(state.bindings.searchQuery))
|
||||
} else {
|
||||
roomSummaryProvider?.setFilter(.all)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,10 +22,20 @@ struct HomeScreenRoomList: View {
|
||||
@ObservedObject var context: HomeScreenViewModel.Context
|
||||
|
||||
var body: some View {
|
||||
content
|
||||
filteredContent
|
||||
.onChange(of: isSearchFieldFocused) { context.isSearchFieldFocused = $0 }
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
private var filteredContent: some View {
|
||||
// Hide the room list when the search bar is focused but the query is empty
|
||||
// This works hand in hand with the room list service layer filtering and
|
||||
// avoids glitches when focusing the search bar
|
||||
if !context.viewState.shouldHideRoomList {
|
||||
content
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
private var content: some View {
|
||||
ForEach(context.viewState.visibleRooms) { room in
|
||||
|
1
changelog.d/pr-2112.bugfix
Normal file
1
changelog.d/pr-2112.bugfix
Normal file
@ -0,0 +1 @@
|
||||
Fix room list search bar focus glitches
|
Loading…
x
Reference in New Issue
Block a user