mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 21:33:26 +00:00
Fix search screen keyboard navigation
This commit is contained in:
@@ -42,15 +42,15 @@ struct SearchScreen: View {
|
|||||||
.searchFocused($isSearchFieldFocused)
|
.searchFocused($isSearchFieldFocused)
|
||||||
.autocorrectionDisabled(true)
|
.autocorrectionDisabled(true)
|
||||||
.onSubmit(of: .search) {
|
.onSubmit(of: .search) {
|
||||||
isSearchFieldFocused = false
|
// A software keyboard's submit/search button just dismisses; only a hardware return selects.
|
||||||
|
if isHardwareKeyboardConnected, let selectedRoomID {
|
||||||
|
context.send(viewAction: .selectRoom(roomID: selectedRoomID))
|
||||||
|
} else {
|
||||||
|
isSearchFieldFocused = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.searchResultsKeyboardNavigation(moveUp: { moveSelection(backwards: true) },
|
.searchResultsKeyboardNavigation(moveUp: { moveSelection(backwards: true) },
|
||||||
moveDown: { moveSelection(backwards: false) },
|
moveDown: { moveSelection(backwards: false) },
|
||||||
select: {
|
|
||||||
if let selectedRoomID {
|
|
||||||
context.send(viewAction: .selectRoom(roomID: selectedRoomID))
|
|
||||||
}
|
|
||||||
},
|
|
||||||
cancel: { context.send(viewAction: .cancel) })
|
cancel: { context.send(viewAction: .cancel) })
|
||||||
// The TabView calls onAppear each time the search tab is selected, so the field re-focuses
|
// The TabView calls onAppear each time the search tab is selected, so the field re-focuses
|
||||||
// and the selection resets on every switch.
|
// and the selection resets on every switch.
|
||||||
@@ -198,7 +198,7 @@ private extension View {
|
|||||||
/// The `.search` role tab owns its text field, so there's no SwiftUI hook for its key presses. We reach the
|
/// The `.search` role tab owns its text field, so there's no SwiftUI hook for its key presses. We reach the
|
||||||
/// field through the navigation stack (as ``SearchFieldStyle`` does) and swap its class for one that overrides
|
/// field through the navigation stack (as ``SearchFieldStyle`` does) and swap its class for one that overrides
|
||||||
/// `pressesBegan` — the same key interception the old global search performed on its own field.
|
/// `pressesBegan` — the same key interception the old global search performed on its own field.
|
||||||
func searchResultsKeyboardNavigation(moveUp: @escaping () -> Void, moveDown: @escaping () -> Void, select: @escaping () -> Void, cancel: @escaping () -> Void) -> some View {
|
func searchResultsKeyboardNavigation(moveUp: @escaping () -> Void, moveDown: @escaping () -> Void, cancel: @escaping () -> Void) -> some View {
|
||||||
introspect(.navigationStack, on: .supportedVersions, scope: .ancestor) { navigationController in
|
introspect(.navigationStack, on: .supportedVersions, scope: .ancestor) { navigationController in
|
||||||
guard let textField = navigationController.navigationBar.topItem?.searchController?.searchBar.searchTextField else {
|
guard let textField = navigationController.navigationBar.topItem?.searchController?.searchBar.searchTextField else {
|
||||||
return
|
return
|
||||||
@@ -214,8 +214,6 @@ private extension View {
|
|||||||
moveUp()
|
moveUp()
|
||||||
case .keyboardDownArrow:
|
case .keyboardDownArrow:
|
||||||
moveDown()
|
moveDown()
|
||||||
case .keyboardReturnOrEnter, .keypadEnter:
|
|
||||||
select()
|
|
||||||
case .keyboardEscape:
|
case .keyboardEscape:
|
||||||
cancel()
|
cancel()
|
||||||
default:
|
default:
|
||||||
|
|||||||
Reference in New Issue
Block a user