obvios / Routing

Routing library for abstracting navigation logic from SwiftUI views.
MIT License
67 stars 6 forks source link

If I set navigationBarBackButtonHidden() and use extension to enable swipe back gesture would cause navigation problem #3

Closed nick-maker closed 6 months ago

nick-maker commented 6 months ago

Hi @obvios, thank you for this library. I followed your blog, however, I encountered some issues.

After setting my navigationBarBackButtonHidden(), and using the extension from StackOverflow, when swiping back, the navigationStack is not removing the view.

extension UINavigationController: UIGestureRecognizerDelegate {

  // MARK: Open

  open override func viewDidLoad() {
    super.viewDidLoad()
    interactivePopGestureRecognizer?.delegate = self
  }

  // MARK: Public

  public func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
    viewControllers.count > 1
  }
}

Please let me know what could be the solution to this issue, thank you very much.

obvios commented 6 months ago

Hi

Thank you for reading! Would you be able to share a sample of your code? Specifically I want to know if and how you are using UIkit + SwiftUI together.

I also want to see how you are using the Routing code within your SwiftUI view code.

Thank you.

nick-maker commented 6 months ago

Hi

Thank you for getting back to me. I was trying to share a sample of code while simplifying my code, I realized the problem. It turns out that it's due to another NavigationStack in my HomeView, after removing it, the code works normally.

HomeView

var body {
  .overlay {
   NavigationStack {  // should remove this.
        LoginView(model: model)
      .opacity(isLogin ? 0 : 1)
    }
}
obvios commented 6 months ago

Ah yes, SwiftUI won't allow you to nest NavigationStack. Glad you found the issue, I will close this issue now.