diff --git a/MVMCoreUI/Atomic/Atoms/Views/Arrow.swift b/MVMCoreUI/Atomic/Atoms/Views/Arrow.swift index cbd80839..bd499dc8 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/Arrow.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/Arrow.swift @@ -20,6 +20,11 @@ open class Arrow: View { return model as? ArrowModel } + public var direction: Direction { + get { return Direction(rawValue: degrees) ?? .right} + set { degrees = newValue.rawValue } + } + open var isEnabled: Bool = true { didSet { isUserInteractionEnabled = isEnabled @@ -47,6 +52,21 @@ open class Arrow: View { set { arrowModel?.lineWidth = newValue } } + //-------------------------------------------------- + // MARK: - Enum + //-------------------------------------------------- + + public enum Direction: Float { + case right = 0 + case upperRight = 45 + case up = 90 + case upperLeft = 135 + case left = 180 + case bottomLeft = 225 + case down = 270 + case bottomRight = 315 + } + //-------------------------------------------------- // MARK: - Constraints //-------------------------------------------------- diff --git a/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/BarsIndicatorView.swift b/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/BarsIndicatorView.swift index 0435e84d..3bfe8585 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/BarsIndicatorView.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/BarsIndicatorView.swift @@ -31,15 +31,15 @@ open class BarsIndicatorView: CarouselIndicator { public static let indicatorBarWidth: CGFloat = 24 public static let indicatorBarHeight: (selected: CGFloat, unselected: CGFloat) = (selected: 4, unselected: 1) + //-------------------------------------------------- + // MARK: - Computed Properties + //-------------------------------------------------- + /// Convenience to access the model. public var barsCarouselIndicatorModel: BarsCarouselIndicatorModel? { return model as? BarsCarouselIndicatorModel } - //-------------------------------------------------- - // MARK: - Computed Properties - //-------------------------------------------------- - open override var isEnabled: Bool { didSet { barReferences.forEach { view, _ in @@ -48,13 +48,10 @@ open class BarsIndicatorView: CarouselIndicator { } } - private(set) var _currentIndicatorColor: UIColor = .black - /// Colors the currently selected index, unique from other indicators public var currentIndicatorColor: UIColor { - get { return _currentIndicatorColor } + get { return barsCarouselIndicatorModel?.currentIndicatorColor.uiColor ?? .mvmBlack } set (newColor) { - _currentIndicatorColor = newColor barsCarouselIndicatorModel?.currentIndicatorColor = Color(uiColor: newColor) if !barReferences.isEmpty { @@ -64,7 +61,7 @@ open class BarsIndicatorView: CarouselIndicator { } public override var indicatorColor: UIColor { - get { return _indicatorColor } + get { return carouselIndicatorModel?.indicatorColor.uiColor ?? .mvmBlack } set (newColor) { super.indicatorColor = newColor diff --git a/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/CarouselIndicator.swift b/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/CarouselIndicator.swift index ccce0266..a2a31bd6 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/CarouselIndicator.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/CarouselIndicator.swift @@ -31,7 +31,7 @@ open class CarouselIndicator: Control, CarouselPageControlProtocol { /// Set this closure to perform an action when a different indicator was selected. /// Passes through oldInde and newIndex, respectively. public var indicatorTouchAction: ((CarouselPageControlProtocol) -> ())? - + open override var isEnabled: Bool { didSet { isUserInteractionEnabled = isEnabled } } @@ -41,15 +41,12 @@ open class CarouselIndicator: Control, CarouselPageControlProtocol { //-------------------------------------------------- private(set) var previousIndex = 0 - private var _currentIndex = 0 public var currentIndex: Int { - get { return _currentIndex } + get { return carouselIndicatorModel?.currentIndex ?? 0 } set (newIndex) { + previousIndex = currentIndex carouselIndicatorModel?.currentIndex = newIndex - previousIndex = _currentIndex - _currentIndex = newIndex - if previousIndex != newIndex { updateUI(previousIndex: previousIndex, @@ -61,18 +58,16 @@ 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. /// Updating this property will potentially update the UI. + /// The maxmum count of pages before the indicatorView forces a Numeric Indicator in place of Bar. public var numberOfPages: Int { - get { return _numberOfPages } + get { return carouselIndicatorModel?.numberOfPages ?? 0 } set (newTotal) { - guard _numberOfPages != newTotal else { return } - carouselIndicatorModel?.numberOfPages = newTotal - _numberOfPages = newTotal + guard numberOfPages != newTotal else { return } + carouselIndicatorModel?.numberOfPages = newTotal + reset() isHidden = (carouselIndicatorModel?.hidesForSinglePage ?? false) && newTotal <= 1 updateUI(previousIndex: previousIndex, newIndex: currentIndex, @@ -81,24 +76,14 @@ open class CarouselIndicator: Control, CarouselPageControlProtocol { } } - private(set) var _disabledIndicatorColor: UIColor = .mvmCoolGray3 - public var disabledIndicatorColor: UIColor { - get { return _disabledIndicatorColor } - set (newDisabledColor) { - _disabledIndicatorColor = newDisabledColor - carouselIndicatorModel?.disabledIndicatorColor = Color(uiColor: newDisabledColor) - } + get { return carouselIndicatorModel?.disabledIndicatorColor.uiColor ?? .mvmCoolGray3 } + set { carouselIndicatorModel?.disabledIndicatorColor = Color(uiColor: newValue) } } - private(set) var _indicatorColor: UIColor = .black - public var indicatorColor: UIColor { - get { return _indicatorColor } - set (newColor) { - _indicatorColor = newColor - carouselIndicatorModel?.indicatorColor = Color(uiColor: newColor) - } + get { return carouselIndicatorModel?.indicatorColor.uiColor ?? .mvmBlack } + set { carouselIndicatorModel?.indicatorColor = Color(uiColor: newValue) } } //-------------------------------------------------- diff --git a/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/CarouselIndicatorModel.swift b/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/CarouselIndicatorModel.swift index 38747771..e2683f70 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/CarouselIndicatorModel.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/CarouselIndicatorModel.swift @@ -109,8 +109,8 @@ open class CarouselIndicatorModel: CarouselPagingModelProtocol, MoleculeModelPro try container.encode(currentIndex, forKey: .currentIndex) try container.encode(alwaysSendAction, forKey: .alwaysSendAction) try container.encode(isAnimated, forKey: .isAnimated) - try container.encodeIfPresent(hidesForSinglePage, forKey: .hidesForSinglePage) - try container.encodeIfPresent(accessibilityHasSlidesInsteadOfPage, forKey: .accessibilityHasSlidesInsteadOfPage) + try container.encode(hidesForSinglePage, forKey: .hidesForSinglePage) + try container.encode(accessibilityHasSlidesInsteadOfPage, forKey: .accessibilityHasSlidesInsteadOfPage) try container.encode(isEnabled, forKey: .isEnabled) try container.encode(disabledIndicatorColor, forKey: .disabledIndicatorColor) try container.encode(indicatorColor, forKey: .indicatorColor) diff --git a/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/NumericIndicatorView.swift b/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/NumericIndicatorView.swift index 8d00786c..bf090066 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/NumericIndicatorView.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/NumericIndicatorView.swift @@ -55,7 +55,7 @@ open class NumericIndicatorView: CarouselIndicator { /// Sets the color for pageCount text, left arrow and right arrow. public override var indicatorColor: UIColor { - get { return _indicatorColor } + get { return carouselIndicatorModel?.indicatorColor.uiColor ?? .mvmBlack } set (newColor) { super.indicatorColor = newColor diff --git a/MVMCoreUI/Atomic/Organisms/Carousel.swift b/MVMCoreUI/Atomic/Organisms/Carousel.swift index 699a036d..c6c9f05c 100644 --- a/MVMCoreUI/Atomic/Organisms/Carousel.swift +++ b/MVMCoreUI/Atomic/Organisms/Carousel.swift @@ -21,7 +21,7 @@ open class Carousel: View { //-------------------------------------------------- // MARK: - Properties //-------------------------------------------------- - + public let collectionView = UICollectionView(frame: .zero, collectionViewLayout: UICollectionViewFlowLayout()) /// The current index of the collection view. Includes dummy cells when looping. @@ -215,7 +215,7 @@ open class Carousel: View { bottomPin?.isActive = true return } - + addSubview(pagingView) pagingView.centerXAnchor.constraint(equalTo: collectionView.centerXAnchor).isActive = true collectionView.bottomAnchor.constraint(equalTo: pagingView.centerYAnchor, constant: position).isActive = true diff --git a/MVMCoreUI/Atomic/Organisms/CarouselModel.swift b/MVMCoreUI/Atomic/Organisms/CarouselModel.swift index 82aee3df..6f1c28b3 100644 --- a/MVMCoreUI/Atomic/Organisms/CarouselModel.swift +++ b/MVMCoreUI/Atomic/Organisms/CarouselModel.swift @@ -93,7 +93,7 @@ import UIKit 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.encodeIfPresent(backgroundColor, forKey: .backgroundColor) try container.encode(molecules, forKey: .molecules) try container.encode(spacing, forKey: .spacing) try container.encode(border, forKey: .border)