diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index d48bba00..6458701e 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -240,6 +240,7 @@ D2092353244F7D630044AD09 /* MVMCoreUIViewControllerMappingObject+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2092352244F7D630044AD09 /* MVMCoreUIViewControllerMappingObject+Extension.swift */; }; D2092355244FA0FD0044AD09 /* ThreeLayerTemplateModelProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2092354244FA0FD0044AD09 /* ThreeLayerTemplateModelProtocol.swift */; }; D2092357244FA1EF0044AD09 /* ThreeLayerModelBase.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2092356244FA1EF0044AD09 /* ThreeLayerModelBase.swift */; }; + D20923592450ECE00044AD09 /* TableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D20923582450ECE00044AD09 /* TableView.swift */; }; D20A9A5E2243D3E300ADE781 /* TwoButtonView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D20A9A5D2243D3E300ADE781 /* TwoButtonView.swift */; }; D20FB165241A5D75004AFC3A /* NavigationItemModelProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = D20FB164241A5D75004AFC3A /* NavigationItemModelProtocol.swift */; }; D213347723843825008E41B3 /* Line.swift in Sources */ = {isa = PBXBuildFile; fileRef = D213347623843825008E41B3 /* Line.swift */; }; @@ -684,6 +685,7 @@ D2092352244F7D630044AD09 /* MVMCoreUIViewControllerMappingObject+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MVMCoreUIViewControllerMappingObject+Extension.swift"; sourceTree = ""; }; D2092354244FA0FD0044AD09 /* ThreeLayerTemplateModelProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThreeLayerTemplateModelProtocol.swift; sourceTree = ""; }; D2092356244FA1EF0044AD09 /* ThreeLayerModelBase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThreeLayerModelBase.swift; sourceTree = ""; }; + D20923582450ECE00044AD09 /* TableView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TableView.swift; sourceTree = ""; }; D20A9A5D2243D3E300ADE781 /* TwoButtonView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TwoButtonView.swift; sourceTree = ""; }; D20FB164241A5D75004AFC3A /* NavigationItemModelProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationItemModelProtocol.swift; sourceTree = ""; }; D213347623843825008E41B3 /* Line.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Line.swift; sourceTree = ""; }; @@ -1900,6 +1902,7 @@ D2B18B7E2360913400A9AEDC /* Control.swift */, D2B18B802360945C00A9AEDC /* View.swift */, 0AE14F63238315D2005417F8 /* TextField.swift */, + D20923582450ECE00044AD09 /* TableView.swift */, D2755D7A23689C7500485468 /* TableViewCell.swift */, D21B7F70243BAC1600051ABF /* CollectionViewCell.swift */, D264FAA92440F97600D98315 /* CollectionView.swift */, @@ -2245,6 +2248,7 @@ D2092357244FA1EF0044AD09 /* ThreeLayerModelBase.swift in Sources */, 0A1B4A96233BB18F005B3FB4 /* CheckboxLabel.swift in Sources */, 0A21DB8B235E06EF00C160A2 /* MFDigitTextBox.m in Sources */, + D20923592450ECE00044AD09 /* TableView.swift in Sources */, D260D7B222D65BDD007E7233 /* MVMCoreUIPageControl.m in Sources */, BB47A586241615EF002BB23C /* ListOneColumnFullWidthTextDividerSubsectionModel.swift in Sources */, AA69AAF82445BF6800AF3D3B /* ListLeftVariableCheckboxBodyTextModel.swift in Sources */, diff --git a/MVMCoreUI/BaseClasses/TableView.swift b/MVMCoreUI/BaseClasses/TableView.swift new file mode 100644 index 00000000..9fb07ac7 --- /dev/null +++ b/MVMCoreUI/BaseClasses/TableView.swift @@ -0,0 +1,25 @@ +// +// TableView.swift +// MVMCoreUI +// +// Created by Scott Pfeil on 4/22/20. +// Copyright © 2020 Verizon Wireless. All rights reserved. +// + +import Foundation + +@objcMembers open class TableView: UITableView { + + /// A block that gets called on tableview frame changes + public var frameChangeAction: (() -> Void)? + + private var previousFrame = CGRect.zero + + open override func layoutSubviews() { + super.layoutSubviews() + if frame != previousFrame { + frameChangeAction?() + } + previousFrame = frame + } +} diff --git a/MVMCoreUI/BaseControllers/ProgrammaticTableViewController.swift b/MVMCoreUI/BaseControllers/ProgrammaticTableViewController.swift index 20ec3c43..21f1de1e 100644 --- a/MVMCoreUI/BaseControllers/ProgrammaticTableViewController.swift +++ b/MVMCoreUI/BaseControllers/ProgrammaticTableViewController.swift @@ -9,9 +9,9 @@ import Foundation open class ProgrammaticTableViewController: ProgrammaticScrollViewController, UITableViewDelegate, UITableViewDataSource { - @IBOutlet public var tableView: UITableView! + @IBOutlet public var tableView: TableView! - public init(with tableView: UITableView) { + public init(with tableView: TableView) { self.tableView = tableView super.init(with: tableView) } @@ -48,8 +48,8 @@ open class ProgrammaticTableViewController: ProgrammaticScrollViewController, UI } /// This class should create the table view that will be used here. Subclass this for different table styles. - open func createTableView() -> UITableView { - let tableView = UITableView(frame: .zero, style: .grouped) + open func createTableView() -> TableView { + let tableView = TableView(frame: .zero, style: .grouped) tableView.backgroundColor = .clear tableView.separatorStyle = UITableViewCell.SeparatorStyle.none tableView.delegate = self diff --git a/MVMCoreUI/BaseControllers/ThreeLayerCollectionViewController.swift b/MVMCoreUI/BaseControllers/ThreeLayerCollectionViewController.swift index 63f86ac2..29d401f0 100644 --- a/MVMCoreUI/BaseControllers/ThreeLayerCollectionViewController.swift +++ b/MVMCoreUI/BaseControllers/ThreeLayerCollectionViewController.swift @@ -22,7 +22,7 @@ import Foundation /// Updates the padding for flexible space (header or footer) private func updateFlexibleSpace() { - guard let tableView = collectionView else { return } + guard false,let collectionView = collectionView else { return } let minimumSpace: CGFloat = minimumFillSpace() var currentSpace: CGFloat = 0 @@ -43,18 +43,18 @@ import Foundation } guard fillTop || fillBottom else { return } - let newSpace = MVMCoreUIUtility.getVariableConstraintHeight(currentSpace, in: tableView, minimumHeight: totalMinimumSpace) + let newSpace = MVMCoreUIUtility.getVariableConstraintHeight(currentSpace, in: collectionView, minimumHeight: totalMinimumSpace) if !MVMCoreGetterUtility.cgfequalwiththreshold(newSpace, currentSpace, 1) { if fillTop && fillBottom { // space both let half = newSpace / 2 headerView?.bottomConstraint?.constant = half footerView?.topConstraint?.constant = half - collectionView?.collectionViewLayout.invalidateLayout() + collectionView.collectionViewLayout.invalidateLayout() } else if fillTop { // Only top is spaced. headerView?.bottomConstraint?.constant = newSpace - collectionView?.collectionViewLayout.invalidateLayout() + collectionView.collectionViewLayout.invalidateLayout() } else if fillBottom { // Only bottom is spaced. footerView?.topConstraint?.constant = newSpace diff --git a/MVMCoreUI/BaseControllers/ThreeLayerTableViewController.swift b/MVMCoreUI/BaseControllers/ThreeLayerTableViewController.swift index 01eabfe6..5cd7086b 100644 --- a/MVMCoreUI/BaseControllers/ThreeLayerTableViewController.swift +++ b/MVMCoreUI/BaseControllers/ThreeLayerTableViewController.swift @@ -46,6 +46,11 @@ open class ThreeLayerTableViewController: ProgrammaticTableViewController { super.viewDidLoad() // Do any additional setup after loading the view. setNoSectionHeadersFooters() + + // Ensures the footer and headers are the right size + tableView.frameChangeAction = { [weak self] in + self?.view.setNeedsUpdateConstraints() + } } //MARK: - Spacing @@ -239,4 +244,9 @@ open class ThreeLayerTableViewController: ProgrammaticTableViewController { deinit { tableView?.delegate = nil } + + // Ensures the footer and headers are the right size + func scrollViewDidChangeAdjustedContentInset(_ scrollView: UIScrollView) { + view.setNeedsUpdateConstraints() + } }