Gemini/Gemini-iOS/ToolBar.swift

126 lines
4.4 KiB
Swift
Raw Normal View History

2020-09-28 19:20:06 +00:00
//
// 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
2020-09-28 19:20:06 +00:00
@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()
2020-12-19 20:19:32 +00:00
Button(action: navigator.goBack) {
2020-09-28 19:20:06 +00:00
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))
}
}
}
2020-09-28 19:20:06 +00:00
.disabled(navigator.backStack.isEmpty)
Spacer()
2020-12-19 20:19:32 +00:00
Button(action: navigator.goForward) {
2020-09-28 19:20:06 +00:00
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))
}
}
}
2020-09-28 19:20:06 +00:00
.disabled(navigator.forwardStack.isEmpty)
Spacer()
Button(action: navigator.reload) {
Image(systemName: "arrow.clockwise")
.font(.system(size: 24))
}
.accessibility(label: Text("Reload"))
.hoverEffect(.highlight)
2020-09-28 19:20:06 +00:00
Spacer()
Button {
showShareSheet = true
} label: {
2020-09-28 19:20:06 +00:00
Image(systemName: "square.and.arrow.up")
.font(.system(size: 24))
}
.accessibility(label: Text("Share"))
.hoverEffect(.highlight)
2020-09-28 19:20:06 +00:00
Spacer()
Button(action: {
showPreferencesSheet = true
}, label: {
Image(systemName: "gear")
.font(.system(size: 24))
})
.accessibility(label: Text("Preferences"))
.hoverEffect(.highlight)
2020-09-28 19:20:06 +00:00
}
Spacer()
}
2020-09-28 19:49:02 +00:00
2020-09-28 19:20:06 +00:00
}
.padding(.bottom, 4)
2020-09-28 19:20:06 +00:00
.background(Color(UIColor.systemBackground).edgesIgnoringSafeArea(.bottom))
.sheet(isPresented: $showPreferencesSheet, content: {
PreferencesView()
2020-09-28 19:20:06 +00:00
})
}
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
}
2020-09-28 19:20:06 +00:00
}
struct ToolBar_Previews: PreviewProvider {
@State private static var showShareSheet = false
2020-09-28 19:20:06 +00:00
static var previews: some View {
ToolBar(navigator: NavigationManager(url: URL(string: "gemini://localhost/overview.gmi")!), showShareSheet: $showShareSheet)
2020-09-28 19:20:06 +00:00
}
}