Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SwiftUI navigationBarHidden doesn't work and throws error

Tags:

ios

swift

swiftui

I am pushing next view with navigation link

        NavigationLink(destination: DetailsView()
            .navigationBarTitle("")
            .navigationBarHidden(true),
                       isActive: $isDetailsActive) {
            EmptyView()
        }

I tried the same inside details view too. All I am getting is empty Navigation Bar on Details View and error in terminal:

"changing items while animating can result in a corrupted navigation bar"

like image 410
Pavel Gatilov Avatar asked Oct 18 '25 13:10

Pavel Gatilov


2 Answers

The error indicates that you should not push or pop new views on the navigation controller until it’s finished with the last push or pop.

like image 93
grow4gaurav Avatar answered Oct 21 '25 02:10

grow4gaurav


I hide my navigation bar using .onAppear and .onDisappear, you can place those modifiers in your parent view or in DetailsView(), look:

NavigationView {
    VStack {
        Text("Hello World")
    }
    .navigationBarTitle("")
    .navigationBarHidden(self.isNavBarHidden)
    .onAppear {
        self.isNavBarHidden = true
    }.onDisappear {
        self.isNavBarHidden = false
    }
}
like image 22
zgluis Avatar answered Oct 21 '25 03:10

zgluis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!