简体   繁体   中英

How do I change the root view with SwiftUI

I want to replace a view with another view using SwiftUI.

Currently I use either a NavigationView or.sheet to transition to a new view and that works fine stacking views.

However I have not found a way to completely replace a view with another view. For example when the user first lands on the App it will give an option to sign in or create a new account. I want either option to replace the previous view, not present on top of it. Another example is when the user logs out of the app. I want to dismiss my entire stack and replace with login screen. Not just dismiss all overlying views.

The analogy to pre swiftUI would be to replace the rootView.

You just display each view conditionally in a root view

var body: some View {
   if isLoggedIn {
      HomeView()
   } else {
      LoginView() {
   }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM