diff --git a/Mastodon/Scene/Settings/About Mastodon/AboutViewController.swift b/Mastodon/Scene/Settings/About Mastodon/AboutViewController.swift index 22bbc9ffe..85fd73788 100644 --- a/Mastodon/Scene/Settings/About Mastodon/AboutViewController.swift +++ b/Mastodon/Scene/Settings/About Mastodon/AboutViewController.swift @@ -3,6 +3,7 @@ import UIKit import MastodonCore import MastodonLocalization +import MastodonAsset protocol AboutViewControllerDelegate: AnyObject { func didSelect(_ viewController: AboutViewController, entry: AboutSettingsEntry) @@ -11,6 +12,9 @@ protocol AboutViewControllerDelegate: AnyObject { class AboutViewController: UIViewController { let tableView: UITableView + let tableFooterView: UIView + let versionLabel: UILabel + private(set) var sections: [AboutSettingsSection] = [] var tableViewDataSource: UITableViewDiffableDataSource? weak var delegate: AboutViewControllerDelegate? @@ -21,6 +25,17 @@ class AboutViewController: UIViewController { tableView.translatesAutoresizingMaskIntoConstraints = false tableView.register(AboutMastodonTableViewCell.self, forCellReuseIdentifier: AboutMastodonTableViewCell.reuseIdentifier) + versionLabel = UILabel() + versionLabel.translatesAutoresizingMaskIntoConstraints = false + versionLabel.text = "Mastodon for iOS v\(UIApplication.appVersion()) (\(UIApplication.appBuild()))" + versionLabel.font = UIFontMetrics(forTextStyle: .footnote).scaledFont(for: .systemFont(ofSize: 12, weight: .regular)) + versionLabel.textColor = Asset.Colors.Label.secondary.color + versionLabel.numberOfLines = 0 + versionLabel.textAlignment = .center + + tableFooterView = UIView() + tableFooterView.addSubview(versionLabel) + super.init(nibName: nil, bundle: nil) let tableViewDataSource = UITableViewDiffableDataSource(tableView: tableView) { [weak self] tableView, indexPath, itemIdentifier in @@ -36,13 +51,15 @@ class AboutViewController: UIViewController { tableView.delegate = self tableView.dataSource = tableViewDataSource + tableView.tableFooterView = tableFooterView + self.tableViewDataSource = tableViewDataSource view.addSubview(tableView) view.backgroundColor = .systemGroupedBackground title = L10n.Scene.Settings.AboutMastodon.title - tableView.pinToParent() + setupConstraints() } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } @@ -61,6 +78,38 @@ class AboutViewController: UIViewController { ) } + override func viewDidLayoutSubviews() { + super.viewDidLayoutSubviews() + guard let footerView = self.tableView.tableFooterView else { + return + } + + let width = self.tableView.bounds.size.width + let size = footerView.systemLayoutSizeFitting(CGSize(width: width, height: UIView.layoutFittingCompressedSize.height)) + if footerView.frame.size.height != size.height { + footerView.frame.size.height = size.height + self.tableView.tableFooterView = footerView + } + } + + private func setupConstraints() { + let constraints = [ + tableView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor), + tableView.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor), + view.trailingAnchor.constraint(equalTo: tableView.safeAreaLayoutGuide.trailingAnchor), + view.bottomAnchor.constraint(equalTo: tableView.safeAreaLayoutGuide.bottomAnchor), + + versionLabel.topAnchor.constraint(equalTo: tableFooterView.topAnchor, constant: 8), + versionLabel.leadingAnchor.constraint(equalTo: tableFooterView.leadingAnchor), + tableFooterView.trailingAnchor.constraint(equalTo: versionLabel.trailingAnchor), + tableFooterView.bottomAnchor.constraint(equalTo: versionLabel.bottomAnchor, constant: 16), + + ] + + NSLayoutConstraint.activate(constraints) + } + + func update(with sections: [AboutSettingsSection]) { self.sections = sections diff --git a/Mastodon/Scene/Settings/Settings Overview/SettingsViewController.swift b/Mastodon/Scene/Settings/Settings Overview/SettingsViewController.swift index b2bb029c9..85cb99055 100644 --- a/Mastodon/Scene/Settings/Settings Overview/SettingsViewController.swift +++ b/Mastodon/Scene/Settings/Settings Overview/SettingsViewController.swift @@ -43,6 +43,7 @@ class SettingsViewController: UIViewController { tableView.dataSource = tableViewDataSource tableView.delegate = self + self.tableViewDataSource = tableViewDataSource navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Done", style: .done, target: self, action: #selector(SettingsViewController.done(_:))) @@ -52,7 +53,7 @@ class SettingsViewController: UIViewController { title = "Settings" - setupConstraints() + tableView.pinToParent() } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } @@ -70,17 +71,6 @@ class SettingsViewController: UIViewController { tableViewDataSource?.apply(snapshot) } - private func setupConstraints() { - let constraints = [ - tableView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor), - tableView.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor), - view.trailingAnchor.constraint(equalTo: tableView.safeAreaLayoutGuide.trailingAnchor), - view.bottomAnchor.constraint(equalTo: tableView.safeAreaLayoutGuide.bottomAnchor), - ] - - NSLayoutConstraint.activate(constraints) - } - //MARK: Actions @objc diff --git a/MastodonSDK/Sources/MastodonUI/Extension/MetaLabel.swift b/MastodonSDK/Sources/MastodonUI/Extension/MetaLabel.swift index 81f45dca1..b352bdbc2 100644 --- a/MastodonSDK/Sources/MastodonUI/Extension/MetaLabel.swift +++ b/MastodonSDK/Sources/MastodonUI/Extension/MetaLabel.swift @@ -25,7 +25,6 @@ extension MetaLabel { case profileCardFamiliarFollowerFooter case recommendAccountName case titleView - case settingTableFooter case autoCompletion case accountListName case accountListUsername @@ -111,13 +110,6 @@ extension MetaLabel { font = .systemFont(ofSize: 18, weight: .semibold) textColor = .white - case .settingTableFooter: - font = .preferredFont(forTextStyle: .footnote) - textColor = Asset.Colors.Label.secondary.color - numberOfLines = 0 - textContainer.maximumNumberOfLines = 0 - paragraphStyle.alignment = .center - case .autoCompletion: font = UIFontMetrics(forTextStyle: .headline).scaledFont(for: .systemFont(ofSize: 17, weight: .semibold), maximumPointSize: 22) textColor = Asset.Colors.Brand.blurple.color