4

I have NavigationStack with its own navigation links, for iOS16 development.

How to change the default slide transition to appear or a custom transition?

Also do you apply the transition on the NavigationStack or on the NavigationLink?

This is my code:

import SwiftUI

struct TestView: View {
    var body: some View {
        NavigationStack() {
            NavigationLink ("Link", value: "Any Value")
                .navigationDestination(for: String.self) { textValue in
                    destinationView(textValue: textValue)
                }
        }
    }
}

struct destinationView: View {
    let textValue: String
    var body: some View {
            Text(textValue)
    }
}

How to change the default transition?

1 Answer 1

6

I don't think SwiftUI natively supports custom transition between Views when using NavigationStack / NavigationSplitView.

There is a package called NavigationTransitions which supports NavigationStack on iOS 16.

How to use:

Add package to you project and import

import NavigationTransitions

Then:

NavigationStack {
    // your content
}
.navigationTransition(.fade(.cross))

You can also combine predefined transitions or make a custom one.

1
  • 2
    Thanks, this is exactly what I was looking to do. It's a shame that the new navigationStack and swiftui do not have native options, also people are getting quite tired of constant changes that brake every previous code or constantly deprecating previews protocols, etc
    – Pro Girl
    Mar 4, 2023 at 20:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.