aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNavan Chauhan <navanchauhan@gmail.com>2024-02-05 17:51:21 -0700
committerNavan Chauhan <navanchauhan@gmail.com>2024-02-05 17:51:21 -0700
commitf973e8f1c1660c77bd067e33871fbef46a3ea844 (patch)
tree73d19679eb50545d40678068cebcbc03499b7d9c
parent40e82124b0617966685f6db30efc601710ea27f4 (diff)
dissmiss keyboard when link is clicked
-rw-r--r--iGopherBrowser/BrowserView.swift32
-rw-r--r--iGopherBrowser/SettingsView.swift12
2 files changed, 36 insertions, 8 deletions
diff --git a/iGopherBrowser/BrowserView.swift b/iGopherBrowser/BrowserView.swift
index aa46818..1ba869c 100644
--- a/iGopherBrowser/BrowserView.swift
+++ b/iGopherBrowser/BrowserView.swift
@@ -18,6 +18,15 @@ func openURL(url: URL) {
#endif
}
+#if canImport(UIKit)
+ extension View {
+ func hideKeyboard() {
+ UIApplication.shared.sendAction(
+ #selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)
+ }
+ }
+#endif
+
struct BrowserView: View {
@AppStorage("homeURL") var homeURL: URL = URL(string: "gopher://gopher.navan.dev:70/")!
@AppStorage("accentColour", store: .standard) var accentColour: Color = Color(.blue)
@@ -62,6 +71,9 @@ struct BrowserView: View {
} else if item.parsedItemType == .directory {
Button(action: {
performGopherRequest(host: item.host, port: item.port, selector: item.selector)
+ #if canImport(UIKit)
+ hideKeyboard()
+ #endif
}) {
HStack {
Text(Image(systemName: "folder"))
@@ -72,6 +84,9 @@ struct BrowserView: View {
} else if item.parsedItemType == .search {
Button(action: {
+ #if canImport(UIKit)
+ hideKeyboard()
+ #endif
self.selectedSearchItem = idx
self.showSearchInput = true
}) {
@@ -140,7 +155,7 @@ struct BrowserView: View {
withAnimation {
// TODO: Fix for macOS
#if os(macOS)
- proxy.scrollTo(topID, anchor: .top)
+ proxy.scrollTo(0, anchor: .top)
#else
proxy.scrollTo(0, anchor: .top)
#endif
@@ -284,6 +299,15 @@ struct BrowserView: View {
.labelStyle(.iconOnly)
}
+ #if os(visionOS)
+ Button {
+ self.showPreferences = true
+ } label: {
+ Label("Settings", systemImage: "gear")
+ .labelStyle(.iconOnly)
+ }
+ #endif
+
Button {
if let curNode = backwardStack.popLast() {
forwardStack.append(curNode)
@@ -358,10 +382,10 @@ struct BrowserView: View {
}
}
) {
- #if os(iOS)
- SettingsView(homeURL: $homeURL, homeURLString: $homeURLString)
- #else
+ #if os(macOS)
SettingsView()
+ #else
+ SettingsView(homeURL: $homeURL, homeURLString: $homeURLString)
#endif
}
.accentColor(accentColour)
diff --git a/iGopherBrowser/SettingsView.swift b/iGopherBrowser/SettingsView.swift
index 24ece75..9ee9e62 100644
--- a/iGopherBrowser/SettingsView.swift
+++ b/iGopherBrowser/SettingsView.swift
@@ -60,13 +60,12 @@ struct SettingsView: View {
@AppStorage("accentColour", store: .standard) var accentColour: Color = Color(.blue)
@AppStorage("linkColour", store: .standard) var linkColour: Color = Color(.white)
- #if os(iOS)
- @Binding var homeURL: URL
- @Binding var homeURLString: String
- #endif
#if os(macOS)
@AppStorage("homeURL") var homeURL: URL = URL(string: "gopher://gopher.navan.dev:70/")!
@State var homeURLString: String = ""
+ #else
+ @Binding var homeURL: URL
+ @Binding var homeURLString: String
#endif
@State private var showAlert = false
@State private var alertMessage: String = ""
@@ -123,6 +122,11 @@ struct SettingsView: View {
self.accentColour = Color(.blue)
}
}
+ #if os(visionOS)
+ Button("Done") {
+ dismiss()
+ }
+ #endif
}
#if os(OSX)
.padding(20)