UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

The case of the unexpectedly closing sheet

Forums > iOS

Hi, I have a project where I'm presenting an edit view in a sheet on iPadOS. The sheet is using @Environment(.dismiss) var dismiss and calling dismiss() with a close toolbar item and also after a save function from a save toolbar item. The edit view is also set with .interactiveDismissDisabled(). That works as expected - the editor is closed either without saving or after saving only from the toolbar buttons.

The edit view I'm presenting in the sheet has a button that displays a view in a popover. When the user first taps on that button the popover view appears as expected and if the user taps outside of the popover it closes and the edit view sheet is still there (as expected). If the user taps a second time on the button to display the popover it still appears to work fine EXCEPT, when the user taps outside the popover it closes AND the edit view sheet also closes (not expected).

Anyone know a way to ensure that the sheet only closes when the user taps on the actual close or save buttons and NOT when dismissing a popover window within that view a second time?

3      

The issue seems to be related to the on-screen software keyboard. My popover window has a couple of text fields to enable editing and adding something to a list it is pointing to in my sheet editor. When the popover goes away, it closes the on-screen keyboard as well and that is when the sheet also closes. I didn't notice this at first because the on-screen keyboard doesn't open in the simulator unless you force the issue. No software keyboard, no issue.

While I really wanted to use a popover for this, I might be better off using another sheet (as I do on iOS). The sheet opened from the sheet editor doesn't seem to have this same issue as the top one is closed the one under it stays open (even as the on-screen keyboard goes away) no matter how many times I open and close it.

3      

Hacking with Swift is sponsored by Superwall

SPONSORED Superwall lets you build & test paywalls without shipping updates. Run experiments, offer sales, segment users, update locked features and more at the click of button. Best part? It's FREE for up to 250 conversions / mo and the Superwall team builds out 100% custom paywalls – free of charge.

Learn More

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.