This commit is contained in:
Kevin G Christiano 2020-03-11 13:30:20 -04:00
parent a011eb73a4
commit 5deb690b33
7 changed files with 31 additions and 176 deletions

View File

@ -8,6 +8,7 @@
import UIKit
open class Arrow: View {
//--------------------------------------------------
// MARK: - Properties

View File

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

View File

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

View File

@ -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<UIGestureRecognizer> = []
/// 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) { }
//--------------------------------------------------

View File

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

View File

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

View File

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