Skip to content

Commit

Permalink
Fix Follow-Button in App-Dark Mode (#1218) (#1222)
Browse files Browse the repository at this point in the history
* Don't set colors (#1218

* Use UIButton.configuration for ... configuration (#1218)

* Fix activity indicator (#1218)
  • Loading branch information
zeitschlag authored Feb 9, 2024
1 parent a236e11 commit a90d5ea
Showing 1 changed file with 25 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,76 +9,39 @@ import UIKit
import MastodonAsset
import MastodonLocalization

public final class ProfileRelationshipActionButton: RoundedEdgesButton {

public let activityIndicatorView: UIActivityIndicatorView = {
let activityIndicatorView = UIActivityIndicatorView(style: .medium)
activityIndicatorView.color = Asset.Colors.Label.primaryReverse.color
return activityIndicatorView
}()

public override init(frame: CGRect) {
super.init(frame: frame)
_init()
}

public required init?(coder: NSCoder) {
super.init(coder: coder)
_init()
}

}
public final class ProfileRelationshipActionButton: UIButton {
public func configure(actionOptionSet: RelationshipActionOptionSet) {

extension ProfileRelationshipActionButton {
private func _init() {
cornerRadius = 10
titleLabel?.font = .systemFont(ofSize: 17, weight: .semibold)

activityIndicatorView.translatesAutoresizingMaskIntoConstraints = false
addSubview(activityIndicatorView)
NSLayoutConstraint.activate([
activityIndicatorView.centerXAnchor.constraint(equalTo: centerXAnchor),
activityIndicatorView.centerYAnchor.constraint(equalTo: centerYAnchor),
])

activityIndicatorView.hidesWhenStopped = true
activityIndicatorView.stopAnimating()

configureAppearance()
}

public override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)

configureAppearance()
}
}
var configuration = UIButton.Configuration.filled()

extension ProfileRelationshipActionButton {
public func configure(actionOptionSet: RelationshipActionOptionSet) {
setTitle(actionOptionSet.title, for: .normal)

configureAppearance()

titleEdgeInsets = UIEdgeInsets(top: 0, left: 4, bottom: 0, right: 4)

activityIndicatorView.stopAnimating()

configuration.contentInsets = NSDirectionalEdgeInsets(top: 0, leading: 4, bottom: 0, trailing: 4)
configuration.baseBackgroundColor = Asset.Scene.Profile.RelationshipButton.background.color
configuration.activityIndicatorColorTransformer = UIConfigurationColorTransformer({ _ in return Asset.Colors.Label.primaryReverse.color })
configuration.background.cornerRadius = 10

let title: String
if let option = actionOptionSet.highPriorityAction(except: .editOptions), option == .blocked || option == .suspended {
isEnabled = false
configuration.showsActivityIndicator = false
title = actionOptionSet.title
} else if actionOptionSet.contains(.updating) {
isEnabled = false
activityIndicatorView.startAnimating()
configuration.showsActivityIndicator = true
title = ""
} else {
isEnabled = true
configuration.showsActivityIndicator = false
title = actionOptionSet.title
}
}

private func configureAppearance() {
setTitleColor(Asset.Colors.Label.primaryReverse.color, for: .normal)
setTitleColor(Asset.Colors.Label.primaryReverse.color.withAlphaComponent(0.5), for: .highlighted)
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)

configuration.attributedTitle = AttributedString(
title,
attributes: AttributeContainer([
.font: UIFont.systemFont(ofSize: 17, weight: .semibold),
.foregroundColor: Asset.Colors.Label.primaryReverse.color
])
)

self.configuration = configuration
}
}

0 comments on commit a90d5ea

Please sign in to comment.