mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 06:55:59 +00:00
Dismiss the whole search tab and move back to the previous when when tapping the search field dismissal button.
This commit is contained in:
@@ -339,6 +339,8 @@ class UserSessionFlowCoordinator: FlowCoordinatorProtocol {
|
|||||||
handleAppRoute(.room(roomID: roomID, via: []), animated: true)
|
handleAppRoute(.room(roomID: roomID, via: []), animated: true)
|
||||||
}
|
}
|
||||||
case .cancel:
|
case .cancel:
|
||||||
|
// The search screen is also dismissed when leaving the tab, ignore it in that case.
|
||||||
|
guard navigationTabCoordinator.selectedTab == .search else { return }
|
||||||
// Return to the tab the user came from, but never back into search.
|
// Return to the tab the user came from, but never back into search.
|
||||||
navigationTabCoordinator.selectedTab = navigationTabCoordinator.previousTab == .search ? .chats : navigationTabCoordinator.previousTab ?? .chats
|
navigationTabCoordinator.selectedTab = navigationTabCoordinator.previousTab == .search ? .chats : navigationTabCoordinator.previousTab ?? .chats
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,6 +79,9 @@ struct SearchScreen: View {
|
|||||||
messagesList
|
messagesList
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Dismissing the search field (the tab bar's close button) leaves the tab.
|
||||||
|
SearchDismissalObserver { context.send(viewAction: .cancel) }
|
||||||
}
|
}
|
||||||
.frame(maxHeight: .infinity, alignment: .top)
|
.frame(maxHeight: .infinity, alignment: .top)
|
||||||
.background(Color.compound.bgCanvasDefault)
|
.background(Color.compound.bgCanvasDefault)
|
||||||
@@ -99,7 +102,7 @@ struct SearchScreen: View {
|
|||||||
moveDown: { moveSelection(backwards: false) },
|
moveDown: { moveSelection(backwards: false) },
|
||||||
cancel: { context.send(viewAction: .cancel) })
|
cancel: { context.send(viewAction: .cancel) })
|
||||||
// The TabView calls onAppear/onDisappear each time the search tab is selected/deselected,
|
// 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.
|
// so the field re-focuses, the query is cleared and the selection resets on every switch.
|
||||||
.onAppear {
|
.onAppear {
|
||||||
context.send(viewAction: .appeared)
|
context.send(viewAction: .appeared)
|
||||||
isSearchFieldFocused = true
|
isSearchFieldFocused = true
|
||||||
@@ -324,6 +327,23 @@ private struct SearchScreenRoomCell: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Reports the search field being dismissed, which `isSearching` only exposes to the searchable view's children.
|
||||||
|
private struct SearchDismissalObserver: View {
|
||||||
|
@Environment(\.isSearching) private var isSearching
|
||||||
|
|
||||||
|
let action: () -> Void
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
Color.clear
|
||||||
|
.frame(width: 0, height: 0)
|
||||||
|
.onChange(of: isSearching) { _, isSearching in
|
||||||
|
if !isSearching {
|
||||||
|
action()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private struct SearchScreenRoomCellButtonStyle: ButtonStyle {
|
private struct SearchScreenRoomCellButtonStyle: ButtonStyle {
|
||||||
let isSelected: Bool
|
let isSelected: Bool
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user