iOS: Add URL field and toolbar
This commit is contained in:
parent
2c023bc02e
commit
87fcc576c5
@ -23,6 +23,11 @@ public class NavigationManager: NSObject, ObservableObject {
|
|||||||
forwardStack = []
|
forwardStack = []
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public func reload() {
|
||||||
|
let url = currentURL
|
||||||
|
currentURL = url
|
||||||
|
}
|
||||||
|
|
||||||
private func cannonicalizeURL(_ url: URL) -> URL {
|
private func cannonicalizeURL(_ url: URL) -> URL {
|
||||||
var components = URLComponents(url: url, resolvingAgainstBaseURL: false)!
|
var components = URLComponents(url: url, resolvingAgainstBaseURL: false)!
|
||||||
if components.scheme == "gemini" && components.port == 1965 {
|
if components.scheme == "gemini" && components.port == 1965 {
|
||||||
|
@ -9,10 +9,92 @@ import SwiftUI
|
|||||||
import BrowserCore
|
import BrowserCore
|
||||||
|
|
||||||
struct ContentView: View {
|
struct ContentView: View {
|
||||||
let navigator: NavigationManager
|
@ObservedObject private var navigator: NavigationManager
|
||||||
|
@State private var urlFieldContents: String
|
||||||
|
@State private var showPreferencesSheet = false
|
||||||
|
|
||||||
|
init(navigator: NavigationManager) {
|
||||||
|
self.navigator = navigator
|
||||||
|
self._urlFieldContents = State(initialValue: navigator.currentURL.absoluteString)
|
||||||
|
}
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
BrowserView(navigator: navigator)
|
VStack(spacing: 0) {
|
||||||
|
urlBar
|
||||||
|
|
||||||
|
barBorder
|
||||||
|
|
||||||
|
Spacer()
|
||||||
|
BrowserView(navigator: navigator)
|
||||||
|
Spacer()
|
||||||
|
|
||||||
|
barBorder
|
||||||
|
|
||||||
|
bottomBar
|
||||||
|
}
|
||||||
|
.onReceive(navigator.$currentURL, perform: { (new) in
|
||||||
|
urlFieldContents = new.absoluteString
|
||||||
|
})
|
||||||
|
.sheet(isPresented: $showPreferencesSheet, content: {
|
||||||
|
Text("Test")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
private var barBorder: some View {
|
||||||
|
Rectangle()
|
||||||
|
.frame(height: 1)
|
||||||
|
.foregroundColor(Color(white: 0.75))
|
||||||
|
}
|
||||||
|
|
||||||
|
private var urlBar: some View {
|
||||||
|
TextField("URL", text: $urlFieldContents, onCommit: commitURL)
|
||||||
|
.keyboardType(.URL)
|
||||||
|
.textFieldStyle(RoundedBorderTextFieldStyle())
|
||||||
|
.padding([.leading, .trailing, .bottom])
|
||||||
|
}
|
||||||
|
|
||||||
|
private var bottomBar: some View {
|
||||||
|
HStack {
|
||||||
|
Spacer()
|
||||||
|
|
||||||
|
Button(action: navigator.back, label: {
|
||||||
|
Image(systemName: "arrow.left")
|
||||||
|
.font(.system(size: 24))
|
||||||
|
})
|
||||||
|
.disabled(navigator.backStack.isEmpty)
|
||||||
|
|
||||||
|
Spacer()
|
||||||
|
|
||||||
|
Button(action: navigator.forward, label: {
|
||||||
|
Image(systemName: "arrow.right")
|
||||||
|
.font(.system(size: 24))
|
||||||
|
})
|
||||||
|
.disabled(navigator.forwardStack.isEmpty)
|
||||||
|
|
||||||
|
Spacer()
|
||||||
|
|
||||||
|
Button(action: navigator.reload, label: {
|
||||||
|
Image(systemName: "arrow.clockwise")
|
||||||
|
.font(.system(size: 24))
|
||||||
|
})
|
||||||
|
|
||||||
|
Spacer()
|
||||||
|
|
||||||
|
Button(action: {
|
||||||
|
showPreferencesSheet = true
|
||||||
|
}, label: {
|
||||||
|
Image(systemName: "gear")
|
||||||
|
.font(.system(size: 24))
|
||||||
|
})
|
||||||
|
|
||||||
|
Spacer()
|
||||||
|
}
|
||||||
|
.padding(.top, 4)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func commitURL() {
|
||||||
|
guard let url = URL(string: urlFieldContents) else { return }
|
||||||
|
navigator.changeURL(url)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user