Popovers
Popovers copied to clipboard
Dismiss mode set to .none always stays on screen
$0.dismissal.mode = .none
When setting this mode, the popover will always stick around even when the presenting parent view disappears. Is this as intended?
Can't say it's intended, but would it be possible to do present = false
inside onDisappear
?
Tried that approach first. Didn't work for me. I'll put together a sample project to demonstrate, just in case it was a result of my complex layouts. I'll close the comment if I can't re-create.
If you run this code and tap the back button the popover remains on screen. Is this intended? If not, I guess this is a bug.
import SwiftUI
import Popovers
extension String: Identifiable {
public var id: String {
return self
}
}
struct ContentView: View {
@State var parks: [String] = ["Central", "Greenwich", "Thorpe"]
var body: some View {
NavigationStack {
List(parks) { park in
NavigationLink(park, value: park)
}
.navigationDestination(for: String.self) { park in
ChildView(parkName: park)
}
}
}
}
struct ChildView: View {
@State var parkName: String
@State var replyPresent = false
var body: some View {
VStack {
Text(parkName)
Button {
self.replyPresent = true
} label: {
Text("Show Popover")
}
}
.padding()
.popover(present: $replyPresent,
attributes: {
$0.dismissal.mode = .none
// $0.dismissal.mode = .dragUp
// $0.dismissal.mode = .dragDown
// $0.dismissal.mode = .tapOutside
}
) {
Text("My Popover")
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
I have same issue
Anyone find a solution?
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
Could this perhaps be used to force the popover closed inside .onDisappear on the parent view ?
edit: I figured out a solution https://github.com/aheze/Popovers/issues/93#issuecomment-1903362448