Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SwiftUI app freezes with no errors in console after attempting to move between textfields on same view

Tags:

swiftui

I have a simple log in view comprising of two text fields, a navigation link to a registration view, a navigation link to a forgot password view and a log in button. I can select either text field and enter text, however attempting to press any other control on the view (textfield or navigation link) after entering text into either text field, simply freezes the app with no error messages logged in the console window.

I have seen in other posts relating to older versions of Xcode / swift that this type of behaviour can be explained by a continuous loop being executed on the main thread, however i can not see how this applies in my case?

struct LoginForm : View {

    @Binding var emailAddress :  String
    @Binding var password: String

    var body: some View{

        VStack(alignment: .leading){

            Text("Email address")
                .foregroundColor(Color.black)
                .bold()
                .font(.subheadline)
                .padding(.leading, 12)
            TextField("Email",text:$emailAddress)
                .padding()


            Text("Password")
                .foregroundColor(Color.black)
                .bold()
                .font(.subheadline)
                .padding(.leading, 12)
            SecureField("Password",text:$password)
                .padding()

        }


    }
}





struct LoginRootView : View {

    @State private var emailAddress: String = ""
    @State private var password: String = ""
    @EnvironmentObject var authData: AuthData


    var body: some View {


        Group{

            if self.authData.authenticationDidSucceed {

                OnBoardRootView()

            }else{

                NavigationView{

                    ZStack{

                        Image("LoginBG")
                            .resizable()
                            .aspectRatio( contentMode: .fill)
                            .edgesIgnoringSafeArea(.all)
                            .opacity(0.5)


                        VStack(alignment: .leading){


                            Text( "Log into")
                                .font(.largeTitle)
                                .bold()


                            Text( "your account")
                                .font(.largeTitle)
                                .bold()


                                LoginForm(emailAddress:$emailAddress, password:$password)
                                    .padding(.bottom, 8)
                                    .padding(.top, 22)






                            //Login button

                            if emailAddress != "" && password != ""{

                                LoginButton(email:self.emailAddress, password: self.password)
                                    .padding(.vertical, 20.0)
                                    .background(Color.blue, cornerRadius: 30.0)
                                    .padding(.horizontal, 8)


                            }else{

                                LoginButton(email:self.emailAddress, password: self.password)
                                    .padding(.vertical, 20.0)
                                    .background(Color.gray, cornerRadius: 30.0)
                                    .padding(.horizontal, 8)
                                    .disabled(emailAddress == "" || password == "")


                            }




                            //Forgot password link

                            HStack{

                                Text( "Forgot password?")


                                NavigationLink(destination: ForgotPasswordRootView()) {
                                    Text( "Get help signing in")
                                        .bold()

                                }

                            }.padding(.top, 20)


                            Spacer()

                            // Registration Link

                            HStack{

                                Text( "Don't have an account? ")

                                NavigationLink(destination: RegistrationRootView()) {
                                    Text( "Sign Up")
                                        .bold()

                                }

                            }
                            .padding(.bottom, 120)


                        }.padding(.all)
                            .padding(.top, 160)

                        // end of vstack


                    }

                    //end of zstack

                }
                //end of navigation view





            }
            //end of authentication if statement



        }
        //end of group




    }
}





like image 706
ben goodenough Avatar asked Jan 25 '23 23:01

ben goodenough


1 Answers

You have to reset the simulator.

Simulator:

Hardware -> Erase All Content And Settings

Xcode:

  1. Make clean build
  2. Run
like image 167
webcpu Avatar answered Jun 25 '23 16:06

webcpu