Debug a bit more

pull/249/head
nielsandriesse 5 years ago
parent f3f55d3aee
commit 67df07537e

@ -2,6 +2,7 @@
final class Button : UIButton {
private let style: Style
private let size: Size
private var heightConstraint: NSLayoutConstraint!
enum Style {
case unimportant, regular, prominentOutline, prominentFilled, regularBorderless
@ -16,6 +17,7 @@ final class Button : UIButton {
self.size = size
super.init(frame: .zero)
setUpStyle()
NotificationCenter.default.addObserver(self, selector: #selector(handleAppModeChangedNotification(_:)), name: .appModeChanged, object: nil)
}
override init(frame: CGRect) {
@ -25,7 +27,11 @@ final class Button : UIButton {
required init?(coder: NSCoder) {
preconditionFailure("Use init(style:) instead.")
}
deinit {
NotificationCenter.default.removeObserver(self)
}
private func setUpStyle() {
let fillColor: UIColor
switch style {
@ -57,7 +63,7 @@ final class Button : UIButton {
case .medium: height = Values.mediumButtonHeight
case .large: height = Values.largeButtonHeight
}
set(.height, to: height)
if heightConstraint == nil { heightConstraint = set(.height, to: height) }
layer.cornerRadius = height / 2
backgroundColor = fillColor
layer.borderColor = borderColor.cgColor
@ -66,4 +72,8 @@ final class Button : UIButton {
titleLabel!.font = .boldSystemFont(ofSize: fontSize)
setTitleColor(textColor, for: UIControl.State.normal)
}
@objc private func handleAppModeChangedNotification(_ notification: Notification) {
setUpStyle()
}
}

@ -217,6 +217,7 @@ private final class NewConversationButton : UIImageView {
self.icon = icon
super.init(frame: CGRect.zero)
setUpViewHierarchy()
NotificationCenter.default.addObserver(self, selector: #selector(handleAppModeChangedNotification(_:)), name: .appModeChanged, object: nil)
}
override init(frame: CGRect) {
@ -226,8 +227,12 @@ private final class NewConversationButton : UIImageView {
required init?(coder: NSCoder) {
preconditionFailure("Use init(isMainButton:) instead.")
}
deinit {
NotificationCenter.default.removeObserver(self)
}
private func setUpViewHierarchy() {
private func setUpViewHierarchy(isUpdate: Bool = false) {
backgroundColor = isMainButton ? Colors.accent : Colors.newConversationButtonCollapsedBackground
let size = Values.newConversationButtonCollapsedSize
layer.cornerRadius = size / 2
@ -238,8 +243,14 @@ private final class NewConversationButton : UIImageView {
let iconColor = (isMainButton && isLightMode) ? UIColor.white : Colors.text
image = icon.asTintedImage(color: iconColor)!
contentMode = .center
widthConstraint = set(.width, to: size)
heightConstraint = set(.height, to: size)
if !isUpdate {
widthConstraint = set(.width, to: size)
heightConstraint = set(.height, to: size)
}
}
@objc private func handleAppModeChangedNotification(_ notification: Notification) {
setUpViewHierarchy(isUpdate: true)
}
}

@ -80,6 +80,10 @@ class BaseVC : UIViewController {
}
}
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
// TODO: Post an appModeChanged notification?
}
@objc internal func handleAppModeChangedNotification(_ notification: Notification) {
if hasGradient {
setUpGradientBackground() // Re-do the gradient

Loading…
Cancel
Save