I've got an onboarding process with a welcome view that has two buttons that open modal sheets for signup and login.
Once signup is completed, the button should close the modal view for Signup and transition to another Dashboard view.
How can I close the modal and then execute the navigationlink to the dashboard view?
import SwiftUI
import Firebase
struct Signup: View {
@State private var isAuthCompleted: Bool = false
@State private var isShowingAlert = false
@State private var localMsg: String = ""
@Environment(\.presentationMode) var presentationMode: Binding<PresentationMode>
.
.
.
// signup button
NavigationView {
VStack {
NavigationLink(destination: ContentView(),
isActive: self.$isAuthCompleted) {
Text("")
}
Button(action: {
Auth.auth().createUser(
withEmail: self.email,
password: self.password
) {
authResult, error in
if let e = error {
print(e.localizedDescription)
self.localMsg = e.localizedDescription
self.isShowingAlert = true
} else {
self.presentationMode.wrappedValue.dismiss() // modal sheet dismiss
self.isAuthCompleted = true // navigationlink execution
}
}
}) {
HStack {
Spacer()
Text("Sign Up")
.font(.headline)
.foregroundColor(.white)
Spacer()
}
.padding()
.background(Color.green)
.cornerRadius(20.0)
}
.alert(isPresented: $isShowingAlert) {
Alert(title: Text("Wait A Minute"), message: Text(self.localMsg), dismissButton: .default(Text("Got it!")))
}
}
.navigationBarTitle("")
.navigationBarHidden(true)
}