You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm wondering if anyone has good patterns for dealing with SwiftUI windows, specifically on macOS, but believe it applies equally to iOS as well. The standard SwiftUI template looks like this:
The problem is if you want to support multi-window, all those windows will just be sharing the same state. Windows can be open in a few ways, but they won't necessarily flow through the reducer like File > New Window or programmatically through openWindow() in the Environment, so I'm not sure how to setup some conditional state like I typically would when presenting a sheet. There's no way to programmatically control the presentation (that I'm aware of.)
Even for a single window, I don't want to load the state until it is shown, so I'm doing something like where I load/unload the state in onAppear/onDisappear:
That seems to work, but doesn't feel great. For multi-window, I could do something similar with an array of IdentifiedArrayOf<MainWindow.State>, but I don't know how to uniquely identify each Window created from that group in order to scope the right child store. Curious if there's something I'm missing, or should I just drop down to AppKit.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I'm wondering if anyone has good patterns for dealing with SwiftUI windows, specifically on macOS, but believe it applies equally to iOS as well. The standard SwiftUI template looks like this:
The problem is if you want to support multi-window, all those windows will just be sharing the same state. Windows can be open in a few ways, but they won't necessarily flow through the reducer like
File > New Window
or programmatically throughopenWindow()
in theEnvironment
, so I'm not sure how to setup some conditional state like I typically would when presenting asheet
. There's no way to programmatically control the presentation (that I'm aware of.)Even for a single window, I don't want to load the state until it is shown, so I'm doing something like where I load/unload the state in onAppear/onDisappear:
That seems to work, but doesn't feel great. For multi-window, I could do something similar with an array of
IdentifiedArrayOf<MainWindow.State>
, but I don't know how to uniquely identify each Window created from that group in order to scope the right child store. Curious if there's something I'm missing, or should I just drop down to AppKit.Beta Was this translation helpful? Give feedback.
All reactions