TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

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 RevenueCat.

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

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.