How it works
NavigationTransition is the protocol that describes the animated transition a NavigationStack runs as it pushes and pops a destination. Rather than accepting SwiftUI's default slide, you adopt a concrete transition type and hand it to the navigation system so the appearing and disappearing views animate the way you want. Reach for it when a push deserves a more meaningful connection between the originating control and its detail — most commonly a zoom that visually grows the tapped element into the full screen. It works hand in hand with a matched-geometry namespace so SwiftUI knows which source view the destination is expanding from.
Apply a transition with navigationTransition(_:)
The navigationTransition(_:) modifier on the destination view sets which NavigationTransition the stack uses when presenting it. You attach it to the pushed content rather than the link, so the transition travels with the destination wherever it is shown. Here it decorates the detail Text, declaring how that screen enters and leaves the stack.
Choose a concrete transition value
Conforming transition values are exposed as static factories you pass to the modifier, so you never construct the protocol type directly. The example uses .zoom, the built-in transition that scales the destination out from a source view, giving the push a sense of physical continuity instead of a flat slide.
Identify the source with sourceID and a namespace
The .zoom(sourceID:in:) form needs to know which on-screen element to grow from, so it takes a matching identifier and the namespace it lives in. In the example the sourceID is "hero" and the namespace argument is namespace, tying the transition's start point to a specific tagged view.
Declare the matched namespace with @Namespace
A zoom transition coordinates geometry across two views, so both the source and the destination must share one namespace. The @Namespace property wrapper here, namespace, vends that shared identity; you pass it into navigationTransition(_:) and tag the originating view with the same id so SwiftUI can pair them.
Let the NavigationStack drive the animation
NavigationTransition only takes effect within a navigation container, which performs the push and runs the transition. The surrounding NavigationStack and NavigationLink ("Show Detail") are simply where the tagged destination is presented — the transition is what governs how that presentation is animated on the way in and out.
Example & preview
Press Run live & edit to compile it in your browser — then edit the Swift on the left and the preview re-renders live.
struct NavigationTransitionDemo: View {
var body: some View {
NavigationStack {
NavigationLink("Show Detail") {
Text("Detail")
.font(.largeTitle)
.navigationTransition(.zoom(sourceID: "hero", in: namespace))
}
.padding()
.navigationTitle("Home")
}
}
@Namespace private var namespace
}