SwiftUI - Navigation bar button not clickable after sheet has been presented SwiftUI - Navigation bar button not clickable after sheet has been presented xcode xcode

SwiftUI - Navigation bar button not clickable after sheet has been presented


I think this happens because the presentationMode is not inherited from the presenter view, so the presenter didn't know that the modal is already closed. You can fix this by adding presentationMode to presenter, in this case to ContentView.

struct ContentView: View {    @Environment(\.presentationMode) var presentation    @State var showSheet = false    var body: some View {        NavigationView {            VStack {                Text("Test")            }.sheet(isPresented: self.$showSheet) {                ModalView()            }.navigationBarItems(trailing:                Button(action: {                    self.showSheet = true                }) {                    Text("SecondView")                }            )        }    }}

Tested on Xcode 12.5.

Here is the full workingexample.


This seems to be a bug in SwiftUI. I am also still seeing this issue with Xcode 11.5 / iOS 13.5.1. The navigationBarMode didn't make a difference.

I filed an issue with Apple:


FB7641003 - Taps on a navigationBarItem Button presenting a sheet sometimes not recognized

You can use the attached example project SwiftUISheet (also available via https://github.com/ralfebert/SwiftUISheet) to reproduce the issue. It just presents a sheet from a navigation bar button.Run the app and tap repeatedly on the 'plus' button in the nav bar. When the sheet pops up, dismiss it by sliding it down. Only some taps to the button will be handled, often a tap is ignored.

Tested on Xcode 11.4 (11E146) with iOS 13.4 (17E255).


So far, I can still observe the disorder of navi buttons right after dismissing its presented sheet.

FYI, I am using a UINavigationController wrapper instead as workaround. It works well.

Unfortunately, I sure that the more that kind of bugs, the farther away the time of using SwiftUI widely by the ios dev guys. Because those are too basic to ignore.