fix: account switch scene not adopt elevated color issue

This commit is contained in:
CMK 2021-11-04 15:13:17 +08:00
parent 00cf2db8a1
commit 469acd12f5
6 changed files with 48 additions and 17 deletions

View File

@ -75,7 +75,7 @@ extension AccountListViewController {
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
view.backgroundColor = ThemeService.shared.currentTheme.value.systemBackgroundColor.withAlphaComponent(0.9) setupBackgroundColor(theme: ThemeService.shared.currentTheme.value)
ThemeService.shared.currentTheme ThemeService.shared.currentTheme
.receive(on: DispatchQueue.main) .receive(on: DispatchQueue.main)
.sink { [weak self] theme in .sink { [weak self] theme in
@ -131,7 +131,15 @@ extension AccountListViewController {
} }
private func setupBackgroundColor(theme: Theme) { private func setupBackgroundColor(theme: Theme) {
view.backgroundColor = theme.systemBackgroundColor.withAlphaComponent(0.9) let backgroundColor = UIColor { traitCollection in
switch traitCollection.userInterfaceLevel {
case .elevated where traitCollection.userInterfaceStyle == .dark:
return theme.systemElevatedBackgroundColor
default:
return theme.systemBackgroundColor.withAlphaComponent(0.9)
}
}
view.backgroundColor = backgroundColor
} }
} }

View File

