I am building an app with SwiftUI and have login capability that uses Django Rest for authentication. When the user successfully logs in they are taken to the home screen that uses a Tab View. One of the tab views is an account page (Navigation View) that lets the user logout by tapping a button.
When they log out I want it to take them back to the login screen, currently this is done using an if statement and a @State variable to capture when the logout button is pressed:
@State var logout = false
var body: some View {
if (logout) {
Test()
} else {
VStack{
Text("Account View")
Spacer()
Spacer()
Button(action: {
self.logout = true
}, label: {Text("Logout")})
}
}
}
}
In this case Test() is the login screen, but when the user gets taken back to this screen the tab bar at the bottom is still showing.
How can I reset the app so that the tab bar doesn't show?