Merge branch 'feature/collection' into 'develop'
Feature/collection See merge request BPHV_MIPS/mvm_core_ui!368
This commit is contained in:
commit
b1caad0928
@ -222,6 +222,10 @@
|
||||
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 */; };
|
||||
D21B7F71243BAC1600051ABF /* CollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D21B7F70243BAC1600051ABF /* CollectionViewCell.swift */; };
|
||||
D21B7F73243BAC6800051ABF /* CollectionItemModelProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = D21B7F72243BAC6800051ABF /* CollectionItemModelProtocol.swift */; };
|
||||
D21B7F75243BAC8900051ABF /* CarouselItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = D21B7F74243BAC8900051ABF /* CarouselItem.swift */; };
|
||||
D21B7F77243BB70700051ABF /* MoleculeCollectionItemModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D21B7F76243BB70700051ABF /* MoleculeCollectionItemModel.swift */; };
|
||||
D21EE53C23AD3AD4003D1A30 /* NSLayoutConstraintAxis+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = D21EE53B23AD3AD4003D1A30 /* NSLayoutConstraintAxis+Extension.swift */; };
|
||||
D224798A2314445E003FCCF9 /* LabelToggle.swift in Sources */ = {isa = PBXBuildFile; fileRef = D22479892314445E003FCCF9 /* LabelToggle.swift */; };
|
||||
D224798C231450C8003FCCF9 /* HeadlineBodyToggle.swift in Sources */ = {isa = PBXBuildFile; fileRef = D224798B231450C8003FCCF9 /* HeadlineBodyToggle.swift */; };
|
||||
@ -254,6 +258,12 @@
|
||||
D260D7B122D65BDD007E7233 /* MVMCoreUIPageControl.h in Headers */ = {isa = PBXBuildFile; fileRef = D260D7AF22D65BDD007E7233 /* MVMCoreUIPageControl.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
D260D7B222D65BDD007E7233 /* MVMCoreUIPageControl.m in Sources */ = {isa = PBXBuildFile; fileRef = D260D7B022D65BDD007E7233 /* MVMCoreUIPageControl.m */; };
|
||||
D260D7B622D68514007E7233 /* MVMCoreUIPagingProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = D260D7B522D68509007E7233 /* MVMCoreUIPagingProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
D264FA8C243BCD8E00D98315 /* CollectionTemplateModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D264FA8B243BCD8E00D98315 /* CollectionTemplateModel.swift */; };
|
||||
D264FA8E243BCD9A00D98315 /* CollectionTemplate.swift in Sources */ = {isa = PBXBuildFile; fileRef = D264FA8D243BCD9A00D98315 /* CollectionTemplate.swift */; };
|
||||
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 */; };
|
||||
@ -632,6 +642,10 @@
|
||||
D20A9A5D2243D3E300ADE781 /* TwoButtonView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TwoButtonView.swift; sourceTree = "<group>"; };
|
||||
D20FB164241A5D75004AFC3A /* NavigationItemModelProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationItemModelProtocol.swift; sourceTree = "<group>"; };
|
||||
D213347623843825008E41B3 /* Line.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Line.swift; sourceTree = "<group>"; };
|
||||
D21B7F70243BAC1600051ABF /* CollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CollectionViewCell.swift; sourceTree = "<group>"; };
|
||||
D21B7F72243BAC6800051ABF /* CollectionItemModelProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CollectionItemModelProtocol.swift; sourceTree = "<group>"; };
|
||||
D21B7F74243BAC8900051ABF /* CarouselItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CarouselItem.swift; sourceTree = "<group>"; };
|
||||
D21B7F76243BB70700051ABF /* MoleculeCollectionItemModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MoleculeCollectionItemModel.swift; sourceTree = "<group>"; };
|
||||
D21EE53B23AD3AD4003D1A30 /* NSLayoutConstraintAxis+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSLayoutConstraintAxis+Extension.swift"; sourceTree = "<group>"; };
|
||||
D22479892314445E003FCCF9 /* LabelToggle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LabelToggle.swift; sourceTree = "<group>"; };
|
||||
D224798B231450C8003FCCF9 /* HeadlineBodyToggle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HeadlineBodyToggle.swift; sourceTree = "<group>"; };
|
||||
@ -664,6 +678,12 @@
|
||||
D260D7AF22D65BDD007E7233 /* MVMCoreUIPageControl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MVMCoreUIPageControl.h; sourceTree = "<group>"; };
|
||||
D260D7B022D65BDD007E7233 /* MVMCoreUIPageControl.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MVMCoreUIPageControl.m; sourceTree = "<group>"; };
|
||||
D260D7B522D68509007E7233 /* MVMCoreUIPagingProtocol.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MVMCoreUIPagingProtocol.h; sourceTree = "<group>"; };
|
||||
D264FA8B243BCD8E00D98315 /* CollectionTemplateModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CollectionTemplateModel.swift; sourceTree = "<group>"; };
|
||||
D264FA8D243BCD9A00D98315 /* CollectionTemplate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CollectionTemplate.swift; sourceTree = "<group>"; };
|
||||
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>"; };
|
||||
@ -920,6 +940,7 @@
|
||||
0A5D59C323AD488600EFD9E9 /* Protocols */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
D21B7F72243BAC6800051ABF /* CollectionItemModelProtocol.swift */,
|
||||
0A5D59C123AD2F5700EFD9E9 /* AppleGuidelinesProtocol.swift */,
|
||||
);
|
||||
path = Protocols;
|
||||
@ -1262,8 +1283,6 @@
|
||||
D26C5A6A23F4A40D007AEECE /* ListItemModel.swift */,
|
||||
01EB368923609801006832FA /* MoleculeListItemModel.swift */,
|
||||
01509D8E2327EC6F00EF99AA /* MoleculeTableViewCell.swift */,
|
||||
012A88C1238D7BCA00FE3DA1 /* CarouselItemModel.swift */,
|
||||
D2A6390422CBCE160052ED1F /* MoleculeCollectionViewCell.swift */,
|
||||
D28A838023CCB0D800DFE4FC /* AccordionListItemModel.swift */,
|
||||
D224799A231965AD003FCCF9 /* AccordionMoleculeTableViewCell.swift */,
|
||||
D28A837C23CCA86A00DFE4FC /* TabsListItemModel.swift */,
|
||||
@ -1275,6 +1294,10 @@
|
||||
D260105E23D0BFFC00764D80 /* StackItem.swift */,
|
||||
01EB368A23609801006832FA /* MoleculeStackItemModel.swift */,
|
||||
D2FB151C23A40F1500C20E10 /* MoleculeStackItem.swift */,
|
||||
D21B7F76243BB70700051ABF /* MoleculeCollectionItemModel.swift */,
|
||||
D2A6390422CBCE160052ED1F /* MoleculeCollectionViewCell.swift */,
|
||||
012A88C1238D7BCA00FE3DA1 /* CarouselItemModel.swift */,
|
||||
D21B7F74243BAC8900051ABF /* CarouselItem.swift */,
|
||||
);
|
||||
path = Items;
|
||||
sourceTree = "<group>";
|
||||
@ -1437,6 +1460,9 @@
|
||||
942C378B2412F4FA0066E45E /* ModalMoleculeListTemplate.swift */,
|
||||
014AA72A23C5059B006F3E93 /* ThreeLayerPageTemplateModel.swift */,
|
||||
D2D6CD4122E78FAB00D701B8 /* ThreeLayerTemplate.swift */,
|
||||
D264FAA4243F66A500D98315 /* CollectionTemplateItemProtocol.swift */,
|
||||
D264FA8B243BCD8E00D98315 /* CollectionTemplateModel.swift */,
|
||||
D264FA8D243BCD9A00D98315 /* CollectionTemplate.swift */,
|
||||
);
|
||||
path = Templates;
|
||||
sourceTree = "<group>";
|
||||
@ -1492,10 +1518,13 @@
|
||||
D29DF2CD21E7C104003B2FB9 /* MFLoadingViewController.m */,
|
||||
D2A5146A2214905000345BFB /* ThreeLayerViewController.swift */,
|
||||
D2E1FADE2268B8E700AEFD8C /* ThreeLayerTableViewController.swift */,
|
||||
D264FAA0243CF66B00D98315 /* ContainerCollectionReusableView.swift */,
|
||||
D264FA8F243BCE6800D98315 /* ThreeLayerCollectionViewController.swift */,
|
||||
D2C521A823EDE79E00CA2634 /* ViewController.swift */,
|
||||
D2A92881241AAB67004E01C6 /* ScrollingViewController.swift */,
|
||||
D2A92883241ACB25004E01C6 /* ProgrammaticScrollViewController.swift */,
|
||||
D2A92885241ACD99004E01C6 /* ProgrammaticTableViewController.swift */,
|
||||
D264FAA2243E632F00D98315 /* ProgrammaticCollectionViewController.swift */,
|
||||
);
|
||||
path = BaseControllers;
|
||||
sourceTree = "<group>";
|
||||
@ -1793,6 +1822,7 @@
|
||||
D2B18B802360945C00A9AEDC /* View.swift */,
|
||||
0AE14F63238315D2005417F8 /* TextField.swift */,
|
||||
D2755D7A23689C7500485468 /* TableViewCell.swift */,
|
||||
D21B7F70243BAC1600051ABF /* CollectionViewCell.swift */,
|
||||
0A5D59C323AD488600EFD9E9 /* Protocols */,
|
||||
);
|
||||
path = BaseClasses;
|
||||
@ -2042,8 +2072,10 @@
|
||||
D2E2A98323D8B32D000B42E6 /* EyebrowHeadlineBodyLinkModel.swift in Sources */,
|
||||
012A88AD238C418100FE3DA1 /* TemplateProtocol.swift in Sources */,
|
||||
BB6C6AC1242232DF005F7224 /* ListOneColumnTextWithWhitespaceDividerTall.swift in Sources */,
|
||||
D21B7F77243BB70700051ABF /* MoleculeCollectionItemModel.swift in Sources */,
|
||||
D29DF2B421E7B76D003B2FB9 /* MFLoadingSpinner.m in Sources */,
|
||||
011D9602240DA20A000E3791 /* FormRuleWatcherFieldProtocol.swift in Sources */,
|
||||
D264FAA1243CF66B00D98315 /* ContainerCollectionReusableView.swift in Sources */,
|
||||
D260106323D0C05000764D80 /* StackItemModel.swift in Sources */,
|
||||
D2E2A99823D8D63C000B42E6 /* ActionDetailWithImageModel.swift in Sources */,
|
||||
BBBBC87D24374A4900B0F079 /* ListThreeColumnBillChangesDividerModel.swift in Sources */,
|
||||
@ -2061,6 +2093,7 @@
|
||||
0A21DB91235E0EDB00C160A2 /* DigitBox.swift in Sources */,
|
||||
D22D1F572204CE5D0077CEC0 /* MVMCoreUIStackableViewController.m in Sources */,
|
||||
D28A838B23CCDA6B00DFE4FC /* ButtonModel.swift in Sources */,
|
||||
D21B7F71243BAC1600051ABF /* CollectionViewCell.swift in Sources */,
|
||||
D2A5145F2211DDC100345BFB /* MoleculeStackView.swift in Sources */,
|
||||
C7F8012323E846C300396FBD /* ListRVWheelModel.swift in Sources */,
|
||||
D29DF27621E79E81003B2FB9 /* MVMCoreUILoggingHandler.m in Sources */,
|
||||
@ -2116,6 +2149,7 @@
|
||||
D29DF13021E6851E003B2FB9 /* MVMCoreUITopAlertShortView.m in Sources */,
|
||||
5248BFEC23F12E350059236A /* ListThreeColumnPlanDataDivider.swift in Sources */,
|
||||
0ABD136D237CAD1E0081388D /* DateDropdownEntryField.swift in Sources */,
|
||||
D264FA8E243BCD9A00D98315 /* CollectionTemplate.swift in Sources */,
|
||||
0A7EF85B23D8A52800B2AAD1 /* EntryFieldModel.swift in Sources */,
|
||||
8DEFA95C243DAC20000D27E5 /* ListThreeColumnDataUsageDividerModel.swift in Sources */,
|
||||
94F217B723E0BF6100A47C06 /* PrimaryButtonView.m in Sources */,
|
||||
@ -2177,6 +2211,7 @@
|
||||
C6FA7D5323C77A4A00A3614A /* StringAndMoleculeStack.swift in Sources */,
|
||||
011D958524042432000E3791 /* RulesProtocol.swift in Sources */,
|
||||
94AF4A3F23E9D13900676048 /* MFCaretButton.m in Sources */,
|
||||
D264FAA3243E632F00D98315 /* ProgrammaticCollectionViewController.swift in Sources */,
|
||||
D29DF27A21E7A533003B2FB9 /* MVMCoreUISession.m in Sources */,
|
||||
D2A5146B2214905000345BFB /* ThreeLayerViewController.swift in Sources */,
|
||||
526A265E240D200500B0D828 /* ListTwoColumnCompareChanges.swift in Sources */,
|
||||
@ -2228,6 +2263,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 */,
|
||||
@ -2250,6 +2286,7 @@
|
||||
D2B1E3E522F37D6A0065F95C /* ImageHeadlineBody.swift in Sources */,
|
||||
0A21DB94235E24ED00C160A2 /* DigitEntryField.swift in Sources */,
|
||||
AA56A211243C5EFC00303286 /* ListTwoColumnSubsectionDivider.swift in Sources */,
|
||||
D264FA8C243BCD8E00D98315 /* CollectionTemplateModel.swift in Sources */,
|
||||
52B201D224081CFB00D2011E /* ListLeftVariableRadioButtonAndPaymentMethod.swift in Sources */,
|
||||
D26C5A6B23F4A40D007AEECE /* ListItemModel.swift in Sources */,
|
||||
0A21DB8D235E06EF00C160A2 /* MFDigitTextField.m in Sources */,
|
||||
@ -2276,10 +2313,12 @@
|
||||
52267A0723FFE25000906CBA /* ListOneColumnFullWidthTextAllTextAndLinks.swift in Sources */,
|
||||
C003506123AA94CD00B6AC29 /* Button.swift in Sources */,
|
||||
DBC4391B224421A0001AB423 /* CaretLink.swift in Sources */,
|
||||
D264FA90243BCE6800D98315 /* ThreeLayerCollectionViewController.swift in Sources */,
|
||||
0198F7A82256A80B0066C936 /* MFRadioButton.m in Sources */,
|
||||
0A6BF4722360C56C0028F841 /* BaseDropdownEntryField.swift in Sources */,
|
||||
BB6C6AC824225290005F7224 /* ListOneColumnTextWithWhitespaceDividerShort.swift in Sources */,
|
||||
0A41BA6E2344FCD400D4C0BC /* CATransaction+Extension.swift in Sources */,
|
||||
D21B7F73243BAC6800051ABF /* CollectionItemModelProtocol.swift in Sources */,
|
||||
C7192E7D23C301750050C2A0 /* HeadLineBodyCaretLinkImage.swift in Sources */,
|
||||
D29DF13221E6851E003B2FB9 /* MVMCoreUITopAlertBaseView.m in Sources */,
|
||||
D29DF29C21E7ADB9003B2FB9 /* MFProgrammaticTableViewController.m in Sources */,
|
||||
@ -2309,6 +2348,7 @@
|
||||
EA5124FD243601600051A3A4 /* BGImageHeadlineBodyButton.swift in Sources */,
|
||||
0105618D224BBE7700E1557D /* FormValidator.swift in Sources */,
|
||||
01509D912327ECE600EF99AA /* CornerLabels.swift in Sources */,
|
||||
D21B7F75243BAC8900051ABF /* CarouselItem.swift in Sources */,
|
||||
D22D1F1B220341F60077CEC0 /* MVMCoreUICheckBox.m in Sources */,
|
||||
C695A69823C990C200BFB94E /* DoughnutChartView.swift in Sources */,
|
||||
8D3BA9BD2433787000D341BA /* ListThreeColumnInternationalDataDividerModel.swift in Sources */,
|
||||
|
||||
@ -112,7 +112,9 @@ import Foundation
|
||||
// Other Items
|
||||
MoleculeObjectMapping.shared()?.register(viewClass: MoleculeStackItem.self, viewModelClass: MoleculeStackItemModel.self)
|
||||
MoleculeObjectMapping.shared()?.register(viewClass: StackItem.self, viewModelClass: StackItemModel.self)
|
||||
MoleculeObjectMapping.shared()?.register(viewClass: MoleculeCollectionViewCell.self, viewModelClass: CarouselItemModel.self)
|
||||
MoleculeObjectMapping.shared()?.register(viewClass: MoleculeCollectionViewCell.self, viewModelClass: MoleculeCollectionItemModel.self)
|
||||
MoleculeObjectMapping.shared()?.register(viewClass: CarouselItem.self, viewModelClass: CarouselItemModel.self)
|
||||
|
||||
|
||||
// Other Container Molecules
|
||||
MoleculeObjectMapping.shared()?.register(viewClass: MoleculeHeaderView.self, viewModelClass: MoleculeHeaderModel.self)
|
||||
|
||||
78
MVMCoreUI/Atomic/Molecules/Items/CarouselItem.swift
Normal file
78
MVMCoreUI/Atomic/Molecules/Items/CarouselItem.swift
Normal file
@ -0,0 +1,78 @@
|
||||
//
|
||||
// CarouselItem.swift
|
||||
// MVMCoreUI
|
||||
//
|
||||
// Created by Scott Pfeil on 4/6/20.
|
||||
// Copyright © 2020 Verizon Wireless. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
open class CarouselItem: MoleculeCollectionViewCell {
|
||||
|
||||
open var allowsPeaking = false
|
||||
var peakingLeftArrow = UIImageView(image: MVMCoreUIUtility.imageNamed("peakingRightArrow")?.withRenderingMode(.alwaysTemplate))
|
||||
var peakingRightArrow = UIImageView(image: MVMCoreUIUtility.imageNamed("peakingRightArrow")?.withRenderingMode(.alwaysTemplate))
|
||||
var peakingCover = MVMCoreUICommonViewsUtility.commonView()
|
||||
|
||||
open override func addMolecule(_ molecule: MoleculeViewProtocol) {
|
||||
super.addMolecule(molecule)
|
||||
contentView.sendSubviewToBack(molecule)
|
||||
}
|
||||
|
||||
open override func setupView() {
|
||||
super.setupView()
|
||||
|
||||
// Covers the card when peaking.
|
||||
peakingCover.backgroundColor = .white
|
||||
peakingCover.alpha = 0
|
||||
contentView.addSubview(peakingCover)
|
||||
NSLayoutConstraint.constraintPinSubview(toSuperview: peakingCover)
|
||||
|
||||
// A small arrow on the next card for when peaking.
|
||||
let ratio: CGFloat = 0.015
|
||||
peakingLeftArrow.translatesAutoresizingMaskIntoConstraints = false
|
||||
peakingLeftArrow.alpha = 0
|
||||
peakingLeftArrow.tintColor = .black
|
||||
contentView.addSubview(peakingLeftArrow)
|
||||
peakingLeftArrow.centerYAnchor.constraint(equalTo: contentView.centerYAnchor).isActive = true
|
||||
NSLayoutConstraint.scalingPinViewLeft(toSuper: peakingLeftArrow, ratio: ratio, anchor: contentView.widthAnchor)
|
||||
|
||||
peakingRightArrow.translatesAutoresizingMaskIntoConstraints = false
|
||||
peakingRightArrow.transform = CGAffineTransform(scaleX: -1, y: 1) // Flip
|
||||
peakingRightArrow.alpha = 0
|
||||
peakingRightArrow.tintColor = .black
|
||||
contentView.addSubview(peakingRightArrow)
|
||||
peakingRightArrow.centerYAnchor.constraint(equalTo: contentView.centerYAnchor).isActive = true
|
||||
NSLayoutConstraint.scalingPinViewRight(toSuper: peakingRightArrow, ratio: ratio, anchor: contentView.widthAnchor)
|
||||
}
|
||||
|
||||
open override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
|
||||
super.set(with: model, delegateObject, additionalData)
|
||||
guard let collectionModel = model as? CarouselItemModel else { return }
|
||||
|
||||
// Handles peaking.
|
||||
allowsPeaking = collectionModel.peakingUI ?? false
|
||||
if let peakingArrowColor = collectionModel.peakingArrowColor {
|
||||
let color = peakingArrowColor.uiColor
|
||||
peakingLeftArrow.tintColor = color
|
||||
peakingRightArrow.tintColor = color
|
||||
}
|
||||
}
|
||||
|
||||
public func setPeaking(_ peaking: Bool, animated: Bool) {
|
||||
guard allowsPeaking else {
|
||||
return
|
||||
}
|
||||
let animation = {() in
|
||||
self.peakingRightArrow.alpha = peaking ? 1 : 0
|
||||
self.peakingLeftArrow.alpha = peaking ? 1 : 0
|
||||
self.peakingCover.alpha = peaking ? 0.5 : 0
|
||||
}
|
||||
if animated {
|
||||
UIView.animate(withDuration: 0.4, animations: animation)
|
||||
} else {
|
||||
animation()
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -9,22 +9,20 @@
|
||||
import Foundation
|
||||
|
||||
|
||||
@objcMembers public class CarouselItemModel: MoleculeContainerModel, CarouselItemModelProtocol {
|
||||
public static var identifier: String = "carouselItem"
|
||||
public var backgroundColor: Color?
|
||||
@objcMembers public class CarouselItemModel: MoleculeCollectionItemModel, CarouselItemModelProtocol {
|
||||
public override class var identifier: String {
|
||||
return "carouselItem"
|
||||
}
|
||||
public var peakingUI: Bool?
|
||||
public var peakingArrowColor: Color?
|
||||
|
||||
private enum CodingKeys: String, CodingKey {
|
||||
case moleculeName
|
||||
case backgroundColor
|
||||
case peakingUI
|
||||
case peakingArrowColor
|
||||
}
|
||||
|
||||
required public init(from decoder: Decoder) throws {
|
||||
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
||||
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
|
||||
peakingUI = try typeContainer.decodeIfPresent(Bool.self, forKey: .peakingUI)
|
||||
peakingArrowColor = try typeContainer.decodeIfPresent(Color.self, forKey: .peakingArrowColor)
|
||||
try super.init(from: decoder)
|
||||
@ -33,8 +31,6 @@ import Foundation
|
||||
public override func encode(to encoder: Encoder) throws {
|
||||
try super.encode(to: encoder)
|
||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||
try container.encode(moleculeName, forKey: .moleculeName)
|
||||
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
||||
try container.encodeIfPresent(peakingUI, forKey: .peakingUI)
|
||||
try container.encodeIfPresent(peakingArrowColor, forKey: .peakingArrowColor)
|
||||
}
|
||||
|
||||
@ -0,0 +1,57 @@
|
||||
//
|
||||
// MoleculeCollectionItemModel.swift
|
||||
// MVMCoreUI
|
||||
//
|
||||
// Created by Scott Pfeil on 4/6/20.
|
||||
// Copyright © 2020 Verizon Wireless. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
/// A model for a collection item that is a container for any molecule.
|
||||
@objcMembers public class MoleculeCollectionItemModel: MoleculeContainerModel, CollectionItemModelProtocol, MoleculeModelProtocol {
|
||||
open class var identifier: String {
|
||||
return "collectionItem"
|
||||
}
|
||||
public var backgroundColor: Color?
|
||||
|
||||
/// Defaults to set
|
||||
public func setDefaults() {
|
||||
if useHorizontalMargins == nil {
|
||||
useHorizontalMargins = true
|
||||
}
|
||||
if useVerticalMargins == nil {
|
||||
useVerticalMargins = true
|
||||
}
|
||||
if topMarginPadding == nil {
|
||||
topMarginPadding = PaddingDefault
|
||||
}
|
||||
if bottomMarginPadding == nil {
|
||||
bottomMarginPadding = PaddingDefault
|
||||
}
|
||||
}
|
||||
|
||||
private enum CodingKeys: String, CodingKey {
|
||||
case moleculeName
|
||||
case backgroundColor
|
||||
}
|
||||
|
||||
public override init(with moleculeModel: MoleculeModelProtocol) {
|
||||
super.init(with: moleculeModel)
|
||||
setDefaults()
|
||||
}
|
||||
|
||||
required public init(from decoder: Decoder) throws {
|
||||
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
||||
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
|
||||
try super.init(from: decoder)
|
||||
setDefaults()
|
||||
}
|
||||
|
||||
public override func encode(to encoder: Encoder) throws {
|
||||
try super.encode(to: encoder)
|
||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||
try container.encode(moleculeName, forKey: .moleculeName)
|
||||
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
||||
}
|
||||
}
|
||||
@ -8,90 +8,15 @@
|
||||
|
||||
import UIKit
|
||||
|
||||
open class MoleculeCollectionViewCell: UICollectionViewCell, MoleculeViewProtocol {
|
||||
|
||||
open var molecule: MoleculeViewProtocol?
|
||||
public let containerHelper = ContainerHelper()
|
||||
|
||||
// In updateView, will set padding to default.
|
||||
open var updateViewHorizontalDefaults = true
|
||||
open var updateViewVerticalDefaults = true
|
||||
|
||||
open var allowsPeaking = false
|
||||
var peakingLeftArrow = UIImageView(image: MVMCoreUIUtility.imageNamed("peakingRightArrow")?.withRenderingMode(.alwaysTemplate))
|
||||
var peakingRightArrow = UIImageView(image: MVMCoreUIUtility.imageNamed("peakingRightArrow")?.withRenderingMode(.alwaysTemplate))
|
||||
var peakingCover = MVMCoreUICommonViewsUtility.commonView()
|
||||
|
||||
public override init(frame: CGRect) {
|
||||
super.init(frame: .zero)
|
||||
setupView()
|
||||
}
|
||||
|
||||
public required init?(coder aDecoder: NSCoder) {
|
||||
super.init(coder: aDecoder)
|
||||
setupView()
|
||||
}
|
||||
|
||||
public func setupView() {
|
||||
guard peakingCover.superview == nil else {
|
||||
return
|
||||
}
|
||||
isAccessibilityElement = false
|
||||
contentView.isAccessibilityElement = false
|
||||
insetsLayoutMarginsFromSafeArea = false
|
||||
contentView.insetsLayoutMarginsFromSafeArea = false
|
||||
contentView.preservesSuperviewLayoutMargins = false
|
||||
|
||||
// Covers the card when peaking.
|
||||
peakingCover.backgroundColor = .white
|
||||
peakingCover.alpha = 0
|
||||
contentView.addSubview(peakingCover)
|
||||
NSLayoutConstraint.constraintPinSubview(toSuperview: peakingCover)
|
||||
|
||||
// A small arrow on the next card for when peaking.
|
||||
let ratio: CGFloat = 0.015
|
||||
peakingLeftArrow.translatesAutoresizingMaskIntoConstraints = false
|
||||
peakingLeftArrow.alpha = 0
|
||||
peakingLeftArrow.tintColor = .black
|
||||
contentView.addSubview(peakingLeftArrow)
|
||||
peakingLeftArrow.centerYAnchor.constraint(equalTo: contentView.centerYAnchor).isActive = true
|
||||
NSLayoutConstraint.scalingPinViewLeft(toSuper: peakingLeftArrow, ratio: ratio, anchor: contentView.widthAnchor)
|
||||
|
||||
peakingRightArrow.translatesAutoresizingMaskIntoConstraints = false
|
||||
peakingRightArrow.transform = CGAffineTransform(scaleX: -1, y: 1) // Flip
|
||||
peakingRightArrow.alpha = 0
|
||||
peakingRightArrow.tintColor = .black
|
||||
contentView.addSubview(peakingRightArrow)
|
||||
peakingRightArrow.centerYAnchor.constraint(equalTo: contentView.centerYAnchor).isActive = true
|
||||
NSLayoutConstraint.scalingPinViewRight(toSuper: peakingRightArrow, ratio: ratio, anchor: contentView.widthAnchor)
|
||||
}
|
||||
|
||||
|
||||
public func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
|
||||
guard let collectionModel = model as? CarouselItemModel else { return }
|
||||
if let useHorizontalMargins = collectionModel.useHorizontalMargins {
|
||||
updateViewHorizontalDefaults = useHorizontalMargins
|
||||
}
|
||||
if let useVerticalMargins = collectionModel.useVerticalMargins {
|
||||
updateViewVerticalDefaults = useVerticalMargins
|
||||
}
|
||||
// Handles peaking.
|
||||
allowsPeaking = collectionModel.peakingUI ?? false
|
||||
if let peakingArrowColor = collectionModel.peakingArrowColor {
|
||||
let color = peakingArrowColor.uiColor
|
||||
peakingLeftArrow.tintColor = color
|
||||
peakingRightArrow.tintColor = color
|
||||
}
|
||||
|
||||
if let backgroundColor = collectionModel.backgroundColor {
|
||||
self.backgroundColor = backgroundColor.uiColor
|
||||
}
|
||||
/// A collection item that is a container for any molecule.
|
||||
open class MoleculeCollectionViewCell: CollectionViewCell {
|
||||
|
||||
open override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
|
||||
super.set(with: model, delegateObject, additionalData)
|
||||
guard let collectionModel = model as? MoleculeCollectionItemModel else { return }
|
||||
if molecule == nil {
|
||||
if let moleculeView = MoleculeObjectMapping.shared()?.createMolecule(collectionModel.molecule, delegateObject: delegateObject, additionalData: additionalData) {
|
||||
contentView.insertSubview(moleculeView, at: 0)
|
||||
containerHelper.constrainView(moleculeView)
|
||||
molecule = moleculeView
|
||||
addMolecule(moleculeView)
|
||||
}
|
||||
} else {
|
||||
molecule?.set(with: collectionModel.molecule, delegateObject, additionalData)
|
||||
@ -102,39 +27,33 @@ open class MoleculeCollectionViewCell: UICollectionViewCell, MoleculeViewProtoco
|
||||
accessibilityElements = molecule.subviews
|
||||
}
|
||||
|
||||
public func reset() {
|
||||
open override func reset() {
|
||||
super.reset()
|
||||
molecule?.reset()
|
||||
updateViewVerticalDefaults = true
|
||||
updateViewHorizontalDefaults = true
|
||||
backgroundColor = .white
|
||||
}
|
||||
|
||||
public class func nameForReuse(_ model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> String? {
|
||||
guard let molecule = (model as? CarouselItemModel)?.molecule,
|
||||
let moleculeClass = MoleculeObjectMapping.shared()?.getMoleculeClass(molecule) else {
|
||||
return nil
|
||||
}
|
||||
return moleculeClass.nameForReuse(with: molecule, delegateObject) ?? molecule.moleculeName
|
||||
open class func nameForReuse(_ model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> String? {
|
||||
guard let moleculeModel = (model as? MoleculeCollectionItemModel)?.molecule else { return "\(self)<>" }
|
||||
let className = MoleculeObjectMapping.shared()?.getMoleculeClass(moleculeModel)
|
||||
let moleculeName = className?.nameForReuse(with: moleculeModel, delegateObject) ?? moleculeModel.moleculeName
|
||||
return "\(self)<\(moleculeName)>"
|
||||
}
|
||||
|
||||
public func updateView(_ size: CGFloat) {
|
||||
(molecule as? MVMCoreViewProtocol)?.updateView(size)
|
||||
MFStyler.setDefaultMarginsFor(contentView, size: size, horizontal: updateViewHorizontalDefaults, vertical: updateViewVerticalDefaults)
|
||||
open class func requiredModules(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, error: AutoreleasingUnsafeMutablePointer<MVMCoreErrorObject?>?) -> [String]? {
|
||||
guard let moleculeModel = (model as? MoleculeCollectionItemModel)?.molecule,
|
||||
let theClass = MoleculeObjectMapping.shared()?.getMoleculeClass(moleculeModel)
|
||||
else { return nil }
|
||||
|
||||
return theClass.requiredModules(with: moleculeModel, delegateObject, error: error)
|
||||
}
|
||||
|
||||
public func setPeaking(_ peaking: Bool, animated: Bool) {
|
||||
guard allowsPeaking else {
|
||||
return
|
||||
}
|
||||
let animation = {() in
|
||||
self.peakingRightArrow.alpha = peaking ? 1 : 0
|
||||
self.peakingLeftArrow.alpha = peaking ? 1 : 0
|
||||
self.peakingCover.alpha = peaking ? 0.5 : 0
|
||||
}
|
||||
if animated {
|
||||
UIView.animate(withDuration: 0.4, animations: animation)
|
||||
} else {
|
||||
animation()
|
||||
}
|
||||
open class func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat {
|
||||
guard let model = model as? MoleculeCollectionItemModel,
|
||||
let classType = MoleculeObjectMapping.shared()?.getMoleculeClass(model.molecule),
|
||||
let height = classType.estimatedHeight(with: model.molecule, delegateObject)
|
||||
else { return 100 }
|
||||
|
||||
return height + (model.topMarginPadding ?? 0) + (model.bottomMarginPadding ?? 0)
|
||||
}
|
||||
}
|
||||
|
||||
@ -52,12 +52,37 @@ open class Carousel: View {
|
||||
|
||||
public var delegateObject: MVMCoreUIDelegateObject?
|
||||
|
||||
private var size: CGFloat?
|
||||
|
||||
// Updates the model and index.
|
||||
public func updateModelIndex() {
|
||||
(model as? CarouselModel)?.index = pageIndex
|
||||
}
|
||||
|
||||
open override func layoutSubviews() {
|
||||
super.layoutSubviews()
|
||||
// Accounts for any collection size changes
|
||||
DispatchQueue.main.async {
|
||||
self.layoutCollection()
|
||||
}
|
||||
}
|
||||
|
||||
/// Invalidates the layout and ensures we are paged to the correct cell.
|
||||
open func layoutCollection() {
|
||||
collectionView.collectionViewLayout.invalidateLayout()
|
||||
showPeaking(false)
|
||||
|
||||
// Go to current cell. layoutIfNeeded is needed otherwise cellForItem returns nil for peaking logic. The dispatch is a sad way to ensure the collection view is ready to be scrolled.
|
||||
DispatchQueue.main.async {
|
||||
self.collectionView.scrollToItem(at: IndexPath(row: self.currentIndex, section: 0), at: self.itemAlignment, animated: false)
|
||||
self.collectionView.layoutIfNeeded()
|
||||
self.showPeaking(true)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - MVMCoreViewProtocol
|
||||
open override func setupView() {
|
||||
super.setupView()
|
||||
guard collectionView.superview == nil else {
|
||||
return
|
||||
}
|
||||
collectionView.translatesAutoresizingMaskIntoConstraints = false
|
||||
collectionView.dataSource = self
|
||||
collectionView.delegate = self
|
||||
@ -73,15 +98,13 @@ open class Carousel: View {
|
||||
|
||||
open override func updateView(_ size: CGFloat) {
|
||||
super.updateView(size)
|
||||
collectionView.collectionViewLayout.invalidateLayout()
|
||||
showPeaking(false)
|
||||
|
||||
// Go to current cell. layoutIfNeeded is needed otherwise cellForItem returns nil for peaking logic. The dispatch is a sad way to ensure the collection view is ready to be scrolled.
|
||||
DispatchQueue.main.async {
|
||||
self.collectionView.scrollToItem(at: IndexPath(row: self.currentIndex, section: 0), at: self.itemAlignment, animated: false)
|
||||
self.collectionView.layoutIfNeeded()
|
||||
self.showPeaking(true)
|
||||
self.size = size
|
||||
|
||||
// Update cells and re-layout.
|
||||
for cell in collectionView.visibleCells {
|
||||
(cell as? MVMCoreViewProtocol)?.updateView(size)
|
||||
}
|
||||
layoutCollection()
|
||||
}
|
||||
|
||||
// MARK: - MoleculeViewProtocol
|
||||
@ -108,6 +131,9 @@ open class Carousel: View {
|
||||
}
|
||||
|
||||
setupPagingMolecule(carouselModel.pagingMolecule, delegateObject: delegateObject)
|
||||
|
||||
pageIndex = carouselModel.index
|
||||
pagingView?.setPage(carouselModel.index)
|
||||
collectionView.reloadData()
|
||||
}
|
||||
|
||||
@ -143,7 +169,7 @@ open class Carousel: View {
|
||||
}
|
||||
|
||||
/// Sets up the paging molecule
|
||||
open func setupPagingMolecule(_ molecule: CarouselPagingModelProtocol?, delegateObject: MVMCoreUIDelegateObject?) {
|
||||
open func setupPagingMolecule(_ molecule: (CarouselPagingModelProtocol & MoleculeModelProtocol)?, delegateObject: MVMCoreUIDelegateObject?) {
|
||||
var pagingView: (UIView & MVMCoreUIPagingProtocol)? = nil
|
||||
if let molecule = molecule {
|
||||
pagingView = MoleculeObjectMapping.shared()?.createMolecule(molecule, delegateObject: delegateObject) as? (UIView & MVMCoreUIPagingProtocol)
|
||||
@ -197,6 +223,7 @@ open class Carousel: View {
|
||||
}
|
||||
let currentPage = pager.currentPage()
|
||||
localSelf.pageIndex = currentPage
|
||||
localSelf.updateModelIndex()
|
||||
localSelf.goTo(localSelf.currentIndex, animated: !UIAccessibility.isVoiceOverRunning)
|
||||
})
|
||||
}
|
||||
@ -208,15 +235,15 @@ open class Carousel: View {
|
||||
// Show overlay and arrow in peaking Cell
|
||||
let visibleItemsPaths = collectionView.indexPathsForVisibleItems.sorted { $0.row < $1.row }
|
||||
if let firstItem = visibleItemsPaths.first, firstItem.row != currentIndex {
|
||||
(collectionView.cellForItem(at: firstItem) as? MoleculeCollectionViewCell)?.setPeaking(true, animated: true)
|
||||
(collectionView.cellForItem(at: firstItem) as? CarouselItem)?.setPeaking(true, animated: true)
|
||||
}
|
||||
if let lastItem = visibleItemsPaths.last, lastItem.row != currentIndex {
|
||||
(collectionView.cellForItem(at: lastItem) as? MoleculeCollectionViewCell)?.setPeaking(true, animated: true)
|
||||
(collectionView.cellForItem(at: lastItem) as? CarouselItem)?.setPeaking(true, animated: true)
|
||||
}
|
||||
} else {
|
||||
// Hide peaking.
|
||||
for item in collectionView.visibleCells {
|
||||
(item as? MoleculeCollectionViewCell)?.setPeaking(false, animated: true)
|
||||
(item as? CarouselItem)?.setPeaking(false, animated: true)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -229,10 +256,12 @@ open class Carousel: View {
|
||||
cell.accessibilityElementsHidden = false
|
||||
var array = cell.accessibilityElements
|
||||
|
||||
if let acc = pagingView?.accessibilityElements {
|
||||
array?.append(contentsOf: acc)
|
||||
} else {
|
||||
array?.append(pagingView!)
|
||||
if let pagingView = pagingView {
|
||||
if let acc = pagingView.accessibilityElements {
|
||||
array?.append(contentsOf: acc)
|
||||
} else {
|
||||
array?.append(pagingView)
|
||||
}
|
||||
}
|
||||
|
||||
self.accessibilityElements = array
|
||||
@ -249,7 +278,7 @@ extension Carousel: UICollectionViewDelegateFlowLayout {
|
||||
}
|
||||
|
||||
open func collectionView(_ collectionView: UICollectionView, didEndDisplaying cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
|
||||
(cell as? MoleculeCollectionViewCell)?.setPeaking(false, animated: false)
|
||||
(cell as? CarouselItem)?.setPeaking(false, animated: false)
|
||||
}
|
||||
}
|
||||
|
||||
@ -268,7 +297,7 @@ extension Carousel: UICollectionViewDataSource {
|
||||
protocolCell.reset()
|
||||
protocolCell.set(with: moleculeInfo.molecule, delegateObject, nil)
|
||||
}
|
||||
(cell as? MVMCoreViewProtocol)?.updateView(collectionView.bounds.width)
|
||||
(cell as? MVMCoreViewProtocol)?.updateView(size ?? collectionView.bounds.width)
|
||||
setAccessiblity(cell, index: indexPath.row)
|
||||
return cell
|
||||
}
|
||||
@ -278,19 +307,18 @@ extension Carousel: UIScrollViewDelegate {
|
||||
|
||||
func goTo(_ index: Int, animated: Bool) {
|
||||
showPeaking(false)
|
||||
setAccessiblity(collectionView.cellForItem(at: IndexPath(row: self.currentIndex, section: 0)), index: index)
|
||||
self.currentIndex = index
|
||||
self.collectionView.scrollToItem(at: IndexPath(row: self.currentIndex, section: 0), at: self.itemAlignment, animated: animated)
|
||||
if let cell = collectionView.cellForItem(at: IndexPath(row: self.currentIndex, section: 0)) {
|
||||
setAccessiblity(collectionView.cellForItem(at: IndexPath(row: self.currentIndex, section: 0)), index: index)
|
||||
setAccessiblity(collectionView.cellForItem(at: IndexPath(row: currentIndex, section: 0)), index: index)
|
||||
currentIndex = index
|
||||
updateModelIndex()
|
||||
collectionView.scrollToItem(at: IndexPath(row: currentIndex, section: 0), at: itemAlignment, animated: animated)
|
||||
if let cell = collectionView.cellForItem(at: IndexPath(row: currentIndex, section: 0)) {
|
||||
setAccessiblity(collectionView.cellForItem(at: IndexPath(row: currentIndex, section: 0)), index: index)
|
||||
UIAccessibility.post(notification: .layoutChanged, argument: cell)
|
||||
}
|
||||
}
|
||||
|
||||
func handleUserOnBufferCell() {
|
||||
guard loop else {
|
||||
return
|
||||
}
|
||||
guard loop else { return }
|
||||
|
||||
let lastPageIndex = numberOfPages + 1
|
||||
let goToIndex = {(index: Int) in
|
||||
@ -318,9 +346,11 @@ extension Carousel: UIScrollViewDelegate {
|
||||
let index = scrollView.contentOffset.x / (itemWidth + separatorWidth)
|
||||
let lastCellIndex = collectionView(collectionView, numberOfItemsInSection: 0) - 1
|
||||
if index < 1 {
|
||||
self.currentIndex = 0
|
||||
currentIndex = 0
|
||||
updateModelIndex()
|
||||
} else if index > CGFloat(lastCellIndex - 1) {
|
||||
self.currentIndex = lastCellIndex
|
||||
currentIndex = lastCellIndex
|
||||
updateModelIndex()
|
||||
}
|
||||
}
|
||||
|
||||
@ -330,7 +360,7 @@ extension Carousel: UIScrollViewDelegate {
|
||||
open func scrollViewDidScroll(_ scrollView: UIScrollView) {
|
||||
|
||||
// Check if the user is dragging the card even further past the next card.
|
||||
checkForDraggingOutOfBounds(scrollView)
|
||||
//checkForDraggingOutOfBounds(scrollView)
|
||||
|
||||
// Let the pager know our progress if needed.
|
||||
pagingView?.scrollViewDidScroll?(collectionView)
|
||||
@ -346,9 +376,7 @@ extension Carousel: UIScrollViewDelegate {
|
||||
targetContentOffset.pointee = scrollView.contentOffset
|
||||
|
||||
// This is for setting up smooth custom paging. (Since UICollectionView only handles paging based on collection view size and not cell size).
|
||||
guard let separatorWidth = (collectionView.collectionViewLayout as? UICollectionViewFlowLayout)?.minimumLineSpacing else {
|
||||
return
|
||||
}
|
||||
guard let separatorWidth = (collectionView.collectionViewLayout as? UICollectionViewFlowLayout)?.minimumLineSpacing else { return }
|
||||
|
||||
// We switch cards if we pass the velocity threshold or position threshold (currently 50%).
|
||||
let itemWidth = collectionView.bounds.width * CGFloat(itemWidthPercent)
|
||||
|
||||
@ -12,14 +12,14 @@ import UIKit
|
||||
public static var identifier: String = "carousel"
|
||||
public var backgroundColor: Color?
|
||||
public var molecules: [CarouselItemModel]
|
||||
|
||||
public var index: Int = 0
|
||||
public var spacing: Float?
|
||||
public var border: Bool?
|
||||
public var loop: Bool?
|
||||
public var height: Float?
|
||||
public var itemWidthPercent: Float?
|
||||
public var itemAlignment: UICollectionView.ScrollPosition?
|
||||
public var pagingMolecule: CarouselPagingModelProtocol?
|
||||
public var pagingMolecule: (CarouselPagingModelProtocol & MoleculeModelProtocol)?
|
||||
|
||||
public init(molecules: [CarouselItemModel]){
|
||||
self.molecules = molecules
|
||||
@ -29,6 +29,7 @@ import UIKit
|
||||
case moleculeName
|
||||
case backgroundColor
|
||||
case molecules
|
||||
case index
|
||||
case spacing
|
||||
case border
|
||||
case loop
|
||||
@ -40,15 +41,16 @@ import UIKit
|
||||
|
||||
required public init(from decoder: Decoder) throws {
|
||||
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
||||
self.molecules = try typeContainer.decode([CarouselItemModel].self, forKey: .molecules)
|
||||
self.backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
|
||||
self.spacing = try typeContainer.decode(Float.self, forKey: .spacing)
|
||||
self.border = try typeContainer.decode(Bool.self, forKey: .border)
|
||||
self.loop = try typeContainer.decode(Bool.self, forKey: .loop)
|
||||
self.height = try typeContainer.decode(Float.self, forKey: .height)
|
||||
self.itemWidthPercent = try typeContainer.decode(Float.self, forKey: .itemWidthPercent)
|
||||
self.itemAlignment = try typeContainer.decode(UICollectionView.ScrollPosition.self, forKey: .itemAlignment)
|
||||
self.pagingMolecule = try typeContainer.decodeModelIfPresent(codingKey: .pagingMolecule)
|
||||
molecules = try typeContainer.decode([CarouselItemModel].self, forKey: .molecules)
|
||||
index = try typeContainer.decodeIfPresent(Int.self, forKey: .index) ?? 0
|
||||
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
|
||||
spacing = try typeContainer.decodeIfPresent(Float.self, forKey: .spacing)
|
||||
border = try typeContainer.decodeIfPresent(Bool.self, forKey: .border)
|
||||
loop = try typeContainer.decodeIfPresent(Bool.self, forKey: .loop)
|
||||
height = try typeContainer.decodeIfPresent(Float.self, forKey: .height)
|
||||
itemWidthPercent = try typeContainer.decodeIfPresent(Float.self, forKey: .itemWidthPercent)
|
||||
itemAlignment = try typeContainer.decodeIfPresent(UICollectionView.ScrollPosition.self, forKey: .itemAlignment)
|
||||
pagingMolecule = try typeContainer.decodeModelIfPresent(codingKey: .pagingMolecule)
|
||||
}
|
||||
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
|
||||
@ -9,6 +9,6 @@
|
||||
import Foundation
|
||||
|
||||
|
||||
public protocol CarouselPagingModelProtocol: MoleculeModelProtocol {
|
||||
public protocol CarouselPagingModelProtocol {
|
||||
var position: Float? { get }
|
||||
}
|
||||
|
||||
195
MVMCoreUI/Atomic/Templates/CollectionTemplate.swift
Normal file
195
MVMCoreUI/Atomic/Templates/CollectionTemplate.swift
Normal file
@ -0,0 +1,195 @@
|
||||
//
|
||||
// CollectionTemplate.swift
|
||||
// MVMCoreUI
|
||||
//
|
||||
// Created by Scott Pfeil on 4/6/20.
|
||||
// Copyright © 2020 Verizon Wireless. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
@objc open class CollectionTemplate: ThreeLayerCollectionViewController, TemplateProtocol {
|
||||
public typealias TemplateModel = CollectionTemplateModel
|
||||
public var templateModel: CollectionTemplateModel?
|
||||
|
||||
public var moleculesInfo: [(identifier: String, class: AnyClass, molecule: (CollectionItemModelProtocol & MoleculeModelProtocol))]?
|
||||
|
||||
var observer: NSKeyValueObservation?
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Computed Properties
|
||||
//--------------------------------------------------
|
||||
open override func parsePageJSON() throws {
|
||||
try parseTemplate(json: loadObject?.pageJSON)
|
||||
try super.parsePageJSON()
|
||||
}
|
||||
|
||||
open override var loadObject: MVMCoreLoadObject? {
|
||||
didSet {
|
||||
guard loadObject != oldValue else { return }
|
||||
|
||||
updateRequiredModules()
|
||||
observer?.invalidate()
|
||||
if let newObject = loadObject {
|
||||
observer = newObject.observe(\MVMCoreLoadObject.pageJSON, options: [.old, .new]) { [weak self] object, change in
|
||||
self?.updateRequiredModules()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Methods
|
||||
//--------------------------------------------------
|
||||
|
||||
open override func viewForTop() -> UIView? {
|
||||
guard let headerModel = templateModel?.header,
|
||||
let molecule = MoleculeObjectMapping.shared()?.createMolecule(headerModel, delegateObject: delegateObjectIVar)
|
||||
else { return super.viewForTop() }
|
||||
|
||||
// Temporary, Default the horizontal padding
|
||||
if var container = templateModel?.header as? ContainerModelProtocol, container.useHorizontalMargins == nil {
|
||||
container.useHorizontalMargins = true
|
||||
}
|
||||
|
||||
return molecule
|
||||
}
|
||||
|
||||
override open func viewForBottom() -> UIView? {
|
||||
guard let footerModel = templateModel?.footer,
|
||||
let molecule = MoleculeObjectMapping.shared()?.createMolecule(footerModel, delegateObject: delegateObjectIVar)
|
||||
else { return super.viewForBottom() }
|
||||
|
||||
return molecule
|
||||
}
|
||||
|
||||
open override func shouldFinishProcessingLoad(_ loadObject: MVMCoreLoadObject, error: AutoreleasingUnsafeMutablePointer<MVMCoreErrorObject>) -> Bool {
|
||||
guard super.shouldFinishProcessingLoad(loadObject, error: error) else { return false }
|
||||
|
||||
// This template requires atleast one of the three layers.
|
||||
if templateModel?.header == nil,
|
||||
templateModel?.molecules?.count ?? 0 == 0,
|
||||
templateModel?.footer == nil,
|
||||
let errorObject = MVMCoreErrorObject(title: nil, message: MVMCoreGetterUtility.hardcodedString(withKey: HardcodedErrorUnableToProcess), messageToLog: "Collection template requires atleast one of the following: header, footer, molecules", code: CoreUIErrorCode.ErrorCodeListMolecule.rawValue, domain: ErrorDomainNative, location: String(describing: self)) {
|
||||
error.pointee = errorObject
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
open override func handleNewData() {
|
||||
setup()
|
||||
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 }
|
||||
|
||||
for moleculeInfo in moleculesInfo {
|
||||
collectionView?.register(moleculeInfo.class, forCellWithReuseIdentifier: moleculeInfo.identifier)
|
||||
}
|
||||
}
|
||||
|
||||
open override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
||||
return moleculesInfo?.count ?? 0
|
||||
}
|
||||
|
||||
open override func numberOfSections(in collectionView: UICollectionView) -> Int {
|
||||
return 1
|
||||
}
|
||||
|
||||
open override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
||||
guard let moleculeInfo = moleculesInfo?[indexPath.row]
|
||||
else { return UICollectionViewCell() }
|
||||
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: moleculeInfo.identifier, for: indexPath)
|
||||
(cell as? MoleculeViewProtocol)?.reset()
|
||||
(cell as? MoleculeViewProtocol)?.set(with: moleculeInfo.molecule, delegateObjectIVar, nil)
|
||||
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
|
||||
//--------------------------------------------------
|
||||
|
||||
/// Returns the (identifier, class) of the molecule for the given map.
|
||||
open func getMoleculeInfo(with item: (CollectionItemModelProtocol & MoleculeModelProtocol)?) -> (identifier: String, class: AnyClass, molecule: CollectionItemModelProtocol & MoleculeModelProtocol)? {
|
||||
guard let item = item,
|
||||
let moleculeClass = MoleculeObjectMapping.shared()?.getMoleculeClass(item) else { return nil }
|
||||
let moleculeName = moleculeClass.nameForReuse(with: item, delegateObjectIVar) ?? item.moleculeName
|
||||
return (moleculeName, moleculeClass, item)
|
||||
}
|
||||
|
||||
/// Sets up the molecule list and ensures no errors loading all content.
|
||||
open func getMoleculeInfoList() -> [(identifier: String, class: AnyClass, molecule: (CollectionItemModelProtocol & MoleculeModelProtocol))]? {
|
||||
|
||||
var moleculeList: [(identifier: String, class: AnyClass, molecule: CollectionItemModelProtocol & MoleculeModelProtocol)] = []
|
||||
|
||||
if let molecules = templateModel?.molecules {
|
||||
for molecule in molecules {
|
||||
if let info = getMoleculeInfo(with: molecule) {
|
||||
moleculeList.append(info)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return moleculeList.count > 0 ? moleculeList : nil
|
||||
}
|
||||
|
||||
/// Sets up the header, footer, molecule list and ensures no errors loading all content.
|
||||
open func setup() {
|
||||
moleculesInfo = getMoleculeInfoList()
|
||||
}
|
||||
|
||||
/// Adds modules from requiredModules() to the MVMCoreViewControllerMapping.requiredModules map.
|
||||
open func updateRequiredModules() {
|
||||
if let requiredModules = requiredModules(), let pageType = pageType {
|
||||
MVMCoreViewControllerMappingObject.shared()?.addRequiredModules(toMapping: requiredModules, forPageType: pageType)
|
||||
}
|
||||
}
|
||||
|
||||
/// Gets modules required by the loadObject.pageJSON.
|
||||
open func requiredModules() -> [Any]? {
|
||||
var modules: [String]? = []
|
||||
var errors: [MVMCoreErrorObject]? = nil
|
||||
MoleculeObjectMapping.addRequiredModules(for: templateModel?.header, delegateObjectIVar, moduleList: &modules, errorList: &errors)
|
||||
MoleculeObjectMapping.addRequiredModules(for: templateModel?.footer, delegateObjectIVar, moduleList: &modules, errorList: &errors)
|
||||
|
||||
if let molecules = templateModel?.molecules {
|
||||
for molecule in molecules {
|
||||
MoleculeObjectMapping.addRequiredModules(for: molecule, delegateObjectIVar, moduleList: &modules, errorList: &errors)
|
||||
}
|
||||
}
|
||||
|
||||
return modules
|
||||
}
|
||||
}
|
||||
@ -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() {}
|
||||
}
|
||||
67
MVMCoreUI/Atomic/Templates/CollectionTemplateModel.swift
Normal file
67
MVMCoreUI/Atomic/Templates/CollectionTemplateModel.swift
Normal file
@ -0,0 +1,67 @@
|
||||
//
|
||||
// CollectionTemplateModel.swift
|
||||
// MVMCoreUI
|
||||
//
|
||||
// Created by Scott Pfeil on 4/6/20.
|
||||
// Copyright © 2020 Verizon Wireless. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
@objcMembers public class CollectionTemplateModel: TemplateModel {
|
||||
//--------------------------------------------------
|
||||
// MARK: - Properties
|
||||
//--------------------------------------------------
|
||||
|
||||
public override class var identifier: String {
|
||||
return "collection"
|
||||
}
|
||||
public var header: MoleculeModelProtocol?
|
||||
public var molecules: [CollectionItemModelProtocol & MoleculeModelProtocol]?
|
||||
public var footer: MoleculeModelProtocol?
|
||||
public var columns: Int?
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Initializer
|
||||
//--------------------------------------------------
|
||||
|
||||
public init(pageType: String, screenHeading: String?, molecules: [CollectionItemModelProtocol & MoleculeModelProtocol]) {
|
||||
super.init(pageType: pageType)
|
||||
self.screenHeading = screenHeading
|
||||
self.molecules = molecules
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Keys
|
||||
//--------------------------------------------------
|
||||
|
||||
private enum CodingKeys: String, CodingKey {
|
||||
case molecules
|
||||
case header
|
||||
case footer
|
||||
case columns
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Codec
|
||||
//--------------------------------------------------
|
||||
|
||||
required public init(from decoder: Decoder) throws {
|
||||
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
||||
molecules = try typeContainer.decodeModelsIfPresent(codingKey: .molecules)
|
||||
header = try typeContainer.decodeModelIfPresent(codingKey: .header)
|
||||
footer = try typeContainer.decodeModelIfPresent(codingKey: .footer)
|
||||
columns = try typeContainer.decodeIfPresent(Int.self, forKey: .columns)
|
||||
try super.init(from: decoder)
|
||||
}
|
||||
|
||||
public override func encode(to encoder: Encoder) throws {
|
||||
try super.encode(to: encoder)
|
||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||
try container.encodeModelsIfPresent(molecules, forKey: .molecules)
|
||||
try container.encodeModelIfPresent(header, forKey: .header)
|
||||
try container.encodeModelIfPresent(footer, forKey: .footer)
|
||||
try container.encodeIfPresent(columns, forKey: .columns)
|
||||
}
|
||||
}
|
||||
|
||||
@ -81,9 +81,9 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol
|
||||
}
|
||||
|
||||
open override func handleNewData() {
|
||||
super.handleNewData()
|
||||
setup()
|
||||
registerWithTable()
|
||||
super.handleNewData()
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
|
||||
@ -51,10 +51,6 @@ import UIKit
|
||||
return molecule
|
||||
}
|
||||
|
||||
open override func spaceBetweenMiddleAndBottom() -> CGFloat? {
|
||||
return 0
|
||||
}
|
||||
|
||||
open override func spaceBetweenTopAndMiddle() -> CGFloat? {
|
||||
return 0
|
||||
}
|
||||
|
||||
104
MVMCoreUI/BaseClasses/CollectionViewCell.swift
Normal file
104
MVMCoreUI/BaseClasses/CollectionViewCell.swift
Normal file
@ -0,0 +1,104 @@
|
||||
//
|
||||
// CollectionViewCell.swift
|
||||
// MVMCoreUI
|
||||
//
|
||||
// Created by Scott Pfeil on 4/6/20.
|
||||
// Copyright © 2020 Verizon Wireless. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
/// A base collection view cell with basic mvm functionality.
|
||||
open class CollectionViewCell: UICollectionViewCell, MoleculeViewProtocol, MVMCoreViewProtocol, CollectionTemplateItemProtocol {
|
||||
|
||||
// Convenience helpers
|
||||
open var molecule: MoleculeViewProtocol?
|
||||
public let containerHelper = ContainerHelper()
|
||||
open var model: CollectionItemModelProtocol?
|
||||
|
||||
/// The width, used for establishing columns
|
||||
open var width: CGFloat?
|
||||
|
||||
private var initialSetupPerformed = false
|
||||
|
||||
// MARK: - Inits
|
||||
public override init(frame: CGRect) {
|
||||
super.init(frame: .zero)
|
||||
initialSetup()
|
||||
}
|
||||
|
||||
public required init?(coder aDecoder: NSCoder) {
|
||||
super.init(coder: aDecoder)
|
||||
initialSetup()
|
||||
}
|
||||
|
||||
private func initialSetup() {
|
||||
if !initialSetupPerformed {
|
||||
initialSetupPerformed = true
|
||||
setupView()
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - MVMCoreViewProtocol
|
||||
open func setupView() {
|
||||
isAccessibilityElement = false
|
||||
contentView.isAccessibilityElement = false
|
||||
insetsLayoutMarginsFromSafeArea = false
|
||||
contentView.insetsLayoutMarginsFromSafeArea = false
|
||||
contentView.preservesSuperviewLayoutMargins = false
|
||||
MVMCoreUIUtility.setMarginsFor(self, leading: 0, top: 0, trailing: 0, bottom: 0)
|
||||
}
|
||||
|
||||
open func updateView(_ size: CGFloat) {
|
||||
if let model = model as? ContainerModelProtocol {
|
||||
containerHelper.updateViewMargins(contentView, model: model, size: size)
|
||||
}
|
||||
(molecule as? MVMCoreViewProtocol)?.updateView(size)
|
||||
}
|
||||
|
||||
open func reset() {
|
||||
molecule?.reset()
|
||||
backgroundColor = .white
|
||||
width = nil
|
||||
}
|
||||
|
||||
// MARK: - MoleculeViewProtocol
|
||||
open func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
|
||||
guard let model = model as? CollectionItemModelProtocol else { return }
|
||||
self.model = model
|
||||
|
||||
if let moleculeModel = model as? MoleculeModelProtocol,
|
||||
let backgroundColor = moleculeModel.backgroundColor {
|
||||
self.backgroundColor = backgroundColor.uiColor
|
||||
}
|
||||
|
||||
// align if needed.
|
||||
if let model = model as? ContainerModelProtocol {
|
||||
containerHelper.set(with: model, for: molecule as? MVMCoreUIViewConstrainingProtocol)
|
||||
}
|
||||
}
|
||||
|
||||
/// Convenience function. Adds a molecule to the view.
|
||||
open func addMolecule(_ molecule: MoleculeViewProtocol) {
|
||||
contentView.addSubview(molecule)
|
||||
containerHelper.constrainView(molecule)
|
||||
self.molecule = molecule
|
||||
}
|
||||
|
||||
// MARK: - CollectionTemplateItemProtocol
|
||||
public func set(width: CGFloat) {
|
||||
self.width = width
|
||||
}
|
||||
|
||||
// Column logic, set width.
|
||||
override open func preferredLayoutAttributesFitting(_ layoutAttributes: UICollectionViewLayoutAttributes) -> UICollectionViewLayoutAttributes {
|
||||
let autoLayoutAttributes = super.preferredLayoutAttributesFitting(layoutAttributes)
|
||||
guard let width = width else { return autoLayoutAttributes }
|
||||
|
||||
let targetSize = CGSize(width: width, height: 0)
|
||||
let newSize = contentView.systemLayoutSizeFitting(targetSize, withHorizontalFittingPriority: UILayoutPriority.required, verticalFittingPriority: UILayoutPriority.defaultLow)
|
||||
let newFrame = CGRect(origin: autoLayoutAttributes.frame.origin, size: newSize)
|
||||
autoLayoutAttributes.frame = newFrame
|
||||
return autoLayoutAttributes
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
//
|
||||
// CollectionItemModelProtocol.swift
|
||||
// MVMCoreUI
|
||||
//
|
||||
// Created by Scott Pfeil on 4/6/20.
|
||||
// Copyright © 2020 Verizon Wireless. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public protocol CollectionItemModelProtocol {
|
||||
|
||||
}
|
||||
@ -0,0 +1,30 @@
|
||||
//
|
||||
// ContainerCollectionReusableView.swift
|
||||
// MVMCoreUI
|
||||
//
|
||||
// Created by Scott Pfeil on 4/7/20.
|
||||
// Copyright © 2020 Verizon Wireless. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
/// CollectionReusableView that can contains any other view.
|
||||
public class ContainerCollectionReusableView: UICollectionReusableView {
|
||||
public var view: UIView?
|
||||
public var topConstraint: NSLayoutConstraint?
|
||||
public var bottomConstraint: NSLayoutConstraint?
|
||||
|
||||
public func addAndContain(view: UIView) {
|
||||
guard self.view != view else { return }
|
||||
self.view?.removeFromSuperview()
|
||||
view.setContentCompressionResistancePriority(.required, for: .vertical)
|
||||
addSubview(view)
|
||||
self.view = view
|
||||
topConstraint = view.topAnchor.constraint(equalTo: topAnchor)
|
||||
topConstraint?.isActive = true
|
||||
bottomConstraint = bottomAnchor.constraint(equalTo: view.bottomAnchor)
|
||||
bottomConstraint?.isActive = true
|
||||
rightAnchor.constraint(equalTo: view.rightAnchor).isActive = true
|
||||
view.leftAnchor.constraint(equalTo: leftAnchor).isActive = true
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,81 @@
|
||||
//
|
||||
// ProgrammaticCollectionViewController.swift
|
||||
// MVMCoreUI
|
||||
//
|
||||
// Created by Scott Pfeil on 4/8/20.
|
||||
// Copyright © 2020 Verizon Wireless. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
/// A base view controller with a collection view.
|
||||
@objc open class ProgrammaticCollectionViewController: ScrollingViewController {
|
||||
|
||||
public var collectionView: UICollectionView?
|
||||
|
||||
open override func loadView() {
|
||||
let view = UIView()
|
||||
view.backgroundColor = .white
|
||||
|
||||
let collection = createCollectionView()
|
||||
view.addSubview(collection)
|
||||
NSLayoutConstraint.constraintPinSubview(toSuperview: collection)
|
||||
|
||||
collectionView = collection
|
||||
scrollView = collectionView
|
||||
self.view = view
|
||||
}
|
||||
|
||||
/// A place to register cells with the collectionView
|
||||
open func registerCells() {}
|
||||
|
||||
open override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
registerCells()
|
||||
}
|
||||
|
||||
/// Creates the layout for the collection.
|
||||
open func createCollectionViewLayout() -> UICollectionViewLayout {
|
||||
let layout = UICollectionViewFlowLayout()
|
||||
layout.scrollDirection = .vertical
|
||||
layout.minimumLineSpacing = 0
|
||||
layout.minimumInteritemSpacing = 0
|
||||
layout.estimatedItemSize = UICollectionViewFlowLayout.automaticSize
|
||||
return layout
|
||||
}
|
||||
|
||||
/// Creates the collection view.
|
||||
open func createCollectionView() -> UICollectionView {
|
||||
let collection = UICollectionView(frame: .zero, collectionViewLayout: createCollectionViewLayout())
|
||||
collection.translatesAutoresizingMaskIntoConstraints = false
|
||||
collection.dataSource = self
|
||||
collection.delegate = self
|
||||
collection.showsHorizontalScrollIndicator = false
|
||||
collection.backgroundColor = .white
|
||||
collection.isAccessibilityElement = false
|
||||
collection.contentInsetAdjustmentBehavior = .always
|
||||
return collection
|
||||
}
|
||||
|
||||
deinit {
|
||||
collectionView?.delegate = nil
|
||||
collectionView?.dataSource = nil
|
||||
}
|
||||
}
|
||||
|
||||
extension ProgrammaticCollectionViewController: UICollectionViewDataSource {
|
||||
open func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
||||
return 0
|
||||
}
|
||||
|
||||
open func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
||||
return UICollectionViewCell()
|
||||
}
|
||||
|
||||
open func numberOfSections(in collectionView: UICollectionView) -> Int {
|
||||
return 1
|
||||
}
|
||||
}
|
||||
|
||||
extension ProgrammaticCollectionViewController: UICollectionViewDelegate {
|
||||
}
|
||||
@ -42,6 +42,11 @@ open class ProgrammaticTableViewController: ProgrammaticScrollViewController, UI
|
||||
self.view = view
|
||||
}
|
||||
|
||||
open override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
registerWithTable()
|
||||
}
|
||||
|
||||
/// 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)
|
||||
|
||||
@ -0,0 +1,223 @@
|
||||
//
|
||||
// ThreeLayerCollectionViewController.swift
|
||||
// MVMCoreUI
|
||||
//
|
||||
// Created by Scott Pfeil on 4/6/20.
|
||||
// Copyright © 2020 Verizon Wireless. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
/// A view controller that has three main layers, a header, collection rows, and a footer. The header is added as a supplement header to the first section, and the footer is added as a supplement footer to the last section. This view controller allows for flexible space between the three layers to fit the screeen.
|
||||
@objc open class ThreeLayerCollectionViewController: ProgrammaticCollectionViewController, UICollectionViewDelegateFlowLayout {
|
||||
|
||||
private var topView: UIView?
|
||||
private var bottomView: UIView?
|
||||
private var headerView: ContainerCollectionReusableView?
|
||||
private var footerView: ContainerCollectionReusableView?
|
||||
private let headerID = "header"
|
||||
private let footerID = "footer"
|
||||
|
||||
/// Updates the padding for flexible space (header or footer)
|
||||
private func updateFlexibleSpace() {
|
||||
guard let tableView = collectionView else { return }
|
||||
|
||||
let minimumSpace: CGFloat = minimumFillSpace()
|
||||
var currentSpace: CGFloat = 0
|
||||
var totalMinimumSpace: CGFloat = 0
|
||||
|
||||
var fillTop = false
|
||||
if spaceBelowTopView() == nil, headerView != nil {
|
||||
fillTop = true
|
||||
currentSpace += headerView?.bottomConstraint?.constant ?? 0
|
||||
totalMinimumSpace += minimumSpace
|
||||
}
|
||||
|
||||
var fillBottom = false
|
||||
if spaceAboveBottomView() == nil, footerView != nil {
|
||||
fillBottom = true
|
||||
currentSpace += footerView?.topConstraint?.constant ?? 0
|
||||
totalMinimumSpace += minimumSpace
|
||||
}
|
||||
|
||||
guard fillTop || fillBottom else { return }
|
||||
|
||||
let newSpace = MVMCoreUIUtility.getVariableConstraintHeight(currentSpace, in: tableView, minimumHeight: totalMinimumSpace)
|
||||
|
||||
// If the bottom view is outside of the scroll, then only the top view constraint is being used, so we have to double it to account for the bottom constraint not being there when we compare to the new value.
|
||||
var currentSpaceForCompare: CGFloat = currentSpace
|
||||
if fillTop {
|
||||
currentSpaceForCompare = currentSpace * 2;
|
||||
}
|
||||
|
||||
if !MVMCoreGetterUtility.cgfequalwiththreshold(newSpace, currentSpaceForCompare, 1) {
|
||||
if fillTop && fillBottom {
|
||||
// space both
|
||||
let half = newSpace / 2
|
||||
headerView?.bottomConstraint?.constant = half
|
||||
footerView?.topConstraint?.constant = half
|
||||
collectionView?.collectionViewLayout.invalidateLayout()
|
||||
} else if fillTop {
|
||||
// Only top is spaced (half the size if the bottom view is out of the scroll because it needs to be sized as if there are two spacers but there is only one.
|
||||
headerView?.bottomConstraint?.constant = newSpace
|
||||
collectionView?.collectionViewLayout.invalidateLayout()
|
||||
} else if fillBottom {
|
||||
// Only bottom is spaced.
|
||||
footerView?.topConstraint?.constant = newSpace
|
||||
collectionView?.collectionViewLayout.invalidateLayout()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//MARK: - ViewController
|
||||
open override func updateViews() {
|
||||
super.updateViews()
|
||||
// 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()
|
||||
}
|
||||
}
|
||||
|
||||
open override func handleNewData() {
|
||||
super.handleNewData()
|
||||
createViewForHeader()
|
||||
createViewForFooter()
|
||||
reloadCollectionData()
|
||||
}
|
||||
|
||||
override open func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
// Do any additional setup after loading the view.
|
||||
}
|
||||
|
||||
//MARK: - Spacing
|
||||
// If both are subclassed to return a value, then the buttons will not be pinned towards the bottom because neither spacing would try to fill the screen.
|
||||
/// Space between the top view and the collection rows, nil to fill. 0 default
|
||||
open func spaceBelowTopView() -> CGFloat? {
|
||||
return 0
|
||||
}
|
||||
|
||||
/// Space between the bottom view and the collection rows, nil to fill. nil default
|
||||
open func spaceAboveBottomView() -> CGFloat? {
|
||||
return nil
|
||||
}
|
||||
|
||||
/// can override to return a minimum fill space. 0 default
|
||||
open func minimumFillSpace() -> CGFloat {
|
||||
return 0
|
||||
}
|
||||
|
||||
//MARK: - Header Footer
|
||||
/// Creates the top view.
|
||||
open func createViewForHeader() {
|
||||
guard let topView = viewForTop() else {
|
||||
self.topView = nil
|
||||
self.headerView = nil
|
||||
return
|
||||
}
|
||||
self.topView = topView
|
||||
}
|
||||
|
||||
/// Creates the footer
|
||||
open func createViewForFooter() {
|
||||
guard let bottomView = viewForBottom() else {
|
||||
self.bottomView = nil
|
||||
self.footerView = nil
|
||||
return
|
||||
}
|
||||
self.bottomView = bottomView
|
||||
}
|
||||
|
||||
//MARK: - Functions to subclass
|
||||
/// Subclass for a top view.
|
||||
open func viewForTop() -> UIView? {
|
||||
return nil
|
||||
}
|
||||
|
||||
/// Subclass for a bottom view.
|
||||
open func viewForBottom() -> UIView? {
|
||||
return nil
|
||||
}
|
||||
|
||||
//MARK: - Collection
|
||||
|
||||
/// Should be used to refresh the layout of the collection view. Updates flexible padding.
|
||||
open func invalidateCollectionLayout() {
|
||||
self.collectionView?.collectionViewLayout.invalidateLayout()
|
||||
// TODO: Improve this workaround (autolayout for cells happens async so contentSize isn't accurate immediately)
|
||||
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.1, execute: {
|
||||
self.updateFlexibleSpace()
|
||||
})
|
||||
}
|
||||
|
||||
/// Should be used to reload the data of the collection view. Updates flexible padding.
|
||||
open func reloadCollectionData() {
|
||||
collectionView?.reloadData()
|
||||
// TODO: Improve this workaround (autolayout for cells happens async so contentSize isn't accurate immediately)
|
||||
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.1, execute: {
|
||||
self.updateFlexibleSpace()
|
||||
})
|
||||
}
|
||||
|
||||
/// 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)
|
||||
collectionView?.register(ContainerCollectionReusableView.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionFooter, withReuseIdentifier: footerID)
|
||||
}
|
||||
|
||||
open override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
||||
return 0
|
||||
}
|
||||
|
||||
open func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
|
||||
guard let _ = topView,
|
||||
section == 0 else { return .zero }
|
||||
|
||||
// Calculate the height of the header since apple doesn't support autolayout. Width is fixed, height is tall as content.
|
||||
let header = headerView ?? self.collectionView(collectionView, viewForSupplementaryElementOfKind: UICollectionView.elementKindSectionHeader, at: IndexPath(row: 0, section: section))
|
||||
return header.systemLayoutSizeFitting(CGSize(width: collectionView.frame.width, height: UIView.layoutFittingExpandedSize.height), withHorizontalFittingPriority: .required, verticalFittingPriority: .fittingSizeLevel)
|
||||
}
|
||||
|
||||
open func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForFooterInSection section: Int) -> CGSize {
|
||||
guard let _ = bottomView,
|
||||
section == numberOfSections(in: collectionView) - 1 else { return .zero }
|
||||
|
||||
// Calculate the height of the footr since apple doesn't support autolayout. Width is fixed, height is tall as content.
|
||||
let footer = footerView ?? self.collectionView(collectionView, viewForSupplementaryElementOfKind: UICollectionView.elementKindSectionFooter, at: IndexPath(row: 0, section: section))
|
||||
return footer.systemLayoutSizeFitting(CGSize(width: collectionView.frame.width, height: UIView.layoutFittingExpandedSize.height), withHorizontalFittingPriority: .required, verticalFittingPriority: .fittingSizeLevel)
|
||||
}
|
||||
|
||||
open func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
|
||||
if kind == UICollectionView.elementKindSectionFooter,
|
||||
let footerView = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: footerID, for: indexPath) as? ContainerCollectionReusableView {
|
||||
footerView.addAndContain(view: bottomView!)
|
||||
footerView.topConstraint?.constant = spaceAboveBottomView() ?? 0
|
||||
self.footerView = footerView
|
||||
return footerView
|
||||
} else if kind == UICollectionView.elementKindSectionHeader,
|
||||
let headerView = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: headerID, for: indexPath) as? ContainerCollectionReusableView {
|
||||
headerView.addAndContain(view: topView!)
|
||||
headerView.bottomConstraint?.constant = spaceBelowTopView() ?? 0
|
||||
self.headerView = headerView
|
||||
return headerView
|
||||
}
|
||||
fatalError()
|
||||
}
|
||||
}
|
||||
@ -33,7 +33,7 @@ open class ThreeLayerTableViewController: ProgrammaticTableViewController {
|
||||
bottomView.updateView(width)
|
||||
showFooter(width)
|
||||
}
|
||||
self.tableView?.reloadData()
|
||||
tableView?.reloadData()
|
||||
}
|
||||
|
||||
open override func handleNewData() {
|
||||
|
||||
@ -24,7 +24,7 @@ import UIKit
|
||||
|
||||
public var formValidator: FormValidator?
|
||||
|
||||
public var needsUpdateUI = true
|
||||
public var needsUpdateUI = false
|
||||
private var observingForResponses = false
|
||||
private var initialLoadFinished = false
|
||||
private var previousScreenSize = CGSize.zero
|
||||
@ -151,8 +151,8 @@ import UIKit
|
||||
/// Calls processNewData and then sets the ui to update with updateView
|
||||
open func handleNewDataAndUpdateUI() {
|
||||
handleNewData()
|
||||
self.needsUpdateUI = true
|
||||
self.view.setNeedsLayout()
|
||||
needsUpdateUI = true
|
||||
view.setNeedsLayout()
|
||||
}
|
||||
|
||||
/// Processes any new data. Called after the page is loaded the first time and on response updates for this page,
|
||||
@ -166,9 +166,9 @@ import UIKit
|
||||
navigationModel.line = LineModel(type: .none)
|
||||
}
|
||||
pageModel?.navigationItem = navigationModel
|
||||
if self.formValidator == nil {
|
||||
if formValidator == nil {
|
||||
let rules = pageModel?.formRules
|
||||
self.formValidator = FormValidator(rules)
|
||||
formValidator = FormValidator(rules)
|
||||
}
|
||||
}
|
||||
|
||||
@ -265,10 +265,10 @@ import UIKit
|
||||
initialLoad()
|
||||
}
|
||||
|
||||
// Handle data on load
|
||||
handleNewData()
|
||||
|
||||
view.setNeedsLayout()
|
||||
// Handle data for first load. Dispatched to allow subclasses to finish their view did load implementations.
|
||||
DispatchQueue.main.async {
|
||||
self.handleNewDataAndUpdateUI()
|
||||
}
|
||||
}
|
||||
|
||||
open override func viewDidLayoutSubviews() {
|
||||
@ -278,7 +278,8 @@ import UIKit
|
||||
return
|
||||
}
|
||||
|
||||
if needsUpdateUI || screenSizeChanged() {
|
||||
// First update should be explicit (hence the zero check)
|
||||
if needsUpdateUI || (previousScreenSize != .zero && screenSizeChanged()) {
|
||||
updateViews()
|
||||
needsUpdateUI = false
|
||||
}
|
||||
|
||||
@ -24,7 +24,8 @@
|
||||
@"list" : [[MVMCoreViewControllerProgrammaticMappingObject alloc] initWithClass:[MoleculeListTemplate class]],
|
||||
@"threeLayer" : [[MVMCoreViewControllerProgrammaticMappingObject alloc] initWithClass:[ThreeLayerTemplate class]],
|
||||
@"modalStack" : [[MVMCoreViewControllerProgrammaticMappingObject alloc] initWithClass:[ModalMoleculeStackTemplate class]],
|
||||
@"modalList" : [[MVMCoreViewControllerProgrammaticMappingObject alloc] initWithClass:[ModalMoleculeListTemplate class]]
|
||||
@"modalList" : [[MVMCoreViewControllerProgrammaticMappingObject alloc] initWithClass:[ModalMoleculeListTemplate class]],
|
||||
@"collection" : [[MVMCoreViewControllerProgrammaticMappingObject alloc] initWithClass:[CollectionTemplate class]]
|
||||
} mutableCopy];
|
||||
});
|
||||
return viewControllerMapping;
|
||||
|
||||
@ -164,11 +164,10 @@
|
||||
CGFloat topInset = scrollview.contentInset.top;
|
||||
CGFloat bottomInset = scrollview.contentInset.bottom;
|
||||
|
||||
if (scrollview.contentInsetAdjustmentBehavior == UIScrollViewContentInsetAdjustmentAutomatic) {
|
||||
if (scrollview.contentInsetAdjustmentBehavior == UIScrollViewContentInsetAdjustmentAutomatic || scrollview.contentInsetAdjustmentBehavior == UIScrollViewContentInsetAdjustmentAlways) {
|
||||
topInset = scrollview.adjustedContentInset.top;
|
||||
bottomInset = scrollview.adjustedContentInset.bottom;
|
||||
}
|
||||
|
||||
CGFloat remainingSpace = frameHeight - contentSizeHeight - topInset - bottomInset;
|
||||
return remainingSpace - 1;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user