Dismiss Keyboard in Search View
Changlog-Fixed: Dismiss keyboard in search view Closes: #749
This commit is contained in:
committed by
William Casarin
parent
6872382bb7
commit
cba6b3aef7
@@ -181,7 +181,13 @@ struct ContentView: View {
|
||||
}
|
||||
switch selected_timeline {
|
||||
case .search:
|
||||
SearchHomeView(damus_state: damus_state!, model: SearchHomeModel(damus_state: damus_state!))
|
||||
if #available(iOS 16.0, *) {
|
||||
SearchHomeView(damus_state: damus_state!, model: SearchHomeModel(damus_state: damus_state!))
|
||||
.scrollDismissesKeyboard(.immediately)
|
||||
} else {
|
||||
// Fallback on earlier versions
|
||||
SearchHomeView(damus_state: damus_state!, model: SearchHomeModel(damus_state: damus_state!))
|
||||
}
|
||||
|
||||
case .home:
|
||||
PostingTimelineView
|
||||
|
||||
@@ -12,30 +12,31 @@ struct SearchHomeView: View {
|
||||
let damus_state: DamusState
|
||||
@StateObject var model: SearchHomeModel
|
||||
@State var search: String = ""
|
||||
@FocusState private var isFocused: Bool
|
||||
|
||||
var SearchInput: some View {
|
||||
ZStack(alignment: .leading) {
|
||||
HStack {
|
||||
HStack{
|
||||
Image(systemName: "magnifyingglass")
|
||||
.foregroundColor(.gray)
|
||||
TextField(NSLocalizedString("Search...", comment: "Placeholder text to prompt entry of search query."), text: $search)
|
||||
.padding(8)
|
||||
.padding(.leading, 35)
|
||||
.autocorrectionDisabled(true)
|
||||
.textInputAutocapitalization(.never)
|
||||
.focused($isFocused)
|
||||
}
|
||||
.padding(10)
|
||||
.background(.secondary.opacity(0.2))
|
||||
.cornerRadius(20)
|
||||
|
||||
if(!search.isEmpty) {
|
||||
Text("Cancel", comment: "Cancel out of search view.")
|
||||
.foregroundColor(.blue)
|
||||
.foregroundColor(.accentColor)
|
||||
.padding(EdgeInsets(top: 0.0, leading: 0.0, bottom: 0.0, trailing: 10.0))
|
||||
.opacity((search == "") ? 0.0 : 1.0)
|
||||
.onTapGesture {
|
||||
self.search = ""
|
||||
isFocused = false
|
||||
}
|
||||
}
|
||||
|
||||
Label("", systemImage: "magnifyingglass")
|
||||
.padding(.leading, 10)
|
||||
}
|
||||
.background {
|
||||
RoundedRectangle(cornerRadius: 8)
|
||||
.foregroundColor(.secondary.opacity(0.2))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user