I'm building a macOS app using SwiftUI and I recently updated to xcode 14.3. Since then I've been debugging why none of my animations were working, it turned out that the NavigationSplitView or NavigationStack are somehow interfering with all the animations from withAnimation
to .transition()
and everything in between.
Is anyone else experiencing this, knows a work around or knows why this is happening?
We are aware of this. This is an internal bug. My sincere apologies for this particular one.
Can you let me know if this workaround works for you? Pass an animated path
binding to your NavigationStack
's path
parameter. If you aren't using the path
parameter, you should be able to simply pass a NavigationPath
value to the stack's initializer and all will behave the same.
struct ContentView: View {
@State private var path = NavigationPath()
@State private var isOn = false
var body: some View {
NavigationStack(path: $path.animation(.linear(duration: 0))) {
VStack {
Toggle("Animate Square?", isOn: $isOn.animation(.linear(duration: 3)))
Color.red
.frame(width: 100, height: 100, alignment: .bottom)
.scaleEffect(isOn ? 1.0 : 0.5)
NavigationLink("Faux non-animated push", value: 3)
}
.navigationDestination(for: Int.self) { _ in
Color.orange
}
.toolbar { Spacer() }
}
}
}
In the code below, notice how I pass a duration of 0 to the $path.animation(.linear(0))
. This achieves a non-nil animation, but doesn't force adoption of animated pushes if you don't want them. The workaround is providing that animation to the path. The bug erroneously disabled all animations when a stack animation wasn't provided. (Rest assured we now have tests for this, and sorry again for the inconvenience)