Hello,
I try to create my first App in Swift. I want to use the TabView. I have 2 fixed tabs button and I want one tab button if has the condition. In the ImprintView,
if u push the button, the var will changed but the TabView not updated. If I change the MyVars.isLoggedIn
to true
on app start, if works, but not if I change via the button.
struct MyVars {
static var isLoggedIn = false;
}
struct DashboardView: View {
var body: some View {
TabView {
ImprintView()
.tabItem(){
Image(systemName: "house")
Text("Imprint")
}
AuthLoginFormView()
.tabItem(){
Image(systemName: "camera.fill")
Text("Scanner")
}
if(MyVars.isLoggedIn){
RandomView()
.tabItem(){
Image(systemName: "cube.fill")
Text("Random")
}
}
}
}
}
struct ImprintView: View {
var body: some View {
Button(action: {
MyVars.isLoggedIn = true
}) {
Text("Einloggen")
.padding(10)
.frame(maxWidth: .infinity)
.foregroundColor(.black)
}
}
}