Embedded SWCollaborationView in SwiftUI

Hello to the team, Our app (targeting iOS 16) is sharing data between users via CloudKit, and now we'd like to add the new SWCollaborationView feature.

I created a CollaborationViewRep: UIViewRepresentable view as follows -

    var activityItem: NSItemProvider
    var eventName: String
    @Binding var isCollaborationViewPresented: Bool

    func makeUIView(context: Context) -> SWCollaborationView {
        let collaborationView = SWCollaborationView(itemProvider: activityItem)
        collaborationView.delegate = context.coordinator
        return collaborationView
    }

    func updateUIView(_ uiView: SWCollaborationView, context: Context) {
    }

    class Coordinator: NSObject, SWCollaborationViewDelegate {

        var parent: CollaborationViewRep

        init(_ parent: CollaborationViewRep) {
            self.parent = parent
        }

        

        func collaborationViewShouldPresentPopover(_ collaborationView: SWCollaborationView) -> Bool {
            return true
        }

        func collaborationViewWillPresentPopover(_ collaborationView: SWCollaborationView) {
        }
    }

    func makeCoordinator() -> Coordinator {
        Coordinator(self)
    }

}

And when I'm trying to add this view as a toolbar item to my SwiftUI view, it doesn't work properly.

If I'm adding this view as the toolbar item, without wrap it into a button, then nothing happens when I'm tapping the view (as it should work on UIKit). If I do wrap it with a button, and present the view as popover, then the view icon is presented and then, only when I tap this popover, the content view is presented (screenshot attached).

It feels like this feature is not fully available for SwiftUI, unless I'm missing something. Unfortunately, the documentation is not covering the SwiftUI flow and there is no sample app for reference.

Any idea how to best practice this situation?

Thanks a lot!

Post not yet marked as solved Up vote post of DudiSG Down vote post of DudiSG
1.1k views