6

I'm trying to add a NavigationLink at the top of the screen, but once I click it, it prompts me to the result and the Back button disappears.

SwiftUI Code:

NavigationView {
    VStack {
        NavigationLink (destination: Text("COOL")) {
            Text("COOL")
        }

        Spacer()
    }
    .navigationBarHidden(true)
    .navigationBarTitle(Text("Home"))
    //.edgesIgnoringSafeArea([.top, .bottom])
}

The back button disappears after clicking on the NavigationLink: https://gyazo.com/9d39936c849f570a05687e41096ddeca

Ivan Kaloyanov
  • 1,748
  • 6
  • 18
  • 24
md123
  • 295
  • 3
  • 8

2 Answers2

1

There is some glitch IMHO, when you use both .navigationBarHidden(true) and .navigationBarTitle(Text("Some text)). If you remove the last one, back button works as usual. Nevertheless I tried to return back button in your code snippet. It still has glitch while returning to first view, but back button don't disappear. I hope it will help and you will go further from here:

struct NotHiddenBackButton: View {

    @State var hiddingNavBar = true
    @State var goToSecondView = false

    var body: some View {

        NavigationView {

            NavigationLink(destination: ViewWithBackButton(hiddingNavBar: $hiddingNavBar), isActive: $goToSecondView) {

                VStack {
                    Text("COOL")
                        .onTapGesture {
                            self.hiddingNavBar = false
                            self.goToSecondView = true
                    }
                    Spacer()

                }


            }
            .navigationBarHidden(hiddingNavBar)
            .navigationBarTitle(Text("Home"))
        }


    }

}

struct ViewWithBackButton: View {

    @Binding var hiddingNavBar: Bool
    var body: some View {

        Text("Second view")
            .navigationBarTitle("Second view")
            .onDisappear() {
                self.hiddingNavBar = true
        }

    }

}
Hrabovskyi Oleksandr
  • 3,070
  • 2
  • 17
  • 36
-2

I believe this was a bug that has now been fixed in iOS 14