diff --git a/Mastodon.xcodeproj/project.pbxproj b/Mastodon.xcodeproj/project.pbxproj index 492f2f38d..ebcbe8783 100644 --- a/Mastodon.xcodeproj/project.pbxproj +++ b/Mastodon.xcodeproj/project.pbxproj @@ -17,7 +17,6 @@ 0FAA101C25E10E760017CCDE /* UIFont.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0FAA101B25E10E760017CCDE /* UIFont.swift */; }; 0FAA102725E1126A0017CCDE /* MastodonPickServerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0FAA102625E1126A0017CCDE /* MastodonPickServerViewController.swift */; }; 0FB3D2F725E4C24D00AAD544 /* MastodonPickServerViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0FB3D2F625E4C24D00AAD544 /* MastodonPickServerViewModel.swift */; }; - 0FB3D2FE25E4CB6400AAD544 /* OnboardingHeadlineTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0FB3D2FD25E4CB6400AAD544 /* OnboardingHeadlineTableViewCell.swift */; }; 0FB3D30F25E525CD00AAD544 /* PickServerCategoryView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0FB3D30E25E525CD00AAD544 /* PickServerCategoryView.swift */; }; 0FB3D31E25E534C700AAD544 /* PickServerCategoryCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0FB3D31D25E534C700AAD544 /* PickServerCategoryCollectionViewCell.swift */; }; 0FB3D33825E6401400AAD544 /* PickServerCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0FB3D33725E6401400AAD544 /* PickServerCell.swift */; }; @@ -546,7 +545,6 @@ 0FAA101B25E10E760017CCDE /* UIFont.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIFont.swift; sourceTree = ""; }; 0FAA102625E1126A0017CCDE /* MastodonPickServerViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MastodonPickServerViewController.swift; sourceTree = ""; }; 0FB3D2F625E4C24D00AAD544 /* MastodonPickServerViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MastodonPickServerViewModel.swift; sourceTree = ""; }; - 0FB3D2FD25E4CB6400AAD544 /* OnboardingHeadlineTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OnboardingHeadlineTableViewCell.swift; sourceTree = ""; }; 0FB3D30E25E525CD00AAD544 /* PickServerCategoryView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PickServerCategoryView.swift; sourceTree = ""; }; 0FB3D31D25E534C700AAD544 /* PickServerCategoryCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PickServerCategoryCollectionViewCell.swift; sourceTree = ""; }; 0FB3D33725E6401400AAD544 /* PickServerCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PickServerCell.swift; sourceTree = ""; }; @@ -2157,7 +2155,6 @@ DB029E94266A20430062874E /* MastodonAuthenticationController.swift */, 2D82B9FE25E7863200E36F0F /* OnboardingViewControllerAppearance.swift */, DB0617EC277F02C50030EE79 /* OnboardingNavigationController.swift */, - 0FB3D2FD25E4CB6400AAD544 /* OnboardingHeadlineTableViewCell.swift */, DB0617EE277F12720030EE79 /* NavigationActionView.swift */, ); path = Share; @@ -3413,7 +3410,6 @@ 6213AF5A28939C8400BCADB6 /* BookmarkViewModel.swift in Sources */, 5B24BBDB262DB14800A9381B /* ReportStatusViewModel+Diffable.swift in Sources */, DB4F0968269ED8AD00D62E92 /* SearchHistoryTableHeaderView.swift in Sources */, - 0FB3D2FE25E4CB6400AAD544 /* OnboardingHeadlineTableViewCell.swift in Sources */, 5DA732CC2629CEF500A92342 /* UIView+Remove.swift in Sources */, 2A506CF4292CD85800059C37 /* FollowedTagsViewController.swift in Sources */, DB1D843026566512000346B3 /* KeyboardPreference.swift in Sources */, diff --git a/Mastodon/Scene/Onboarding/Privacy/PrivacyTableViewController.swift b/Mastodon/Scene/Onboarding/Privacy/PrivacyTableViewController.swift index 903907b2d..6c10ed23d 100644 --- a/Mastodon/Scene/Onboarding/Privacy/PrivacyTableViewController.swift +++ b/Mastodon/Scene/Onboarding/Privacy/PrivacyTableViewController.swift @@ -71,7 +71,7 @@ class PrivacyTableViewController: UIViewController, NeedsDependency { private func setupConstraints() { let constraints = [ - tableView.topAnchor.constraint(equalTo: view.topAnchor), + tableView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor), tableView.leadingAnchor.constraint(equalTo: view.leadingAnchor), view.trailingAnchor.constraint(equalTo: tableView.trailingAnchor), view.bottomAnchor.constraint(equalTo: tableView.bottomAnchor) @@ -79,6 +79,12 @@ class PrivacyTableViewController: UIViewController, NeedsDependency { NSLayoutConstraint.activate(constraints) } + override func viewDidLoad() { + super.viewDidLoad() + + setupOnboardingAppearance() + } + //MARK: - Actions @objc private func backButtonPressed(_ sender: UIButton) { navigationController?.popViewController(animated: true) @@ -124,4 +130,26 @@ extension PrivacyTableViewController: UITableViewDelegate { _ = coordinator.present(scene: .safari(url: url), from: self, transition: .safariPresent(animated: true)) } + + func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { + let wrapper = UIView() + + let label = UILabel() + label.translatesAutoresizingMaskIntoConstraints = false + label.numberOfLines = 0 + label.text = L10n.Scene.Privacy.description + label.textColor = Asset.Colors.Label.primary.color + wrapper.addSubview(label) + + NSLayoutConstraint.activate([ + label.topAnchor.constraint(equalTo: wrapper.topAnchor, constant: 16), + label.leadingAnchor.constraint(equalTo: wrapper.leadingAnchor), + wrapper.trailingAnchor.constraint(equalTo: label.trailingAnchor), + wrapper.bottomAnchor.constraint(equalTo: label.bottomAnchor, constant: 16), + ]) + + return wrapper + } } + +extension PrivacyTableViewController: OnboardingViewControllerAppearance { } diff --git a/Mastodon/Scene/Onboarding/ServerRules/Cell/ServerRulesTableViewCell.swift b/Mastodon/Scene/Onboarding/ServerRules/Cell/ServerRulesTableViewCell.swift index 1c6705de6..94fbeec41 100644 --- a/Mastodon/Scene/Onboarding/ServerRules/Cell/ServerRulesTableViewCell.swift +++ b/Mastodon/Scene/Onboarding/ServerRules/Cell/ServerRulesTableViewCell.swift @@ -27,12 +27,6 @@ final class ServerRulesTableViewCell: UITableViewCell { return label }() - let separatorLine: UIView = { - let view = UIView() - view.backgroundColor = Asset.Theme.System.separator.color - return view - }() - override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { super.init(style: style, reuseIdentifier: reuseIdentifier) _init() diff --git a/Mastodon/Scene/Onboarding/ServerRules/MastodonServerRulesViewController.swift b/Mastodon/Scene/Onboarding/ServerRules/MastodonServerRulesViewController.swift index 69e16fcc4..5ad1b740c 100644 --- a/Mastodon/Scene/Onboarding/ServerRules/MastodonServerRulesViewController.swift +++ b/Mastodon/Scene/Onboarding/ServerRules/MastodonServerRulesViewController.swift @@ -29,10 +29,8 @@ final class MastodonServerRulesViewController: UIViewController, NeedsDependency let tableView: UITableView = { let tableView = UITableView(frame: .zero, style: .insetGrouped) - tableView.register(OnboardingHeadlineTableViewCell.self, forCellReuseIdentifier: String(describing: OnboardingHeadlineTableViewCell.self)) tableView.register(ServerRulesTableViewCell.self, forCellReuseIdentifier: String(describing: ServerRulesTableViewCell.self)) tableView.rowHeight = UITableView.automaticDimension - tableView.backgroundColor = .secondarySystemGroupedBackground tableView.keyboardDismissMode = .onDrag tableView.sectionHeaderTopPadding = 0 return tableView @@ -54,7 +52,6 @@ extension MastodonServerRulesViewController { tableView.delegate = self viewModel.setupDiffableDataSource(tableView: tableView) - navigationItem.rightBarButtonItem = UIBarButtonItem(title: L10n.Scene.ServerRules.Button.confirm, style: .done, target: self, action: #selector(MastodonServerRulesViewController.nextButtonPressed(_:))) title = L10n.Scene.ServerRules.title } @@ -86,20 +83,24 @@ extension MastodonServerRulesViewController: OnboardingViewControllerAppearance // MARK: - UITableViewDelegate extension MastodonServerRulesViewController: UITableViewDelegate { func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { - return UIView() - } - - func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { - guard let diffableDataSource = viewModel.diffableDataSource, - section < diffableDataSource.snapshot().numberOfSections - else { return .leastNonzeroMagnitude } - - let sectionItem = diffableDataSource.snapshot().sectionIdentifiers[section] - switch sectionItem { - case .header: - return .leastNonzeroMagnitude - case .rules: - return 16 - } + let wrapper = UIView() + + let label = UILabel() + label.translatesAutoresizingMaskIntoConstraints = false + label.font = MastodonPickServerViewController.subTitleFont + label.textColor = Asset.Colors.Label.primary.color + label.adjustsFontForContentSizeCategory = true + label.numberOfLines = 0 + label.text = L10n.Scene.ServerRules.subtitle(viewModel.domain) + wrapper.addSubview(label) + + NSLayoutConstraint.activate([ + label.topAnchor.constraint(equalTo: wrapper.topAnchor, constant: 16), + label.leadingAnchor.constraint(equalTo: wrapper.leadingAnchor), + wrapper.trailingAnchor.constraint(equalTo: label.trailingAnchor), + wrapper.bottomAnchor.constraint(equalTo: label.bottomAnchor, constant: 16), + ]) + + return wrapper } } diff --git a/Mastodon/Scene/Onboarding/ServerRules/MastodonServerRulesViewModel+Diffable.swift b/Mastodon/Scene/Onboarding/ServerRules/MastodonServerRulesViewModel+Diffable.swift index ecb868eb0..1f8d55c76 100644 --- a/Mastodon/Scene/Onboarding/ServerRules/MastodonServerRulesViewModel+Diffable.swift +++ b/Mastodon/Scene/Onboarding/ServerRules/MastodonServerRulesViewModel+Diffable.swift @@ -14,8 +14,7 @@ extension MastodonServerRulesViewModel { diffableDataSource = ServerRuleSection.tableViewDiffableDataSource(tableView: tableView) var snapshot = NSDiffableDataSourceSnapshot() - snapshot.appendSections([.header, .rules]) - snapshot.appendItems([.header(domain: domain)], toSection: .header) + snapshot.appendSections([.rules]) let ruleItems: [ServerRuleItem] = rules.enumerated().map { i, rule in let ruleContext = ServerRuleItem.RuleContext(index: i, rule: rule) return ServerRuleItem.rule(ruleContext) diff --git a/Mastodon/Scene/Onboarding/ServerRules/ServerRuleItem.swift b/Mastodon/Scene/Onboarding/ServerRules/ServerRuleItem.swift index 37d8b6ee7..f82b1e5e4 100644 --- a/Mastodon/Scene/Onboarding/ServerRules/ServerRuleItem.swift +++ b/Mastodon/Scene/Onboarding/ServerRules/ServerRuleItem.swift @@ -9,7 +9,6 @@ import Foundation import MastodonSDK enum ServerRuleItem: Hashable { - case header(domain: String) case rule(RuleContext) } diff --git a/Mastodon/Scene/Onboarding/ServerRules/ServerRuleSection.swift b/Mastodon/Scene/Onboarding/ServerRules/ServerRuleSection.swift index 3ec8bb2dc..4c589e041 100644 --- a/Mastodon/Scene/Onboarding/ServerRules/ServerRuleSection.swift +++ b/Mastodon/Scene/Onboarding/ServerRules/ServerRuleSection.swift @@ -10,7 +10,6 @@ import MastodonAsset import MastodonLocalization enum ServerRuleSection: Hashable { - case header case rules } @@ -20,10 +19,6 @@ extension ServerRuleSection { ) -> UITableViewDiffableDataSource { return UITableViewDiffableDataSource(tableView: tableView) { tableView, indexPath, item in switch item { - case .header(let domain): - let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: OnboardingHeadlineTableViewCell.self), for: indexPath) as! OnboardingHeadlineTableViewCell - cell.subTitleLabel.text = L10n.Scene.ServerRules.subtitle(domain) - return cell case .rule(let ruleContext): let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: ServerRulesTableViewCell.self), for: indexPath) as! ServerRulesTableViewCell cell.indexImageView.image = UIImage(systemName: "\(ruleContext.index + 1).circle") ?? UIImage(systemName: "questionmark.circle") diff --git a/Mastodon/Scene/Onboarding/Share/OnboardingHeadlineTableViewCell.swift b/Mastodon/Scene/Onboarding/Share/OnboardingHeadlineTableViewCell.swift deleted file mode 100644 index a1e2894dc..000000000 --- a/Mastodon/Scene/Onboarding/Share/OnboardingHeadlineTableViewCell.swift +++ /dev/null @@ -1,57 +0,0 @@ -// -// OnboardingHeadlineTableViewCell.swift -// Mastodon -// -// Created by BradGao on 2021/2/23. -// - -import UIKit -import MastodonAsset -import MastodonLocalization - -final class OnboardingHeadlineTableViewCell: UITableViewCell { - - static let reuseIdentifier = "OnboardingHeadlineTableViewCell" - - let subTitleLabel: UILabel = { - let label = UILabel() - label.font = MastodonPickServerViewController.subTitleFont - label.textColor = Asset.Colors.Label.primary.color - label.adjustsFontForContentSizeCategory = true - label.numberOfLines = 0 - return label - }() - - override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { - super.init(style: style, reuseIdentifier: reuseIdentifier) - _init() - } - - required init?(coder: NSCoder) { - super.init(coder: coder) - _init() - } -} - -extension OnboardingHeadlineTableViewCell { - - private func _init() { - selectionStyle = .none - backgroundColor = Asset.Scene.Onboarding.background.color - - let container = UIStackView() - container.axis = .vertical - container.spacing = 16 - container.translatesAutoresizingMaskIntoConstraints = false - contentView.addSubview(container) - NSLayoutConstraint.activate([ - container.topAnchor.constraint(equalTo: contentView.topAnchor), - container.leadingAnchor.constraint(equalTo: contentView.readableContentGuide.leadingAnchor), - container.trailingAnchor.constraint(equalTo: contentView.readableContentGuide.trailingAnchor), - contentView.bottomAnchor.constraint(equalTo: container.bottomAnchor), - ]) - - container.addArrangedSubview(subTitleLabel) - } - -}