5

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.

JanMensch
  • 1,720
  • 1
  • 18
  • 27

1 Answers1

2

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.

JanMensch
  • 1,720
  • 1
  • 18
  • 27
  • yes its strange, if you put the navigationTitle and Displaymode on a ZStack it works fine, but if i put i on a scrollView its not working. – saro Sep 25 '22 at 20:31
  • Due to this, we now have to set the title and title display mode in two places when pushing UIHostingControllers in UINavigationControllers: First, we have to configure the UIHostingController's navigationItem.title and navigationItem.largeTitleDisplayMode to ensure that the style changes without delay as the VC is pushed. Then, we have to configure the wrapped SwiftUI view's .navigationTitle and .navigationBarTitleDisplayMode to prevent the style from changing after the view has appeared in iOS 16. – rberggreen Sep 29 '22 at 09:49