@ -12,6 +12,7 @@ import MetaTextKit
final class AccountListTableViewCell: UITableViewCell { final class AccountListTableViewCell: UITableViewCell {
private var _disposeBag = Set<AnyCancellable>()
var disposeBag = Set<AnyCancellable>() var disposeBag = Set<AnyCancellable>()
let avatarButton = CircleAvatarButton(frame: .zero) let avatarButton = CircleAvatarButton(frame: .zero)
@ -47,6 +48,15 @@ final class AccountListTableViewCell: UITableViewCell {
extension AccountListTableViewCell { extension AccountListTableViewCell {
private func _init() { private func _init() {
backgroundColor = ThemeService.shared.currentTheme.value.secondarySystemGroupedBackgroundColor
ThemeService.shared.currentTheme
.receive(on: RunLoop.main)
.sink { [weak self] theme in
guard let self = self else { return }
self.backgroundColor = ThemeService.shared.currentTheme.value.secondarySystemGroupedBackgroundColor
}
.store(in: &_disposeBag)
avatarButton.translatesAutoresizingMaskIntoConstraints = false avatarButton.translatesAutoresizingMaskIntoConstraints = false
contentView.addSubview(avatarButton) contentView.addSubview(avatarButton)
NSLayoutConstraint.activate([ NSLayoutConstraint.activate([

View File

@ -6,10 +6,13 @@
// //
import UIKit import UIKit
import Combine
import MetaTextKit import MetaTextKit
final class AddAccountTableViewCell: UITableViewCell { final class AddAccountTableViewCell: UITableViewCell {
private var _disposeBag = Set<AnyCancellable>()
let iconImageView: UIImageView = { let iconImageView: UIImageView = {
let image = UIImage(systemName: "plus.circle.fill")! let image = UIImage(systemName: "plus.circle.fill")!
let imageView = UIImageView(image: image) let imageView = UIImageView(image: image)
@ -41,6 +44,15 @@ final class AddAccountTableViewCell: UITableViewCell {
extension AddAccountTableViewCell { extension AddAccountTableViewCell {
private func _init() { private func _init() {
backgroundColor = ThemeService.shared.currentTheme.value.secondarySystemGroupedBackgroundColor
ThemeService.shared.currentTheme
.receive(on: RunLoop.main)
.sink { [weak self] theme in
guard let self = self else { return }
self.backgroundColor = ThemeService.shared.currentTheme.value.secondarySystemGroupedBackgroundColor
}
.store(in: &_disposeBag)
iconImageView.translatesAutoresizingMaskIntoConstraints = false iconImageView.translatesAutoresizingMaskIntoConstraints = false
contentView.addSubview(iconImageView) contentView.addSubview(iconImageView)
NSLayoutConstraint.activate([ NSLayoutConstraint.activate([

View File

@ -312,7 +312,7 @@ extension MastodonRegisterViewController {
view.addGestureRecognizer(tapGestureRecognizer) view.addGestureRecognizer(tapGestureRecognizer)
tapGestureRecognizer.addTarget(self, action: #selector(tapGestureRecognizerHandler)) tapGestureRecognizer.addTarget(self, action: #selector(tapGestureRecognizerHandler))
// stackview // stackView
stackView.axis = .vertical stackView.axis = .vertical
stackView.distribution = .fill stackView.distribution = .fill
stackView.spacing = 40 stackView.spacing = 40
@ -370,7 +370,7 @@ extension MastodonRegisterViewController {
scrollView.frameLayoutGuide.widthAnchor.constraint(equalTo: scrollView.contentLayoutGuide.widthAnchor), scrollView.frameLayoutGuide.widthAnchor.constraint(equalTo: scrollView.contentLayoutGuide.widthAnchor),
]) ])
// stackview // stackView
scrollView.addSubview(stackView) scrollView.addSubview(stackView)
stackView.translatesAutoresizingMaskIntoConstraints = false stackView.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([ NSLayoutConstraint.activate([

View File

@ -51,7 +51,7 @@ class ReportViewController: UIViewController, NeedsDependency {
return view return view
}() }()
lazy var stackview: UIStackView = { lazy var stackView: UIStackView = {
let view = UIStackView() let view = UIStackView()
view.axis = .vertical view.axis = .vertical
view.alignment = .fill view.alignment = .fill
@ -122,19 +122,19 @@ class ReportViewController: UIViewController, NeedsDependency {
setupNavigation() setupNavigation()
stackview.addArrangedSubview(header) stackView.addArrangedSubview(header)
stackview.addArrangedSubview(contentView) stackView.addArrangedSubview(contentView)
stackview.addArrangedSubview(footer) stackView.addArrangedSubview(footer)
stackview.addArrangedSubview(bottomSpacing) stackView.addArrangedSubview(bottomSpacing)
contentView.addSubview(tableView) contentView.addSubview(tableView)
view.addSubview(stackview) view.addSubview(stackView)
NSLayoutConstraint.activate([ NSLayoutConstraint.activate([
stackview.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor), stackView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor),
stackview.leadingAnchor.constraint(equalTo: view.leadingAnchor), stackView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
stackview.bottomAnchor.constraint(equalTo: view.bottomAnchor), stackView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
stackview.trailingAnchor.constraint(equalTo: view.trailingAnchor), stackView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
tableView.topAnchor.constraint(equalTo: contentView.topAnchor), tableView.topAnchor.constraint(equalTo: contentView.topAnchor),
tableView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor), tableView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor),
tableView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor), tableView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor),
@ -273,8 +273,8 @@ class ReportViewController: UIViewController, NeedsDependency {
navigationItem.titleView = titleView navigationItem.titleView = titleView
if let user = beReportedUser { if let user = beReportedUser {
do { do {
let mastodonConent = MastodonContent(content: user.displayNameWithFallback, emojis: user.emojiMeta) let mastodonContent = MastodonContent(content: user.displayNameWithFallback, emojis: user.emojiMeta)
let metaContent = try MastodonMetaContent.convert(document: mastodonConent) let metaContent = try MastodonMetaContent.convert(document: mastodonContent)
titleView.update(titleMetaContent: metaContent, subtitle: nil) titleView.update(titleMetaContent: metaContent, subtitle: nil)
} catch { } catch {
let metaContent = PlaintextMetaContent(string: user.displayNameWithFallback) let metaContent = PlaintextMetaContent(string: user.displayNameWithFallback)

View File

@ -19,6 +19,7 @@ final class ReportedStatusTableViewCell: UITableViewCell, StatusCell {
static let bottomPaddingHeight: CGFloat = 10 static let bottomPaddingHeight: CGFloat = 10
weak var dependency: ReportViewController? weak var dependency: ReportViewController?
private var _disposeBag = Set<AnyCancellable>()
var disposeBag = Set<AnyCancellable>() var disposeBag = Set<AnyCancellable>()
var observations = Set<NSKeyValueObservation>() var observations = Set<NSKeyValueObservation>()
@ -98,7 +99,7 @@ extension ReportedStatusTableViewCell {
guard let self = self else { return } guard let self = self else { return }
self.backgroundColor = ThemeService.shared.currentTheme.value.secondarySystemGroupedBackgroundColor self.backgroundColor = ThemeService.shared.currentTheme.value.secondarySystemGroupedBackgroundColor
} }
.store(in: &disposeBag) .store(in: &_disposeBag)
checkbox.translatesAutoresizingMaskIntoConstraints = false checkbox.translatesAutoresizingMaskIntoConstraints = false
contentView.addSubview(checkbox) contentView.addSubview(checkbox)