Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
339 views
in Technique[技术] by (71.8m points)

swift - Navigate to Home Screen (Content View) after FireBase log in process. (SwiftUI)

I tried to navigate to Home Screen after FireBase loging in, but this code presents the Home Screen view inside log in View. I put isReadyToNavigateToHomePage.toggle() when the sign in is successful. And I use it to navigate to Home Screen when it is true.

 Button(action: {
        let error = validateFields()
        if error != nil{
            errM = error!
            showErrorAleart.toggle()
     

         showError(error!)
            print(error!)
        }
        else{
            Auth.auth().signIn(withEmail: email, password: password) {(result, error) in
                if error != nil {
                    errr = error!.localizedDescription
                   print(error!.localizedDescription)
                    
                }
                
                else{
                    self.presentationMode.wrappedValue.dismiss()
                    print("successful log in")
                    isReadyToNavigateToHomePage.toggle()
                    
                }
               
              }
         
                }
            }
       
    ){
      
        HStack{
            Spacer()
        Text("Sign In")
            .padding(.horizontal).padding(.vertical,5).padding(.trailing,20)
            .background(Color.green)
            .foregroundColor(.white)
            .cornerRadius(10)
            .padding(.top, 30)
            .overlay(Image("signInBtn").resizable().frame(width: 12, height: 12).padding(5).background(Color.white).cornerRadius(5).offset(x: 35, y: 15))
         Spacer()
        }
        if isReadyToNavigateToHomePage == true {
            ContentView()
              
        }
    }
        .alert(isPresented: $showErrorAleart){
        Alert(title: Text("Warning"), message: Text(errM + errr), dismissButton: .default(Text("Ok")))
    }
  
question from:https://stackoverflow.com/questions/65646005/navigate-to-home-screen-content-view-after-firebase-log-in-process-swiftui

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I created a fake navigationLink until it toggled,

 NavigationLink(destination: ContentView(showHomeScreen: $showHomeScreen),     isActive: $showHomeScreen){
                Text("")
        }.hidden()

   else{
           
            Auth.auth().signIn(withEmail: email, password: password) {(result, error) in
                if error != nil {
                    errr = error!.localizedDescription
                   print(error!.localizedDescription)
                    
                }
                else{
                    showHomeScreen.toggle()
                    print("login successcfully")
                }
               
              }
         
                }

when I tap on Sign In button, it toggled and take me to Home Screen. I found the solution on a website for videos.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...