mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 12:07:55 +00:00
Clear the search query when leaving the search tab
Switching away from the search tab now resets the query, so returning to it shows the recent searches instead of the previous results. The search field no longer focuses itself on appearance.
This commit is contained in:
@@ -97,14 +97,19 @@ struct SearchScreen: View {
|
||||
.searchResultsKeyboardNavigation(moveUp: { moveSelection(backwards: true) },
|
||||
moveDown: { moveSelection(backwards: false) },
|
||||
cancel: { context.send(viewAction: .cancel) })
|
||||
// The TabView calls onAppear each time the search tab is selected, so the field re-focuses
|
||||
// and the selection resets on every switch.
|
||||
// The TabView calls onAppear/onDisappear each time the search tab is selected/deselected,
|
||||
// so the query is cleared and the selection resets on every switch.
|
||||
.onAppear {
|
||||
context.send(viewAction: .appeared)
|
||||
isSearchFieldFocused = true
|
||||
selectedID = selectableIDs.first
|
||||
updateHardwareKeyboardConnected()
|
||||
}
|
||||
.onDisappear {
|
||||
// Previews and snapshot tests mount and unmount the view, don't clear their fixed state.
|
||||
guard !ProcessInfo.isXcodePreview, !ProcessInfo.isRunningTests else { return }
|
||||
context.searchQuery = ""
|
||||
}
|
||||
.onReceive(NotificationCenter.default.publisher(for: .GCKeyboardDidConnect)) { _ in
|
||||
updateHardwareKeyboardConnected()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user