【发布时间】:2021-02-11 09:05:56
【问题描述】:
我是一个带有 Firebase 登录/注销的简单应用。登录完美运行,当我注销 LoginView 时,我的应用程序显示出来,但问题是 TabView 仍然存在,您可以导航到另一个选项卡。那么应该发生什么:标签栏应该是不可见/隐藏的,或者我的 LoginView 应该出现在其他所有内容之上。
ContentView.swift
var body: some View {
if Auth.auth().currentUser == nil {
LoginView()
}
else {
AppView()
}
}
AppView.swift
var body: some View {
TabView {
PlacesView()
.tabItem {
Image(systemName: "mappin.and.ellipse")
Text("Places")
}
MeetupsView()
.tabItem {
Image(systemName: "person.3")
Text("Meetups")
}
ProfileView()
.tabItem {
Image(systemName: "person.crop.circle")
Text("Profile")
}
SettingsView()
.tabItem {
Image(systemName: "gear")
Text("Settings")
}
}
}
LoginView.swift
@State var signInSuccess = false
var body: some View {
return Group {
if signInSuccess {
AppView()
}
else {
LoginFormView(signInSuccess: $signInSuccess)
}
}
}
设置退出
NavigationView {
if !signedIn {
ContentView()
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity)
.background(Color.red)
.edgesIgnoringSafeArea(.all)
}
else {
List {
Button(action: {
do {
try Auth.auth().signOut()
signedIn.toggle()
} catch let signOutError as NSError {
print ("Error signing out: %@", signOutError)
}
}){
Text("Sign out")
.fontWeight(.light)
.foregroundColor(Color.red)
.frame(maxWidth: .infinity, alignment: .center)
.font(/*@START_MENU_TOKEN@*/.title2/*@END_MENU_TOKEN@*/)
}
}
}
【问题讨论】: