When some calculation happens in viewModel I want to present modal view. Normally I need to set some boolean binding for method:
.fullScreenCover(isPresented: $isGalleryPresented) {
GalleryPickerView())
}
where isGalleryPresented, is @State definied in view. However browsing SO, i have found out that I could have property in viewModel:
@Published var isGalleryPresented = false
and then do something like this:
.fullScreenCover(isPresented: $viewModel.isGalleryPresented) {
GalleryPickerView()
}
And this works just fine, although I don't know how. fullScreenCover method argument of type isPresented: Binding<Bool>, and I pass as far as I can tell a publisher. How does this work?