Home > Software design >  SwiftUI 4: ShareLink as a swipe action
SwiftUI 4: ShareLink as a swipe action

Time:11-19

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!

CodePudding user response:

a share sheet

struct SheetView: View {

   @Binding var showSheetView: Bool
    @State private var isShare = false
   var body: some View {


      // Below share Sheet - now works!
      Button(action: {
            isShare = true    // present activity
      }) {
        Text("Share Me")
      }
      .background(SharingViewController(isPresenting: $isShare) {
         let url = URL(string: "https://apple.com")
         let av = UIActivityViewController(activityItems: [url!], applicationActivities: nil)
         av.completionWithItemsHandler = { _, _, _, _ in
                isShare = false // required for re-open !!!
            }
            return av
        })
   }
}

  • Related