This commit is contained in:
Pfeil, Scott Robert 2020-04-09 11:17:10 -04:00
parent 40efdc4968
commit b7edafc5d8
6 changed files with 89 additions and 17 deletions

View File

@ -257,6 +257,7 @@
D264FA90243BCE6800D98315 /* ThreeLayerCollectionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D264FA8F243BCE6800D98315 /* ThreeLayerCollectionViewController.swift */; };
D264FAA1243CF66B00D98315 /* ContainerCollectionReusableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D264FAA0243CF66B00D98315 /* ContainerCollectionReusableView.swift */; };
D264FAA3243E632F00D98315 /* ProgrammaticCollectionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D264FAA2243E632F00D98315 /* ProgrammaticCollectionViewController.swift */; };
D264FAA5243F66A500D98315 /* CollectionTemplateItemProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = D264FAA4243F66A500D98315 /* CollectionTemplateItemProtocol.swift */; };
D268C70C2386DFFD007F2C1C /* MoleculeStackItemModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01EB368A23609801006832FA /* MoleculeStackItemModel.swift */; };
D268C70E238C22D7007F2C1C /* DropDownFilterTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D268C70D238C22D7007F2C1C /* DropDownFilterTableViewCell.swift */; };
D26C5A6B23F4A40D007AEECE /* ListItemModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D26C5A6A23F4A40D007AEECE /* ListItemModel.swift */; };
@ -670,6 +671,7 @@
D264FA8F243BCE6800D98315 /* ThreeLayerCollectionViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThreeLayerCollectionViewController.swift; sourceTree = "<group>"; };
D264FAA0243CF66B00D98315 /* ContainerCollectionReusableView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerCollectionReusableView.swift; sourceTree = "<group>"; };
D264FAA2243E632F00D98315 /* ProgrammaticCollectionViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProgrammaticCollectionViewController.swift; sourceTree = "<group>"; };
D264FAA4243F66A500D98315 /* CollectionTemplateItemProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CollectionTemplateItemProtocol.swift; sourceTree = "<group>"; };
D268C70D238C22D7007F2C1C /* DropDownFilterTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DropDownFilterTableViewCell.swift; sourceTree = "<group>"; };
D26C5A6A23F4A40D007AEECE /* ListItemModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListItemModel.swift; sourceTree = "<group>"; };
D274CA322236A78900B01B62 /* FooterView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FooterView.swift; sourceTree = "<group>"; };
@ -1442,6 +1444,7 @@
942C378B2412F4FA0066E45E /* ModalMoleculeListTemplate.swift */,
014AA72A23C5059B006F3E93 /* ThreeLayerPageTemplateModel.swift */,
D2D6CD4122E78FAB00D701B8 /* ThreeLayerTemplate.swift */,
D264FAA4243F66A500D98315 /* CollectionTemplateItemProtocol.swift */,
D264FA8B243BCD8E00D98315 /* CollectionTemplateModel.swift */,
D264FA8D243BCD9A00D98315 /* CollectionTemplate.swift */,
);
@ -2237,6 +2240,7 @@
01EB3684236097C0006832FA /* MoleculeModelProtocol.swift in Sources */,
D27CD4102339057800C1DC07 /* EyebrowHeadlineBodyLink.swift in Sources */,
8D070BB2241B56AD0099AC56 /* ListRightVariableTotalData.swift in Sources */,
D264FAA5243F66A500D98315 /* CollectionTemplateItemProtocol.swift in Sources */,
D29DF11D21E684A9003B2FB9 /* MVMCoreUISplitViewController.m in Sources */,
8DD1E36E243B3CFB00D8F2DF /* ListThreeColumnInternationalDataModel.swift in Sources */,
D243859923A16B1800332775 /* Container.swift in Sources */,

View File

@ -83,11 +83,23 @@ import Foundation
registerCells()
super.handleNewData()
}
//--------------------------------------------------
// MARK: - Collection
//--------------------------------------------------
open override func update(cell: UICollectionViewCell, size: CGFloat) {
super.update(cell: cell, size: size)
// Update the width for columns.
if let collectionView = collectionView,
let columns = templateModel?.columns, columns > 0,
let cell = cell as? CollectionTemplateItemProtocol {
let width = (size - collectionView.adjustedContentInset.left - collectionView.adjustedContentInset.right) / CGFloat(columns)
cell.set(width: width)
}
}
open override func registerCells() {
super.registerCells()
guard let moleculesInfo = moleculesInfo else { return }
@ -111,13 +123,20 @@ import Foundation
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: moleculeInfo.identifier, for: indexPath)
(cell as? MoleculeViewProtocol)?.reset()
(cell as? MoleculeViewProtocol)?.set(with: moleculeInfo.molecule, delegateObjectIVar, nil)
(cell as? MVMCoreViewProtocol)?.updateView(view.bounds.width)
update(cell: cell, size: view.frame.width)
// Neded to fix an apple defect where the cell is not the correct size on certain devices for certain cells
cell.layoutIfNeeded()
return cell
}
public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
(collectionView.cellForItem(at: indexPath) as? CollectionTemplateItemProtocol)?.didSelectCell(at: indexPath, delegateObject: delegateObjectIVar, additionalData: nil)
}
public func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
(cell as? CollectionTemplateItemProtocol)?.willDisplay()
}
//--------------------------------------------------
// MARK: - Convenience
//--------------------------------------------------

