summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAndrej Mihajlov <and@mullvad.net>2021-04-13 14:41:11 +0200
committerAndrej Mihajlov <and@mullvad.net>2021-05-03 16:37:57 +0200
commitd468446a73399bc8129b6d1dc1b2314179e0e8e2 (patch)
treedc8cc5bc50f330a124e27d79a049481e061496cf
parent0356a79adc379a5a377fda4dbf2817a8178954ba (diff)
downloadmullvadvpn-d468446a73399bc8129b6d1dc1b2314179e0e8e2.tar.xz
mullvadvpn-d468446a73399bc8129b6d1dc1b2314179e0e8e2.zip
SelectLocation: show header view at the bottom when presented inline and at the top when presented modally
-rw-r--r--ios/MullvadVPN/SelectLocationViewController.swift62
1 files changed, 55 insertions, 7 deletions
diff --git a/ios/MullvadVPN/SelectLocationViewController.swift b/ios/MullvadVPN/SelectLocationViewController.swift
index 04cdb97aef..969335454f 100644
--- a/ios/MullvadVPN/SelectLocationViewController.swift
+++ b/ios/MullvadVPN/SelectLocationViewController.swift
@@ -29,6 +29,12 @@ class SelectLocationViewController: UIViewController, UITableViewDelegate {
private var setScrollPositionOnViewDidLoad: UITableView.ScrollPosition = .none
private var isViewAppeared = false
+ private var showHeaderViewAtTheBottom = false {
+ didSet {
+ setTableHeaderFooterDimensions()
+ }
+ }
+
weak var delegate: SelectLocationViewControllerDelegate?
var scrollToSelectedRelayOnViewWillAppear = true
@@ -52,13 +58,15 @@ class SelectLocationViewController: UIViewController, UITableViewDelegate {
tableView.separatorColor = .secondaryColor
tableView.separatorInset = .zero
tableView.estimatedRowHeight = 53
- tableView.estimatedSectionHeaderHeight = 109
tableView.indicatorStyle = .white
tableView.register(SelectLocationHeaderView.self, forHeaderFooterViewReuseIdentifier: ReuseIdentifiers.header.rawValue)
tableView.register(SelectLocationCell.self, forCellReuseIdentifier: ReuseIdentifiers.cell.rawValue)
self.tableView = tableView
+
+ setTableHeaderFooterDimensions()
+
view.backgroundColor = .secondaryColor
view.addSubview(tableView)
@@ -103,6 +111,10 @@ class SelectLocationViewController: UIViewController, UITableViewDelegate {
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
+ // Show header view at the bottom when controller is presented inline and show header view
+ // at the top of the view when controller is presented modally.
+ showHeaderViewAtTheBottom = self.presentingViewController == nil
+
if let indexPath = dataSource?.indexPathForSelectedRelay(), scrollToSelectedRelayOnViewWillAppear, !isViewAppeared {
self.tableView?.scrollToRow(at: indexPath, at: .middle, animated: false)
}
@@ -164,15 +176,27 @@ class SelectLocationViewController: UIViewController, UITableViewDelegate {
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
assert(section == 0)
- let view = tableView.dequeueReusableHeaderFooterView(withIdentifier: ReuseIdentifiers.header.rawValue) as! SelectLocationHeaderView
+ if showHeaderViewAtTheBottom {
+ return nil
+ } else {
+ let view = tableView.dequeueReusableHeaderFooterView(withIdentifier: ReuseIdentifiers.header.rawValue) as! SelectLocationHeaderView
+ updateTopLayoutMargin(forHeaderView: view)
- // When contained within the navigation controller, we want the distance between the navigation title
- // and the table header label to be exactly 24pt.
- if let navigationBar = navigationController?.navigationBar as? CustomNavigationBar {
- view.topLayoutMarginAdjustmentForNavigationBarTitle = navigationBar.titleLabelBottomInset
+ return view
}
+ }
+
+ func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
+ assert(section == 0)
+
+ if showHeaderViewAtTheBottom {
+ let view = tableView.dequeueReusableHeaderFooterView(withIdentifier: ReuseIdentifiers.header.rawValue) as! SelectLocationHeaderView
+ view.topLayoutMarginAdjustmentForNavigationBarTitle = 0
- return view
+ return view
+ } else {
+ return nil
+ }
}
// MARK: - Public
@@ -210,4 +234,28 @@ class SelectLocationViewController: UIViewController, UITableViewDelegate {
dataSource.toggleChildren(location, animated: true)
}
+
+ // MARK: - Private
+
+ private func updateTopLayoutMargin(forHeaderView view: SelectLocationHeaderView) {
+ // When contained within the navigation controller, we want the distance between the navigation title
+ // and the table header label to be exactly 24pt.
+ if let navigationBar = navigationController?.navigationBar as? CustomNavigationBar {
+ view.topLayoutMarginAdjustmentForNavigationBarTitle = navigationBar.titleLabelBottomInset
+ } else {
+ view.topLayoutMarginAdjustmentForNavigationBarTitle = 0
+ }
+ }
+
+ private func setTableHeaderFooterDimensions() {
+ let headerFooterHeight: CGFloat = 109
+
+ if showHeaderViewAtTheBottom {
+ self.tableView?.estimatedSectionHeaderHeight = 0
+ self.tableView?.estimatedSectionFooterHeight = headerFooterHeight
+ } else {
+ self.tableView?.estimatedSectionHeaderHeight = headerFooterHeight
+ self.tableView?.estimatedSectionFooterHeight = 0
+ }
+ }
}