mirror of
https://github.com/kean/Pulse.git
synced 2026-05-30 21:07:33 +00:00
43 lines
1.1 KiB
Swift
43 lines
1.1 KiB
Swift
// The MIT License (MIT)
|
||
//
|
||
// Copyright (c) 2020–2023 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
|