It would be a huge issue if views can't change @Published variables in the View Model.
A workaround was provided above by rayx: it's not a beautiful solution in my opinion but it works. To simplify it, I found a way to modify only the main view, so we don't need to touch any of the sheet views. Here below, I apply the solution to Cwie's code:
struct ContentView: View {
@ObservedObject
var viewModel: ViewModel
// Local variable
@State private var isPresented = false
var body: some View {
VStack {
Button {
viewModel.showSheet()
} label: {
Text("Show Sheet")
}
}
.padding()
// Use isPresented
.sheet(isPresented: $isPresented) {
if viewModel.sheetVM != nil {
SheetView(sheetVM: sheetVM!)
}
}
// The View Model controls the local variable
.onChange(of: viewModel.sheetVM) { value in
if value != nil {
isPresented = true
} else {
isPresented = false
}
}
}
}
I hope Apple clarifies and solves this quickly.