Popovers icon indicating copy to clipboard operation
Popovers copied to clipboard

how to dismiss popover when parent view will disappear

Open AngelDev0329 opened this issue 1 year ago • 3 comments

I am using popover in swiftUI project. When I pop the paged attached popover, showed popover doesn't disappear.

How can I dismiss showed popover?

AngelDev0329 avatar Jun 25 '23 12:06 AngelDev0329

I have same issue

massimilianochiodi avatar Sep 06 '23 09:09 massimilianochiodi

Ever find a solution to this?

aehlke avatar Jan 22 '24 05:01 aehlke

I wonder if this commit in a fork can help resolve this by retaining access to the hosting container: https://github.com/aheze/Popovers/compare/main...chariotsolutions:Popovers:preserve-popover-host#diff-e2a643bfa30cc7d3b75f535698c31a998c099a263a60db12da9ee43c55df1ac6 cc @aheze

Could this perhaps be used to force the popover closed inside .onDisappear on the parent view ?

edit: I now see that this change is included in this PR: https://github.com/aheze/Popovers/pull/73

edit: Success! I used that PR plus some other changes to make properties public to retain presentedPopoverContainer in my SwiftUI view that uses popover, then I can dismiss it in onDisappear. Yay. Messy code but maybe there's a way to resolve this within the library itself.

edit: The #73 PR is likely irrelevant to my fix, which just requires exposing presentedPopoverContainer as public and capturing it in a PopoverReader. A better solution would be to solve this inside Popovers itself.

aehlke avatar Jan 22 '24 06:01 aehlke