canopas/UIPilot

How to do I make fade animation when push and pop?

iosYash opened this issue · 6 comments

How to do I make fade animation when push and pop?

Navigation Controller is not designed for such requirements, I think you should present the controller if you want to control the animation part.

If you really want to hack, you should be able to do it by forking library and adding this code in NavigationControllerHost.

    private func addTransition(nav: UINavigationController, transitionType type: CATransitionType = .fade, duration: CFTimeInterval = 0.6) {
        let transition = CATransition()
        transition.duration = duration
        transition.timingFunction = CAMediaTimingFunction(name: .easeInEaseOut)
        transition.type = type
        nav.view.layer.add(transition, forKey: nil)
    }

and then call this function before pushing or popping the view controller.
For example

        uipilot.onPush = { route in
            addTransition(nav: navigation)

            navigation.pushViewController(
                UIHostingController(rootView: routeMap(route)), animated: false
            )
        }

@jimmy0251 Any update on above question?

@iosYash If you consider HomeRoutes as your route and it has all screens like below case

enum HomeRoutes: Equatable {
    case homeView
    case signIn
    case screenA
    case screenB
}

Then you can get the behaviour you asked like below

struct AppRouteView: View {
    private let pilot: UIPilot<HomeRoutes> 
    
    init() {
        let auth = AuthManager()
        pilot = .init(initial: auth.isLoggedIn ? .homeView : .signIn)
    }
  var body: some View {
 }
}

in this if use is loggedIn then pilot initialised with homeView other wise with signIn view

Fixed