0

I'm curious, is there a way to override the default slide-in behaviour when navigating in SwiftUI? Here's some code where I'm unsuccessfully attempting to use .transition to affect the animation:

struct TransitionOnNavigation: View {
    var body: some View {
        NavigationStack {
            NavigationLink("Press Me") {
                Text("Hello World!")
                    .transition(.move(edge: .bottom)) // this doesn't do anything
            }
        }
    }
}

I'm surprised that I haven't found anything in my searches for something so fundamental, and I don't recall seeing anything about this in WWDC videos. I did find this library, but I wonder if there's something built-in that I'm missing.

Ideally, I'd want to:

  1. Change the basic type of transition (move, scale, fade, etc)

  2. Affect the rate of animation (eg using duration parameters)

  3. Have the ability to use matchedGeometryEffect control individual views in interesting ways.

Curious Jorge
  • 354
  • 1
  • 9

1 Answers1

1

As per I know SwiftUI natively supports custom transition between Views when using NavigationStack / NavigationSplitView. You can try with NavigationTransition which supports NavigationStack on iOS 16.

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.

  • Yes, that is using the library I linked to in the question. So it looks like there's no built-in way of doing this easily using only Apple's APIs. – Curious Jorge Jul 13 '23 at 05:01