johnpatrickmorgan / FlowStacks

FlowStacks allows you to hoist SwiftUI navigation and presentation state into a Coordinator
MIT License
783 stars 56 forks source link

[Feature Request] Embedding stack inside a custom view? #22

Open josephktcheung opened 2 years ago

josephktcheung commented 2 years ago

Hi,

We tried using TCACoordinators in our iOS and macOS app. Since macOS doesn't support StackNavigationViewStyle, I wonder if the library can be extensible so that it can wrap a Node inside a custom view that can provide alternative navigation in macOS.

I looked into some other SwiftUI navigation libraries and here's one that also uses coordinator pattern that allows user to define a custom coordinator https://github.com/rundfunk47/stinsen#defining-the-coordinator

In addition, Stinsen also has two Coordinators you can use, ViewWrapperCoordinator and NavigationViewCoordinator. ViewWrapperCoordinator is a coordinator you can either subclass or use right away to wrap your coordinator in a view, and NavigationViewCoordinator is a ViewWrapperCoordinator subclass that wraps your coordinator in a NavigationView.

Perhaps we can do something similar in this library as well?

Best, Joseph

johnpatrickmorgan commented 2 years ago

Thanks for raising this issue @josephktcheung. I really wish macOS would support StackNavigationViewStyle, it seems strange that it doesn't. Hopefully that will come soon. If I understand correctly, you're suggesting that FlowStacks could reproduce the stack style for macOS, or at least allow some customisation hooks so that a user could do so. I think that would be very tricky to get right, and would become obsolete if Apple do bring StackNavigationViewStyle to macOS. I don't think it fits into the scope of FlowStacks, which is intended to be quite lightweight. I had a look at Stinson, but I'm not sure that that library offers a solution to this problem either. I'll keep the problem in mind in case a solution presents itself though.

In the meantime, would Mac Catalyst allow you to build your macOS app in the way you want? Or might it work to use sheet presentation for the macOS app instead? Not great solutions I'm afraid but fingers crossed macOS gets a bit more SwiftUI love soon!

josephktcheung commented 2 years ago

Hi @johnpatrickmorgan, thanks for replying. We tried Mac Catalyst first but hit various limitations such that we are exploring to build a native MacOS app using SwiftUI e.g. TextKit 2 fully supported in MacOS but UITextView with TextKit 2 is not available in iOS 15., menu bar support etc (https://www.highcaffeinecontent.com/blog/20220216-Where-Mac-Catalyst-Falls-Short)

I haven't tested Stinsen thoroughly, perhaps I'll make a demo project and see how to create a custom navigation flow using it. At least from its documentation it says we can create our own Coordinatables / Coordinators:

Stinsen comes with a couple of Coordinatables for standard SwiftUI views. If you for instance want to use it for a Hamburger-menu, you need to create your own. Check the source-code to get some inspiration.