View File

@ -0,0 +1,29 @@
//
// CollectionTemplateItemProtocol.swift
// MVMCoreUI
//
// Created by Scott Pfeil on 4/9/20.
// Copyright © 2020 Verizon Wireless. All rights reserved.
//
import Foundation
/// A protocol that items of the CollectionTemplate must conform to.
public protocol CollectionTemplateItemProtocol: UICollectionViewCell {
/// Set the width of the item. Used for the columns functionality
func set(width: CGFloat)
/// Handle action when cell is pressed
func didSelectCell(at index: IndexPath, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?)
/// Called when the cell will display.
func willDisplay()
}
// Default implementation does nothing
extension CollectionTemplateItemProtocol {
public func didSelectCell(at index: IndexPath, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) {}
public func willDisplay() {}
}

View File

@ -9,12 +9,13 @@
import Foundation
/// A base collection view cell with basic mvm functionality.
open class CollectionViewCell: UICollectionViewCell, MoleculeViewProtocol, MVMCoreViewProtocol {
open class CollectionViewCell: UICollectionViewCell, MoleculeViewProtocol, MVMCoreViewProtocol, CollectionTemplateItemProtocol {
// Convenience helpers
open var molecule: MoleculeViewProtocol?
public let containerHelper = ContainerHelper()
open var model: CollectionItemModelProtocol?
open var widthConstraint: NSLayoutConstraint?
private var initialSetupPerformed = false
@ -56,6 +57,7 @@ open class CollectionViewCell: UICollectionViewCell, MoleculeViewProtocol, MVMCo
open func reset() {
molecule?.reset()
backgroundColor = .white
widthConstraint?.isActive = false
}
// MARK: - MoleculeViewProtocol
@ -80,4 +82,15 @@ open class CollectionViewCell: UICollectionViewCell, MoleculeViewProtocol, MVMCo
containerHelper.constrainView(molecule)
self.molecule = molecule
}
// MARK: - CollectionTemplateItemProtocol
public func set(width: CGFloat) {
if let widthConstraint = widthConstraint {
widthConstraint.constant = width
widthConstraint.isActive = true
} else {
widthConstraint = contentView.widthAnchor.constraint(equalToConstant: width)
widthConstraint?.isActive = true
}
}
}

View File

@ -50,7 +50,7 @@ import Foundation
currentSpaceForCompare = currentSpace * 2;
}
if !MVMCoreGetterUtility.cgfequalwiththreshold(newSpace, currentSpaceForCompare, 2) {
if !MVMCoreGetterUtility.cgfequalwiththreshold(newSpace, currentSpaceForCompare, 1) {
if fillTop && fillBottom {
// space both
let half = newSpace / 2
@ -72,19 +72,22 @@ import Foundation
//MARK: - ViewController
open override func updateViews() {
super.updateViews()
let width = view.bounds.width
if let topView = topView as? MVMCoreViewProtocol {
topView.updateView(width)
}
if let bottomView = bottomView as? MVMCoreViewProtocol {
bottomView.updateView(width)
}
if let cells = collectionView?.visibleCells {
for cell in cells {
(cell as? MVMCoreViewProtocol)?.updateView(width)
// Needed due to dispatch in reloadCollectionData.
DispatchQueue.main.async {
let width = self.view.bounds.width
if let topView = self.topView as? MVMCoreViewProtocol {
topView.updateView(width)
}
if let bottomView = self.bottomView as? MVMCoreViewProtocol {
bottomView.updateView(width)
}
if let cells = self.collectionView?.visibleCells {
for cell in cells {
self.update(cell: cell, size: width)
}
}
self.invalidateCollectionLayout()
}
invalidateCollectionLayout()
}
open override func handleNewData() {
@ -168,6 +171,11 @@ import Foundation
})
}
/// Called in updateView, updates the cell.
open func update(cell: UICollectionViewCell, size: CGFloat) {
(cell as? MVMCoreViewProtocol)?.updateView(size)
}
open override func registerCells() {
super.registerCells()
collectionView?.register(ContainerCollectionReusableView.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: headerID)

View File

@ -169,7 +169,6 @@
bottomInset = scrollview.adjustedContentInset.bottom;
}
CGFloat remainingSpace = frameHeight - contentSizeHeight - topInset - bottomInset;
NSLog(@"scc SPACCEEE remaining: %f frame: %f, content: %f, insets:(%f,%f)",remainingSpace,frameHeight,contentSizeHeight,topInset,bottomInset);
return remainingSpace - 1;
}