Handling Multiple Sheets in SwiftUI
Solving the issue you may encounter when using multiple Sheets in a SwiftUI View
In many screens, for a user, is quite common to have multiple selections: just tap a button and a second screens is presented. This can be achieved in many ways, one of them is presenting a SwiftUI sheet
. If you have worked with this component, you may have stumbled in a very annoying behavior… The item selections doesn't seem to work at the beginning but only after a second tap.
The User Interface
Ok, let’s first build a super easy app to show the problem.
We need a model for our item to present. Let’s fake a money transaction item:
Almost nothing to say here… we just need an Identifiable
object to univocally identify it.
The second step is to create a super simple detail view: