no
This commit is contained in:
parent
a011eb73a4
commit
5deb690b33
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
|
|
||||||
open class Arrow: View {
|
open class Arrow: View {
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Properties
|
// MARK: - Properties
|
||||||
|
|||||||
@ -7,37 +7,14 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
import UIKit
|
import UIKit
|
||||||
/*
|
|
||||||
|
|
||||||
open class BarsCarouselIndicatorModel: CarouselIndicatorModel {
|
open class BarsCarouselIndicatorModel: CarouselIndicatorModel {
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Properties
|
// MARK: - Properties
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
||||||
public class var identifier: String {
|
public class override var identifier: String {
|
||||||
return "barsCarouselIndicator"
|
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)
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|||||||
@ -37,15 +37,15 @@ open class BarsIndicatorView: CarouselIndicator {
|
|||||||
public var parentCarouselIndicator: CarouselIndicator? {
|
public var parentCarouselIndicator: CarouselIndicator? {
|
||||||
return superview as? CarouselIndicator
|
return superview as? CarouselIndicator
|
||||||
}
|
}
|
||||||
//
|
|
||||||
// open override var isEnabled: Bool = true {
|
open override var isEnabled: Bool {
|
||||||
// didSet {
|
didSet {
|
||||||
// barReferences.forEach { view, heightConstraint in
|
barReferences.forEach { view, heightConstraint in
|
||||||
// view.backgroundColor = isEnabled ? parentCarouselIndicator?.indicatorTintColor ?? .mvmBlack : parentCarouselIndicator?.disabledIndicatorColor ?? .mvmCoolGray3
|
view.backgroundColor = isEnabled ? parentCarouselIndicator?.indicatorTintColor ?? .mvmBlack : parentCarouselIndicator?.disabledIndicatorColor ?? .mvmCoolGray3
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Initializers
|
// MARK: - Initializers
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -111,7 +111,7 @@ open class BarsIndicatorView: CarouselIndicator {
|
|||||||
barReferences = []
|
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 }
|
guard !barReferences.isEmpty else { return }
|
||||||
|
|
||||||
|
|||||||
@ -8,21 +8,8 @@
|
|||||||
|
|
||||||
import Foundation
|
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 {
|
open class CarouselIndicator: Control, CarouselPageControlProtocol {
|
||||||
//--------------------------------------------------
|
|
||||||
// MARK: - Outlets
|
|
||||||
//--------------------------------------------------
|
|
||||||
|
|
||||||
// public typealias IndicatorView = UIView & IndicatorViewProtocol
|
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Constraints
|
// MARK: - Constraints
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -34,57 +21,20 @@ open class CarouselIndicator: Control, CarouselPageControlProtocol {
|
|||||||
// MARK: - Properties
|
// 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> = []
|
public var uiGestures: Set<UIGestureRecognizer> = []
|
||||||
|
|
||||||
/// The currently active indicator view.
|
|
||||||
// public var currentIndicator: IndicatorView?
|
|
||||||
|
|
||||||
/// Convenience to access the model.
|
/// Convenience to access the model.
|
||||||
public var carouselIndicatorModel: CarouselIndicatorModel? {
|
public var carouselIndicatorModel: CarouselIndicatorModel? {
|
||||||
return model as? 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.
|
/// Set this closure to perform an action when a different indicator was selected.
|
||||||
/// Passes through oldInde and newIndex, respectively.
|
/// Passes through oldInde and newIndex, respectively.
|
||||||
public var indicatorTouchAction: ((CarouselPageControlProtocol) -> ())?
|
public var indicatorTouchAction: ((CarouselPageControlProtocol) -> ())?
|
||||||
|
|
||||||
public override var isEnabled: Bool {
|
open override var isEnabled: Bool {
|
||||||
didSet {
|
didSet {
|
||||||
isUserInteractionEnabled = isEnabled
|
isUserInteractionEnabled = isEnabled
|
||||||
// indicatorView?.isEnabled = isEnabled
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,7 +52,7 @@ open class CarouselIndicator: Control, CarouselPageControlProtocol {
|
|||||||
previousIndex = _currentIndex
|
previousIndex = _currentIndex
|
||||||
_currentIndex = newIndex
|
_currentIndex = newIndex
|
||||||
performAction()
|
performAction()
|
||||||
updateUI()
|
updateUI(previousIndex: previousIndex, newIndex: newIndex, totalCount: numberOfPages, isAnimated: carouselIndicatorModel?.isAnimated ?? true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,12 +67,7 @@ open class CarouselIndicator: Control, CarouselPageControlProtocol {
|
|||||||
_numberOfPages = newTotal
|
_numberOfPages = newTotal
|
||||||
|
|
||||||
isHidden = carouselIndicatorModel?.hidesForSinglePage ?? false && newTotal <= 1
|
isHidden = carouselIndicatorModel?.hidesForSinglePage ?? false && newTotal <= 1
|
||||||
|
updateUI(previousIndex: previousIndex, newIndex: currentIndex, totalCount: newTotal, isAnimated: carouselIndicatorModel?.isAnimated ?? true)
|
||||||
// if isBarIndicator() {
|
|
||||||
// (indicatorView as? BarsIndicatorView)?.generateBars()
|
|
||||||
// }
|
|
||||||
|
|
||||||
updateUI()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,11 +117,6 @@ open class CarouselIndicator: Control, CarouselPageControlProtocol {
|
|||||||
self.init(frame: .zero)
|
self.init(frame: .zero)
|
||||||
}
|
}
|
||||||
|
|
||||||
// public init(indicatorType: IndicatorType) {
|
|
||||||
// self.indicatorType = indicatorType
|
|
||||||
// super.init(frame: .zero)
|
|
||||||
// }
|
|
||||||
|
|
||||||
required public init?(coder: NSCoder) {
|
required public init?(coder: NSCoder) {
|
||||||
super.init(coder: coder)
|
super.init(coder: coder)
|
||||||
}
|
}
|
||||||
@ -195,7 +135,6 @@ open class CarouselIndicator: Control, CarouselPageControlProtocol {
|
|||||||
open override func setupView() {
|
open override func setupView() {
|
||||||
super.setupView()
|
super.setupView()
|
||||||
|
|
||||||
// assignIndicatorView()
|
|
||||||
setupGestures()
|
setupGestures()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -205,7 +144,7 @@ open class CarouselIndicator: Control, CarouselPageControlProtocol {
|
|||||||
|
|
||||||
private func setupGestures() {
|
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 leftSwipe = UISwipeGestureRecognizer(target: self, action: #selector(swipeLeft))
|
||||||
let rightSwipe = UISwipeGestureRecognizer(target: self, action: #selector(swipeRight))
|
let rightSwipe = UISwipeGestureRecognizer(target: self, action: #selector(swipeRight))
|
||||||
|
|
||||||
@ -262,7 +201,7 @@ open class CarouselIndicator: Control, CarouselPageControlProtocol {
|
|||||||
// MARK: - Methods
|
// MARK: - Methods
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
||||||
public func updateUI() {
|
open func updateUI(previousIndex: Int, newIndex: Int, totalCount: Int, isAnimated: Bool) {
|
||||||
|
|
||||||
// indicatorView?.updateUI(previousIndex: previousIndex,
|
// indicatorView?.updateUI(previousIndex: previousIndex,
|
||||||
// newIndex: currentIndex,
|
// newIndex: currentIndex,
|
||||||
@ -276,27 +215,6 @@ open class CarouselIndicator: Control, CarouselPageControlProtocol {
|
|||||||
indicatorTouchAction?(self)
|
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) { }
|
public func scrollViewDidScroll(_ collectionView: UICollectionView) { }
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|||||||
@ -9,7 +9,7 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
|
|
||||||
public class CarouselIndicatorModel: CarouselPagingModelProtocol {
|
open class CarouselIndicatorModel: CarouselPagingModelProtocol {
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Properties
|
// MARK: - Properties
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -20,10 +20,9 @@ public class CarouselIndicatorModel: CarouselPagingModelProtocol {
|
|||||||
|
|
||||||
public var backgroundColor: Color?
|
public var backgroundColor: Color?
|
||||||
public var moleculeName: String?
|
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.
|
/// 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 numberOfPages: Int = 0
|
||||||
public var isAnimated: Bool = true
|
public var isAnimated: Bool = true
|
||||||
public var hidesForSinglePage: Bool = false
|
public var hidesForSinglePage: Bool = false
|
||||||
@ -46,7 +45,6 @@ public class CarouselIndicatorModel: CarouselPagingModelProtocol {
|
|||||||
case moleculeName
|
case moleculeName
|
||||||
case backgroundColor
|
case backgroundColor
|
||||||
case type
|
case type
|
||||||
// case hybridThreshold
|
|
||||||
case numberOfPages
|
case numberOfPages
|
||||||
case alwaysSendAction
|
case alwaysSendAction
|
||||||
case isAnimated
|
case isAnimated
|
||||||
@ -67,14 +65,6 @@ public class CarouselIndicatorModel: CarouselPagingModelProtocol {
|
|||||||
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
||||||
moleculeName = try typeContainer.decodeIfPresent(String.self, forKey: .moleculeName)
|
moleculeName = try typeContainer.decodeIfPresent(String.self, forKey: .moleculeName)
|
||||||
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
|
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) {
|
if let numberOfPages = try typeContainer.decodeIfPresent(Int.self, forKey: .numberOfPages) {
|
||||||
self.numberOfPages = numberOfPages
|
self.numberOfPages = numberOfPages
|
||||||
@ -121,8 +111,6 @@ public class CarouselIndicatorModel: CarouselPagingModelProtocol {
|
|||||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||||
try container.encode(moleculeName, forKey: .moleculeName)
|
try container.encode(moleculeName, forKey: .moleculeName)
|
||||||
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
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(numberOfPages, forKey: .numberOfPages)
|
||||||
try container.encodeIfPresent(alwaysSendAction, forKey: .alwaysSendAction)
|
try container.encodeIfPresent(alwaysSendAction, forKey: .alwaysSendAction)
|
||||||
try container.encodeIfPresent(isAnimated, forKey: .isAnimated)
|
try container.encodeIfPresent(isAnimated, forKey: .isAnimated)
|
||||||
|
|||||||
@ -7,36 +7,13 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
import UIKit
|
import UIKit
|
||||||
/*
|
|
||||||
class NumericCarouselIndicatorModel: CarouselIndicatorModel {
|
open class NumericCarouselIndicatorModel: CarouselIndicatorModel {
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Properties
|
// MARK: - Properties
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
||||||
public class var identifier: String {
|
public class override var identifier: String {
|
||||||
return "numericCarouselIndicator"
|
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)
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|||||||
@ -38,20 +38,14 @@ open class NumericIndicatorView: CarouselIndicator {
|
|||||||
// MARK: - Computed Properties
|
// MARK: - Computed Properties
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
||||||
public var parentCarouselIndicator: CarouselIndicator? {
|
open override var isEnabled: Bool = true {
|
||||||
return superview as? CarouselIndicator
|
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
|
// MARK: - Initializers
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -106,7 +100,7 @@ open class NumericIndicatorView: CarouselIndicator {
|
|||||||
// MARK: - IndicatorViewProtocol
|
// 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)"
|
pageCount.text = "\(newIndex + 1)/\(totalCount)"
|
||||||
layoutIfNeeded()
|
layoutIfNeeded()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user