damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

commit cba6b3aef7d770688d13255d0dff0f17e46ea162
parent 6872382bb763257f528f61a506a1586ffe40a35b
Author: ericholguin <eric.holguinsanchez@gmail.com>
Date:   Mon,  6 Mar 2023 19:46:13 -0700

Dismiss Keyboard in Search View

Changlog-Fixed: Dismiss keyboard in search view
Closes: #749

Diffstat:
Mdamus/ContentView.swift | 8+++++++-
Mdamus/Views/SearchHomeView.swift | 25+++++++++++++------------
2 files changed, 20 insertions(+), 13 deletions(-)

diff --git a/damus/ContentView.swift b/damus/ContentView.swift @@ -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 diff --git a/damus/Views/SearchHomeView.swift b/damus/Views/SearchHomeView.swift @@ -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)) } }