From 0f9ab62415bb430b779b877036a57c31f485185e Mon Sep 17 00:00:00 2001 From: Justin Mazzocchi <2831158+jzzocc@users.noreply.github.com> Date: Sat, 30 Jan 2021 22:47:49 -0800 Subject: [PATCH] UI adjustments --- Views/UIKit/CapsuleButton.swift | 7 +++++++ Views/UIKit/PollView.swift | 13 ++----------- Views/UIKit/StatusBodyView.swift | 6 ++---- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/Views/UIKit/CapsuleButton.swift b/Views/UIKit/CapsuleButton.swift index df0e4f1..e51b6dc 100644 --- a/Views/UIKit/CapsuleButton.swift +++ b/Views/UIKit/CapsuleButton.swift @@ -25,6 +25,12 @@ final class CapsuleButton: UIButton { backgroundColor = isHighlighted ? Self.highlightedColor : .link } } + + override var isEnabled: Bool { + didSet { + backgroundColor = isEnabled ? .link : UIColor.link.withAlphaComponent(0.5) + } + } } private extension CapsuleButton { @@ -45,5 +51,6 @@ private extension CapsuleButton { titleLabel?.font = .preferredFont(forTextStyle: .headline) setTitleColor(.white, for: .normal) setTitleColor(.lightText, for: .highlighted) + setTitleColor(.lightText, for: .disabled) } } diff --git a/Views/UIKit/PollView.swift b/Views/UIKit/PollView.swift index ad2570d..8fb3b2e 100644 --- a/Views/UIKit/PollView.swift +++ b/Views/UIKit/PollView.swift @@ -7,9 +7,8 @@ import ViewModels final class PollView: UIView { private let stackView = UIStackView() - private let voteButtonStackView = UIStackView() private let bottomStackView = UIStackView() - private let voteButton = UIButton(type: .system) + private let voteButton = CapsuleButton() private let refreshButton = UIButton(type: .system) private let refreshDividerLabel = UILabel() private let votesCountLabel = UILabel() @@ -65,7 +64,7 @@ final class PollView: UIView { } if !viewModel.isPollExpired, !viewModel.hasVotedInPoll { - stackView.addArrangedSubview(voteButtonStackView) + stackView.addArrangedSubview(voteButton) selectionCancellable = viewModel.$pollOptionSelections.sink { [weak self] in guard let self = self else { return } @@ -147,11 +146,6 @@ private extension PollView { stackView.axis = .vertical stackView.spacing = .defaultSpacing - voteButtonStackView.addArrangedSubview(voteButton) - voteButtonStackView.addArrangedSubview(UIView()) - - voteButton.titleLabel?.font = .preferredFont(forTextStyle: .headline) - voteButton.titleLabel?.adjustsFontForContentSizeCategory = true voteButton.setTitle(NSLocalizedString("status.poll.vote", comment: ""), for: .normal) voteButton.addAction(UIAction { [weak self] _ in self?.viewModel?.vote() }, for: .touchUpInside) @@ -175,19 +169,16 @@ private extension PollView { bottomStackView.addArrangedSubview(UIView()) - let voteButtonHeightConstraint = voteButton.heightAnchor.constraint(equalToConstant: .minimumButtonDimension) let refreshButtonHeightConstraint = refreshButton.heightAnchor.constraint( equalToConstant: .minimumButtonDimension / 2) refreshButtonHeightConstraint.priority = .justBelowMax - refreshButtonHeightConstraint.priority = .justBelowMax NSLayoutConstraint.activate([ stackView.leadingAnchor.constraint(equalTo: leadingAnchor), stackView.topAnchor.constraint(equalTo: topAnchor), stackView.trailingAnchor.constraint(equalTo: trailingAnchor), stackView.bottomAnchor.constraint(equalTo: bottomAnchor), - voteButtonHeightConstraint, refreshButtonHeightConstraint ]) } diff --git a/Views/UIKit/StatusBodyView.swift b/Views/UIKit/StatusBodyView.swift index 749dc0e..79d79be 100644 --- a/Views/UIKit/StatusBodyView.swift +++ b/Views/UIKit/StatusBodyView.swift @@ -6,7 +6,7 @@ import ViewModels final class StatusBodyView: UIView { let spoilerTextLabel = UILabel() - let toggleShowContentButton = UIButton(type: .system) + let toggleShowContentButton = CapsuleButton() let contentTextView = TouchFallthroughTextView() let attachmentsView = AttachmentsView() let pollView = PollView() @@ -152,14 +152,12 @@ private extension StatusBodyView { addSubview(stackView) stackView.translatesAutoresizingMaskIntoConstraints = false stackView.axis = .vertical - stackView.spacing = .compactSpacing + stackView.spacing = .defaultSpacing spoilerTextLabel.numberOfLines = 0 spoilerTextLabel.adjustsFontForContentSizeCategory = true stackView.addArrangedSubview(spoilerTextLabel) - toggleShowContentButton.titleLabel?.font = .preferredFont(forTextStyle: .headline) - toggleShowContentButton.titleLabel?.adjustsFontForContentSizeCategory = true toggleShowContentButton.addAction( UIAction { [weak self] _ in self?.viewModel?.toggleShowContent() }, for: .touchUpInside)