// // ContentView.swift // Gemini-iOS // // Created by Shadowfacts on 7/15/20. // import SwiftUI import BrowserCore struct ContentView: View { @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 { 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) } } struct ContentView_Previews: PreviewProvider { static var previews: some View { ContentView(navigator: NavigationManager(url: URL(string: "gemini://localhost/overview.gmi")!)) } }