[NavigationStack] No animation on push after programmatically pop view

Hello! As written in the post title, when I try to pop view programmatically, the next push transition doesn't have animations. Specifically, I pop view programmatically by removing the last element or all the elements from the path array. If I pop the view by tapping the system back button, the animations on push transitions work correctly.

Here an example of the code I am using with the navigationStack:

struct ContentView: View {
    @Binding var navigationPath: [Int]
    
    var body: some View {
        NavigationStack(path: $navigationPath) {
                DetailView(level: 0)
                    .navigationDestination(for: Int.self, destination: DetailView.init)
        }
    }
}

Furthermore, I have noticed that if I embed the DetailView of my example in a List, the push animations works always in the correct way using the programmatically pop view.

Is there any workaround which could solve the problem?

Thank you in advance!

Hi ,

I am attaching some sample code, please try something like this for programmatic navigation. The animations should work in this and have in my testing. Since you have not posted all of the code to your implementation I am unsure of the behavior you are seeing, but here I have used a button to append an integer to the path and then removed all items from the path in the detail view to go back to ContentView.

import SwiftUI

struct ContentView: View {
    @State private var path: [Int] = []
    
    var body: some View {
        NavigationStack(path: $path) {
            Button("Forwards") {
                path.append(0)
            }
            .navigationDestination(for: Int.self) { _ in
                DetailView(path: $path)
            }
        }
    }
}

struct DetailView: View {
    @Binding var path: [Int]
    
    var body: some View {
        Button("Back") {
            path = []
        }
    }
}
[NavigationStack] No animation on push after programmatically pop view
 
 
Q