iOS 16 NavigationBar sets large title and hides inline title

Viewed 86

When checking our app for bugs on iOS 16 we have realized that behavior on the NavigationBar changes, even on non 14 Pro models. There are multiple issues and we are wondering how to fix them. All issues came with no change in code. Just running the app on iOS 16.

  1. On some views iOS changes the title style to "large". It used to be and should be inline.
  2. On some views the title gets displayed inline during the push animation but as soon as the animation finishes the title style changes to large. This causes a UI jump. On other views the title just disappears completely.
  3. On some views the title is properly inline, but when showing a sheet and dismissing it causes the title to completely disappear from the NavigationBar.

We are using UIHostingControllers to wrap all our SwiftUI views. Maybe there's some issue here.

1 Answers

It seems like the UIHostingController and SwiftUI clash a bit on iOS 16. iOS gets confused when setting properties on the ViewController that also can be set via SwiftUI. Try to set the title and title style in your root SwiftUI view that you put into the HostingController:

var body: some View {
    yourContentViewsHere
        .navigationTitle("NavBar title")
        .navigationBarTitleDisplayMode(.inline)
}

All of the issues in the question should get resolved by this fix.

Related