Dismissing
Closed this issue · 3 comments
avi-screenovate commented
Is there a way to have the popover dismiss when any portion of the screen other than the popover is tapped?
DominikButz commented
Hi,
you can solve this problem as follows.
- attach the popover to the outer view in your view hierarchy - e.g. to a navigation view
- before the popover, add an overlay modifier with a Color that is clear if the popover is not showing and black with opacity if the popover is showing
- add a tap gesture to the overlay content
Example
/// navigation view
.navigationViewStyle(StackNavigationViewStyle())
.overlay( Group { self.showPopover ? Color.black.opacity(0.3): Color.clear}.onTapGesture {
self.showPopover = false
} )
.popoverView(....
You need to apply the tap gesture modifier to the group wrapper, that's important.
DominikButz commented
Of course, there is an even shorter alternative:
.overlay(Color.black.opacity(self.showPopover ? 0.3 : 0).onTapGesture {
self.showPopover = false
} )
I will close this issue on 9/1/2021.
toseefkhilji commented
@DominikButz : Thanks for workaround!.
But it should built in functionality.