Gemini/Gemini-iOS/NavigationBar.swift

52 lines
1.5 KiB
Swift
Raw Normal View History

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
2020-09-29 20:28:05 +00:00
self._urlFieldContents = State(initialValue: navigator.displayURL)
2020-09-28 19:20:06 +00:00
}
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-29 20:28:05 +00:00
.onReceive(navigator.$currentURL) { (_) in
urlFieldContents = navigator.displayURL
2020-09-28 19:49:02 +00:00
}
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")!))
}
}