ios – Displaying a UIKit View in a SwiftUI sheet

0
47


I’m making an attempt to point out a UiKit view in a SwiftUI sheet, nevertheless once I open the sheet, it’s fully empty, not one of the UIKit components present up. All I can see is the navigation view bar title. I’ve positioned the UIKit element right into a UIViewController in order that I can show it in my foremost view.

My SwiftUI element:

Button("Login") {
    isShowingGoogleLogin = true
}.sheet(isPresented: $isShowingGoogleLogin, content material: {
    NavigationView {
        GoogleSignInViewController()
            .edgesIgnoringSafeArea(.all)
            .navigationBarTitle("Google Signal In")
    }
                
})

And my UIKit view:

import Basis
import UIKit
import GoogleSignIn
import SwiftUI

struct GoogleSignInViewController: UIViewControllerRepresentable {
    func makeUIViewController(context: Context) -> ViewController {
        return ViewController()
    }
    
    func updateUIViewController(_ uiViewController: ViewController, context: Context) {}
}


class ViewController: UIViewController {
    //MARK:  @IBOutlet
    @IBOutlet weak var btnGoogleSignIn: UIButton!
    @IBOutlet weak var btnGoogleSignOut: UIButton!
    @IBOutlet weak var lblSignInStatus: UILabel!
    
    //MARK: viewDidLoad
    override func viewDidLoad() {
        tremendous.viewDidLoad()
        // Do any further setup after loading the view.
    }
}

//MARK: @IBAction
extension ViewController {
    @IBAction func btnGoogleSingInDidTap(_ sender: Any) {
        GIDSignIn.sharedInstance.signIn(withPresenting: self) { signInResult, error in
            self.btnGoogleSignIn.isHidden = false
            self.btnGoogleSignOut.isHidden = true
            self.lblSignInStatus.textual content = "Welcome To GoogleSignIn! To proceed with GoogleSignIn please hit under button. "
            guard error == nil else { return }

          // If check in succeeded, show the app's foremost content material View.
            guard let signInResult = signInResult else { return }
            let consumer = signInResult.consumer

            let emailAddress = consumer.profile?.electronic mail
            let fullName = consumer.profile?.identify
            let familyName = consumer.profile?.familyName
            let profilePicUrl = consumer.profile?.imageURL(withDimension: 320)
                
            self.lblSignInStatus.textual content = "Hi (fullName ?? "")"
            self.btnGoogleSignIn.isHidden = true
            self.btnGoogleSignOut.isHidden = false
        }
    }
    
    @IBAction func btnGoogleSignOutDidTap(_ sender: Any) {
        GIDSignIn.sharedInstance.signOut()
    }
}