1

Problem: I Have no NavigationBar on my RootViewController. But when I navigate two steps into the navigationstack or further from my RootViewController and I pop back from there to my RootViewController. I get a navigationBar that should not exist or be there.

This is the code that I'm trying to fix it on right now

import SwiftUI

struct DemoPop: View {

    @State private var path = NavigationPath()
    
    var body: some View {
        
        VStack {
            
            NavigationStack(path: $path) {
                   
                List {
                    Section("List One") {
                        NavigationLink("Navigate to View 1", value: "View 1")
                        NavigationLink("Navigate to View 2", value: "View 2")
                    }
                }
                .navigationDestination(for: String.self) { textDesc in
                    
                    VStack {
                        Text(textDesc).padding()
                        Button("Navigate to View 3") {
                            path.append("View 3")
                        }.padding()
                        
                        Button("Pop to Root View") {
                            path.removeLast(path.count)
                        }.padding()
                    }
                }
                .navigationTitle("Test Pop To Root")
            }
        }
    }
    }

struct DemoPop_Previews: PreviewProvider {
    static var previews: some View {
        DemoPop()
    }
}

I have tried a few different ways like building a router class and navigating through that to get rid of this but I have not succeeded yet, last thing I tried I just took some easy, readable code from stacked to figure out the problem. But no luck so far.

  • https://stackoverflow.com/questions/73753796/why-doesnt-clearing-the-new-ios-16-swiftui-navigationpath-to-pop-to-root-anim – Jay Patel Jul 25 '23 at 18:54
  • Does this answer your question? [NavigationStack iOS16 with Route, how to pop back to root?](https://stackoverflow.com/questions/76079519/navigationstack-ios16-with-route-how-to-pop-back-to-root) – lorem ipsum Jul 25 '23 at 20:09
  • It did not solve the problem. I updated my question to be more clear what it is about. It's not about not being able to popToRootViewController, it's the hidden navigationBar that I get from nowhere when I popback to the root – Kevin Zetterlind Jul 26 '23 at 20:30

1 Answers1

0

Found a solution:

Removing the transition animation seem to be working!

var antimation = Transaction()
antimation.disablesAnimations = true
withTransaction(antimation) {
    navPath = .init()
}