I am having problems with dismiss
environment variable in SwiftUI.
@Environment(.dismiss) private var dismiss
Under certain conditions, the view body keeps getting recomputed and thereby calling all the functions invoked in .task
modifier. Logging changes via Self._printChanges()
shows that _dismiss
changed. This is most likely an iOS bug has been reported on Apple developer forums by other users as well.
I want to avoid using dismiss
therefore and want to know if there is an alternative to dismissing a view modally in SwiftUI.
It depends on how you present the view. If you are using a sheet modifier, you can pass in a binding and change its value. This might be useful: SwiftUI dismiss modal