Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change status bar style with theme #14

Closed
tapizquent opened this issue Apr 15, 2019 · 8 comments
Closed

Change status bar style with theme #14

tapizquent opened this issue Apr 15, 2019 · 8 comments

Comments

@tapizquent
Copy link

Is there any way to update the Status Bar Style as well when themeService.switch happens?

@wddwycc
Copy link
Member

wddwycc commented Apr 15, 2019

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.

@tapizquent
Copy link
Author

The would definitely be great. To have that option to set it to each ViewController. I'll try to do that now. Thank you!

@tapizquent
Copy link
Author

tapizquent commented Apr 16, 2019

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.

@wddwycc
Copy link
Member

wddwycc commented Apr 18, 2019

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.

@tapizquent
Copy link
Author

tapizquent commented Apr 18, 2019

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.

@wddwycc
Copy link
Member

wddwycc commented May 1, 2019

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
    }
}

@wddwycc
Copy link
Member

wddwycc commented May 1, 2019

@wddwycc
Copy link
Member

wddwycc commented May 1, 2019

After investigation, I noticed UIViewController.rx.statusBarStyle is currently impossible to implement.
So I would like to close this issue.

@wddwycc wddwycc closed this as completed May 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants