抱歉措辞糟糕,但在 onAppear 中我正在更改状态变量,但是除非我在视图内的某处使用该状态变量,否则这不会重新渲染视图。
如果用户未登录,我会尝试弹出模式,但除非我将变量放在视图中,否则它不会弹出,如下所示
struct SearchView: View {
// Environment Variables
@EnvironmentObject var session: SessionStore
@State var sheetIsPresented: Bool = false
var body: some View {
NavigationView {
// Just having a line like this will cause it to work
if self.sheetIsPresented || !self.sheetIsPresented {}
}
.onAppear {
if self.session.userSession != nil {
self.sheetIsPresented = true
}
}
.sheet(isPresented: $sheetIsPresented) {
WelcomeSignInModal(sheetIsPresented: self.$sheetIsPresented)
}
}
}