Last active
November 7, 2022 19:18
-
-
Save oliverfoggin/25f54a66c7eb8dfa8a3ed6f0db239764 to your computer and use it in GitHub Desktop.
SwiftUI bug with TabBars and switching them out for other views
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
struct ContentView: View { | |
@State var loggedIn: Bool = false | |
var body: some View { | |
switch loggedIn { | |
case false: | |
Button("Login") { | |
loggedIn = true | |
} | |
case true: | |
TabView { | |
NavigationView { | |
Text("Home") | |
.navigationBarTitle("Home") | |
.onAppear { | |
print("ππππππππππππππππππππ") | |
print("Home on appear") | |
print("ππππππππππππππππππππ") | |
} | |
.toolbar { | |
ToolbarItem(placement: .navigationBarTrailing) { | |
Button("Logout") { | |
loggedIn = false | |
} | |
} | |
} | |
} | |
.tabItem { | |
Image(systemName: "house") | |
Text("Home") | |
} | |
NavigationView { | |
Text("Savings") | |
.navigationBarTitle("Savings") | |
.onAppear { | |
print("ππππππππππππππππππππ") | |
print("Savings tab on appear") | |
print("ππππππππππππππππππππ") | |
} | |
.toolbar { | |
ToolbarItem(placement: .navigationBarTrailing) { | |
Button("Logout") { | |
loggedIn = false | |
} | |
} | |
} | |
} | |
.tabItem { | |
Image(systemName: "dollarsign.circle") | |
Text("Savings") | |
} | |
NavigationView { | |
Text("Profile") | |
.navigationBarTitle("Profile") | |
.onAppear { | |
print("ππππππππππππππππππππ") | |
print("Profile tab on appear") | |
print("ππππππππππππππππππππ") | |
} | |
.toolbar { | |
ToolbarItem(placement: .navigationBarTrailing) { | |
Button("Logout") { | |
loggedIn = false | |
} | |
} | |
} | |
} | |
.tabItem { | |
Image(systemName: "person") | |
Text("Profile") | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment