Popovers icon indicating copy to clipboard operation
Popovers copied to clipboard

Dismiss mode set to .none always stays on screen

Open elprl opened this issue 1 year ago • 6 comments

$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?

elprl avatar Aug 02 '22 18:08 elprl

Can't say it's intended, but would it be possible to do present = false inside onDisappear?

aheze avatar Aug 04 '22 07:08 aheze

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.

elprl avatar Aug 04 '22 11:08 elprl

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()
    }
}

elprl avatar Aug 15 '22 12:08 elprl

I have same issue

massimilianochiodi avatar Sep 06 '23 09:09 massimilianochiodi

Anyone find a solution?

aehlke avatar Jan 22 '24 06: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

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

aehlke avatar Jan 22 '24 06:01 aehlke