AnyNavigationTransition
A type-erasing navigation transition that allows for providing any navigation transition value dynamically.
Declaration
struct AnyNavigationTransitionOverview
Use this navigation transition when you need to dynamically configure the transition of your content. For example, you could use this in a sheet(isPresented:onDismiss:content:) modifier to dynamically configure how the sheet transitions in and out.
This example shows a sheet that uses a different transition based on model state.
struct ContentView: View {
@State private var showSheet = false
@Environment(Model.self) var model
var body: some View {
VStack {
Button("Show Sheet") {
showSheet = true
}
.sheet(isPresented: $showSheet) {
let transition = model.useCrossDissolve
? AnyNavigationTransition(.crossFade)
: AnyNavigationTransition(.automatic)
Text("Sheet Content")
.presentationDetents([.medium])
.navigationTransition(transition)
}
}
}
}