I've a main view that displays a modal sheet. As I've multiple modals, I use enum and State to control which sheet is presented.
@State var activeSheet: Sheet?
Inside my MainView:
Button(action: {
activeSheet = .settings
}, label: {
Text(“Button”)
})
.sheet(item: $activeSheet) { sheet in
switch sheet {
case .info:
InfoView()
case .settings:
SettingsView()
}
}
SettingsView:
struct SettingsView: View {
@Environment(\.presentationMode) private var presentationMode
@EnvironmentObject var model: MainModel
var body: some View {
Button("Action") {
model.myFunction()
}
}
}
In my InfoView-sheet I have a button that calls a function inside an EnvironmentObject. How do I dismiss the sheet once the function has completed in the EnvironmentObject?
Every view is linked to the same EnvironmentObject btw.
Thanks!