diff --git a/MVMCoreUI/Atoms/Views/CaretViewModel.swift b/MVMCoreUI/Atoms/Views/CaretViewModel.swift index 37d095d8..5a8998db 100644 --- a/MVMCoreUI/Atoms/Views/CaretViewModel.swift +++ b/MVMCoreUI/Atoms/Views/CaretViewModel.swift @@ -10,11 +10,8 @@ import Foundation @objcMembers public class CaretViewModel: MoleculeProtocol { - public static var identifier: String { - get{ return "caretView" } - } + public static var identifier: String = "caretView" public var backgroundColor: String? - public var strokeColor: String? public var isHidden: Bool? public var isOpaque: Bool? diff --git a/MVMCoreUI/Atoms/Views/ProgressBar.swift b/MVMCoreUI/Atoms/Views/ProgressBar.swift index 0a29d62a..b640e4c7 100644 --- a/MVMCoreUI/Atoms/Views/ProgressBar.swift +++ b/MVMCoreUI/Atoms/Views/ProgressBar.swift @@ -57,7 +57,7 @@ import Foundation } isRounded = progressBarModel.isRounded ?? false thickness = progressBarModel.thickness ?? 8 - progress = (progressBarModel.percentage )/100.0 + progress = (progressBarModel.percentage)/100.0 if let progressColor = progressBarModel.progressColor { progressTintColor = UIColor.mfGet(forHex: progressColor) } diff --git a/MVMCoreUI/Models/ModelProtocols/MoleculeProtocol.swift b/MVMCoreUI/Models/ModelProtocols/MoleculeProtocol.swift index 581f487c..e05f16b6 100644 --- a/MVMCoreUI/Models/ModelProtocols/MoleculeProtocol.swift +++ b/MVMCoreUI/Models/ModelProtocols/MoleculeProtocol.swift @@ -2,7 +2,7 @@ import Foundation public protocol MoleculeProtocol: Model { var moleculeName: String? { get } - var backgroundColor: String? { get } + var backgroundColor: String? { get set} } extension MoleculeProtocol { diff --git a/MVMCoreUI/Models/Molecules/CarouselItemModel.swift b/MVMCoreUI/Models/Molecules/CarouselItemModel.swift index bb45f29c..3339ed09 100644 --- a/MVMCoreUI/Models/Molecules/CarouselItemModel.swift +++ b/MVMCoreUI/Models/Molecules/CarouselItemModel.swift @@ -12,6 +12,7 @@ import Foundation @objcMembers public class CarouselItemModel: ContainerMoleculeProtocol { public static var identifier: String = "carouselItem" public var molecule: MoleculeProtocol + public var backgroundColor: String? public init(molecule: MoleculeProtocol) { self.molecule = molecule @@ -26,13 +27,13 @@ import Foundation required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) molecule = try typeContainer.decodeMolecule(codingKey: .molecule) - //(codingKey: .molecule) + backgroundColor = try typeContainer.decodeIfPresent(String.self, forKey: .backgroundColor) } public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(moleculeName, forKey: .moleculeName) - try container.encode(backgroundColor, forKey: .backgroundColor) - try container.encodeModel(molecule, forKey: .molecule) + try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) + try container.encodeModelIfPresent(molecule, forKey: .molecule) } } diff --git a/MVMCoreUI/Models/Molecules/CarouselModel.swift b/MVMCoreUI/Models/Molecules/CarouselModel.swift index e735d516..56bec824 100644 --- a/MVMCoreUI/Models/Molecules/CarouselModel.swift +++ b/MVMCoreUI/Models/Molecules/CarouselModel.swift @@ -21,20 +21,13 @@ import UIKit public var itemAlignment: String? public var pagingMolecule: PagingMoleculeProtocol? - public init(molecules: [CarouselItemModel], spacing: Float?, border: Bool?, loop: Bool?, height: Float?, itemWidthPercent: Float?, itemAlignment: String?, pagingMolecule: PagingMoleculeProtocol?, backgroundColor: String?){ + public init(molecules: [CarouselItemModel]){ self.molecules = molecules - self.spacing = spacing - self.border = border - self.loop = loop - self.height = height - self.itemWidthPercent = itemWidthPercent - self.itemAlignment = itemAlignment - self.pagingMolecule = pagingMolecule - self.backgroundColor = backgroundColor } enum CodingKeys: String, CodingKey { case moleculeName + case backgroundColor case molecules case spacing case border @@ -48,6 +41,7 @@ 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(String.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) @@ -59,7 +53,8 @@ import UIKit public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(moleculeName, forKey: .moleculeName) + try container.encodeIfPresent(moleculeName, forKey: .moleculeName) + try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) try container.encode(molecules, forKey: .molecules) try container.encode(spacing, forKey: .spacing) try container.encode(border, forKey: .border) diff --git a/MVMCoreUI/Models/Molecules/DropDownListItemModel.swift b/MVMCoreUI/Models/Molecules/DropDownListItemModel.swift index 13ed71e2..9e447713 100644 --- a/MVMCoreUI/Models/Molecules/DropDownListItemModel.swift +++ b/MVMCoreUI/Models/Molecules/DropDownListItemModel.swift @@ -35,7 +35,7 @@ import Foundation let typeContainer = try decoder.container(keyedBy: CodingKeys.self) molecule = try typeContainer.decodeMolecule(codingKey: .molecule) self.molecules = try typeContainer.decode([[ListItemModel]].self, forKey: .molecules) - self.separator = try typeContainer.decode(LineModel.self, forKey: .separator) + self.separator = try typeContainer.decodeIfPresent(LineModel.self, forKey: .separator) self.backgroundColor = try typeContainer.decodeIfPresent(String.self, forKey: .backgroundColor) self.dropDown = try typeContainer.decode(DropDownModel.self, forKey: .dropDown) } diff --git a/MVMCoreUI/Models/Molecules/FooterModel.swift b/MVMCoreUI/Models/Molecules/FooterModel.swift index fe8f688e..83043f81 100644 --- a/MVMCoreUI/Models/Molecules/FooterModel.swift +++ b/MVMCoreUI/Models/Molecules/FooterModel.swift @@ -23,7 +23,6 @@ import Foundation case moleculeName case molecule case backgroundColor - case separator } required public init(from decoder: Decoder) throws { diff --git a/MVMCoreUI/Models/Molecules/MoleculeStackItemModel.swift b/MVMCoreUI/Models/Molecules/MoleculeStackItemModel.swift index f9f92c05..fe532654 100644 --- a/MVMCoreUI/Models/Molecules/MoleculeStackItemModel.swift +++ b/MVMCoreUI/Models/Molecules/MoleculeStackItemModel.swift @@ -31,6 +31,7 @@ import Foundation enum CodingKeys: String, CodingKey { case moleculeName case molecule + case backgroundColor case spacing case percentage case verticalAlignment @@ -41,6 +42,7 @@ import Foundation required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) self.molecule = try typeContainer.decodeMoleculeIfPresent(codingKey: .molecule) + self.backgroundColor = try typeContainer.decodeIfPresent(String.self, forKey: .backgroundColor) self.spacing = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .spacing) self.percentage = try typeContainer.decodeIfPresent(Int.self, forKey: .percentage) @@ -53,5 +55,10 @@ import Foundation var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(moleculeName, forKey: .moleculeName) try container.encodeModelIfPresent(self.molecule, forKey: .molecule) + try container.encodeIfPresent(spacing, forKey: .spacing) + try container.encodeIfPresent(percentage, forKey: .percentage) + try container.encodeIfPresent(verticalAlignment, forKey: .verticalAlignment) + try container.encodeIfPresent(horizontalAlignment, forKey: .horizontalAlignment) + try container.encodeIfPresent(gone, forKey: .gone) } } diff --git a/MVMCoreUI/Models/Molecules/MoleculeStackModel.swift b/MVMCoreUI/Models/Molecules/MoleculeStackModel.swift index 9c462339..b50e1ae6 100644 --- a/MVMCoreUI/Models/Molecules/MoleculeStackModel.swift +++ b/MVMCoreUI/Models/Molecules/MoleculeStackModel.swift @@ -16,31 +16,28 @@ import Foundation public var axis: String? public var spacing: Float? - public init(axis: String?, molecules: [MoleculeStackItemModel]?, spacing: Float?) { - self.axis = axis - self.molecules = molecules - self.spacing = spacing - } - enum CodingKeys: String, CodingKey { case moleculeName case molecules case axis case spacing + case backgroundColor } required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) - self.molecules = try typeContainer.decodeIfPresent([MoleculeStackItemModel].self, forKey: .molecules) - self.axis = try typeContainer.decodeIfPresent(String.self, forKey: .axis) - self.spacing = try typeContainer.decodeIfPresent(Float.self, forKey: .spacing) + molecules = try typeContainer.decodeIfPresent([MoleculeStackItemModel].self, forKey: .molecules) + axis = try typeContainer.decodeIfPresent(String.self, forKey: .axis) + spacing = try typeContainer.decodeIfPresent(Float.self, forKey: .spacing) + backgroundColor = try typeContainer.decodeIfPresent(String.self, forKey: .backgroundColor) } public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(moleculeName, forKey: .moleculeName) + try container.encodeIfPresent(moleculeName, forKey: .moleculeName) try container.encodeIfPresent(molecules, forKey: .molecules) - try container.encode(axis, forKey: .axis) - try container.encode(spacing, forKey: .spacing) + try container.encodeIfPresent(axis, forKey: .axis) + try container.encodeIfPresent(spacing, forKey: .spacing) + try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) } } diff --git a/MVMCoreUI/Models/Template/ListPageTemplateModel.swift b/MVMCoreUI/Models/Template/ListPageTemplateModel.swift index 7533d722..587cf6a5 100644 --- a/MVMCoreUI/Models/Template/ListPageTemplateModel.swift +++ b/MVMCoreUI/Models/Template/ListPageTemplateModel.swift @@ -55,7 +55,7 @@ import Foundation try container.encode(pageType, forKey: .pageType) try container.encode(screenHeading, forKey: .screenHeading) - try container.encodeModelsIfPresent(molecules, forKey: .molecules) + try container.encodeModels(molecules, forKey: .molecules) try container.encodeIfPresent(isAtomicTabs, forKey: .isAtomicTabs) try container.encodeIfPresent(header, forKey: .header) try container.encodeIfPresent(footer, forKey: .footer) diff --git a/MVMCoreUI/Molecules/Items/ListItemModel.swift b/MVMCoreUI/Molecules/Items/ListItemModel.swift index a24ff967..1311e69f 100644 --- a/MVMCoreUI/Molecules/Items/ListItemModel.swift +++ b/MVMCoreUI/Molecules/Items/ListItemModel.swift @@ -25,6 +25,7 @@ import MVMCore enum CodingKeys: String, CodingKey { case moleculeName case molecule + case backgroundColor case action case hideArrow case separator @@ -43,7 +44,8 @@ import MVMCore public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(moleculeName, forKey: .moleculeName) - try container.encodeModel(molecule, forKey: .molecule) + try container.encodeModelIfPresent(molecule, forKey: .molecule) + try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) try container.encodeModelIfPresent(action, forKey: .action) try container.encodeIfPresent(hideArrow, forKey: .hideArrow) try container.encodeIfPresent(separator, forKey: .separator) diff --git a/MVMCoreUI/Organisms/Carousel.swift b/MVMCoreUI/Organisms/Carousel.swift index 116f1135..3adba7a7 100644 --- a/MVMCoreUI/Organisms/Carousel.swift +++ b/MVMCoreUI/Organisms/Carousel.swift @@ -35,7 +35,7 @@ open class Carousel: ViewConstrainingView, ModelMoleculeViewProtocol { var itemAlignment = UICollectionView.ScrollPosition.left /// From 0-1. The item width as a percent of the carousel width. - var itemWidthPercent: CGFloat = 1 + var itemWidthPercent: Float = 1 /// The height of the carousel. Default is 300. var collectionViewHeight: NSLayoutConstraint? @@ -98,7 +98,7 @@ open class Carousel: ViewConstrainingView, ModelMoleculeViewProtocol { registerCells(with: caroselModel, delegateObject: delegateObject) setupLayout(with: caroselModel) prepareMolecules(with: caroselModel) - itemWidthPercent = CGFloat((caroselModel.itemWidthPercent ?? 100) / 100) + itemWidthPercent = (caroselModel.itemWidthPercent ?? 100) / 100 setAlignment(with: caroselModel.itemAlignment) if let height = caroselModel.height { @@ -263,7 +263,7 @@ open class Carousel: ViewConstrainingView, ModelMoleculeViewProtocol { extension Carousel: UICollectionViewDelegateFlowLayout { public func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { - let itemWidth = collectionView.bounds.width * itemWidthPercent + let itemWidth = collectionView.bounds.width * CGFloat(itemWidthPercent) return CGSize(width: itemWidth, height: collectionView.bounds.height) } @@ -333,7 +333,7 @@ extension Carousel: UIScrollViewDelegate { } // Checks if the user is not paging but attempting to drag endlessly and goes out of bounds. Caps the index. if let separatorWidth = (collectionView.collectionViewLayout as? UICollectionViewFlowLayout)?.minimumLineSpacing { - let itemWidth = collectionView.bounds.width * itemWidthPercent + let itemWidth = collectionView.bounds.width * CGFloat(itemWidthPercent) let index = scrollView.contentOffset.x / (itemWidth + separatorWidth) let lastCellIndex = collectionView(collectionView, numberOfItemsInSection: 0) - 1 if index < 1 { @@ -370,7 +370,7 @@ extension Carousel: UIScrollViewDelegate { } // We switch cards if we pass the velocity threshold or position threshold (currently 50%). - let itemWidth = collectionView.bounds.width * itemWidthPercent + let itemWidth = collectionView.bounds.width * CGFloat(itemWidthPercent) var cellToSwipeTo = Int(scrollView.contentOffset.x/(itemWidth + separatorWidth) + 0.5) let lastCellIndex = collectionView(collectionView, numberOfItemsInSection: 0) - 1 let velocityThreshold: CGFloat = 1.1