Skip to content

Commit

Permalink
added hack for non-responder search focus binding
Browse files Browse the repository at this point in the history
  • Loading branch information
EricBAndrews committed Dec 28, 2023
1 parent a1fb05e commit 9307743
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions Mlem/Views/Shared/Search Bar/SearchBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -133,19 +133,34 @@ import SwiftUI
(uiView as? _UISearchBar)?.isFirstResponderBinding = isFocused

do {
if let uiView = uiView as? _UISearchBar, environment.isEnabled {
DispatchQueue.main.async {
if let isFocused, uiView.window != nil {
uiView.isFirstResponderBinding = isFocused

if isFocused.wrappedValue, !uiView.isFirstResponder {
uiView.becomeFirstResponder()
} else if !isFocused.wrappedValue, uiView.isFirstResponder {
uiView.resignFirstResponder()
}
// version of below with no responder binding. it's not a pretty hack but it does work
// note that switching tabs with search selected will result in search still displaying "search for communities and users,"
// but since the keyboard hides the tab bar that probably won't come up for 99% of users
if let isFocused, environment.isEnabled {
if isFocused.wrappedValue, !uiView.isFirstResponder {
DispatchQueue.main.async {
uiView.becomeFirstResponder()
}
} else if !isFocused.wrappedValue, uiView.isFirstResponder {
DispatchQueue.main.async {
uiView.resignFirstResponder()
}
}
}

// if let uiView = uiView as? _UISearchBar, environment.isEnabled {
// DispatchQueue.main.async {
// if let isFocused, uiView.window != nil {
// uiView.isFirstResponderBinding = isFocused
//
// if isFocused.wrappedValue, !uiView.isFirstResponder {
// uiView.becomeFirstResponder()
// } else if !isFocused.wrappedValue, uiView.isFirstResponder {
// uiView.resignFirstResponder()
// }
// }
// }
// }
}
}

Expand Down

0 comments on commit 9307743

Please sign in to comment.