DEV Community

How to Present and Dismiss a Modal in SwiftUI

Maegan Wilson on August 26, 2019

How to Present and Dismiss a Modal in SwiftUI In this post, we will cover how to present and dismiss a modal view. Find the source co...
Collapse
 
careerunderdog profile image
Lance

For me, I can only present the sheet once when dismissing with the button. If I try to present it again it does nothing, but if I drag to dismiss I can keep presenting and dismissing repeatedly. Any suggestions?

Collapse
 
maeganwilson_ profile image
Maegan Wilson

I'm running this on a device and in the Xcode simulator, and I'm not experiencing this. Any chance you have a link or some code to look at?

Are you running Catalina? I did have the issue you are reporting with the Catalina betas sometimes, but every time I ran on a real device it worked.

Collapse
 
careerunderdog profile image
Lance

Well, after some more testing, it works as expected unless I am using a button in navigation bar trailing items. For some reason the problem I described only happens when it's a navigation bar button. If I just put a button somewhere else in the View it works perfectly. This solves my problem for now. Thanks for the reply, and for the tutorial!

And yes I am running Catalina, still on a beta so I'll try again when I am on the real Catalina/Xcode.

Thread Thread
 
maeganwilson_ profile image
Maegan Wilson • Edited

I also had this problem in the simulator at some point in the beta process, but when on a real device it works.
In my app on the App Store, I have this implemented as a nav bar button and it works as expected. You can see the code on my GitHub. I linked to the direct file.

Collapse
 
kevindorfer profile image
Kevin ⚜️ Dorfer

Very helpful

Collapse
 
maeganwilson_ profile image
Maegan Wilson

Thanks!!