Hiding the status bar when a specific native UIVie...
# compose-ios
j
Hiding the status bar when a specific native UIViewController is being shown with
UIKitViewController
Compose call? I have tried a few things:
UIApplication.sharedApplication.setStatusBarHidden(true, UIStatusBarAnimation.UIStatusBarAnimationNone)
but this is deprecated in iOS 10 (9 years ago) and has problems that if the app is closed/crashed in between the call with
true
and
false
the next time the app is started the status bar is still hidden... Then I found out that the
ComposeUIViewControllerConfiguration
has a delegate that can help control this a bit better, but that delegate is also deprecated now with a suggestion to create a parent
UIViewController
around the Compose Host UIViewController, so I tried the following but this causes issues with the sizing of the entire Compose hierarchy (basically seems to assume the initial viewport never changes regardless of rotations and other updates). How to fix this? Is there some additional methods to override in the
UIViewController
wrapper that will fix it? Thanks!
Copy code
class MainViewControllerWrapper(val vc: UIViewController): UIViewController(null, null) {
    @OptIn(ExperimentalForeignApi::class)
    override fun loadView() {
        super.loadView()
        vc.willMoveToParentViewController(this)
        vc.view.setFrame(view.frame)
        view.addSubview(vc.view)
        addChildViewController(vc)
        vc.didMoveToParentViewController(this)
    }

    override fun prefersStatusBarHidden() = anyPrefersStatusBarHidden()
    companion object {
        fun UIViewController.anyPrefersStatusBarHidden(): Boolean =
            childViewControllers.any { (it as? UIViewController)?.anyPrefersStatusBarHidden() == true }
    }
}