12

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?

6
  • 3
    This seems like a bug to me. It didn't work for me either. Hope, somebody(WWDC attendees) checks with Apple folks during SwiftUI labs..
    – SMP
    Commented Jun 6, 2019 at 18:13
  • @SMP Do u know should we fill issue somewhere?
    – ShurupuS
    Commented Jun 7, 2019 at 7:04
  • Also had this issue. Even weirder, I had another button above my presentation button and after the first click of the presentation button, the Button above took over the presentation button's action.
    – Slayter
    Commented Jun 7, 2019 at 17:45
  • 1
    @apocolipse I have the issue on both platforms (catalina & mojave)
    – ShurupuS
    Commented Jun 8, 2019 at 10:28
  • 1
    I have the same issue, even with the tutorial project downloaded from apple developer site. Definitely a bug
    – Andre
    Commented Jun 8, 2019 at 11:22

1 Answer 1

5

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.