Closed tapizquent closed 5 years ago
The property UIApplication.rx.statusBarStyle
is removed in older version of RxTheme
because UIApplication.statusBarStyle
is deprecated by Apple.
But you still can do the binding manually:
themeService.typeStream
.map { $0 == .dark ? UIStatusBarStyle.lightContent : UIStatusBarStyle.default }
.bind { val in UIApplication.shared.statusBarStyle = val }
.disposed(by: disposeBag)
Since Apple encourages developers to set status bar color per ViewController
, I am considering adding a UIViewController.rx.statusBarStyle
.
The would definitely be great. To have that option to set it to each ViewController. I'll try to do that now. Thank you!
Tried your method and that does not work as most of my VCs are inside a navigationController. I also encountered another error.
I developed an extension to be able to set the UITabBar.unselectedItemTintColor, and when I do this, it resets my other customizations. Like for example I am setting the color of the UITabBarItem Title to clear so I only see the icon, and when the theme switches, it replaces my clear color to the unselectedBarItemColor. I have tried to re-set the color to .clear inside the Reactive extension of TabBar but it does not really work.
What reactive extension does is only run a block of code you predefined when event happens. It seems your issue has nothing to do with it.
It seems that the reactive extension is returning a NEW tabBarItem, clearing my previous customization.
I will look deeper into it to see where it's going wrong. But even trying to set the color of the TabBarItem Title to UIColor.clear after, or inside the reactive block, it won't work.
Since preferredStatusBarStyle
is a generated property for UIViewController
, there is no way to intercept it and create a binder for it. Currently my solution is to observe theme change manually
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
themeService.typeStream
.bind { [unowned self] val in
self.setNeedsStatusBarAppearanceUpdate()
}
.disposed(by: disposeBag)
}
override var preferredStatusBarStyle: UIStatusBarStyle {
return themeService.type == .light ? .default : .lightContent
}
}
If you are looking for a solution for UINavigationController
, here it is https://stackoverflow.com/questions/41026514/preferred-status-bar-style-of-view-controller-is-ignored-when-in-navigation-cont/41026726#41026726
After investigation, I noticed UIViewController.rx.statusBarStyle
is currently impossible to implement.
So I would like to close this issue.
Is there any way to update the Status Bar Style as well when themeService.switch happens?