2020-07-16 03:45:37 +00:00
|
|
|
//
|
|
|
|
// ContentView.swift
|
|
|
|
// Gemini-iOS
|
|
|
|
//
|
|
|
|
// Created by Shadowfacts on 7/15/20.
|
|
|
|
//
|
|
|
|
|
|
|
|
import SwiftUI
|
|
|
|
import BrowserCore
|
|
|
|
|
|
|
|
struct ContentView: View {
|
2020-09-28 02:11:34 +00:00
|
|
|
@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)
|
|
|
|
}
|
2020-07-16 03:45:37 +00:00
|
|
|
|
|
|
|
var body: some View {
|
2020-09-28 02:11:34 +00:00
|
|
|
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: {
|
2020-09-28 02:26:44 +00:00
|
|
|
PreferencesView(presented: $showPreferencesSheet)
|
2020-09-28 02:11:34 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
2020-07-16 03:45:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct ContentView_Previews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
|
|
|
ContentView(navigator: NavigationManager(url: URL(string: "gemini://localhost/overview.gmi")!))
|
|
|
|
}
|
|
|
|
}
|