From 97db759242cb2bc488013612aad8cc2003e77f03 Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Thu, 4 Apr 2019 19:53:08 +0200 Subject: [PATCH] Drop empty space between Account sections Reuse code for heightForHeader. --- Passepartout-iOS/Global/Theme+Titles.swift | 22 +++++++++++++++++++ .../Scenes/AccountViewController.swift | 5 +++++ .../Scenes/ConfigurationViewController.swift | 8 +------ .../Scenes/ServiceViewController.swift | 14 ++++-------- 4 files changed, 32 insertions(+), 17 deletions(-) diff --git a/Passepartout-iOS/Global/Theme+Titles.swift b/Passepartout-iOS/Global/Theme+Titles.swift index 56bc0875..613658bf 100644 --- a/Passepartout-iOS/Global/Theme+Titles.swift +++ b/Passepartout-iOS/Global/Theme+Titles.swift @@ -34,3 +34,25 @@ extension UIViewController { navigationItem.largeTitleDisplayMode = theme.detailTitleDisplayMode } } + +extension TableModel { + func headerHeight(for section: Int) -> CGFloat { + guard let title = header(for: section) else { + return 1.0 + } + guard !title.isEmpty else { + return 0.0 + } + return UITableView.automaticDimension + } + + func footerHeight(for section: Int) -> CGFloat { + guard let title = footer(for: section) else { + return 1.0 + } + guard !title.isEmpty else { + return 0.0 + } + return UITableView.automaticDimension + } +} diff --git a/Passepartout-iOS/Scenes/AccountViewController.swift b/Passepartout-iOS/Scenes/AccountViewController.swift index d6d4c088..4d9ef108 100644 --- a/Passepartout-iOS/Scenes/AccountViewController.swift +++ b/Passepartout-iOS/Scenes/AccountViewController.swift @@ -103,6 +103,7 @@ class AccountViewController: UIViewController, TableModelHost { model.add(.noAccount) model.set([], in: .noAccount) + model.setHeader("", for: .credentials) if guidance != nil { let footer: String if let _ = guidanceURL { @@ -184,6 +185,10 @@ extension AccountViewController: UITableViewDataSource, UITableViewDelegate, Fie return model.footer(for: section) } + func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { + return model.headerHeight(for: section) + } + func tableView(_ tableView: UITableView, willDisplayFooterView view: UIView, forSection section: Int) { var optButton = view.viewWithTag(AccountViewController.footerButtonTag + section) as? UIButton if optButton == nil { diff --git a/Passepartout-iOS/Scenes/ConfigurationViewController.swift b/Passepartout-iOS/Scenes/ConfigurationViewController.swift index 6c585cef..7ebcf354 100644 --- a/Passepartout-iOS/Scenes/ConfigurationViewController.swift +++ b/Passepartout-iOS/Scenes/ConfigurationViewController.swift @@ -219,13 +219,7 @@ extension ConfigurationViewController: UITableViewDataSource, UITableViewDelegat } func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { - guard let title = model.header(for: section) else { - return 1.0 - } - guard !title.isEmpty else { - return 0.0 - } - return UITableView.automaticDimension + return model.headerHeight(for: section) } func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { diff --git a/Passepartout-iOS/Scenes/ServiceViewController.swift b/Passepartout-iOS/Scenes/ServiceViewController.swift index 3838ac84..4961f51c 100644 --- a/Passepartout-iOS/Scenes/ServiceViewController.swift +++ b/Passepartout-iOS/Scenes/ServiceViewController.swift @@ -593,16 +593,6 @@ extension ServiceViewController: UITableViewDataSource, UITableViewDelegate, Tog return model.header(for: section) } - func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { - guard let title = model.header(for: section) else { - return 1.0 - } - guard !title.isEmpty else { - return 0.0 - } - return UITableView.automaticDimension - } - func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? { let rows = model.rows(for: section) if rows.contains(.providerRefresh), let date = lastInfrastructureUpdate { @@ -611,6 +601,10 @@ extension ServiceViewController: UITableViewDataSource, UITableViewDelegate, Tog return model.footer(for: section) } + func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { + return model.headerHeight(for: section) + } + func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return model.count(for: section) }