5

I'd like the view to instantly appear. Instead of the default iOS push animation.

This method USED to work with a NavigationView + NavigationLink. iOS 16 deprecated NavigationView

enum Nav {
    case a
}

struct ContentView: View {
    @State var nav: [Nav] = []
    
    var body: some View {
        NavigationStack(path: $nav) {
            Button {
                var transaction = Transaction()
                transaction.disablesAnimations = true
                withTransaction(transaction) {
                    nav = [.a] // Doesn't work. Still animates
                }
            } label: {
                Text("Go to a")
            }
                .navigationDestination(for: Nav.self) { path in
                    switch path {
                    case .a:
                        Text("a")
                    }
                }
        }
    }
}
joshuakcockrell
  • 5,200
  • 2
  • 34
  • 47
  • Maybe this will help: [How to disable NavigationView push and pop animations](https://stackoverflow.com/questions/57305495/how-to-disable-navigationview-push-and-pop-animations) – Ori Jul 01 '22 at 16:34
  • 1
    @Ori Yeah, that answer uses the now deprecated `NavigationView`. I'd like to accomplish the same thing with the newer `NavigationStack`. – joshuakcockrell Jul 01 '22 at 16:38

1 Answers1

7

This looks like a bug and worth submitting feedback to Apple.

Meanwhile here is a possible workaround. Tested with Xcode 14b2 / iOS 16

Button {
    UIView.setAnimationsEnabled(false)

        nav = [.a]

    DispatchQueue.main.asyncAfter(deadline: .now() + 0.25) {
        UIView.setAnimationsEnabled(true)
    }
} label: {
  // ...
Asperi
  • 228,894
  • 20
  • 464
  • 690