Quick Start
Getting started with SwiftUINavigationTransitions
is as simple as adding a single modifier to your existing navigation view. Here’s how you can apply a basic slide transition.
iOS 16+ with NavigationStack
If your app targets iOS 16 or newer, you can apply the transition modifier directly to a NavigationStack
.
import SwiftUI
import SwiftUINavigationTransitions
struct ContentView: View {
var body: some View {
NavigationStack {
List {
NavigationLink("Go to Detail View", value: "detail")
}
.navigationTitle("Home")
.navigationDestination(for: String.self) { _ in
DetailView()
}
}
.navigationTransition(.slide) // Apply the transition here
}
}
struct DetailView: View {
var body: some View {
Text("This is the detail view.")
.navigationTitle("Detail")
}
}
iOS 13+ with NavigationView
For projects supporting older iOS versions, the same modifier works on a NavigationView
as long as you use the .stack
navigation view style.
import SwiftUI
import SwiftUINavigationTransitions
struct ContentView: View {
var body: some View {
NavigationView {
List {
NavigationLink("Go to Detail View") {
DetailView()
}
}
.navigationTitle("Home")
}
.navigationViewStyle(.stack) // Required for transitions
.navigationTransition(.slide) // Apply the transition here
}
}
struct DetailView: View {
var body: some View {
Text("This is the detail view.")
.navigationTitle("Detail")
}
}
With just one line of code, you've replaced the default push and pop animation with a custom slide transition.