Issue #718
Use NSSharingService.sharingServices(forItems:)
with an array of one empty string gives a list of sharing items. There we show image
and title
of each menu item.
We should cache sharing items as that can cause performance issue
import SwiftUI
import AppKit
import EasySwiftUI
extension NSSharingService {
private static let items = NSSharingService.sharingServices(forItems: [""])
static func submenu(text: String) -> some View {
return Menu(
content: {
ForEach(items, id: \.title) { item in
Button(action: { item.perform(withItems: [string]) }) {
Image(nsImage: item.image)
Text(item.title)
}
}
},
label: {
Text("Share")
Image(systemName: SFSymbol.squareAndArrowUp.rawValue)
}
)
}
}
Alternative, you can trigger NSSharingServicePicker
from a button, it shows a context menu with sharing options