Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Native MacOs app has strange behavior #8

Open
Higher08 opened this issue Dec 28, 2021 · 6 comments
Open

Native MacOs app has strange behavior #8

Higher08 opened this issue Dec 28, 2021 · 6 comments

Comments

@Higher08
Copy link

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
screenshot
How can I fix this?

@johnpatrickmorgan
Copy link
Owner

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.

@Higher08
Copy link
Author

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.

@zntfdr
Copy link
Contributor

zntfdr commented Jan 6, 2022

@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! 🙌🏻

@Higher08
Copy link
Author

Higher08 commented Jan 8, 2022

@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

@igortxito
Copy link

@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!

@johnpatrickmorgan
Copy link
Owner

johnpatrickmorgan commented Mar 15, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants