SwiftUI 4: ShareLink as a swipe action

532 Views Asked by At

I would like to present a share sheet when the user interacts with a swipe action. To achieve this I currently have simply this code:

            .swipeActions(edge: .leading, allowsFullSwipe: false) {
                ShareLink("Text", item: "Text")
                    .tint(.accentColor)
            }

And it looks like this: enter image description here

but when I tap it, nothing happens...

I really appreciate any help!

1

There are 1 best solutions below

0
On

I got the same error but I found the sollution:

.swipeActions(){
Button(action: {
let url = URL(string: "your url here")
let av = UIActivityViewController(activityItems: [url!], applicationActivities: nil)

UIApplication.shared.windows.first?.rootViewController?.present(av, animated: true, completion: nil)
}) {
Label("", systemImage: "square.and.arrow.up")
}

Hope it works for you :)