Use native navigationItem instead of bottom-view (#690)

This commit is contained in:
Nathan Mattes 2022-12-11 23:57:58 +01:00
parent c22f1fc66e
commit 3a00010d89
4 changed files with 21 additions and 100 deletions

View File

@ -67,8 +67,6 @@ extension MastodonConfirmEmailViewController {
override func viewDidLoad() {
navigationItem.leftBarButtonItem = UIBarButtonItem()
setupOnboardingAppearance()
configureTitleLabel()
configureMargin()

View File

@ -234,7 +234,6 @@ extension MastodonPickServerViewController {
}
.store(in: &disposeBag)
navigationActionView.backButton.addTarget(self, action: #selector(MastodonPickServerViewController.backButtonDidPressed(_:)), for: .touchUpInside)
navigationActionView.nextButton.addTarget(self, action: #selector(MastodonPickServerViewController.nextButtonDidPressed(_:)), for: .touchUpInside)
}
@ -261,10 +260,6 @@ extension MastodonPickServerViewController {
extension MastodonPickServerViewController {
@objc private func backButtonDidPressed(_ sender: UIButton) {
navigationController?.popViewController(animated: true)
}
@objc private func nextButtonDidPressed(_ sender: UIButton) {
os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s", ((#file as NSString).lastPathComponent), #line, #function)
guard let server = viewModel.selectedServer.value else { return }

View File

@ -54,17 +54,6 @@ final class MastodonRegisterViewController: UIViewController, NeedsDependency, O
documentPickerController.delegate = self
return documentPickerController
}()
let navigationActionView: NavigationActionView = {
let navigationActionView = NavigationActionView()
navigationActionView.backgroundColor = Asset.Scene.Onboarding.background.color
return navigationActionView
}()
deinit {
os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s", (#file as NSString).lastPathComponent, #line, #function)
}
}
extension MastodonRegisterViewController {
@ -72,8 +61,6 @@ extension MastodonRegisterViewController {
override func viewDidLoad() {
super.viewDidLoad()
navigationItem.leftBarButtonItem = UIBarButtonItem()
setupOnboardingAppearance()
viewModel.backgroundColor = view.backgroundColor ?? .clear
defer {
@ -87,33 +74,13 @@ extension MastodonRegisterViewController {
view.addSubview(hostingViewController.view)
hostingViewController.view.pinToParent()
navigationActionView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(navigationActionView)
defer {
view.bringSubviewToFront(navigationActionView)
}
NSLayoutConstraint.activate([
navigationActionView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
navigationActionView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
view.bottomAnchor.constraint(equalTo: navigationActionView.bottomAnchor),
])
navigationActionView
.observe(\.bounds, options: [.initial, .new]) { [weak self] navigationActionView, _ in
guard let self = self else { return }
let inset = navigationActionView.frame.height
self.viewModel.bottomPaddingHeight = inset
}
.store(in: &observations)
navigationActionView.backButton.addTarget(self, action: #selector(MastodonRegisterViewController.backButtonPressed(_:)), for: .touchUpInside)
navigationActionView.nextButton.addTarget(self, action: #selector(MastodonRegisterViewController.nextButtonPressed(_:)), for: .touchUpInside)
navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Next", style: .done, target: self, action: #selector(MastodonRegisterViewController.nextButtonPressed(_:)))
viewModel.$isAllValid
.receive(on: DispatchQueue.main)
.sink { [weak self] isAllValid in
guard let self = self else { return }
self.navigationActionView.nextButton.isEnabled = isAllValid
self.navigationItem.rightBarButtonItem?.isEnabled = isAllValid
}
.store(in: &disposeBag)
@ -165,13 +132,15 @@ extension MastodonRegisterViewController {
}
.store(in: &disposeBag)
viewModel.$isRegistering
.receive(on: DispatchQueue.main)
.sink { [weak self] isRegistering in
guard let self = self else { return }
isRegistering ? self.navigationActionView.nextButton.showLoading() : self.navigationActionView.nextButton.stopLoading()
}
.store(in: &disposeBag)
// viewModel.$isRegistering
// .receive(on: DispatchQueue.main)
// .sink { [weak self] isRegistering in
// guard let self = self else { return }
// isRegistering ? self.navigationActionView.nextButton.showLoading() : self.navigationActionView.nextButton.stopLoading()
// }
// .store(in: &disposeBag)
title = L10n.Scene.Register.title(viewModel.domain)
}
override func viewDidAppear(_ animated: Bool) {
@ -184,11 +153,6 @@ extension MastodonRegisterViewController {
extension MastodonRegisterViewController {
@objc private func backButtonPressed(_ sender: UIButton) {
logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public)")
navigationController?.popViewController(animated: true)
}
@objc private func nextButtonPressed(_ sender: UIButton) {
logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public)")

View File

@ -27,8 +27,6 @@ final class MastodonServerRulesViewController: UIViewController, NeedsDependency
var viewModel: MastodonServerRulesViewModel!
let stackView = UIStackView()
let tableView: UITableView = {
let tableView = UITableView()
tableView.register(OnboardingHeadlineTableViewCell.self, forCellReuseIdentifier: String(describing: OnboardingHeadlineTableViewCell.self))
@ -40,17 +38,6 @@ final class MastodonServerRulesViewController: UIViewController, NeedsDependency
tableView.sectionHeaderTopPadding = 0
return tableView
}()
let navigationActionView: NavigationActionView = {
let navigationActionView = NavigationActionView()
navigationActionView.backgroundColor = Asset.Scene.Onboarding.background.color
return navigationActionView
}()
deinit {
os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s", ((#file as NSString).lastPathComponent), #line, #function)
}
}
extension MastodonServerRulesViewController {
@ -58,8 +45,6 @@ extension MastodonServerRulesViewController {
override func viewDidLoad() {
super.viewDidLoad()
navigationItem.leftBarButtonItem = UIBarButtonItem()
setupOnboardingAppearance()
defer { setupNavigationBarBackgroundView() }
@ -67,30 +52,12 @@ extension MastodonServerRulesViewController {
view.addSubview(tableView)
tableView.pinToParent()
navigationActionView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(navigationActionView)
defer {
view.bringSubviewToFront(navigationActionView)
}
NSLayoutConstraint.activate([
navigationActionView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
navigationActionView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
view.bottomAnchor.constraint(equalTo: navigationActionView.bottomAnchor),
])
navigationActionView
.observe(\.bounds, options: [.initial, .new]) { [weak self] navigationActionView, _ in
guard let self = self else { return }
let inset = navigationActionView.frame.height
self.tableView.contentInset.bottom = inset
}
.store(in: &observations)
tableView.delegate = self
viewModel.setupDiffableDataSource(tableView: tableView)
navigationActionView.backButton.addTarget(self, action: #selector(MastodonServerRulesViewController.backButtonPressed(_:)), for: .touchUpInside)
navigationActionView.nextButton.addTarget(self, action: #selector(MastodonServerRulesViewController.nextButtonPressed(_:)), for: .touchUpInside)
navigationItem.rightBarButtonItem = UIBarButtonItem(title: "I agree", style: .done, target: self, action: #selector(MastodonServerRulesViewController.nextButtonPressed(_:)))
title = L10n.Scene.ServerRules.title
}
override func viewDidAppear(_ animated: Bool) {
@ -104,13 +71,10 @@ extension MastodonServerRulesViewController {
extension MastodonServerRulesViewController {
@objc private func backButtonPressed(_ sender: UIButton) {
logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public)")
navigationController?.popViewController(animated: true)
}
@objc private func nextButtonPressed(_ sender: UIButton) {
logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public)")
let viewModel = MastodonRegisterViewModel(
context: context,
domain: viewModel.domain,