Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PresentationButton didn't trigger action twice

Tags:

ios

swift

swiftui

I want to present modally view and after dismissing present it once again.

struct ContentView : View {
    var body: some View {
        NavigationView {
            Group {
                Text("hi")
                Text("hello")
                }
                .navigationBarItem(title: Text("Demo"))
                .navigationBarItems(trailing:
                    PresentationButton(
                        Image(systemName: "person.crop.circle")
                            .imageScale(.large)
                            .accessibility(label: Text("User Profile"))
                            .padding(),
                        destination: Text("User Profile")
                    )
            )
        }
    }
}

It triggers only during first tap. After dismissing destination view the tap on PresentationButton do nothing. Do someone have the solution for this?

like image 213
ShurupuS Avatar asked Jun 05 '19 12:06

ShurupuS


1 Answers

It looks like a bug, here's a workaround:

struct ContentView : View {

    @State var showModal: Bool = false

    var body: some View {
        NavigationView {
            Group {
                Text("hi")
                Text("hello")
            }
            .navigationBarItem(title: Text("Demo"))
            .navigationBarItems(trailing:
                Button(action: {
                    self.showModal = true
                }) {
                    Image(systemName: "person.crop.circle")
                }
            )
            }.presentation(showModal ? Modal(Text("Hey"),
                                             onDismiss: { self.showModal = false }) : nil)
    }
}
like image 132
Matteo Pacini Avatar answered Oct 23 '22 14:10

Matteo Pacini