Home > Mobile >  How to open Share Sheet from presented sheet
How to open Share Sheet from presented sheet

Time:10-24

Following several tutorials (demo

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
        })
   }
}

struct SharingViewController: UIViewControllerRepresentable {
    @Binding var isPresenting: Bool
    var content: () -> UIViewController

    func makeUIViewController(context: Context) -> UIViewController {
        UIViewController()
    }

    func updateUIViewController(_ uiViewController: UIViewController, context: Context) {
        if isPresenting {
            uiViewController.present(content(), animated: true, completion: nil)
        }
    }
}
  • Related