The scenario:
I have a simple SwiftUI view that looks like this:
struct AuthView: View { var body: some View { VStack { Button(action: handleLogin) { Text("Login to twitter") } } } private func handleLogin() { // do login stuff here } } Now ideally in the handleLogin function I would simply perform an OAuth request and handle logging in, etc. However, I am using a library I found on GitHub for demo purposes.
This library has a method authorize(callBackUrl: URL, presentingController: UIViewController) which when called presents a safari controller which allows the user to login to twitter. However, to call authorize you need to pass in a controller which conforms to SFSafariViewControllerDelegate. From my current basic understanding is that View type from SwiftUI isn't a view controller and moreover could not conform to the SFSafariViewControllerDelegate since it's a struct.
I looked at the Interfacing with UIKit tutorial from Apples site, and they seem to create a UIViewControllerRepresentable type and then from the View type return this "controller" in the body of the View. This allows them to use PageViewController from UIKit. However, this isn't entirely the use case I have or need. I simply need to be able to somehow convert my simple View into a UIViewController. Would UIHostingController be the thing to use here, and if so, how would this dependency be injected or should the view even know/use a controller?
Mostly my confusion lies on not yet knowing what the best practices are for SwiftUI. The View type seems to replace the use of UIViewController in UIKit, but then how does the conversion work when interfacing with UIKit?
If anyone has any ideas or would like to discuss this I'd appreciate it! Thanks.
UIViewControlleror does it need anSFSafariViewControllerDelegate? Asking for the former that conforms to the latter when it just needs the latter is probably a poor design.