Search code examples
swiftuiswiftui-navigationlink

Hidden Navbar still pushes down view


I have a:

contentView()
SignUpView()
SignInView()

The contentView calls the SignInView()

struct ContentView: View {

    var body: some View {
        NavigationView {
            SignInView()
        }
    }
}

In my SignUpView() I have:

var body: some View {
    VStack(alignment: .leading) {
       NavigationLink(destination: SignInView()) {
          Text("Sign in")
            .fontWeight(.semibold)
            .foregroundColor(Color("startColor"))
        }
   }.navigationBarHidden(true)

In my SigbInView I have:

var body: some View {
  VStack(alignment: .leading) {
    NavigationLink(destination: SignUpView()) {
       Text("Sign up")
       .fontWeight(.semibold)
       .foregroundColor(Color("startColor"))
     }.navigationBarHidden(true)

Im using .navigationBarHidden(true) to hide the bar, but the < back still appears in the top left hand corner to take you back to the previous screen, Iv also tried adding the navbar text = "" and setting the property to .inline

Im trying to only use these navigationLinks on the SignInView and SignUpViews to navigate, i don't want the bar to appear or push the view down.


Solution

  • So it looks like another property can be set to true to hide the back button:

    .navigationBarBackButtonHidden(true)
    

    This worked for me.