Search code examples
iosxcodeswiftuiuikit

Xcode 14 navigation bar whited out with UIHostingController


I have noticed a bug introduced when building with Xcode 14. The navigation bar of my swiftui view is whited out and does not properly display the title, back button or other navigation items. I haven't found anyone else reporting this issue online but it is clearly a change in how Xcode builds the app.

I have verified that building with Xcode 13.4.1 produces the expected navigation bar.

I manually downloaded 13.4.1 in order to continue deploying builds without this bug but I know eventually I will have to investigate why Xcode 14 is causing this issue. I'm hoping there is a fix that Apple discovers and releases to fix this issue.

The navigation bar is programmatically set through a view controller using a UIHostingController as its rootView.

I have found that this only happens when injecting swiftui into a UIKit app using UIHostingController. The SwiftUI view does not use a NavigationView so there shouldn't be any overlap between what is displayed in the navigation bar from the viewController and what is displayed from the SwiftUI view.


Solution

  • I never heard back from Apple but I figured out the issue!

    In my case the app had a few settings that worked in Xcode 13 but created the issue in Xcode 14.

    1. I had to remove this key/val from the Info.plist for my app UIStatusBarStyle UIStatusBarStyleDarkContent
    2. I removed a setting that was set in AppDelegate
      application.setStatusBarStyle(UIStatusBarStyleLightContent)
    
    1. I explicitly called this in every ViewController (I used a base class that all my View Controllers inherit)
        navigationController.setNavigationBarHidden(false, animated:false)
    

    After the above changes the navigation bar showed up correctly and the top status bar also displayed correctly.