SwiftUI animation

2026-05-28

In addition to the 100 Days of SwiftUI project, I’m playing around with a MacOS app.

I have 2 screens that I want to go between with a nice transition. I found a nice example on Stack Overflow and I like how it looks.

However, XCode is complaining that “animation was deprecated” and I should use withAnimation or animation(_:value:) and I cannot figure out how to make it go.

Here’s the offending portion:

rootView()
    .frame(maxWidth: .infinity, maxHeight: .infinity)
    .transition(AnyTransition.move(edge: .leading))
    .animation(.default)

I have at least two problems.

  1. What animation value? I know it has to be linked to a State variable, but my View struct is in a separate file
  2. If I use withAnimation where does it go? I tried putting it on the button that calls the second screen but that didn’t seem to make any difference (once I got it to compile, that is)

Here’s what I want it to look like:


What I get (no video this time), is just a quick change of screen without any nice transitions.

Maybe I should turn this into some sort of animation settings project…