chore: update setting appearance assets

This commit is contained in:
CMK 2021-07-27 13:54:03 +08:00
parent e98e81ede1
commit 0c74880152
20 changed files with 84 additions and 19 deletions

View File

@ -7,12 +7,12 @@
<key>AppShared.xcscheme_^#shared#^_</key> <key>AppShared.xcscheme_^#shared#^_</key>
<dict> <dict>
<key>orderHint</key> <key>orderHint</key>
<integer>31</integer> <integer>35</integer>
</dict> </dict>
<key>CoreDataStack.xcscheme_^#shared#^_</key> <key>CoreDataStack.xcscheme_^#shared#^_</key>
<dict> <dict>
<key>orderHint</key> <key>orderHint</key>
<integer>30</integer> <integer>36</integer>
</dict> </dict>
<key>Mastodon - ASDK.xcscheme_^#shared#^_</key> <key>Mastodon - ASDK.xcscheme_^#shared#^_</key>
<dict> <dict>
@ -37,7 +37,7 @@
<key>MastodonIntent.xcscheme_^#shared#^_</key> <key>MastodonIntent.xcscheme_^#shared#^_</key>
<dict> <dict>
<key>orderHint</key> <key>orderHint</key>
<integer>29</integer> <integer>38</integer>
</dict> </dict>
<key>MastodonIntents.xcscheme_^#shared#^_</key> <key>MastodonIntents.xcscheme_^#shared#^_</key>
<dict> <dict>
@ -52,12 +52,12 @@
<key>NotificationService.xcscheme_^#shared#^_</key> <key>NotificationService.xcscheme_^#shared#^_</key>
<dict> <dict>
<key>orderHint</key> <key>orderHint</key>
<integer>3</integer> <integer>4</integer>
</dict> </dict>
<key>ShareActionExtension.xcscheme_^#shared#^_</key> <key>ShareActionExtension.xcscheme_^#shared#^_</key>
<dict> <dict>
<key>orderHint</key> <key>orderHint</key>
<integer>28</integer> <integer>37</integer>
</dict> </dict>
</dict> </dict>
<key>SuppressBuildableAutocreation</key> <key>SuppressBuildableAutocreation</key>

View File

@ -111,9 +111,11 @@ internal enum Asset {
} }
} }
internal enum Settings { internal enum Settings {
internal static let appearanceAutomatic = ImageAsset(name: "Settings/appearance.automatic") internal static let blackAuto = ImageAsset(name: "Settings/black.auto")
internal static let appearanceDark = ImageAsset(name: "Settings/appearance.dark") internal static let black = ImageAsset(name: "Settings/black")
internal static let appearanceLight = ImageAsset(name: "Settings/appearance.light") internal static let darkAuto = ImageAsset(name: "Settings/dark.auto")
internal static let dark = ImageAsset(name: "Settings/dark")
internal static let light = ImageAsset(name: "Settings/light")
} }
internal enum Theme { internal enum Theme {
internal enum Mastodon { internal enum Mastodon {

View File

@ -1,7 +1,7 @@
{ {
"images" : [ "images" : [
{ {
"filename" : "iPhone 11 Pro _ X - 1.pdf", "filename" : "Mixed_Black_Light.png",
"idiom" : "universal" "idiom" : "universal"
} }
], ],

Binary file not shown.

After

Width:  |  Height:  |  Size: 379 KiB

View File

@ -1,7 +1,7 @@
{ {
"images" : [ "images" : [
{ {
"filename" : "iPhone 11 Pro _ X - 1 (1).pdf", "filename" : "Home Black.png",
"idiom" : "universal" "idiom" : "universal"
} }
], ],

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 MiB

View File

@ -1,7 +1,7 @@
{ {
"images" : [ "images" : [
{ {
"filename" : "iPhone 11 Pro _ X - 1 (2).pdf", "filename" : "Mixed_Dark_Light.png",
"idiom" : "universal" "idiom" : "universal"
} }
], ],

Binary file not shown.

After

Width:  |  Height:  |  Size: 375 KiB

View File

@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "Home Dark.png",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 MiB

View File

@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "Home Light.png",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 403 KiB

View File

@ -10,6 +10,9 @@ import UIKit
class AppearanceView: UIView { class AppearanceView: UIView {
lazy var imageView: UIImageView = { lazy var imageView: UIImageView = {
let view = UIImageView() let view = UIImageView()
view.layer.masksToBounds = true
view.layer.cornerRadius = 14
view.layer.cornerCurve = .continuous
// accessibility // accessibility
view.accessibilityIgnoresInvertColors = true view.accessibilityIgnoresInvertColors = true
return view return view

View File

@ -15,26 +15,26 @@ protocol SettingsAppearanceTableViewCellDelegate: AnyObject {
class SettingsAppearanceTableViewCell: UITableViewCell { class SettingsAppearanceTableViewCell: UITableViewCell {
var disposeBag = Set<AnyCancellable>() var disposeBag = Set<AnyCancellable>()
static let spacing: CGFloat = 18
weak var delegate: SettingsAppearanceTableViewCellDelegate? weak var delegate: SettingsAppearanceTableViewCellDelegate?
var appearance: SettingsItem.AppearanceMode = .automatic var appearance: SettingsItem.AppearanceMode = .automatic
lazy var stackView: UIStackView = { lazy var stackView: UIStackView = {
let view = UIStackView() let view = UIStackView()
view.isLayoutMarginsRelativeArrangement = true
view.layoutMargins = UIEdgeInsets(top: 0, left: 20, bottom: 0, right: 20)
view.axis = .horizontal view.axis = .horizontal
view.distribution = .fillEqually view.distribution = .fillEqually
view.spacing = 18 view.spacing = SettingsAppearanceTableViewCell.spacing
view.translatesAutoresizingMaskIntoConstraints = false view.translatesAutoresizingMaskIntoConstraints = false
return view return view
}() }()
let automatic = AppearanceView(image: Asset.Settings.appearanceAutomatic.image, let automatic = AppearanceView(image: Asset.Settings.darkAuto.image,
title: L10n.Scene.Settings.Section.Appearance.automatic) title: L10n.Scene.Settings.Section.Appearance.automatic)
let light = AppearanceView(image: Asset.Settings.appearanceLight.image, let light = AppearanceView(image: Asset.Settings.light.image,
title: L10n.Scene.Settings.Section.Appearance.light) title: L10n.Scene.Settings.Section.Appearance.light)
let dark = AppearanceView(image: Asset.Settings.appearanceDark.image, let dark = AppearanceView(image: Asset.Settings.dark.image,
title: L10n.Scene.Settings.Section.Appearance.dark) title: L10n.Scene.Settings.Section.Appearance.dark)
lazy var automaticTap: UITapGestureRecognizer = { lazy var automaticTap: UITapGestureRecognizer = {
@ -80,6 +80,8 @@ class SettingsAppearanceTableViewCell: UITableViewCell {
subview.removeFromSuperview() subview.removeFromSuperview()
} }
} }
setupAsset(theme: ThemeService.shared.currentTheme.value)
} }
func update(with data: SettingsItem.AppearanceMode) { func update(with data: SettingsItem.AppearanceMode) {
@ -115,10 +117,36 @@ class SettingsAppearanceTableViewCell: UITableViewCell {
NSLayoutConstraint.activate([ NSLayoutConstraint.activate([
stackView.topAnchor.constraint(equalTo: contentView.topAnchor), stackView.topAnchor.constraint(equalTo: contentView.topAnchor),
stackView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor), stackView.leadingAnchor.constraint(equalTo: contentView.readableContentGuide.leadingAnchor),
stackView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor), stackView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor),
stackView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor), stackView.trailingAnchor.constraint(equalTo: contentView.readableContentGuide.trailingAnchor),
]) ])
setupAsset(theme: ThemeService.shared.currentTheme.value)
ThemeService.shared.currentTheme
.receive(on: DispatchQueue.main)
.sink { [weak self] theme in
guard let self = self else { return }
self.setupAsset(theme: theme)
}
.store(in: &disposeBag)
}
private func setupAsset(theme: Theme) {
let aspectRatio = Asset.Settings.light.image.size
let width = floor(frame.width - 2 * SettingsAppearanceTableViewCell.spacing) / 3
let height = width / aspectRatio.width * aspectRatio.height
let size = CGSize(width: width, height: height)
light.imageView.image = Asset.Settings.light.image.af.imageAspectScaled(toFill: size, scale: UIScreen.main.scale)
switch theme.themeName {
case .mastodon:
automatic.imageView.image = Asset.Settings.darkAuto.image.af.imageAspectScaled(toFill: size, scale: UIScreen.main.scale)
dark.imageView.image = Asset.Settings.dark.image.af.imageAspectScaled(toFill: size, scale: UIScreen.main.scale)
case .system:
automatic.imageView.image = Asset.Settings.blackAuto.image.af.imageAspectScaled(toFill: size, scale: UIScreen.main.scale)
dark.imageView.image = Asset.Settings.black.image.af.imageAspectScaled(toFill: size, scale: UIScreen.main.scale)
}
} }
// MARK: - Actions // MARK: - Actions

View File

@ -8,6 +8,9 @@
import UIKit import UIKit
struct MastodonTheme: Theme { struct MastodonTheme: Theme {
let themeName: ThemeName = .mastodon
let systemBackgroundColor = Asset.Theme.Mastodon.systemBackground.color let systemBackgroundColor = Asset.Theme.Mastodon.systemBackground.color
let secondarySystemBackgroundColor = Asset.Theme.Mastodon.secondarySystemBackground.color let secondarySystemBackgroundColor = Asset.Theme.Mastodon.secondarySystemBackground.color
let tertiarySystemBackgroundColor = Asset.Theme.Mastodon.tertiarySystemBackground.color let tertiarySystemBackgroundColor = Asset.Theme.Mastodon.tertiarySystemBackground.color

View File

@ -8,6 +8,9 @@
import UIKit import UIKit
struct SystemTheme: Theme { struct SystemTheme: Theme {
let themeName: ThemeName = .system
let systemBackgroundColor = Asset.Theme.System.systemBackground.color let systemBackgroundColor = Asset.Theme.System.systemBackground.color
let secondarySystemBackgroundColor = Asset.Theme.System.secondarySystemBackground.color let secondarySystemBackgroundColor = Asset.Theme.System.secondarySystemBackground.color
let tertiarySystemBackgroundColor = Asset.Theme.System.tertiarySystemBackground.color let tertiarySystemBackgroundColor = Asset.Theme.System.tertiarySystemBackground.color

View File

@ -8,6 +8,8 @@
import UIKit import UIKit
public protocol Theme { public protocol Theme {
var themeName: ThemeName { get }
var systemBackgroundColor: UIColor { get } var systemBackgroundColor: UIColor { get }
var secondarySystemBackgroundColor: UIColor { get } var secondarySystemBackgroundColor: UIColor { get }