Search code examples
swiftswiftuiswiftui-navigationlink

How can I change the direction of the page transition animation?


When I tap on the navigation link on ContentView1 I want ContentView2 to slide in from the left rather than from the right.

So, I want to override the default.

I have not been able to find a solution which works with Swift 5.

The code I'm using is as follows:

import SwiftUI

struct ContentView1: View {

    var body: some View {
        NavigationView {
            NavigationLink(destination: ContentView2()) {
                Text("Hello, World!")
            }
            .navigationBarTitle("One")
        }
    }
}

struct ContentView2: View {

    var body: some View {
        Text("Hello, World #2!")
    }
}

Solution

  • Thank you everybody who took the time to answer.

    It seems this behaviour isn't supported by default in swift 5.

    I will need to rethink how I implement the screen.