From be11f632cc55a3738486885896fa9c5b2492da02 Mon Sep 17 00:00:00 2001 From: Nathan Mattes Date: Tue, 26 Sep 2023 14:26:16 +0200 Subject: [PATCH] Disable "Follow all"-button if there are no suggestions (#1124) --- .../SuggestionAccountViewController.swift | 2 ++ .../SuggestionAccountViewModel.swift | 2 +- .../SuggestionAccountTableViewFooter.swift | 20 +++++++++---------- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/Mastodon/Scene/SuggestionAccount/SuggestionAccountViewController.swift b/Mastodon/Scene/SuggestionAccount/SuggestionAccountViewController.swift index 4962d3e71..35e1f929d 100644 --- a/Mastodon/Scene/SuggestionAccount/SuggestionAccountViewController.swift +++ b/Mastodon/Scene/SuggestionAccount/SuggestionAccountViewController.swift @@ -104,6 +104,8 @@ extension SuggestionAccountViewController: UITableViewDelegate { return nil } + footerView.followAllButton.isEnabled = viewModel.userFetchedResultsController.records.isNotEmpty + footerView.delegate = self return footerView } diff --git a/Mastodon/Scene/SuggestionAccount/SuggestionAccountViewModel.swift b/Mastodon/Scene/SuggestionAccount/SuggestionAccountViewModel.swift index a57d71df0..81238105b 100644 --- a/Mastodon/Scene/SuggestionAccount/SuggestionAccountViewModel.swift +++ b/Mastodon/Scene/SuggestionAccount/SuggestionAccountViewModel.swift @@ -66,7 +66,7 @@ final class SuggestionAccountViewModel: NSObject { } - guard !userIDs.isEmpty else { return } + guard userIDs.isNotEmpty else { return } userFetchedResultsController.userIDs = userIDs } diff --git a/Mastodon/Scene/SuggestionAccount/TableView-Components/SuggestionAccountTableViewFooter.swift b/Mastodon/Scene/SuggestionAccount/TableView-Components/SuggestionAccountTableViewFooter.swift index cf0408977..3037b2ef3 100644 --- a/Mastodon/Scene/SuggestionAccount/TableView-Components/SuggestionAccountTableViewFooter.swift +++ b/Mastodon/Scene/SuggestionAccount/TableView-Components/SuggestionAccountTableViewFooter.swift @@ -14,20 +14,20 @@ class SuggestionAccountTableViewFooter: UITableViewHeaderFooterView { weak var delegate: SuggestionAccountTableViewFooterDelegate? - let followAllButton: FollowButton + let followAllButton: UIButton override init(reuseIdentifier: String?) { - //TODO: Check if we can use UIButton.configuration here instead? - followAllButton = FollowButton() - followAllButton.translatesAutoresizingMaskIntoConstraints = false - followAllButton.setTitle(L10n.Scene.SuggestionAccount.followAll, for: .normal) - followAllButton.setBackgroundColor(Asset.Colors.Button.userFollow.color, for: .normal) - followAllButton.setTitleColor(.white, for: .normal) - followAllButton.contentEdgeInsets = .init(horizontal: 20, vertical: 12) - followAllButton.cornerRadius = 10 - followAllButton.titleLabel?.font = UIFontMetrics(forTextStyle: .subheadline).scaledFont(for: .boldSystemFont(ofSize: 15)) + var buttonConfiguration = UIButton.Configuration.filled() + buttonConfiguration.baseForegroundColor = .white + buttonConfiguration.baseBackgroundColor = Asset.Colors.Button.userFollow.color + buttonConfiguration.background.cornerRadius = 10 + buttonConfiguration.attributedTitle = AttributedString(L10n.Scene.SuggestionAccount.followAll, attributes: AttributeContainer([.font: UIFontMetrics(forTextStyle: .subheadline).scaledFont(for: .boldSystemFont(ofSize: 15))])) + buttonConfiguration.contentInsets = NSDirectionalEdgeInsets(top: 12, leading: 20, bottom: 12, trailing: 20) + followAllButton = UIButton(configuration: buttonConfiguration) + followAllButton.isEnabled = false + followAllButton.translatesAutoresizingMaskIntoConstraints = false followAllButton.setContentCompressionResistancePriority(.required, for: .horizontal) followAllButton.setContentHuggingPriority(.required, for: .horizontal)