// // ToolBar.swift // Gemini-iOS // // Created by Shadowfacts on 9/28/20. // import SwiftUI import BrowserCore struct ToolBar: View { @ObservedObject var navigator: NavigationManager @Binding var showShareSheet: Bool @State private var showPreferencesSheet = false @Environment(\.colorScheme) var colorScheme: ColorScheme var body: some View { VStack(spacing: 4) { Rectangle() .frame(height: 1) .foregroundColor(Color(white: colorScheme == .dark ? 0.25 : 0.75)) 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)) } .accessibility(label: Text("Back")) .hoverEffect(.highlight) .contextMenu { ForEach(Array(navigator.backStack.suffix(5).enumerated()), id: \.1) { (index, url) in Button { navigator.back(count: min(5, navigator.backStack.count) - index) } label: { Text(verbatim: urlForDisplay(url)) } } } .disabled(navigator.backStack.isEmpty) Spacer() Button(action: navigator.forward) { Image(systemName: "arrow.right") .font(.system(size: 24)) } .accessibility(label: Text("Forward")) .hoverEffect(.highlight) .contextMenu { ForEach(navigator.forwardStack.prefix(5).enumerated().reversed(), id: \.1) { (index, url) in Button { navigator.forward(count: index + 1) } label: { Text(verbatim: urlForDisplay(url)) } } } .disabled(navigator.forwardStack.isEmpty) Spacer() Button(action: navigator.reload) { Image(systemName: "arrow.clockwise") .font(.system(size: 24)) } .accessibility(label: Text("Reload")) .hoverEffect(.highlight) Spacer() Button { showShareSheet = true } label: { Image(systemName: "square.and.arrow.up") .font(.system(size: 24)) } .accessibility(label: Text("Share")) .hoverEffect(.highlight) Spacer() Button(action: { showPreferencesSheet = true }, label: { Image(systemName: "gear") .font(.system(size: 24)) }) .accessibility(label: Text("Preferences")) .hoverEffect(.highlight) } Spacer() } } .padding(.bottom, 4) .background(Color(UIColor.systemBackground).edgesIgnoringSafeArea(.bottom)) .sheet(isPresented: $showPreferencesSheet, content: { PreferencesView() }) } private func urlForDisplay(_ url: URL) -> String { var str = url.host! if let port = url.port, url.scheme != "gemini" || port != 1965 { str += ":\(port)" } str += url.path return str } } struct ToolBar_Previews: PreviewProvider { @State private static var showShareSheet = false static var previews: some View { ToolBar(navigator: NavigationManager(url: URL(string: "gemini://localhost/overview.gmi")!), showShareSheet: $showShareSheet) } }