Files
yattee/Yattee/Views/Components/ShareSheet.swift
Arkadiusz Fal 926c6ebc97 Set popover anchor for share sheets to fix iPad crash
UIActivityViewController is presented as a popover on iPad and requires an
anchor; without a sourceView/barButtonItem UIKit aborts in
-[UIPopoverPresentationController presentationTransitionWillBegin]. Set
sourceView/sourceRect on both the direct presentation in the swipe-actions
modifier and the ShareSheet representable.

Fixes a SIGABRT seen in TestFlight build 261.
2026-05-12 23:54:57 +02:00

58 lines
1.8 KiB
Swift

//
// ShareSheet.swift
// Yattee
//
// Cross-platform share sheet for exporting content.
//
import SwiftUI
#if os(iOS)
struct ShareSheet: UIViewControllerRepresentable {
let items: [Any]
func makeUIViewController(context: Context) -> UIActivityViewController {
let controller = UIActivityViewController(activityItems: items, applicationActivities: nil)
// On iPad the activity sheet is presented as a popover and requires an
// anchor; without one UIKit aborts in presentationTransitionWillBegin.
if let popover = controller.popoverPresentationController {
popover.sourceView = controller.view
popover.permittedArrowDirections = []
}
return controller
}
func updateUIViewController(_ uiViewController: UIActivityViewController, context: Context) {}
}
#elseif os(macOS)
struct ShareSheet: View {
let items: [Any]
var body: some View {
VStack(spacing: 12) {
if let text = items.first as? String {
ScrollView {
Text(text)
.font(.caption)
.fontDesign(.monospaced)
.textSelection(.enabled)
.frame(maxWidth: .infinity, alignment: .leading)
.padding()
}
.frame(maxHeight: 400)
}
Button(String(localized: "settings.advanced.logs.export.copy")) {
if let text = items.first as? String {
NSPasteboard.general.clearContents()
NSPasteboard.general.setString(text, forType: .string)
}
}
.keyboardShortcut(.defaultAction)
}
.padding()
.frame(minWidth: 420, minHeight: 320)
}
}
#endif