3 year old bug in SwiftUI's Navigation Bar still present. Anyone know a good workaround?

It is well known that a trailing button on a SwiftUI navigation bar is hard to tap. Its tappable area seems to be covered by a trailing inset, making it not register taps correctly (its as if the trailing half of its tappable area is disabled). I wrote a minimum reproducible example to make it clearer.

struct ContentView: View {
    var body: some View {
        NavigationView {
            Text("Hello, world!")
                .navigationBarItems(
                    trailing:
                        Button(action: {
                            print("Tapped!")
                        }) {
                            Image(systemName: "plus")
                        }
                )
        }
        .navigationViewStyle(
            StackNavigationViewStyle()
        )
    }
}

Copy and paste this on a new Xcode project, run it on an iPhone (not a simulator, it works fine there), and try to tap the plus button, you'll see what I mean.

Anyone have a way to get around this? I've tried the usually suggested ones like .imageScale(.large), overlaying a rectangle, and using other types of view with a .onTapmethod, but they don't work.

Thanks!

  • The issue is still present when using toolbar instead of navigationBar.

Add a Comment