canopas / UIPilot

The missing typesafe SwiftUI navigation library
https://canopas.github.io/UIPilot
MIT License
309 stars 27 forks source link

Provide a means to suppress intermediate transitions on a pop(to:) #12

Closed jackrwright closed 2 years ago

jackrwright commented 2 years ago

Hello, great library! I would like to be able to suppress intermediate transitions when using pop(to:). I made a local change that seems to work (below), but may not be the best solution. If you prefer I can open a PR.

private var showTransition: Bool = true

    var paths: [Path<T>] = [] {
        didSet {
            if showTransition {
                updateViewState()
            }
        }
    }

    public func popTo(_ route: T, inclusive: Bool = false, showIntermediateTransitions: Bool = false) {
...
        if !showIntermediateTransitions {
            // remove intermediate paths supressing transition animations
            var numToPop = (found..<paths.endIndex).count - 1
            logger.log("UIPilot - Popping \(numToPop + 1) routes")
            showTransition = false
            paths.removeLast(numToPop)
            showTransition = true
            // pop the final path with a transition animation
            pop()
        } else {
            // The original code: pop showing all transitions
            for _ in found..<paths.count {
                logger.log("UIPilot - Route \(route) Popped.")
                pop()
            }
        }
...
jimmy0251 commented 2 years ago

Released fix in 1.1.7. Closing this..