Files
Pulse/Sources/PulseUI/Features/Console/Views/ConsoleShareButton.swift
T
2023-02-03 20:23:41 -05:00

43 lines
1.1 KiB
Swift
Raw 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) 20202023 Alexander Grebenyuk (github.com/kean).
#if os(iOS)
import SwiftUI
struct ConsoleShareButton: View {
let viewModel: ConsoleViewModel
@State private var selectedShareOutput: ShareOutput?
var body: some View {
if let _ = selectedShareOutput {
ProgressView()
.frame(width: 27, height: 27)
} else {
Menu(content: {
Button(action: { share(as: .plainText) }) {
Label("Share as Text", systemImage: "square.and.arrow.up")
}
Button(action: { share(as: .html) }) {
Label("Share as HTML", systemImage: "square.and.arrow.up")
}
}, label: {
Image(systemName: "square.and.arrow.up")
})
.disabled(selectedShareOutput != nil)
}
}
private func share(as output: ShareOutput) {
selectedShareOutput = output
viewModel.prepareForSharing(as: output) { item in
selectedShareOutput = nil
viewModel.router.shareItems = item
}
}
}
#endif