From 00794a259af341956944fe4f937ad82e5c98cd45 Mon Sep 17 00:00:00 2001 From: sunxiaojian Date: Sun, 25 Apr 2021 00:44:38 -0700 Subject: [PATCH] fix: pick server scene Dark Mode --- .../Section/CategoryPickerSection.swift | 2 +- Mastodon/Generated/Assets.swift | 1 + .../background.colorset/Contents.json | 38 +++++++++++++++++++ .../TableViewCell/PickServerCell.swift | 2 +- .../TableViewCell/PickServerSearchCell.swift | 4 +- .../View/PickServerCategoryView.swift | 2 +- .../OnboardingViewControllerAppearance.swift | 5 +-- .../View/Button/PrimaryActionButton.swift | 22 +++++++++-- 8 files changed, 65 insertions(+), 11 deletions(-) create mode 100644 Mastodon/Resources/Assets.xcassets/Colors/TextField/background.colorset/Contents.json diff --git a/Mastodon/Diffiable/Section/CategoryPickerSection.swift b/Mastodon/Diffiable/Section/CategoryPickerSection.swift index 456d193f3..938683f99 100644 --- a/Mastodon/Diffiable/Section/CategoryPickerSection.swift +++ b/Mastodon/Diffiable/Section/CategoryPickerSection.swift @@ -34,7 +34,7 @@ extension CategoryPickerSection { cell.categoryView.titleLabel.textColor = .white } } else { - cell.categoryView.bgView.backgroundColor = Asset.Colors.Background.systemBackground.color + cell.categoryView.bgView.backgroundColor = Asset.Colors.Background.secondaryGroupedSystemBackground.color cell.categoryView.bgView.applyShadow(color: Asset.Colors.brandBlue.color, alpha: 0, x: 0, y: 0, blur: 0.0) if case .all = item { cell.categoryView.titleLabel.textColor = Asset.Colors.brandBlue.color diff --git a/Mastodon/Generated/Assets.swift b/Mastodon/Generated/Assets.swift index d26424c75..a4b5692ba 100644 --- a/Mastodon/Generated/Assets.swift +++ b/Mastodon/Generated/Assets.swift @@ -84,6 +84,7 @@ internal enum Asset { internal static let bar = ColorAsset(name: "Colors/Slider/bar") } internal enum TextField { + internal static let background = ColorAsset(name: "Colors/TextField/background") internal static let highlight = ColorAsset(name: "Colors/TextField/highlight") internal static let invalid = ColorAsset(name: "Colors/TextField/invalid") internal static let valid = ColorAsset(name: "Colors/TextField/valid") diff --git a/Mastodon/Resources/Assets.xcassets/Colors/TextField/background.colorset/Contents.json b/Mastodon/Resources/Assets.xcassets/Colors/TextField/background.colorset/Contents.json new file mode 100644 index 000000000..cde0cdf00 --- /dev/null +++ b/Mastodon/Resources/Assets.xcassets/Colors/TextField/background.colorset/Contents.json @@ -0,0 +1,38 @@ +{ + "colors" : [ + { + "color" : { + "color-space" : "srgb", + "components" : { + "alpha" : "0.600", + "blue" : "213", + "green" : "212", + "red" : "212" + } + }, + "idiom" : "universal" + }, + { + "appearances" : [ + { + "appearance" : "luminosity", + "value" : "dark" + } + ], + "color" : { + "color-space" : "srgb", + "components" : { + "alpha" : "0.240", + "blue" : "128", + "green" : "118", + "red" : "118" + } + }, + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/Mastodon/Scene/Onboarding/PickServer/TableViewCell/PickServerCell.swift b/Mastodon/Scene/Onboarding/PickServer/TableViewCell/PickServerCell.swift index bf2299122..9313aa5cc 100644 --- a/Mastodon/Scene/Onboarding/PickServer/TableViewCell/PickServerCell.swift +++ b/Mastodon/Scene/Onboarding/PickServer/TableViewCell/PickServerCell.swift @@ -27,7 +27,7 @@ class PickServerCell: UITableViewCell { let containerView: UIView = { let view = UIView() view.layoutMargins = UIEdgeInsets(top: 16, left: 16, bottom: 10, right: 16) - view.backgroundColor = Asset.Colors.Background.systemBackground.color + view.backgroundColor = Asset.Colors.Background.secondaryGroupedSystemBackground.color view.translatesAutoresizingMaskIntoConstraints = false return view }() diff --git a/Mastodon/Scene/Onboarding/PickServer/TableViewCell/PickServerSearchCell.swift b/Mastodon/Scene/Onboarding/PickServer/TableViewCell/PickServerSearchCell.swift index b708313ac..fb1be2aad 100644 --- a/Mastodon/Scene/Onboarding/PickServer/TableViewCell/PickServerSearchCell.swift +++ b/Mastodon/Scene/Onboarding/PickServer/TableViewCell/PickServerSearchCell.swift @@ -17,7 +17,7 @@ class PickServerSearchCell: UITableViewCell { private var bgView: UIView = { let view = UIView() - view.backgroundColor = Asset.Colors.Background.systemBackground.color + view.backgroundColor = Asset.Colors.Background.secondaryGroupedSystemBackground.color view.translatesAutoresizingMaskIntoConstraints = false view.layer.maskedCorners = [ .layerMinXMinYCorner, @@ -30,7 +30,7 @@ class PickServerSearchCell: UITableViewCell { private var textFieldBgView: UIView = { let view = UIView() - view.backgroundColor = Asset.Colors.Background.secondarySystemBackground.color.withAlphaComponent(0.6) + view.backgroundColor = Asset.Colors.TextField.background.color view.translatesAutoresizingMaskIntoConstraints = false view.layer.masksToBounds = true view.layer.cornerRadius = 6 diff --git a/Mastodon/Scene/Onboarding/PickServer/View/PickServerCategoryView.swift b/Mastodon/Scene/Onboarding/PickServer/View/PickServerCategoryView.swift index 16d5a9fcc..fd1a3ea6d 100644 --- a/Mastodon/Scene/Onboarding/PickServer/View/PickServerCategoryView.swift +++ b/Mastodon/Scene/Onboarding/PickServer/View/PickServerCategoryView.swift @@ -48,7 +48,7 @@ extension PickServerCategoryView { addSubview(bgView) addSubview(titleLabel) - bgView.backgroundColor = Asset.Colors.Background.systemBackground.color + bgView.backgroundColor = Asset.Colors.Background.secondaryGroupedSystemBackground.color NSLayoutConstraint.activate([ bgView.leadingAnchor.constraint(equalTo: self.leadingAnchor), diff --git a/Mastodon/Scene/Onboarding/Share/OnboardingViewControllerAppearance.swift b/Mastodon/Scene/Onboarding/Share/OnboardingViewControllerAppearance.swift index c4b26321a..0784b51ea 100644 --- a/Mastodon/Scene/Onboarding/Share/OnboardingViewControllerAppearance.swift +++ b/Mastodon/Scene/Onboarding/Share/OnboardingViewControllerAppearance.swift @@ -20,8 +20,7 @@ extension OnboardingViewControllerAppearance { static var viewBottomPaddingHeight: CGFloat { return 11 } func setupOnboardingAppearance() { - overrideUserInterfaceStyle = .light - view.backgroundColor = Asset.Colors.Background.onboardingBackground.color + view.backgroundColor = Asset.Colors.Background.systemGroupedBackground.color setupNavigationBarAppearance() @@ -43,7 +42,7 @@ extension OnboardingViewControllerAppearance { func setupNavigationBarBackgroundView() { let navigationBarBackgroundView: UIView = { let view = UIView() - view.backgroundColor = Asset.Colors.Background.onboardingBackground.color + view.backgroundColor = Asset.Colors.Background.systemGroupedBackground.color return view }() diff --git a/Mastodon/Scene/Share/View/Button/PrimaryActionButton.swift b/Mastodon/Scene/Share/View/Button/PrimaryActionButton.swift index aa36fd237..8fefc06c8 100644 --- a/Mastodon/Scene/Share/View/Button/PrimaryActionButton.swift +++ b/Mastodon/Scene/Share/View/Button/PrimaryActionButton.swift @@ -38,9 +38,8 @@ extension PrimaryActionButton { private func _init() { titleLabel?.font = UIFontMetrics(forTextStyle: .headline).scaledFont(for: .systemFont(ofSize: 17, weight: .semibold)) setTitleColor(.white, for: .normal) - setBackgroundImage(UIImage.placeholder(color: Asset.Colors.Button.normal.color), for: .normal) - setBackgroundImage(UIImage.placeholder(color: Asset.Colors.Button.normal.color.withAlphaComponent(0.5)), for: .highlighted) - setBackgroundImage(UIImage.placeholder(color: Asset.Colors.Button.disabled.color), for: .disabled) + setBackgroundImage(UIImage.placeholder(color: Asset.Colors.brandBlue.color), for: .normal) + setupButtonBackground() applyCornerRadius(radius: 10) } @@ -68,4 +67,21 @@ extension PrimaryActionButton { isEnabled = true self.setTitle(originalButtonTitle, for: .disabled) } + + override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { + setupButtonBackground() + } + + func setupButtonBackground() { + if UIScreen.main.traitCollection.userInterfaceStyle == .light { + setTitleColor(.white, for: .disabled) + setBackgroundImage(UIImage.placeholder(color: Asset.Colors.Button.normal.color.withAlphaComponent(0.5)), for: .highlighted) + setBackgroundImage(UIImage.placeholder(color: Asset.Colors.Button.disabled.color), for: .disabled) + + } else { + setTitleColor(UIColor.white.withAlphaComponent(0.5), for: .disabled) + setBackgroundImage(UIImage.placeholder(color: Asset.Colors.brandBlue.color.withAlphaComponent(0.5)), for: .highlighted) + setBackgroundImage(UIImage.placeholder(color: Asset.Colors.brandBlue.color.withAlphaComponent(0.5)), for: .disabled) + } + } }