diff --git a/MVMCoreUI/Atoms/Views/Arrow.swift b/MVMCoreUI/Atoms/Views/Arrow.swift index e932dd60..2ed4a70d 100644 --- a/MVMCoreUI/Atoms/Views/Arrow.swift +++ b/MVMCoreUI/Atoms/Views/Arrow.swift @@ -34,6 +34,24 @@ open class Arrow: View { widthConstraint?.isActive = true } + //-------------------------------------------------- + // MARK: - Initializers + //-------------------------------------------------- + + public override init(frame: CGRect) { + super.init(frame: frame) + } + + public convenience init(model: ArrowModel, degrees: Float = 0) { + self.init(frame: .zero) + self.model = model + arrowModel?.degrees = degrees + } + + public required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + //-------------------------------------------------- // MARK: - Lifecycle //-------------------------------------------------- diff --git a/MVMCoreUI/Atoms/Views/ArrowModel.swift b/MVMCoreUI/Atoms/Views/ArrowModel.swift index a0f24d15..69a6dd1f 100644 --- a/MVMCoreUI/Atoms/Views/ArrowModel.swift +++ b/MVMCoreUI/Atoms/Views/ArrowModel.swift @@ -29,6 +29,12 @@ open class ArrowModel: MoleculeModelProtocol { public var height: CGFloat = 12 public var width: CGFloat = 12 + + //-------------------------------------------------- + // MARK: - Initializer + //-------------------------------------------------- + + public init() { } //-------------------------------------------------- // MARK: - Keys diff --git a/MVMCoreUI/Atoms/Views/CarouselIndicator/CarouselIndicator.swift b/MVMCoreUI/Atoms/Views/CarouselIndicator/CarouselIndicator.swift index f5ca5342..f374fafe 100644 --- a/MVMCoreUI/Atoms/Views/CarouselIndicator/CarouselIndicator.swift +++ b/MVMCoreUI/Atoms/Views/CarouselIndicator/CarouselIndicator.swift @@ -58,10 +58,10 @@ open class CarouselIndicator: Control, CarouselPageControlProtocol { /// The view control relative to the state of the indicator type. private(set) var indicatorView: IndicatorView? { - willSet { - indicatorView?.removeFromSuperview() - } + willSet { indicatorView?.removeFromSuperview() } didSet { + indicatorView?.removeFromSuperview() + guard let indicatorView = indicatorView else { return } addSubview(indicatorView) @@ -73,6 +73,7 @@ open class CarouselIndicator: Control, CarouselPageControlProtocol { indicatorView.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true trailingAnchor.constraint(equalTo: indicatorView.trailingAnchor).isActive = true + updateUI() } } @@ -137,12 +138,7 @@ open class CarouselIndicator: Control, CarouselPageControlProtocol { guard _numberOfPages != newTotal else { return } _numberOfPages = newTotal - if hidesForSinglePage && newTotal <= 1 { - isHidden = true - } else { - isHidden = false - indicatorView = BarsIndicatorView() - } + isHidden = hidesForSinglePage && newTotal <= 1 if isBarIndicator() { (indicatorView as? BarsIndicatorView)?.generateBars() diff --git a/MVMCoreUI/Atoms/Views/CarouselIndicator/IndicatorViews/BarsIndicatorView.swift b/MVMCoreUI/Atoms/Views/CarouselIndicator/IndicatorViews/BarsIndicatorView.swift index 5ca80ba7..69c34895 100644 --- a/MVMCoreUI/Atoms/Views/CarouselIndicator/IndicatorViews/BarsIndicatorView.swift +++ b/MVMCoreUI/Atoms/Views/CarouselIndicator/IndicatorViews/BarsIndicatorView.swift @@ -69,7 +69,6 @@ open class BarsIndicatorView: View, IndicatorViewProtocol { isUserInteractionEnabled = false stackView.heightAnchor.constraint(equalToConstant: 4).isActive = true -// heightAnchor.constraint(equalToConstant: 4).isActive = true stackView.centerXAnchor.constraint(equalTo: centerXAnchor).isActive = true stackView.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true trailingAnchor.constraint(equalTo: stackView.trailingAnchor).isActive = true diff --git a/MVMCoreUI/Atoms/Views/CarouselIndicator/IndicatorViews/NumericIndicatorView.swift b/MVMCoreUI/Atoms/Views/CarouselIndicator/IndicatorViews/NumericIndicatorView.swift index 776c9ff6..41be20cd 100644 --- a/MVMCoreUI/Atoms/Views/CarouselIndicator/IndicatorViews/NumericIndicatorView.swift +++ b/MVMCoreUI/Atoms/Views/CarouselIndicator/IndicatorViews/NumericIndicatorView.swift @@ -15,7 +15,7 @@ open class NumericIndicatorView: View, IndicatorViewProtocol { //-------------------------------------------------- /// Text to display the current count of total pages for viewing. - open var pageCountLabel: Label = { + open var pageCount: Label = { let label = Label.commonLabelB2(true) label.setContentCompressionResistancePriority(.required, for: .vertical) label.textAlignment = .center @@ -23,15 +23,13 @@ open class NumericIndicatorView: View, IndicatorViewProtocol { }() let leftArrow: Arrow = { - let arrow = Arrow() - (arrow.model as? ArrowModel)?.degrees = 180 + let arrow = Arrow(model: ArrowModel(), degrees: 180) arrow.pinHeightAndWidth() - arrow.setNeedsDisplay() return arrow }() let rightArrow: Arrow = { - let arrow = Arrow() + let arrow = Arrow(model: ArrowModel()) arrow.pinHeightAndWidth() return arrow }() @@ -41,19 +39,19 @@ open class NumericIndicatorView: View, IndicatorViewProtocol { //-------------------------------------------------- public var parentCarouselIndicator: CarouselIndicator? { - return superview as? CarouselIndicator - } + return superview as? CarouselIndicator + } open var isEnabled: Bool = true { didSet { let enabledColor = parentCarouselIndicator?.indicatorTintColor ?? .mvmBlack let disabledColor = parentCarouselIndicator?.disabledIndicatorColor ?? .mvmCoolGray3 - pageCountLabel.textColor = isEnabled ? enabledColor : disabledColor + pageCount.textColor = isEnabled ? enabledColor : disabledColor leftArrow.tintColor = isEnabled ? enabledColor : disabledColor rightArrow.tintColor = isEnabled ? enabledColor : disabledColor } } - + //-------------------------------------------------- // MARK: - Initializers //-------------------------------------------------- @@ -76,7 +74,7 @@ open class NumericIndicatorView: View, IndicatorViewProtocol { open override func updateView(_ size: CGFloat) { super.updateView(size) - pageCountLabel.updateView(size) + pageCount.updateView(size) } //-------------------------------------------------- @@ -87,23 +85,21 @@ open class NumericIndicatorView: View, IndicatorViewProtocol { super.setupView() isUserInteractionEnabled = false - backgroundColor = .black - addSubview(pageCountLabel) + addSubview(pageCount) addSubview(leftArrow) addSubview(rightArrow) - pageCountLabel.centerXAnchor.constraint(equalTo: centerXAnchor).isActive = true - pageCountLabel.topAnchor.constraint(equalTo: topAnchor).isActive = true - bottomAnchor.constraint(equalTo: pageCountLabel.bottomAnchor).isActive = true - leftArrow.centerYAnchor.constraint(equalTo: centerYAnchor).isActive = true - rightArrow.centerYAnchor.constraint(equalTo: centerYAnchor).isActive = true - - NSLayoutConstraint.activate(NSLayoutConstraint.constraints(withVisualFormat: "H:|-[leftArrow]-(padding)-[pageCountLabel]-(padding)-[rightArrow]-|", - options: .directionLeadingToTrailing, - metrics: ["padding": PaddingOne], - views: ["leftArrow": leftArrow, - "pageCountLabel": pageCountLabel, - "rightArrow": rightArrow])) + NSLayoutConstraint.activate([ + pageCount.centerXAnchor.constraint(equalTo: centerXAnchor), + pageCount.topAnchor.constraint(equalTo: topAnchor), + bottomAnchor.constraint(equalTo: pageCount.bottomAnchor), + leftArrow.centerYAnchor.constraint(equalTo: centerYAnchor), + rightArrow.centerYAnchor.constraint(equalTo: centerYAnchor), + leftArrow.leadingAnchor.constraint(equalTo: leadingAnchor), + pageCount.leadingAnchor.constraint(equalTo: leftArrow.trailingAnchor, constant: PaddingOne), + rightArrow.leadingAnchor.constraint(equalTo: pageCount.trailingAnchor, constant: PaddingOne), + trailingAnchor.constraint(equalTo: rightArrow.trailingAnchor) + ]) } //-------------------------------------------------- @@ -112,7 +108,7 @@ open class NumericIndicatorView: View, IndicatorViewProtocol { open func updateUI(previousIndex oldIndex: Int, newIndex: Int, totalCount: Int, isAnimated: Bool) { - pageCountLabel.text = "\(newIndex)/\(totalCount)" + pageCount.text = "\(newIndex + 1)/\(totalCount)" layoutIfNeeded() } }