In my Button action event handler, I'd to transition to authorizeView() in the else code block. This else logic throwing me a fist.

Button(action: { if email.isEmpty { print("* Email is required.") } else { authorizeView() } }) { HStack { Text("NEXT") .fontWeight(.semibold) Image(systemName: "arrow.right") } .foregroundColor(.white) .frame(width: UIScreen.main.bounds.width - 32, height: 48) } .background(Color(.systemBlue)) .cornerRadius(10) .disabled(!formIsValid) .opacity(formIsValid ? 1.0 : 0.5)

This doesn't make any sense. And also, please use the code formatting.

Here is a readable code:

            Button(action: {
                if email.isEmpty {
                    print("* Email is required.")
                } else {
                    authorizeView()
                }
            })  {
                HStack {
                    Text("NEXT")
                        .fontWeight(.semibold)
                    Image(systemName: "arrow.right")
                }
                .foregroundColor(.white)
                .frame(width: UIScreen.main.bounds.width - 32, height: 48)
            }
            .background(Color(.systemBlue))
            .cornerRadius(10)
            .disabled(!formIsValid)
            .opacity(formIsValid ? 1.0 : 0.5)

You cannot call a view in a button action.

To do this, declare a state var and set it in the action.

    @State private var showAuthView = false

Then use it in the action:

            if showAuthView {
                AuthorizeView()
            }
            Button(action: {
                if email.isEmpty {
                    print("* Email is required.")
                } else {
                    showAuthView = true // Now AuthorizeView will show
                }
            })  {
                HStack {
                    Text("NEXT")
                        .fontWeight(.semibold)
                    Image(systemName: "arrow.right")
                }
                .foregroundColor(.white)
                .frame(width: UIScreen.main.bounds.width - 32, height: 48)
            }
            .background(Color(.systemBlue))
            .cornerRadius(10)
            .disabled(!formIsValid)
            .opacity(formIsValid ? 1.0 : 0.5)

Notes:

  • AuthorizeView should start with uppercase as it is a struct.
  • when you report an error, please show the error message you get, not your comment on the error.
In my Button action event handler, I'd to transition to authorizeView() in the else code block. This else logic throwing me a fist.
 
 
Q