Search code examples
swiftuiswiftui-navigationlinkswiftui-navigationview

How to disable NavigationView push and pop animations


Given this simple NavigationView:

struct ContentView : View {
    var body: some View {
        NavigationView {
            VStack {
                NavigationLink("Push Me", destination: Text("PUSHED VIEW"))
            }
        }
    }
}

Did anyone find a way of disabling the NavigationView animation when a destination view is pushed/popped into/from the stack?

This has been possible in UIKit since iOS2.0! I think it is not too much to ask from the framework. I tried all sorts of modifiers on all views (i.e., the NavigationView container, the destination view, the NavigationLink, etc)

These are some of the modifiers I tried:

.animation(nil)
.transition(.identity)
.transaction { t in t.disablesAnimations = true }
.transaction { t in t.animation = nil }

None made a difference. I did not find anything useful in the EnvironmentValues either :-(

Am I missing something very obvious, or is the functionality just not there yet?


Solution

  • Xcode 11.3:

    Right now there is no modifier to disable NavigationView animations.

    You can use your struct init() to disable animations, as below:

    struct ContentView : View {
    
        init(){
            UINavigationBar.setAnimationsEnabled(false)
        }
    
        var body: some View {
            NavigationView {
                VStack {
                    NavigationLink("Push Me", destination: Text("PUSHED VIEW"))
                }
            }
        }
    }