How to disable NavigationLink transition animation

Is it possible to disable NavigationLink transition animation in SwiftUI? To be more precisely. I want to disable it only for a few links/views. Not the whole app

Replies

There are a couple of ways to disable the transition animation, but not a way to specifically target a singular NavigationLink. However, if you're trying to disable it for a single link, perhaps you are willing to compromise and use a Button?

You can disable Buttons animations that append to the path as a one-off, and you can disable NavigationLink pushes via the path argument in a state driven fashion. But you can't "hook-in" to that state right before a particular link is pushed to set that animation. Does either work for your use case?

struct ContentView: View {
    @State private var path = NavigationPath()
    @State private var disableAnimation: Bool = true

    private var transaction: Transaction {
        var t = Transaction()
        t.disablesAnimations = disableAnimation
        return t
    }

    var body: some View {
        NavigationStack(path: $path.transaction(transaction)) {
            VStack {
                Text("The root")
                NavigationLink("A link", value: 4)
                Button("A button") {
                    var t = Transaction()
                    t.disablesAnimations = true
                    withTransaction(t) {
                        path.append(10)
                    }
                }
                .navigationDestination(for: Int.self) { int in
                    ZStack {
                        Color.green
                        Text("You pushed: \(int)")
                    }
                }
            }
        }
    }
}

I REALLY want to disable these unwanted and distracting animations in the Navigation bar with the title text and the back button when navigating to a new view and after tapping the back button.

This "sudden flying static text" is unwanted, startling and distracting to the viewer. It serves NO USEFUL PURPOSE AT ALL in creating a helpful user interface for the user.

Why Apple UI designers think this is a good thing clearly shows that Apple has lost the plot when it comes to solid UI and UX design.

Sudden unexpected motion of UI elements that have no purpose flying across the screen are startling and draw the user's attention away from the task they are trying to accomplish.

The flying and resizing title text and back button when coupled with a removal of a border between the title bar and the control content below it remove clear delineation of separation between the Navigation region and the content below it. When you REMOVE CLEAR VISUAL INDICATORS from content, you don't make the UI more understandable to users, you muddy the waters and make it more vague to them.

A good UI has VISUAL STANDARDS that TELEGRAPH THE FUNCTIONALITY OF THE ELEMENTS TO THE USERS so that they do not have be guessing if they can or should be interacting with elements.

User interface elements ONLY should start animating when the effect HELPS THE USER UNDERSTAND THE PURPOSE OF THE UI ELEMENT and therefore HELPS THE USER FOCUS ON THE TASK THEY ARE TRYING TO ACCOMPLISH AND COMPLETE IT.

Gratuitous animation - and especially motion - for no purpose, pulls the eye to the motion. In doing that, pulls the user's attention and concentration away from the task they are trying to complete. Therefore sudden startling animation like that in the title bar is counter to useful when this happens every time a screen changes. There's simply NO useful purpose to it.

We want to focus on creating useful, predictable and informative user interfaces for our users, not interfaces with trendy techniques simply because everyone else is using them. Techniques like sudden motion are used by Casinos to startle their customers and take over their attention. This is the ANTITHESIS to the principles that Apple's foundation UI elements should contain. Especially considering that Apple gives them to their developers for us to make (hopefully) useful user interfaces for our clients and users.

Apple needs to STOP adding such purposeless (and counterproductive) trends such at these to their UI elements. And in the meantime we need standardized methods to TURN THESE COUNTERPRODUCTIVE UNWANTED DISTRACTING ANIMATIONS OFF. And hopefully, never ever see them again.

People who are designing foundation class user interface elements should know better. Apparently, they don't and we are the ones suffering their poor decisions. How these made it out the door means that no one with any sense is watching the shop and the amateurs are at the wheel in the UI/UX department.