title: Why is part of previous SwiftUI view showing on newly created view
body: <p>My first initial view for my app is a splash screen:</p>
  <p><a href="https://i.stack.imgur.com/2ssMT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2ssMT.png" alt="enter image description here" /></a></p>
  <p>This screen has code to check if an <code>authToken</code> is available, if it's not then it will toggle the <code>showLogin</code> bool, which in turn causes my view to go to the <code>LoginView()</code>. Else if there is a <code>authToken</code> available, then it calls a function which fetches information about the user, stores it in an Observable Object and then sets <code>showMain</code> bool to true, which in turn changes my view to my main screen.</p>
  <p>It works, but whenever it changes view, it puts the previous view at the bottom of the new view. I know I should use a navigation link for this but I can't get it to work properly with my logic and this is the closest I've gotten:</p>
  <p><a href="https://i.stack.imgur.com/9ML6C.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9ML6C.png" alt="enter image description here" /></a></p>
  <p>This is my code:</p>
  <pre><code>struct Splash: View {
  
  let keychain = KeychainSwift()
  
  @EnvironmentObject var user: userData
  
  @State var showLogin = false
  @State var showMain = false
  
  var body: some View {
      NavigationView{
          VStack{
              if(showLogin){
                  LoginView()
              }
              if(showMain){
                  Main()
              }
              Text(&quot;Splash Screen&quot;)
                  .onAppear(){
                      if(checkLogin()){
                          let authToken = keychain.get(&quot;authToken&quot;)
                          getDataAPI().getUserData(authToken: authToken!, completion: { response, error in
                              print(&quot;Starting&quot;)
                              if(error == nil){
                                  let code = response![&quot;code&quot;] as? String
                                  if(code == &quot;100&quot;){
                                      print(&quot;Done&quot;)
                                      DispatchQueue.main.async {
                                          user.email = response?[&quot;email&quot;] as! String
                                          user.uid = response?[&quot;uid&quot;] as! String
                                          user.username = response?[&quot;username&quot;] as! String
                                      }
                                      showMain.toggle()
                                  }else{
                                      print(error!)
                                  }
                              }
                          })
                      }else{
                          showLogin.toggle()
                      }
                  }
          }
      }
  }
  } 
  </code></pre>