From 5deb690b338b5b4f7cedc7d9b0a491121f32f62f Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Wed, 11 Mar 2020 13:30:20 -0400 Subject: [PATCH] no --- MVMCoreUI/Atoms/Views/Arrow.swift | 1 + .../BarsCarouselIndicatorModel.swift | 29 +----- .../CarouselIndicator/BarsIndicatorView.swift | 20 ++-- .../CarouselIndicator/CarouselIndicator.swift | 92 +------------------ .../CarouselIndicatorModel.swift | 16 +--- .../NumericCarouselIndicatorModel.swift | 29 +----- .../NumericIndicatorView.swift | 20 ++-- 7 files changed, 31 insertions(+), 176 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/Arrow.swift b/MVMCoreUI/Atoms/Views/Arrow.swift index 2ed4a70d..eea6071d 100644 --- a/MVMCoreUI/Atoms/Views/Arrow.swift +++ b/MVMCoreUI/Atoms/Views/Arrow.swift @@ -8,6 +8,7 @@ import UIKit + open class Arrow: View { //-------------------------------------------------- // MARK: - Properties diff --git a/MVMCoreUI/Atoms/Views/CarouselIndicator/BarsCarouselIndicatorModel.swift b/MVMCoreUI/Atoms/Views/CarouselIndicator/BarsCarouselIndicatorModel.swift index 70ddac66..16adfe46 100644 --- a/MVMCoreUI/Atoms/Views/CarouselIndicator/BarsCarouselIndicatorModel.swift +++ b/MVMCoreUI/Atoms/Views/CarouselIndicator/BarsCarouselIndicatorModel.swift @@ -7,37 +7,14 @@ // import UIKit -/* + + open class BarsCarouselIndicatorModel: CarouselIndicatorModel { //-------------------------------------------------- // MARK: - Properties //-------------------------------------------------- - public class var identifier: String { + public class override var identifier: String { return "barsCarouselIndicator" } - - //-------------------------------------------------- - // MARK: - Keys - //-------------------------------------------------- - - private enum CodingKeys: String, CodingKey { - case moleculeName - case backgroundColor - - } - - //-------------------------------------------------- - // MARK: - Codec - //-------------------------------------------------- - - required public init(from decoder: Decoder) throws { - let typeContainer = try decoder.container(keyedBy: CodingKeys.self) - } - - public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - - } } -*/ diff --git a/MVMCoreUI/Atoms/Views/CarouselIndicator/BarsIndicatorView.swift b/MVMCoreUI/Atoms/Views/CarouselIndicator/BarsIndicatorView.swift index 936a971a..1004ed25 100644 --- a/MVMCoreUI/Atoms/Views/CarouselIndicator/BarsIndicatorView.swift +++ b/MVMCoreUI/Atoms/Views/CarouselIndicator/BarsIndicatorView.swift @@ -37,15 +37,15 @@ open class BarsIndicatorView: CarouselIndicator { public var parentCarouselIndicator: CarouselIndicator? { return superview as? CarouselIndicator } -// -// open override var isEnabled: Bool = true { -// didSet { -// barReferences.forEach { view, heightConstraint in -// view.backgroundColor = isEnabled ? parentCarouselIndicator?.indicatorTintColor ?? .mvmBlack : parentCarouselIndicator?.disabledIndicatorColor ?? .mvmCoolGray3 -// } -// } -// } -// + + open override var isEnabled: Bool { + didSet { + barReferences.forEach { view, heightConstraint in + view.backgroundColor = isEnabled ? parentCarouselIndicator?.indicatorTintColor ?? .mvmBlack : parentCarouselIndicator?.disabledIndicatorColor ?? .mvmCoolGray3 + } + } + } + //-------------------------------------------------- // MARK: - Initializers //-------------------------------------------------- @@ -111,7 +111,7 @@ open class BarsIndicatorView: CarouselIndicator { barReferences = [] } - public func updateUI(previousIndex: Int, newIndex: Int, totalCount: Int, isAnimated: Bool) { + public override func updateUI(previousIndex: Int, newIndex: Int, totalCount: Int, isAnimated: Bool) { guard !barReferences.isEmpty else { return } diff --git a/MVMCoreUI/Atoms/Views/CarouselIndicator/CarouselIndicator.swift b/MVMCoreUI/Atoms/Views/CarouselIndicator/CarouselIndicator.swift index 2d9fb117..805edffa 100644 --- a/MVMCoreUI/Atoms/Views/CarouselIndicator/CarouselIndicator.swift +++ b/MVMCoreUI/Atoms/Views/CarouselIndicator/CarouselIndicator.swift @@ -8,21 +8,8 @@ import Foundation -/// Set protocols for all indicator faces of the Carousel Indicator. -//public protocol IndicatorViewProtocol { -// func updateUI(previousIndex: Int, newIndex: Int, totalCount: Int, isAnimated: Bool) -// func reset() -// var isEnabled: Bool { get set } -//} - open class CarouselIndicator: Control, CarouselPageControlProtocol { - //-------------------------------------------------- - // MARK: - Outlets - //-------------------------------------------------- - -// public typealias IndicatorView = UIView & IndicatorViewProtocol - //-------------------------------------------------- // MARK: - Constraints //-------------------------------------------------- @@ -34,57 +21,20 @@ open class CarouselIndicator: Control, CarouselPageControlProtocol { // MARK: - Properties //-------------------------------------------------- - /// The types of indicators that can appear. -// public enum IndicatorType: String { -// case bars -// case numeric -// case hybrid // bar & numeric -// } - - /// Determines interactivity and appearance of the indicator. -// public var indicatorType: IndicatorType = .hybrid { -// didSet { assignIndicatorView() } -// } - public var uiGestures: Set = [] - /// The currently active indicator view. -// public var currentIndicator: IndicatorView? - /// Convenience to access the model. public var carouselIndicatorModel: CarouselIndicatorModel? { return model as? CarouselIndicatorModel } - /// The view control relative to the state of the indicator type. -// private(set) var indicatorView: IndicatorView? { -// willSet { indicatorView?.removeFromSuperview() } -// didSet { -// indicatorView?.removeFromSuperview() -// -// guard let indicatorView = indicatorView else { return } -// addSubview(indicatorView) -// -// topConstraint = indicatorView.topAnchor.constraint(equalTo: topAnchor, constant: PaddingTwo) -// topConstraint?.isActive = true -// -// bottomConstraint = bottomAnchor.constraint(equalTo: indicatorView.bottomAnchor, constant: PaddingTwo) -// bottomConstraint?.isActive = true -// -// indicatorView.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true -// trailingAnchor.constraint(equalTo: indicatorView.trailingAnchor).isActive = true -// updateUI() -// } -// } - /// Set this closure to perform an action when a different indicator was selected. /// Passes through oldInde and newIndex, respectively. public var indicatorTouchAction: ((CarouselPageControlProtocol) -> ())? - public override var isEnabled: Bool { + open override var isEnabled: Bool { didSet { isUserInteractionEnabled = isEnabled -// indicatorView?.isEnabled = isEnabled } } @@ -102,7 +52,7 @@ open class CarouselIndicator: Control, CarouselPageControlProtocol { previousIndex = _currentIndex _currentIndex = newIndex performAction() - updateUI() + updateUI(previousIndex: previousIndex, newIndex: newIndex, totalCount: numberOfPages, isAnimated: carouselIndicatorModel?.isAnimated ?? true) } } @@ -117,12 +67,7 @@ open class CarouselIndicator: Control, CarouselPageControlProtocol { _numberOfPages = newTotal isHidden = carouselIndicatorModel?.hidesForSinglePage ?? false && newTotal <= 1 - -// if isBarIndicator() { -// (indicatorView as? BarsIndicatorView)?.generateBars() -// } - - updateUI() + updateUI(previousIndex: previousIndex, newIndex: currentIndex, totalCount: newTotal, isAnimated: carouselIndicatorModel?.isAnimated ?? true) } } @@ -172,11 +117,6 @@ open class CarouselIndicator: Control, CarouselPageControlProtocol { self.init(frame: .zero) } -// public init(indicatorType: IndicatorType) { -// self.indicatorType = indicatorType -// super.init(frame: .zero) -// } - required public init?(coder: NSCoder) { super.init(coder: coder) } @@ -195,7 +135,6 @@ open class CarouselIndicator: Control, CarouselPageControlProtocol { open override func setupView() { super.setupView() -// assignIndicatorView() setupGestures() } @@ -205,7 +144,7 @@ open class CarouselIndicator: Control, CarouselPageControlProtocol { private func setupGestures() { - let tap = UITapGestureRecognizer(target: self, action: #selector(indicatorTapped(_:))) + let tap = UITapGestureRecognizer(target: self, action: #selector(indicatorTapped)) let leftSwipe = UISwipeGestureRecognizer(target: self, action: #selector(swipeLeft)) let rightSwipe = UISwipeGestureRecognizer(target: self, action: #selector(swipeRight)) @@ -262,7 +201,7 @@ open class CarouselIndicator: Control, CarouselPageControlProtocol { // MARK: - Methods //-------------------------------------------------- - public func updateUI() { + open func updateUI(previousIndex: Int, newIndex: Int, totalCount: Int, isAnimated: Bool) { // indicatorView?.updateUI(previousIndex: previousIndex, // newIndex: currentIndex, @@ -276,27 +215,6 @@ open class CarouselIndicator: Control, CarouselPageControlProtocol { indicatorTouchAction?(self) } - /// Sets the indicatorView based on the current indicatorType. -// func assignIndicatorView() { -// -// switch indicatorType { -// case .bars: -// indicatorView = BarsIndicatorView() -// -// case .numeric: -// indicatorView = NumericIndicatorView() -// -// case .hybrid: -// -// indicatorView = numberOfPages >= carouselIndicatorModel?.hybridThreshold ?? 0 ? NumericIndicatorView() : BarsIndicatorView() -// } -// } - - /// Convenience to determine if current view is displaying bars. -// func isBarIndicator() -> Bool { -// return indicatorType == .bars || indicatorType == .hybrid && numberOfPages <= carouselIndicatorModel?.hybridThreshold ?? 5 -// } - public func scrollViewDidScroll(_ collectionView: UICollectionView) { } //-------------------------------------------------- diff --git a/MVMCoreUI/Atoms/Views/CarouselIndicator/CarouselIndicatorModel.swift b/MVMCoreUI/Atoms/Views/CarouselIndicator/CarouselIndicatorModel.swift index b395b1b5..aa333f2a 100644 --- a/MVMCoreUI/Atoms/Views/CarouselIndicator/CarouselIndicatorModel.swift +++ b/MVMCoreUI/Atoms/Views/CarouselIndicator/CarouselIndicatorModel.swift @@ -9,7 +9,7 @@ import Foundation -public class CarouselIndicatorModel: CarouselPagingModelProtocol { +open class CarouselIndicatorModel: CarouselPagingModelProtocol { //-------------------------------------------------- // MARK: - Properties //-------------------------------------------------- @@ -20,10 +20,9 @@ public class CarouselIndicatorModel: CarouselPagingModelProtocol { public var backgroundColor: Color? public var moleculeName: String? - public var type: String = "hybrid" /// The maxmum count of pages before the indicatorView forces a Numeric Indicator in place of Bar. -// public var hybridThreshold: Int = 5 + public var numberOfPages: Int = 0 public var isAnimated: Bool = true public var hidesForSinglePage: Bool = false @@ -46,7 +45,6 @@ public class CarouselIndicatorModel: CarouselPagingModelProtocol { case moleculeName case backgroundColor case type -// case hybridThreshold case numberOfPages case alwaysSendAction case isAnimated @@ -67,14 +65,6 @@ public class CarouselIndicatorModel: CarouselPagingModelProtocol { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) moleculeName = try typeContainer.decodeIfPresent(String.self, forKey: .moleculeName) backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) - - if let type = try typeContainer.decodeIfPresent(String.self, forKey: .type) { - self.type = type - } - -// if let hybridThreshold = try typeContainer.decodeIfPresent(Int.self, forKey: .hybridThreshold) { -// self.hybridThreshold = hybridThreshold -// } if let numberOfPages = try typeContainer.decodeIfPresent(Int.self, forKey: .numberOfPages) { self.numberOfPages = numberOfPages @@ -121,8 +111,6 @@ public class CarouselIndicatorModel: CarouselPagingModelProtocol { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(moleculeName, forKey: .moleculeName) try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) - try container.encodeIfPresent(type, forKey: .type) -// try container.encodeIfPresent(hybridThreshold, forKey: .hybridThreshold) try container.encodeIfPresent(numberOfPages, forKey: .numberOfPages) try container.encodeIfPresent(alwaysSendAction, forKey: .alwaysSendAction) try container.encodeIfPresent(isAnimated, forKey: .isAnimated) diff --git a/MVMCoreUI/Atoms/Views/CarouselIndicator/NumericCarouselIndicatorModel.swift b/MVMCoreUI/Atoms/Views/CarouselIndicator/NumericCarouselIndicatorModel.swift index 1898c05c..2b454fc8 100644 --- a/MVMCoreUI/Atoms/Views/CarouselIndicator/NumericCarouselIndicatorModel.swift +++ b/MVMCoreUI/Atoms/Views/CarouselIndicator/NumericCarouselIndicatorModel.swift @@ -7,36 +7,13 @@ // import UIKit -/* -class NumericCarouselIndicatorModel: CarouselIndicatorModel { + +open class NumericCarouselIndicatorModel: CarouselIndicatorModel { //-------------------------------------------------- // MARK: - Properties //-------------------------------------------------- - public class var identifier: String { + public class override var identifier: String { return "numericCarouselIndicator" } - - //-------------------------------------------------- - // MARK: - Keys - //-------------------------------------------------- - - private enum CodingKeys: String, CodingKey { - - } - - //-------------------------------------------------- - // MARK: - Codec - //-------------------------------------------------- - - required public init(from decoder: Decoder) throws { - let typeContainer = try decoder.container(keyedBy: CodingKeys.self) - - } - - public override func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - - } } -*/ diff --git a/MVMCoreUI/Atoms/Views/CarouselIndicator/NumericIndicatorView.swift b/MVMCoreUI/Atoms/Views/CarouselIndicator/NumericIndicatorView.swift index 9bd31aa7..28e6b0e0 100644 --- a/MVMCoreUI/Atoms/Views/CarouselIndicator/NumericIndicatorView.swift +++ b/MVMCoreUI/Atoms/Views/CarouselIndicator/NumericIndicatorView.swift @@ -38,20 +38,14 @@ open class NumericIndicatorView: CarouselIndicator { // MARK: - Computed Properties //-------------------------------------------------- - public var parentCarouselIndicator: CarouselIndicator? { - return superview as? CarouselIndicator + open override var isEnabled: Bool = true { + didSet { + pageCount.textColor = isEnabled ? indicatorTintColor : disabledIndicatorColor + leftArrow.tintColor = isEnabled ? indicatorTintColor : disabledIndicatorColor + rightArrow.tintColor = isEnabled ? indicatorTintColor : disabledIndicatorColor + } } -// open var isEnabled: Bool = true { -// didSet { -// let enabledColor = parentCarouselIndicator?.indicatorTintColor ?? .mvmBlack -// let disabledColor = parentCarouselIndicator?.disabledIndicatorColor ?? .mvmCoolGray3 -// pageCount.textColor = isEnabled ? enabledColor : disabledColor -// leftArrow.tintColor = isEnabled ? enabledColor : disabledColor -// rightArrow.tintColor = isEnabled ? enabledColor : disabledColor -// } -// } - //-------------------------------------------------- // MARK: - Initializers //-------------------------------------------------- @@ -106,7 +100,7 @@ open class NumericIndicatorView: CarouselIndicator { // MARK: - IndicatorViewProtocol //-------------------------------------------------- - open func updateUI(previousIndex oldIndex: Int, newIndex: Int, totalCount: Int, isAnimated: Bool) { + open override func updateUI(previousIndex oldIndex: Int, newIndex: Int, totalCount: Int, isAnimated: Bool) { pageCount.text = "\(newIndex + 1)/\(totalCount)" layoutIfNeeded()