title: Custom segue animation (navigation animation) in SwiftUI
body: <p>In SwiftUI we use <code>NavigationView</code> and <code>NavigationLink</code> views to perform navigations (what we used to call <code>segue</code> in <code>UIKit</code>). The standard segue in UIKit is the <code>show</code> segue. In SwiftUI we can simply do:</p>
  
  <pre><code>struct ContentView: View {
      var body: some View {
          NavigationView {
              VStack {
                  NavigationLink(destination: Text("Destination")) {
                      Text("Navigate!")
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>to have the exact same effect (even if the word <code>segue</code> has disappeared).</p>
  
  <p>Sometimes (actually rather often) we need to customise the segue animation. </p>
  
  <ul>
  <li>We can decide not to animate the segue at all, indeed in the
  storyboard we can find the attribute <code>Animates</code> (true/false) in the
  attribute inspector by clicking on a segue. This way the destination view controller appears immediately in place of the source view controller.</li>
  <li>Or we can decide to perform a custom animation. Usually this is done by implementing an object that conforms to the <code>UIViewControllerAnimatedTransitioning</code> protocol. All the magic happens in the <code>animateTransition</code> method that gives us access to the source view controller and the destination view controller.</li>
  </ul>
  
  <p>For example, a simple cross-fade segue animation could be something like:</p>
  
  <pre><code>-(void)animateTransition:(id&lt;UIViewControllerContextTransitioning&gt;)transitionContext{
      UIView* containerView = [transitionContext containerView];
      UIViewController* fromVC = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
      UIViewController* toVC = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
  
      toVC.view.alpha = 0;
      [containerView addSubview:toVC.view];
  
      [UIView animateWithDuration:1 animations:^{
          toVC.view.alpha = 1;
          fromVC.view.alpha = 0;
      } completion:^(BOOL finished) {
          [fromVC.view removeFromSuperview];
          [transitionContext completeTransition:YES];
      }];
  }
  </code></pre>
  
  <p>Now the question: how can I get the same in SwiftUI? Is it possible not to animate a navigation or to customise the navigation animation? I expected to be able to do:</p>
  
  <pre><code>struct ContentView: View {
      var body: some View {
          NavigationView {
              VStack {
                  NavigationLink(destination: Text("Destination")) {
                      Text("Navigate!")
                  }
              }
          }
          .animation(nil)
      }
  }
  </code></pre>
  
  <p>or something similar to prevent the animation (or to add a custom animation), but nothing changes.</p>