largeTitleDisplayMode doesn't work when using UIHostingController

When using a UIHostingController to host my SwiftUI content, I can't get the navigation title to start large and shift to inline as the user scrolls. Is this a known problem with using the UIHostingController?

    var viewModel: DashboardViewModel!
    lazy var contentView = UIHostingController(rootView: DashboardView(viewModel: viewModel))

    override func viewDidLoad() {
        super.viewDidLoad()
        addChild(contentView)
        view.addSubview(contentView.view)
        setupConstraints()
        navigationItem.title = "Test Title"
        navigationItem.largeTitleDisplayMode = .automatic
    }

The title in the navigation controller shows inline

You need to specify that the navigation bar can display large titles, like this:

navigationController?.navigationBar.prefersLargeTitles = true

Try changing the part in viewDidLoad to this:

addChild(contentView)
view.addSubview(contentView.view)
contentView.didMove(toParent: self) // add this

You can set it directly on the UINavigationController()

  let dashBoardNavigationController = UINavigationController(rootView: DashBoardView())
  dashBoardNavigationController.navigationBar.prefersLargeTitles = true

I'm also seeing this issue. Frustrating.

largeTitleDisplayMode doesn't work when using UIHostingController
 
 
Q