Onboarding screen, Signup and Password recovery I'm working on this link project. How can I go to the ContentView after login?, how do I get out of the loop and come to the ContentView? I would be happy if you help..
Asked
Active
Viewed 123 times
1 Answers
0
You can use a ZStack to overlay the different pieces of content and conditionally choose which are visible.
struct ContentView: View {
@State var isLoggedIn = false
var body: some View {
ZStack {
if self.isLoggedIn {
Text("You're In!")
} else {
LoginView(isLoggedIn: self.$isLoggedIn)
}
}
}
}
Where the LoginView updates the state to indicate a valid login.
struct LoginView: View {
@Binding var isLoggedIn: Bool
var body: some View {
Button("Log in") {
self.isLoggedIn = true
}
}
}
Because SwiftUI presents views as a function of state, there is no loop running to present the login view and then pass off to the other content. Instead all possible content is described and any time @State is changed, the views are re-created to match the current values.

Ben
- 425
- 6
- 11