ios – SwiftUI view detect modal dismissal


I have a SwiftUI view wrapped in UIHostingController and presented modally as formSheet on iPad. I have a done button to dismiss and have a call back closure passed from parent view controller to perform actions when this done button is pressed. The problem happens on iPad where the user may tap outside of the view and the view gets dismissed thereby missing the callback.

One way to solve it would be to trigger the callback closure in onDismiss of the SwiftUI view. While it works, I am not sure if it is the right place and if it is reliable enough. The documentation only says that onDismiss is called when the “view disappears from the screen”. However, what if we push a view on top of this view in a navigation hierarchy, will onDismiss be still called?

Latest articles

spot_imgspot_img

Related articles

Leave a reply

Please enter your comment!
Please enter your name here

spot_imgspot_img