Popovers icon indicating copy to clipboard operation
Popovers copied to clipboard

Is there ability present popover with "item"

Open anivaros opened this issue 1 year ago • 1 comments

Hi! Awesome lib, thank you for sharing it! One feature I missing:

Apple's popover implementation has ability to init popover with Item: Identifiable property instead of just bool isPresented. It helps to parametrise popover's view.

Does Popovers has something like that?

anivaros avatar Sep 10 '22 15:09 anivaros

Hey! Currently no, Popovers doesn't have something like SwiftUI's .sheet(item:onDismiss:content:). It would be a great addition though. Feel free to open a PR if you have ideas.

However there is a .popover(selection:tag:attributes:view:) modifier that mimics NavigationLink(destination:tag:selection:label:) (which happens to be deprecated currently — might need to redesign this). This lets you have multiple Popovers.

struct ContentView: View {
    @State var selection: String?
    
    var body: some View {
        HStack {
            Button("Present First Popover") { selection = "1" }
            .popover(selection: $selection, tag: "1") {

                /// Will be presented when selection == "1".
                Text("Hi, I'm a popover.")
                    .background(.blue)
            }
            
            Button("Present Second Popover") { selection = "2" }
            .popover(selection: $selection, tag: "2") {

                /// Will be presented when selection == "2".
                Text("Hi, I'm a popover.")
                    .background(.green)
            }
        }
    }
}

aheze avatar Sep 11 '22 01:09 aheze