I have a Google Sign-in screen, and then it should transition to a TabView. I tried using a ZStack, but it's causing the app to glitch before each tab is loaded. It will show the sign-in button for a second, and then the correct tab will appear.
Is there a way to totally segue similar to ViewControllers? Or is there a way to totally remove the sign-in button before I call the new view (MainView)?
MainView is just a SwiftUI view with a tabView, and tabItems.
I have a SwiftUI SignInView:
import SwiftUI
import GoogleSignIn
struct SignInView: View {
@State var loggedIn = false
let logo = Image('googleLogo')
var body: some View {
ZStack {
Button(action: {
self.signIn {
self.loggedIn = true
}
}, label: {
VStack {
logo
.padding(EdgeInsets(top: 8, leading: 16, bottom: 8, trailing: 16))
.background(Color.white)
.cornerRadius(8.0)
.shadow(radius: 4.0)
Text("Sign-In")
.foregroundColor(.primary)
.multilineTextAlignment(.center)
.padding(5)
}
}).zIndex(-1)
if loggedIn {
MainView()
}
}
}
func signIn(completion: @escaping () -> Void) {
GIDSignIn.sharedInstance()?.presentingViewController = UIApplication.shared.windows.last?.rootViewController
GIDSignIn.sharedInstance()?.signIn()
DispatchQueue(label: "SignIn Check", qos: DispatchQoS.background).async(execute: { () -> Void in
while true {
if GIDSignIn.sharedInstance()?.currentUser != nil {
completion()
break
}
}
})
}
}
struct SignInView_Previews: PreviewProvider {
static var previews: some View {
SignInView()
}
}