2020-09-28 19:20:06 +00:00
|
|
|
//
|
|
|
|
// NavigationBar.swift
|
|
|
|
// Gemini-iOS
|
|
|
|
//
|
|
|
|
// Created by Shadowfacts on 9/28/20.
|
|
|
|
//
|
|
|
|
|
|
|
|
import SwiftUI
|
|
|
|
import BrowserCore
|
|
|
|
|
|
|
|
struct NavigationBar: View {
|
|
|
|
@ObservedObject var navigator: NavigationManager
|
|
|
|
@State private var urlFieldContents: String
|
|
|
|
|
|
|
|
@Environment(\.colorScheme) var colorScheme: ColorScheme
|
|
|
|
|
|
|
|
init(navigator: NavigationManager) {
|
|
|
|
self.navigator = navigator
|
|
|
|
self._urlFieldContents = State(initialValue: navigator.currentURL.absoluteString)
|
|
|
|
}
|
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
VStack(spacing: 0) {
|
|
|
|
TextField("URL", text: $urlFieldContents, onCommit: commitURL)
|
|
|
|
.keyboardType(.URL)
|
|
|
|
.autocapitalization(.none)
|
|
|
|
.disableAutocorrection(true)
|
|
|
|
.textFieldStyle(RoundedBorderTextFieldStyle())
|
|
|
|
.padding([.leading, .trailing, .bottom])
|
|
|
|
|
|
|
|
Rectangle()
|
|
|
|
.frame(height: 1)
|
|
|
|
.foregroundColor(Color(white: colorScheme == .dark ? 0.25 : 0.75))
|
|
|
|
}
|
|
|
|
.background(Color(UIColor.systemBackground).edgesIgnoringSafeArea(.top))
|
2020-09-28 19:49:02 +00:00
|
|
|
.onReceive(navigator.$currentURL) { (newURL) in
|
|
|
|
urlFieldContents = newURL.absoluteString
|
|
|
|
}
|
2020-09-28 19:20:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private func commitURL() {
|
|
|
|
guard let url = URL(string: urlFieldContents) else { return }
|
|
|
|
navigator.changeURL(url)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct NavigationBar_Previews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
|
|
|
NavigationBar(navigator: NavigationManager(url: URL(string: "gemini://localhost/overview.gmi")!))
|
|
|
|
}
|
|
|
|
}
|