I’d like to present share menu with multiple options. I’ve created a Menu and added all ShareLink views. I can tap the share button, but if I select a ShareLink, nothing happens. No error message.
This is the only way I can think of to create such a "share menu":
ToolbarItemGroup(placement: SwiftUI.ToolbarItemPlacement.navigationBarTrailing) {
Menu {
ShareLink(
item: URL(string: "https://www.apple.com")!,
preview: SharePreview(
"Test 123",
image: Image(systemName: "plus")
)
)
ShareLink(
item: URL(string: "https://www.microsoft.com")!,
preview: SharePreview(
"Tests 321",
image: Image(systemName: "minus")
)
)
} label: {
Image(systemName: "square.and.arrow.up")
}
}
3
Answers
ShareLink
inside a menu doesn’t currently work. A Menu is technically a new View Controller (UIContextMenuActionsOnlyViewController
) presented over the active window. The Share Action Sheet needs a View controller to present from. When aShareLink
inside aMenu
is tapped, it dismisses the menu VC, along with the share action sheet. You can verify this by checking the view hierarchy when a Menu is open.One workaround is to manually create Button/MenuItem/s and show a share action sheet on button tap from the underlying View; which avoids using ShareLink directly.
Workaround:
I’ve managed to achieve the desired behavior with custom popover bridged from UIKit.
This was fixed in iOS 16.1! Thanks for the report.