Enricoza / EZCustomNavigation

Easy Custom Navigation Controller that allows popping view controllers with pan gesture from center too and UnPop them back in.
MIT License
23 stars 5 forks source link

Swift UI Support #1

Closed brennanerbz closed 3 years ago

brennanerbz commented 4 years ago

How would you use this with Swift UI Navigation?

Enricoza commented 4 years ago

Hi @brennanerbz, thank you for opening this issue.

I'm no expert about SwiftUI but I do know a couple things:

  1. You can embed a UIView inside a SwiftUI component by creating a struct that implements UIViewRepresentable protocol
  2. You can embed a SwiftUI view inside a UIHostingController that can later be used normally inside any other UIView

Now, of the two, I personally (and unfortunately) would choose none. You could do it, with one of the two according to the kind of project you are working with, but then I think you'd be really missing out on some cool features of either SwiftUI or this library. Anyway, that's your choice.


Now comes the tricky part. There is something else you could try. I think that SwiftUI is using UINavigationController too. If that's the case, you could try to swizzle the UINavigationController itself, replace the viewDidLoad method with your own, and inside of it you have to call the original one, plus the method to add the custom transitioning (addCustomTransitioning) which I placed inside the UINavigationController extension.

The removeCustomTransitioning shouldn't be needed (if I did everything correctly). If I did something wrong then it would mean that some UINavigationController would not deallocate. If you see this happen please let me know.

If you do actually end up swizzling the viewDidLoad method and everything works... well you're all set. Just test it a lot because it's an unknown territory for me too. And then let me know, so maybe I can add some documentation for someone else who might have the same issue you have.

If that doesn't work, and you are not happy with the 2 options listed in the first place, then I think that the only option left is to write this back from 0 for SwiftUI, which I'm afraid I can't do right now.

I hope this helps, let me know about your progress

Enricoza commented 3 years ago

@brennanerbz hope you solved your issues. I'm gonna close this as it's been opened for a long time.

Feel free to reopen it or ask any other question you feel needed.