matteopuc / swiftui-navigation-stack

An alternative SwiftUI NavigationView implementing classic stack-based navigation giving also some more control on animations and programmatic navigation.
MIT License
927 stars 86 forks source link

Default UINavigationController animation? #43

Open kutakmir opened 3 years ago

kutakmir commented 3 years ago

Hi, quick question - how do I replicate the default NavigationView's transition animation?

It's not a plain .slide, it's both slide and slide of the original one at a half distance.

matteopuc commented 3 years ago

Hi @kutakmir, thanks for this interesting question. I'd like to have the actual default animation too, but at the moment I can't manage to do it. Basically you should try to play with the defaultTransitions property in the NavigationStack.swift file. If I try to write something like this (100 is just an example of course):

public static var defaultTransitions: (push: AnyTransition, pop: AnyTransition) {
    let pushTrans = AnyTransition.asymmetric(insertion: .move(edge: .trailing), removal: .offset(x: -100))
    let popTrans = AnyTransition.asymmetric(insertion: .offset(x: -100), removal: .move(edge: .trailing))
    return (pushTrans, popTrans)
}

The outcome is not the expected one. I think it is something related to this (still open) issue: #17

davidscheutz commented 1 year ago

Hey @kutakmir, depending on your use case I created a much simpler SwiftUI navigation library that basically wraps the UINavigation controller and makes programmatic navigation super easy. You get exactly the benefit mentioned above, the native iOS push transition including the drag to dismiss gesture.

Feel free to take a look here: https://github.com/davidscheutz/swiftui-infinite-navigation 😊