I need to display different WindowGroup depending on the condition, how is this possible?
var body: some Scene
{
WindowGroup(id: "startView")
{
StartView(isLogined: $isLogined)
.onAppear
{
useMiniWindowStyle(status: true)
}
}// startView window
.windowResizability(.contentSize)
WindowGroup(id: "loginView")
{
AuthView(currentLogin: $isLogined)
.frame(minWidth: screen!.width / 1.8, minHeight: screen!.height - 200)
} // loginView window
.windowResizability(.contentSize)
.windowStyle(HiddenTitleBarWindowStyle())
}
Currently, control flow statement cannot be used within SceneBuilder. You would need to use the openWindow action environment value to create a new window that matches the unique strings identifier for the WindowGroup you intend to open. Keep in mind that SwiftUI lunches the first scene that appears in the SceneBuilder and on platforms like macOS and iPadOS, people can open more than one window from the group simultaneously.
You might consider using navigationDestination(for:destination:) to associate a destination view with a presented data type instead. The pseudocode below is an example.
struct ContentView: View {
@State private var appState: AppState?
var body: some View {
NavigationStack {
List {
NavigationLink("SignIn", value: AppState.signIn)
NavigationLink("SignUp", value: AppState.signUp)
}
.navigationDestination(for: AppState.self) { state in
switch state {
case .signIn: Text("Signed In")
case .signUp: Text("SignUp")
}
}
}
}
}