I have a UIKit and AppKit app, and I am displaying a SwiftUI view within it via UIHostingController / NSHostingController. The view has some buttons on it, and I want to pass back the tap event back to a UIKit/AppKit view controller to show UIAlertController from the button that got tapped (I would prefer to use ActionSheet within SwiftUI but it isn't supported on macOS). I pass a delegate through the hosting controller into the SwiftUI view, and use that to call back into the UIKit/AppKit view. But to display a UIAlertController (or even UIActivityViewController
), I would need to get some information about the sourceView
and sourceRect
from the SwiftUI view, else it might crash on iPad.
How do I pass back that information, from the SwiftUI view into the UIKit/Appkit app? I guess the sourceView
could be the SwiftUI view on display, but how do I read (and pass back) the rect of the SwiftUI button that was tapped?