Hi everyone I'm new to SwiftUI .. I need to present a view containing two textFields with modal presentation only after a condition has been checked.
Example .. When the user pushes the login button I need the app to check the database for the existence of the user. If the user exists he can access the app otherwise he must show a view where he must enter his name and surname.
With UIKit I used this to present a structure or class
self.present(userFound ? Home() : UserNameInfo(), animated: true, completion: nil) but with SwiftUI I can't figure out how to solve this problem.
Can you help me in any way?
My code
var body: some View { ZStack(alignment: .top) { Color(.black).ignoresSafeArea() gradientBackground().ignoresSafeArea() VStack(alignment: .center, spacing: 25) { Spacer() logoStack() // Messaggio di benvenuto VStack(alignment: .leading, spacing: 15) { Text("Effettua l'accesso al tuo account") .font(.title2.bold()) Text("Riserva un momento esclusivo prenotando un taglio tradizionale oppure una rasatura con panni caldi e trattamenti viso") .font(.callout.weight(.light)) } .foregroundColor(.white) //.dynamicTypeSize(.medium) // Apple Sign In Button SignInWithAppleView() .frame(width: screen.size.width - 56) .frame(height: 45, alignment: .center) .onTapGesture(perform: showAppleLoginView) // Divisore Divider().background(.gray) // Messaggio sull'accettazione della Privacy e delle Condizioni di utilizzo VStack(spacing: 5) { Text("Continuando dichiaro di accettare le ") .multilineTextAlignment(.center) HStack(spacing: 0) { Button("Condizioni di Utilizzo") {} .foregroundColor(.white) .font(.footnote.bold()) Text(" ed i ") Button("Termini sulla Privacy") {} .foregroundColor(.white) .font(.footnote.bold()) Text(".") } } .foregroundColor(.gray) .font(.footnote) .padding(.bottom, 25) } .padding(.horizontal) } private func showAppleLoginView() { // Show modalview if user not exist in Firebase } // MARK: - Apple Sign In Button View Representable struct SignInWithAppleView: UIViewRepresentable { typealias UIViewType = ASAuthorizationAppleIDButton func makeUIView(context: Context) -> UIViewType { ASAuthorizationAppleIDButton(type: .signIn, style: .white) } func updateUIView(_ uiView: UIViewType, context: Context) {} }