fix: background color may set with delay issue

This commit is contained in:
CMK 2021-07-06 18:00:39 +08:00
parent 31a79cbef0
commit 489f8d0448
10 changed files with 51 additions and 32 deletions

View File

@ -144,13 +144,12 @@ extension ComposeViewController {
self.title = title self.title = title
} }
.store(in: &disposeBag) .store(in: &disposeBag)
view.backgroundColor = ThemeService.shared.currentTheme.value.systemElevatedBackgroundColor self.setupBackgroundColor(theme: ThemeService.shared.currentTheme.value)
ThemeService.shared.currentTheme ThemeService.shared.currentTheme
.receive(on: RunLoop.main) .receive(on: RunLoop.main)
.sink { [weak self] theme in .sink { [weak self] theme in
guard let self = self else { return } guard let self = self else { return }
self.view.backgroundColor = theme.systemElevatedBackgroundColor self.setupBackgroundColor(theme: theme)
self.tableView.backgroundColor = theme.systemElevatedBackgroundColor
} }
.store(in: &disposeBag) .store(in: &disposeBag)
navigationItem.leftBarButtonItem = cancelBarButtonItem navigationItem.leftBarButtonItem = cancelBarButtonItem
@ -607,6 +606,11 @@ extension ComposeViewController {
// }) // })
} }
private func setupBackgroundColor(theme: Theme) {
view.backgroundColor = theme.systemElevatedBackgroundColor
tableView.backgroundColor = theme.systemElevatedBackgroundColor
}
} }
extension ComposeViewController { extension ComposeViewController {

View File

@ -58,7 +58,8 @@ extension HashtagTimelineViewController {
title = "#\(viewModel.hashtag)" title = "#\(viewModel.hashtag)"
titleView.update(title: viewModel.hashtag, subtitle: nil, emojiDict: [:]) titleView.update(title: viewModel.hashtag, subtitle: nil, emojiDict: [:])
navigationItem.titleView = titleView navigationItem.titleView = titleView
view.backgroundColor = ThemeService.shared.currentTheme.value.secondarySystemBackgroundColor
ThemeService.shared.currentTheme ThemeService.shared.currentTheme
.receive(on: RunLoop.main) .receive(on: RunLoop.main)
.sink { [weak self] theme in .sink { [weak self] theme in

View File

@ -80,8 +80,8 @@ extension HomeTimelineViewController {
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
title = L10n.Scene.HomeTimeline.title title = L10n.Scene.HomeTimeline.title
view.backgroundColor = ThemeService.shared.currentTheme.value.secondarySystemBackgroundColor
ThemeService.shared.currentTheme ThemeService.shared.currentTheme
.receive(on: RunLoop.main) .receive(on: RunLoop.main)
.sink { [weak self] theme in .sink { [weak self] theme in

View File

@ -48,7 +48,8 @@ final class NotificationViewController: UIViewController, NeedsDependency {
extension NotificationViewController { extension NotificationViewController {
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
view.backgroundColor = ThemeService.shared.currentTheme.value.secondarySystemBackgroundColor
ThemeService.shared.currentTheme ThemeService.shared.currentTheme
.receive(on: RunLoop.main) .receive(on: RunLoop.main)
.sink { [weak self] theme in .sink { [weak self] theme in

View File

@ -238,13 +238,12 @@ extension NotificationStatusTableViewCell {
statusView.bottomAnchor.constraint(equalTo: statusContainerView.layoutMarginsGuide.bottomAnchor), statusView.bottomAnchor.constraint(equalTo: statusContainerView.layoutMarginsGuide.bottomAnchor),
]) ])
setupBackgroundColor(theme: ThemeService.shared.currentTheme.value)
ThemeService.shared.currentTheme ThemeService.shared.currentTheme
.receive(on: RunLoop.main) .receive(on: RunLoop.main)
.sink { [weak self] theme in .sink { [weak self] theme in
guard let self = self else { return } guard let self = self else { return }
self.statusContainerView.backgroundColor = UIColor(dynamicProvider: { traitCollection in self.setupBackgroundColor(theme: theme)
return traitCollection.userInterfaceStyle == .light ? theme.systemBackgroundColor : theme.tertiarySystemGroupedBackgroundColor
})
} }
.store(in: &disposeBag) .store(in: &disposeBag)
// remove item don't display // remove item don't display
@ -286,6 +285,16 @@ extension NotificationStatusTableViewCell {
} }
extension NotificationStatusTableViewCell {
private func setupBackgroundColor(theme: Theme) {
statusContainerView.backgroundColor = UIColor(dynamicProvider: { traitCollection in
return traitCollection.userInterfaceStyle == .light ? theme.systemBackgroundColor : theme.tertiarySystemGroupedBackgroundColor
})
}
}
extension NotificationStatusTableViewCell { extension NotificationStatusTableViewCell {
@objc private func avatarImageViewTapGestureRecognizerHandler(_ sender: UITapGestureRecognizer) { @objc private func avatarImageViewTapGestureRecognizerHandler(_ sender: UITapGestureRecognizer) {
os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s", ((#file as NSString).lastPathComponent), #line, #function) os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s", ((#file as NSString).lastPathComponent), #line, #function)

View File

@ -88,6 +88,7 @@ extension ProfileHeaderViewController {
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
view.backgroundColor = ThemeService.shared.currentTheme.value.systemGroupedBackgroundColor
ThemeService.shared.currentTheme ThemeService.shared.currentTheme
.receive(on: RunLoop.main) .receive(on: RunLoop.main)
.sink { [weak self] theme in .sink { [weak self] theme in

View File

@ -141,7 +141,8 @@ extension ProfileViewController {
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
view.backgroundColor = ThemeService.shared.currentTheme.value.secondarySystemBackgroundColor
ThemeService.shared.currentTheme ThemeService.shared.currentTheme
.receive(on: RunLoop.main) .receive(on: RunLoop.main)
.sink { [weak self] theme in .sink { [weak self] theme in

View File

@ -135,14 +135,12 @@ extension SearchViewController {
navigationItem.compactAppearance = barAppearance navigationItem.compactAppearance = barAppearance
navigationItem.scrollEdgeAppearance = barAppearance navigationItem.scrollEdgeAppearance = barAppearance
setupBackgroundColor(theme: ThemeService.shared.currentTheme.value)
ThemeService.shared.currentTheme ThemeService.shared.currentTheme
.receive(on: RunLoop.main) .receive(on: RunLoop.main)
.sink { [weak self] theme in .sink { [weak self] theme in
guard let self = self else { return } guard let self = self else { return }
self.view.backgroundColor = theme.systemGroupedBackgroundColor self.setupBackgroundColor(theme: theme)
self.searchHeader.backgroundColor = theme.systemGroupedBackgroundColor
self.searchingTableView.backgroundColor = theme.systemBackgroundColor
self.statusBar.backgroundColor = theme.navigationBarBackgroundColor
} }
.store(in: &disposeBag) .store(in: &disposeBag)
@ -171,6 +169,13 @@ extension SearchViewController {
viewModel.viewDidAppeared.send() viewModel.viewDidAppeared.send()
} }
private func setupBackgroundColor(theme: Theme) {
view.backgroundColor = theme.systemGroupedBackgroundColor
searchHeader.backgroundColor = theme.systemGroupedBackgroundColor
searchingTableView.backgroundColor = theme.systemBackgroundColor
statusBar.backgroundColor = theme.navigationBarBackgroundColor
}
func setupSearchBar() { func setupSearchBar() {
searchBar.delegate = self searchBar.delegate = self
view.addSubview(searchBar) view.addSubview(searchBar)

View File

@ -205,27 +205,12 @@ class SettingsViewController: UIViewController, NeedsDependency {
} }
private func setupView() { private func setupView() {
self.view.backgroundColor = UIColor(dynamicProvider: { traitCollection in setupBackgroundColor(theme: ThemeService.shared.currentTheme.value)
switch traitCollection.userInterfaceLevel {
case .elevated where traitCollection.userInterfaceStyle == .dark:
return ThemeService.shared.currentTheme.value.systemElevatedBackgroundColor
default:
return ThemeService.shared.currentTheme.value.secondarySystemBackgroundColor
}
})
ThemeService.shared.currentTheme ThemeService.shared.currentTheme
.receive(on: RunLoop.main) .receive(on: RunLoop.main)
.sink { [weak self] theme in .sink { [weak self] theme in
guard let self = self else { return } guard let self = self else { return }
self.view.backgroundColor = UIColor(dynamicProvider: { traitCollection in self.setupBackgroundColor(theme: theme)
switch traitCollection.userInterfaceLevel {
case .elevated where traitCollection.userInterfaceStyle == .dark:
return theme.systemElevatedBackgroundColor
default:
return theme.secondarySystemBackgroundColor
}
})
} }
.store(in: &disposeBag) .store(in: &disposeBag)
@ -241,6 +226,17 @@ class SettingsViewController: UIViewController, NeedsDependency {
updateSectionHeaderStackViewLayout() updateSectionHeaderStackViewLayout()
} }
private func setupBackgroundColor(theme: Theme) {
view.backgroundColor = UIColor(dynamicProvider: { traitCollection in
switch traitCollection.userInterfaceLevel {
case .elevated where traitCollection.userInterfaceStyle == .dark:
return theme.systemElevatedBackgroundColor
default:
return theme.secondarySystemBackgroundColor
}
})
}
private func setupNavigation() { private func setupNavigation() {
navigationController?.navigationBar.prefersLargeTitles = true navigationController?.navigationBar.prefersLargeTitles = true

View File

@ -51,7 +51,8 @@ extension ThreadViewController {
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
view.backgroundColor = ThemeService.shared.currentTheme.value.secondarySystemBackgroundColor
ThemeService.shared.currentTheme ThemeService.shared.currentTheme
.receive(on: RunLoop.main) .receive(on: RunLoop.main)
.sink { [weak self] theme in .sink { [weak self] theme in