Go to a new view when button tapped (SwiftUI)

185 Views Asked by At

My expectation: I want to open a new full screen view (PhoneNumberView) on click of confirmation dialog button. Reality: Nothing happens when I click to Back button (please check my code below)

Here is my code:

                SetPasswordButton(value: "exitButton",
                                  password: $password,
                                  key: $key,
                                  unlocked: $unlocked,
                                  repeatPassword: $repeatPassword, isExitButtonTapped: $isExitButtonTapped)
                .confirmationDialog("", isPresented: $isExitButtonTapped) {
                    
                    Button("Back", role: .destructive) {
                        goToPhoneScreen = true
                    }
                    .fullScreenCover(isPresented: $goToPhoneScreen {
                            PhoneNumberView()
                    }                   
                    
                    Button("Cancel", role: .cancel) {}
                }

Could you help me?

1

There are 1 best solutions below

0
On

You have misplaced the .fullScreenCover in your code, that should be something like this, i have tested it and it's working as expected, here is the Full code,

struct ContentView: View {

var body: some View {
    SetPasswordButton(value: "exitButton",
                      password: $password,
                      key: $key,
                      unlocked: $unlocked,
                      repeatPassword: $repeatPassword, isExitButtonTapped: $isExitButtonTapped)
    .confirmationDialog("", isPresented: $isExitButtonTapped) {
        Button("Back") {
            goToPhoneScreen = true
        }
    }
    .fullScreenCover(isPresented: $goToPhoneScreen){
        PhoneNumberView()
    }
    Button("Cancel", role: .cancel) {}
  }
}