diff --git a/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/CarouselIndicator.swift b/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/CarouselIndicator.swift index 1e4db496..0604d3a0 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/CarouselIndicator.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/CarouselIndicator.swift @@ -58,6 +58,7 @@ open class CarouselIndicator: Control, CarouselPageControlProtocol { } } + /// The maxmum count of pages before the indicatorView forces a Numeric Indicator in place of Bar. private var _numberOfPages = 0 /// Holds the total number of pages displayed by the carousel. diff --git a/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/CarouselIndicatorModel.swift b/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/CarouselIndicatorModel.swift index 206e67de..3705beaa 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/CarouselIndicatorModel.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/CarouselIndicatorModel.swift @@ -15,13 +15,11 @@ open class CarouselIndicatorModel: CarouselPagingModelProtocol, MoleculeModelPro //-------------------------------------------------- public class var identifier: String { - return "" + return "barsCarouselIndicator" } public var backgroundColor: Color? public var moleculeName: String? - - /// The maxmum count of pages before the indicatorView forces a Numeric Indicator in place of Bar. public var numberOfPages: Int = 0 // Sets the current Index to focus on. @@ -67,10 +65,6 @@ open class CarouselIndicatorModel: CarouselPagingModelProtocol, MoleculeModelPro moleculeName = try typeContainer.decodeIfPresent(String.self, forKey: .moleculeName) backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) - if let numberOfPages = try typeContainer.decodeIfPresent(Int.self, forKey: .numberOfPages) { - self.numberOfPages = numberOfPages - } - if let currentIndex = try typeContainer.decodeIfPresent(Int.self, forKey: .currentIndex) { self.currentIndex = currentIndex } diff --git a/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/NumericCarouselIndicatorModel.swift b/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/NumericCarouselIndicatorModel.swift index 2b454fc8..7739dc12 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/NumericCarouselIndicatorModel.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/NumericCarouselIndicatorModel.swift @@ -8,6 +8,7 @@ import UIKit + open class NumericCarouselIndicatorModel: CarouselIndicatorModel { //-------------------------------------------------- // MARK: - Properties diff --git a/MVMCoreUI/Atomic/Organisms/Carousel.swift b/MVMCoreUI/Atomic/Organisms/Carousel.swift index 7e529ae2..215f9c12 100644 --- a/MVMCoreUI/Atomic/Organisms/Carousel.swift +++ b/MVMCoreUI/Atomic/Organisms/Carousel.swift @@ -105,25 +105,22 @@ open class Carousel: View { public override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { self.delegateObject = delegateObject super.set(with: model, delegateObject, additionalData) + guard let carouselModel = model as? CarouselModel else { return } collectionView.backgroundColor = backgroundColor collectionView.layer.borderColor = backgroundColor?.cgColor - collectionView.layer.borderWidth = (carouselModel.border ?? false) ? 1 : 0 + collectionView.layer.borderWidth = carouselModel.border ? 1 : 0 backgroundColor = .white registerCells(with: carouselModel, delegateObject: delegateObject) setupLayout(with: carouselModel) prepareMolecules(with: carouselModel) - itemWidthPercent = (carouselModel.itemWidthPercent ?? 100) / 100 - if let alignment = carouselModel.itemAlignment { - itemAlignment = alignment - } - - if let height = carouselModel.height { - collectionViewHeight?.constant = CGFloat(height) - collectionViewHeight?.isActive = true - } + itemWidthPercent = carouselModel.itemWidthPercent / 100 + itemAlignment = carouselModel.itemAlignment + + collectionViewHeight?.constant = CGFloat(carouselModel.height) + collectionViewHeight?.isActive = true setupPagingMolecule((carouselModel.pagingMolecule as! (CarouselPagingModelProtocol & MoleculeModelProtocol)), delegateObject: delegateObject) collectionView.reloadData() diff --git a/MVMCoreUI/Atomic/Organisms/CarouselModel.swift b/MVMCoreUI/Atomic/Organisms/CarouselModel.swift index 6f7d1a88..09ab708b 100644 --- a/MVMCoreUI/Atomic/Organisms/CarouselModel.swift +++ b/MVMCoreUI/Atomic/Organisms/CarouselModel.swift @@ -21,12 +21,12 @@ import UIKit public var backgroundColor: Color? public var molecules: [CarouselItemModel] public var moleculeName: String? - 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 spacing: Float = 1 + public var border: Bool = false + public var loop: Bool = false + public var height: Float = 300 + public var itemWidthPercent: Float = 100 + public var itemAlignment: UICollectionView.ScrollPosition = .left public var pagingMolecule: MoleculeModelProtocol? //-------------------------------------------------- @@ -62,12 +62,31 @@ import UIKit 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) + + if let spacing = try typeContainer.decodeIfPresent(Float.self, forKey: .spacing) { + self.spacing = spacing + } + + if let border = try typeContainer.decodeIfPresent(Bool.self, forKey: .border) { + self.border = border + } + + if let loop = try typeContainer.decodeIfPresent(Bool.self, forKey: .loop) { + self.loop = loop + } + + if let height = try typeContainer.decodeIfPresent(Float.self, forKey: .height) { + self.height = height + } + + if let itemWidthPercent = try typeContainer.decodeIfPresent(Float.self, forKey: .itemWidthPercent) { + self.itemWidthPercent = itemWidthPercent + } + + if let itemAlignment = try typeContainer.decodeIfPresent(UICollectionView.ScrollPosition.self, forKey: .itemAlignment) { + self.itemAlignment = itemAlignment + } + self.pagingMolecule = try typeContainer.decodeModelIfPresent(codingKey: .pagingMolecule) }