mirror of
https://github.com/yattee/yattee.git
synced 2026-07-20 14:22:02 +00:00
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.
This commit is contained in:
@@ -12,7 +12,14 @@ struct ShareSheet: UIViewControllerRepresentable {
|
||||
let items: [Any]
|
||||
|
||||
func makeUIViewController(context: Context) -> UIActivityViewController {
|
||||
UIActivityViewController(activityItems: items, applicationActivities: nil)
|
||||
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) {}
|
||||
|
||||
@@ -202,6 +202,16 @@ struct VideoSwipeActionsModifier: ViewModifier {
|
||||
while let presented = topVC.presentedViewController {
|
||||
topVC = presented
|
||||
}
|
||||
// On iPad UIActivityViewController is presented as a popover and
|
||||
// requires an anchor; without sourceView/barButtonItem UIKit aborts
|
||||
// in -[UIPopoverPresentationController presentationTransitionWillBegin].
|
||||
if let popover = activityVC.popoverPresentationController {
|
||||
popover.sourceView = topVC.view
|
||||
popover.sourceRect = CGRect(x: topVC.view.bounds.midX,
|
||||
y: topVC.view.bounds.midY,
|
||||
width: 0, height: 0)
|
||||
popover.permittedArrowDirections = []
|
||||
}
|
||||
topVC.present(activityVC, animated: true)
|
||||
}
|
||||
#elseif os(macOS)
|
||||
|
||||
Reference in New Issue
Block a user