Open Higher08 opened 2 years ago
Hi, thanks for raising this issue. I'm afraid navigationViewStyle(.columns)
is the only navigation view style supported on macOS at the moment. It gives the behaviour you've described. From your description, I guess you'd like to be able to use navigationViewStyle(.stack)
but that's not currently available on macOS. Hopefully in the future, it or something similar will be.
If you look at the appkit, which for about 15 years still does not have the ability to change the view in one window (only open a new one), then it is very doubtful that this will appear in swiftui. However, if just remove the NavigationView, it works fine. But each time it creates a new one View, but does not clear the old from memory. I was able to solve this through the AnyView array, and made additional parameters for switching views as separate ViewModel parameters.
@Higher08 not really a solution, but you can refer to this sample app from Apple for an alternative approach.
In short navigation master/detail share a binding, and the detail screen changes based on that (no need to pop/push).
I hope this helps! 🙌🏻
@zntfdr This approach is not navigation anyway. Yeah, I change view content but not navigate
. And it can be a huge problem when I need to change the view not from the sidebar
@johnpatrickmorgan what approach would you recommend using your library if it's for an ipad app where sometimes is neccsary the navigationViewStyle(.columns) approach? THANKS!
Hi @igortxito! On macOS, you can have a coordinator whose root screen is the side bar, that pushes screens into the second (and possibly third) columns, e.g.:
NavigationView {
MainCoordinator()
MiddleColumnPlaceholder()
RightColumnPlaceholder()
}
where the MainCoordinator
would use a Router whose root screen (the sidebar) would have embedInNavigationView: false
, since you are managing the NavigationView
outside the coordinator.
However, on iPad, SwiftUI behaves rather strangely for the columns
style. When a pushed screen is dismissed (a NavigationLink's binding is set to false) it doesn't dismiss the screen - it remains visible and can be interacted with, which makes things a bit trickier.
I use this library in MacOS SwiftUi; And it doesn't change screens at the same position; it opens a new type of window. I don't think that's right Here is screenshot How can I fix this?