// // 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 private let shareCurrentURL: () -> Void @Environment(\.colorScheme) var colorScheme: ColorScheme init(navigator: NavigationManager, shareCurrentURL: @escaping () -> Void) { self.navigator = navigator self._urlFieldContents = State(initialValue: navigator.currentURL.absoluteString) self.shareCurrentURL = shareCurrentURL } var body: some View { VStack(spacing: 0) { urlBar barBorder Spacer(minLength: 0) BrowserView(navigator: navigator) Spacer(minLength: 0) barBorder bottomBar } .onAppear(perform: tweakAppearance) .onReceive(navigator.$currentURL, perform: { (new) in urlFieldContents = new.absoluteString }) .sheet(isPresented: $showPreferencesSheet, content: { PreferencesView(presented: $showPreferencesSheet) }) } private var barBorder: some View { Rectangle() .frame(height: 1) .foregroundColor(Color(white: colorScheme == .dark ? 0.25 : 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 { // use a group because this exceeds the 10 view limit :/ Group { Spacer() Button(action: navigator.back) { Image(systemName: "arrow.left") .font(.system(size: 24)) } .disabled(navigator.backStack.isEmpty) Spacer() Button(action: navigator.forward) { Image(systemName: "arrow.right") .font(.system(size: 24)) } .disabled(navigator.forwardStack.isEmpty) Spacer() Button(action: navigator.reload) { Image(systemName: "arrow.clockwise") .font(.system(size: 24)) } Spacer() Button(action: shareCurrentURL) { Image(systemName: "square.and.arrow.up") .font(.system(size: 24)) } Spacer() Button(action: { showPreferencesSheet = true }, label: { Image(systemName: "gear") .font(.system(size: 24)) }) } Spacer() } .padding(.top, 4) } private func tweakAppearance() { UIScrollView.appearance().keyboardDismissMode = .interactive } 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")!), shareCurrentURL: {}) } }