I have an app with many nested views, some which show a sheet based on a user action.
But I also have a sheet that I'd like to present on the main view based on a timer (ie, not a user action). But you can't have 2 sheets at the same time, so I'd like to check "something" to see if a sheet is already up, and not present the one from the timer.
I'd like to do this in a general way, and not check every place in the code where a sheet might be presented.
Any suggestions?
Here is how you can handle the sheets - the example below is fully functioning, just pass the view model to the environment before calling
TabsView()in theApp.Identifiableobject that will handle all the sheets in the program:@Publishedvar and one function in the view model; the var will tell the program what sheet is open:viewModel.showSheet(...).sheet(item:)to observe the type of sheet to openviewModel.sheet.screento know what sheet is openviewModel.showSheet(.none)The following code completes the minimal reproducible example: