Migrate FollowButton to use UIButton.Configuration
also: Refactor Button-Background-Stuff
This commit is contained in:
parent
a3733ea578
commit
94c51eaed6
|
@ -0,0 +1,38 @@
|
|||
{
|
||||
"colors" : [
|
||||
{
|
||||
"color" : {
|
||||
"color-space" : "srgb",
|
||||
"components" : {
|
||||
"alpha" : "1.000",
|
||||
"blue" : "0.216",
|
||||
"green" : "0.173",
|
||||
"red" : "0.157"
|
||||
}
|
||||
},
|
||||
"idiom" : "universal"
|
||||
},
|
||||
{
|
||||
"appearances" : [
|
||||
{
|
||||
"appearance" : "luminosity",
|
||||
"value" : "dark"
|
||||
}
|
||||
],
|
||||
"color" : {
|
||||
"color-space" : "srgb",
|
||||
"components" : {
|
||||
"alpha" : "1.000",
|
||||
"blue" : "0.933",
|
||||
"green" : "0.933",
|
||||
"red" : "0.933"
|
||||
}
|
||||
},
|
||||
"idiom" : "universal"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
{
|
||||
"colors" : [
|
||||
{
|
||||
"color" : {
|
||||
"color-space" : "srgb",
|
||||
"components" : {
|
||||
"alpha" : "1.000",
|
||||
"blue" : "0.933",
|
||||
"green" : "0.933",
|
||||
"red" : "0.933"
|
||||
}
|
||||
},
|
||||
"idiom" : "universal"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
{
|
||||
"colors" : [
|
||||
{
|
||||
"color" : {
|
||||
"color-space" : "srgb",
|
||||
"components" : {
|
||||
"alpha" : "1.000",
|
||||
"blue" : "0.106",
|
||||
"green" : "0.082",
|
||||
"red" : "0.075"
|
||||
}
|
||||
},
|
||||
"idiom" : "universal"
|
||||
},
|
||||
{
|
||||
"appearances" : [
|
||||
{
|
||||
"appearance" : "luminosity",
|
||||
"value" : "dark"
|
||||
}
|
||||
],
|
||||
"color" : {
|
||||
"color-space" : "srgb",
|
||||
"components" : {
|
||||
"alpha" : "1.000",
|
||||
"blue" : "0.729",
|
||||
"green" : "0.729",
|
||||
"red" : "0.729"
|
||||
}
|
||||
},
|
||||
"idiom" : "universal"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
{
|
||||
"colors" : [
|
||||
{
|
||||
"color" : {
|
||||
"color-space" : "srgb",
|
||||
"components" : {
|
||||
"alpha" : "1.000",
|
||||
"blue" : "0.729",
|
||||
"green" : "0.729",
|
||||
"red" : "0.729"
|
||||
}
|
||||
},
|
||||
"idiom" : "universal"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
{
|
||||
"colors" : [
|
||||
{
|
||||
"color" : {
|
||||
"color-space" : "srgb",
|
||||
"components" : {
|
||||
"alpha" : "1.000",
|
||||
"blue" : "0.106",
|
||||
"green" : "0.082",
|
||||
"red" : "0.075"
|
||||
}
|
||||
},
|
||||
"idiom" : "universal"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
{
|
||||
"colors" : [
|
||||
{
|
||||
"color" : {
|
||||
"color-space" : "srgb",
|
||||
"components" : {
|
||||
"alpha" : "1.000",
|
||||
"blue" : "0.216",
|
||||
"green" : "0.173",
|
||||
"red" : "0.157"
|
||||
}
|
||||
},
|
||||
"idiom" : "universal"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
|
@ -190,10 +190,8 @@ public enum Asset {
|
|||
public static let usernameGray = ColorAsset(name: "Scene/Profile/Banner/username.gray")
|
||||
}
|
||||
public enum RelationshipButton {
|
||||
public static let backgroundDark = ColorAsset(name: "Scene/Profile/RelationshipButton/background.dark")
|
||||
public static let backgroundHighlightedDark = ColorAsset(name: "Scene/Profile/RelationshipButton/background.highlighted.dark")
|
||||
public static let backgroundHighlightedLight = ColorAsset(name: "Scene/Profile/RelationshipButton/background.highlighted.light")
|
||||
public static let backgroundLight = ColorAsset(name: "Scene/Profile/RelationshipButton/background.light")
|
||||
public static let background = ColorAsset(name: "Scene/Profile/RelationshipButton/background")
|
||||
public static let backgroundHighlighted = ColorAsset(name: "Scene/Profile/RelationshipButton/background.highlighted")
|
||||
}
|
||||
}
|
||||
public enum Report {
|
||||
|
|
|
@ -3,29 +3,18 @@
|
|||
import UIKit
|
||||
import MastodonAsset
|
||||
|
||||
public final class FollowButton: RoundedEdgesButton {
|
||||
public final class FollowButton: UIButton {
|
||||
|
||||
public init() {
|
||||
super.init(frame: .zero)
|
||||
configureAppearance()
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
|
||||
|
||||
private func configureAppearance() {
|
||||
setTitleColor(Asset.Colors.Label.primaryReverse.color, for: .normal)
|
||||
setTitleColor(Asset.Colors.Label.primaryReverse.color.withAlphaComponent(0.5), for: .highlighted)
|
||||
switch traitCollection.userInterfaceStyle {
|
||||
case .dark:
|
||||
setBackgroundImage(.placeholder(color: Asset.Scene.Profile.RelationshipButton.backgroundDark.color), for: .normal)
|
||||
setBackgroundImage(.placeholder(color: Asset.Scene.Profile.RelationshipButton.backgroundHighlightedDark.color), for: .highlighted)
|
||||
setBackgroundImage(.placeholder(color: Asset.Scene.Profile.RelationshipButton.backgroundHighlightedDark.color), for: .disabled)
|
||||
default:
|
||||
setBackgroundImage(.placeholder(color: Asset.Scene.Profile.RelationshipButton.backgroundLight.color), for: .normal)
|
||||
setBackgroundImage(.placeholder(color: Asset.Scene.Profile.RelationshipButton.backgroundHighlightedLight.color), for: .highlighted)
|
||||
setBackgroundImage(.placeholder(color: Asset.Scene.Profile.RelationshipButton.backgroundHighlightedLight.color), for: .disabled)
|
||||
}
|
||||
var buttonConfiguration = UIButton.Configuration.filled()
|
||||
buttonConfiguration.background.cornerRadius = 10
|
||||
self.configuration = buttonConfiguration
|
||||
}
|
||||
}
|
||||
|
|
|
@ -103,7 +103,6 @@ public final class UserView: UIView {
|
|||
private let followButtonWrapper = UIView()
|
||||
private let followButton: FollowButton = {
|
||||
let button = FollowButton()
|
||||
button.cornerRadius = 10
|
||||
button.isHidden = true
|
||||
button.translatesAutoresizingMaskIntoConstraints = false
|
||||
button.setContentCompressionResistancePriority(.required, for: .horizontal)
|
||||
|
@ -257,57 +256,57 @@ public extension UserView {
|
|||
func setButtonState(_ state: ButtonState) {
|
||||
currentButtonState = state
|
||||
prepareButtonStateLayout(for: state)
|
||||
|
||||
|
||||
switch state {
|
||||
|
||||
case .loading:
|
||||
followButtonWrapper.isHidden = false
|
||||
followButton.isHidden = false
|
||||
followButton.setTitle(nil, for: .normal)
|
||||
followButton.setBackgroundColor(Asset.Colors.Button.disabled.color, for: .normal)
|
||||
|
||||
case .follow:
|
||||
followButtonWrapper.isHidden = false
|
||||
followButton.isHidden = false
|
||||
followButton.setTitle(L10n.Common.Controls.Friendship.follow, for: .normal)
|
||||
followButton.setBackgroundColor(Asset.Colors.Button.userFollow.color, for: .normal)
|
||||
followButton.setTitleColor(.white, for: .normal)
|
||||
case .loading:
|
||||
followButtonWrapper.isHidden = false
|
||||
followButton.isHidden = false
|
||||
followButton.configuration?.title = nil
|
||||
followButton.setBackgroundColor(Asset.Colors.Button.disabled.color, for: .normal)
|
||||
|
||||
case .request:
|
||||
followButtonWrapper.isHidden = false
|
||||
followButton.isHidden = false
|
||||
followButton.setTitle(L10n.Common.Controls.Friendship.request, for: .normal)
|
||||
followButton.setBackgroundColor(Asset.Colors.Button.userFollow.color, for: .normal)
|
||||
followButton.setTitleColor(.white, for: .normal)
|
||||
case .follow:
|
||||
followButtonWrapper.isHidden = false
|
||||
followButton.isHidden = false
|
||||
followButton.configuration?.title = L10n.Common.Controls.Friendship.follow
|
||||
followButton.configuration?.baseBackgroundColor = Asset.Colors.Button.userFollow.color
|
||||
followButton.configuration?.baseForegroundColor = .white
|
||||
|
||||
case .pending:
|
||||
followButtonWrapper.isHidden = false
|
||||
followButton.isHidden = false
|
||||
followButton.setTitle(L10n.Common.Controls.Friendship.pending, for: .normal)
|
||||
followButton.setTitleColor(Asset.Colors.Button.userFollowingTitle.color, for: .normal)
|
||||
followButton.setBackgroundColor(Asset.Colors.Button.userFollowing.color, for: .normal)
|
||||
case .request:
|
||||
followButtonWrapper.isHidden = false
|
||||
followButton.isHidden = false
|
||||
followButton.configuration?.title = L10n.Common.Controls.Friendship.request
|
||||
followButton.configuration?.baseBackgroundColor = Asset.Colors.Button.userFollow.color
|
||||
followButton.configuration?.baseForegroundColor = .white
|
||||
|
||||
case .unfollow:
|
||||
followButtonWrapper.isHidden = false
|
||||
followButton.isHidden = false
|
||||
followButton.setTitle(L10n.Common.Controls.Friendship.following, for: .normal)
|
||||
followButton.setBackgroundColor(Asset.Colors.Button.userFollowing.color, for: .normal)
|
||||
followButton.setTitleColor(Asset.Colors.Button.userFollowingTitle.color, for: .normal)
|
||||
|
||||
case .blocked:
|
||||
followButtonWrapper.isHidden = false
|
||||
followButton.isHidden = false
|
||||
followButton.setTitle(L10n.Common.Controls.Friendship.blocked, for: .normal)
|
||||
followButton.setBackgroundColor(Asset.Colors.Button.userBlocked.color, for: .normal)
|
||||
followButton.setTitleColor(.systemRed, for: .normal)
|
||||
case .pending:
|
||||
followButtonWrapper.isHidden = false
|
||||
followButton.isHidden = false
|
||||
followButton.configuration?.title = L10n.Common.Controls.Friendship.pending
|
||||
followButton.configuration?.baseForegroundColor = Asset.Colors.Button.userFollowingTitle.color
|
||||
followButton.configuration?.baseBackgroundColor = Asset.Colors.Button.userFollowing.color
|
||||
|
||||
case .none:
|
||||
followButtonWrapper.isHidden = true
|
||||
followButton.isHidden = true
|
||||
followButton.setTitle(nil, for: .normal)
|
||||
followButton.setBackgroundColor(.clear, for: .normal)
|
||||
case .unfollow:
|
||||
followButtonWrapper.isHidden = false
|
||||
followButton.isHidden = false
|
||||
followButton.configuration?.title = L10n.Common.Controls.Friendship.following
|
||||
followButton.configuration?.baseBackgroundColor = Asset.Colors.Button.userFollowing.color
|
||||
followButton.configuration?.baseForegroundColor = Asset.Colors.Button.userFollowingTitle.color
|
||||
|
||||
case .blocked:
|
||||
followButtonWrapper.isHidden = false
|
||||
followButton.isHidden = false
|
||||
followButton.configuration?.title = L10n.Common.Controls.Friendship.blocked
|
||||
followButton.configuration?.baseBackgroundColor = Asset.Colors.Button.userBlocked.color
|
||||
followButton.configuration?.baseForegroundColor = .systemRed
|
||||
|
||||
case .none:
|
||||
followButtonWrapper.isHidden = true
|
||||
followButton.isHidden = true
|
||||
followButton.configuration?.title = nil
|
||||
followButton.configuration?.baseBackgroundColor = .clear
|
||||
}
|
||||
|
||||
|
||||
followButton.addTarget(self, action: #selector(didTapButton), for: .touchUpInside)
|
||||
followButton.titleLabel?.font = UIFontMetrics(forTextStyle: .subheadline).scaledFont(for: .boldSystemFont(ofSize: 15))
|
||||
}
|
||||
|
|
|
@ -77,15 +77,8 @@ extension ProfileRelationshipActionButton {
|
|||
private func configureAppearance() {
|
||||
setTitleColor(Asset.Colors.Label.primaryReverse.color, for: .normal)
|
||||
setTitleColor(Asset.Colors.Label.primaryReverse.color.withAlphaComponent(0.5), for: .highlighted)
|
||||
switch traitCollection.userInterfaceStyle {
|
||||
case .dark:
|
||||
setBackgroundImage(.placeholder(color: Asset.Scene.Profile.RelationshipButton.backgroundDark.color), for: .normal)
|
||||
setBackgroundImage(.placeholder(color: Asset.Scene.Profile.RelationshipButton.backgroundHighlightedDark.color), for: .highlighted)
|
||||
setBackgroundImage(.placeholder(color: Asset.Scene.Profile.RelationshipButton.backgroundHighlightedDark.color), for: .disabled)
|
||||
default:
|
||||
setBackgroundImage(.placeholder(color: Asset.Scene.Profile.RelationshipButton.backgroundLight.color), for: .normal)
|
||||
setBackgroundImage(.placeholder(color: Asset.Scene.Profile.RelationshipButton.backgroundHighlightedLight.color), for: .highlighted)
|
||||
setBackgroundImage(.placeholder(color: Asset.Scene.Profile.RelationshipButton.backgroundHighlightedLight.color), for: .disabled)
|
||||
}
|
||||
setBackgroundImage(.placeholder(color: Asset.Scene.Profile.RelationshipButton.background.color), for: .normal)
|
||||
setBackgroundImage(.placeholder(color: Asset.Scene.Profile.RelationshipButton.backgroundHighlighted.color), for: .highlighted)
|
||||
setBackgroundImage(.placeholder(color: Asset.Scene.Profile.RelationshipButton.backgroundHighlighted.color), for: .disabled)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue