FlowStacks icon indicating copy to clipboard operation
FlowStacks copied to clipboard

Native MacOs app has strange behavior

Open dhrysh opened this issue 4 years ago • 6 comments

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?

dhrysh avatar Dec 28 '21 16:12 dhrysh

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.

johnpatrickmorgan avatar Dec 29 '21 21:12 johnpatrickmorgan

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.

dhrysh avatar Dec 31 '21 15:12 dhrysh

@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 avatar Jan 06 '22 10:01 zntfdr

@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

dhrysh avatar Jan 08 '22 18:01 dhrysh

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

igortxito avatar Mar 12 '22 13:03 igortxito

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.

johnpatrickmorgan avatar Mar 15 '22 00:03 johnpatrickmorgan