This commit is contained in:
Suresh, Kamlesh 2019-12-20 12:07:59 -05:00
commit 7b0e423759
12 changed files with 38 additions and 40 deletions

View File

@ -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?

View File

@ -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)
}

View File

@ -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 {

View File

@ -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)
}
}

View File

@ -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)

View File

@ -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)
}

View File

@ -23,7 +23,6 @@ import Foundation
case moleculeName
case molecule
case backgroundColor
case separator
}
required public init(from decoder: Decoder) throws {

View File

@ -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)
}
}

View File

@ -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)
}
}

View File

@ -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)

View File

@ -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)

View File

@ -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