Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions share/ios/Sources/SharePlugin/SharePlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,28 @@ public class SharePlugin: CAPPlugin, CAPBridgedPlugin {
}

}
if self?.bridge?.viewController?.presentedViewController != nil {
call.reject("Can't share while sharing is in progress")
return
// Present from the topmost presented view controller so the share sheet appears
// above any view controller the app has presented over the webview. With nothing
// presented this resolves to the bridge view controller, i.e. unchanged behaviour.
// A share is only in progress when a share sheet is already presented.
var presenter = self?.bridge?.viewController
while let presented = presenter?.presentedViewController {
if presented is UIActivityViewController {
call.reject("Can't share while sharing is in progress")
return
}
presenter = presented
}
// `setCenteredPopover` anchors to the bridge view controller's view, which is not in
// the presenter's hierarchy when presenting from a different view controller. Anchor
// the popover to the presenting view controller's own view instead, centered and
// without an arrow, matching `setCenteredPopover` behaviour.
if let popover = actionController.popoverPresentationController, let presenterView = presenter?.view {
popover.sourceView = presenterView
popover.sourceRect = CGRect(x: presenterView.bounds.midX, y: presenterView.bounds.midY, width: 0, height: 0)
popover.permittedArrowDirections = []
}
self?.setCenteredPopover(actionController)
self?.bridge?.viewController?.present(actionController, animated: true, completion: nil)
presenter?.present(actionController, animated: true, completion: nil)
}
}
}