Files

76 lines
2.2 KiB
Swift
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// The MIT License (MIT)
//
// Copyright (c) 2020–2023 Alexander Grebenyuk (github.com/kean).
import SwiftUI
import CoreData
import Pulse
import Combine
#if os(iOS)
public struct ConsoleView: View {
@StateObject private var environment: ConsoleEnvironment // Never reloads
@Environment(\.presentationMode) private var presentationMode
private var isCloseButtonHidden = false
init(environment: ConsoleEnvironment) {
_environment = StateObject(wrappedValue: environment)
}
public var body: some View {
ConsoleListView()
.navigationTitle(environment.title)
.toolbar {
ToolbarItemGroup(placement: .navigationBarLeading) {
if !isCloseButtonHidden && presentationMode.wrappedValue.isPresented {
Button("Close") {
presentationMode.wrappedValue.dismiss()
}
}
}
ToolbarItemGroup(placement: .navigationBarTrailing) {
trailingNavigationBarItems
}
}
.injecting(environment)
}
/// Changes the default close button visibility.
public func closeButtonHidden(_ isHidden: Bool = true) -> ConsoleView {
var copy = self
copy.isCloseButtonHidden = isHidden
return copy
}
@ViewBuilder private var trailingNavigationBarItems: some View {
Button(action: { environment.router.isShowingShareStore = true }) {
Label("Share", systemImage: "square.and.arrow.up")
}
Button(action: { environment.router.isShowingFilters = true }) {
Image(systemName: "line.horizontal.3.decrease.circle")
}
ConsoleContextMenu()
}
}
// MARK: - Previews
#if DEBUG
struct ConsoleView_Previews: PreviewProvider {
static var previews: some View {
Group {
NavigationView {
ConsoleView(environment: .init(store: .mock))
}.previewDisplayName("Console")
NavigationView {
ConsoleView(store: .mock, mode: .network)
}.previewDisplayName("Network")
}
}
}
#endif
#endif