Better Programming

Advice for programmers.

Follow publication

Member-only story

The Navigation Bar Isn’t Hidden as Expected in SwiftUI

Xuan-Gieng (Jasper) Nguyen
Better Programming
Published in
6 min readJun 22, 2020
Your navigation bar is still covering UI elements behind the scene — even if you hide it

TL;DR: If you can’t tap on buttons in the navigation-bar area, you can jump directly to “4. The Solution” to fix the issue.

If you’re not that rushed, feel free to read my full article with a cup of coffee.

1. The Requirements

On a nice day, you’re tasked with implementing a custom navigation bar in your new iOS app. With SwiftUI, you’re confident you can get it done within just an hour because it’s really simple, as it needs only two buttons:

  • Back button: To let users go back to the previous screen
  • Close button: To let users dismiss the current flow and dismiss to the first screen of the flow

2. The Situation

You might think of using native navigationBarItems to provide a leading item and trailing item, like this:

var body: some View {
VStack {
EmptyView()
}
.navigationBarItems(leading: backButton, trailing: closeButton)
.background(Color.white)
.edgesIgnoringSafeArea(.all)
}

With the back button as the leading button and the close button, you’re confident running the code. Oops! There’s…

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Xuan-Gieng (Jasper) Nguyen
Xuan-Gieng (Jasper) Nguyen

Written by Xuan-Gieng (Jasper) Nguyen

Aka Jasper Nguyen | ex-Mobile Engineering Director @ GXS Bank — Grab Digibank.

Write a response