general working order

This commit is contained in:
Kevin G Christiano 2020-03-02 13:01:07 -05:00
parent 64ada3e61d
commit 3e3b7dac79
5 changed files with 50 additions and 35 deletions

View File

@ -34,6 +34,24 @@ open class Arrow: View {
widthConstraint?.isActive = true 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 // MARK: - Lifecycle
//-------------------------------------------------- //--------------------------------------------------

View File

@ -29,6 +29,12 @@ open class ArrowModel: MoleculeModelProtocol {
public var height: CGFloat = 12 public var height: CGFloat = 12
public var width: CGFloat = 12 public var width: CGFloat = 12
//--------------------------------------------------
// MARK: - Initializer
//--------------------------------------------------
public init() { }
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Keys // MARK: - Keys

View File

@ -58,10 +58,10 @@ open class CarouselIndicator: Control, CarouselPageControlProtocol {
/// The view control relative to the state of the indicator type. /// The view control relative to the state of the indicator type.
private(set) var indicatorView: IndicatorView? { private(set) var indicatorView: IndicatorView? {
willSet { willSet { indicatorView?.removeFromSuperview() }
indicatorView?.removeFromSuperview()
}
didSet { didSet {
indicatorView?.removeFromSuperview()
guard let indicatorView = indicatorView else { return } guard let indicatorView = indicatorView else { return }
addSubview(indicatorView) addSubview(indicatorView)
@ -73,6 +73,7 @@ open class CarouselIndicator: Control, CarouselPageControlProtocol {
indicatorView.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true indicatorView.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true
trailingAnchor.constraint(equalTo: indicatorView.trailingAnchor).isActive = true trailingAnchor.constraint(equalTo: indicatorView.trailingAnchor).isActive = true
updateUI()
} }
} }
@ -137,12 +138,7 @@ open class CarouselIndicator: Control, CarouselPageControlProtocol {
guard _numberOfPages != newTotal else { return } guard _numberOfPages != newTotal else { return }
_numberOfPages = newTotal _numberOfPages = newTotal
if hidesForSinglePage && newTotal <= 1 { isHidden = hidesForSinglePage && newTotal <= 1
isHidden = true
} else {
isHidden = false
indicatorView = BarsIndicatorView()
}
if isBarIndicator() { if isBarIndicator() {
(indicatorView as? BarsIndicatorView)?.generateBars() (indicatorView as? BarsIndicatorView)?.generateBars()

View File

@ -69,7 +69,6 @@ open class BarsIndicatorView: View, IndicatorViewProtocol {
isUserInteractionEnabled = false isUserInteractionEnabled = false
stackView.heightAnchor.constraint(equalToConstant: 4).isActive = true stackView.heightAnchor.constraint(equalToConstant: 4).isActive = true
// heightAnchor.constraint(equalToConstant: 4).isActive = true
stackView.centerXAnchor.constraint(equalTo: centerXAnchor).isActive = true stackView.centerXAnchor.constraint(equalTo: centerXAnchor).isActive = true
stackView.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true stackView.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true
trailingAnchor.constraint(equalTo: stackView.trailingAnchor).isActive = true trailingAnchor.constraint(equalTo: stackView.trailingAnchor).isActive = true

View File

@ -15,7 +15,7 @@ open class NumericIndicatorView: View, IndicatorViewProtocol {
//-------------------------------------------------- //--------------------------------------------------
/// Text to display the current count of total pages for viewing. /// Text to display the current count of total pages for viewing.
open var pageCountLabel: Label = { open var pageCount: Label = {
let label = Label.commonLabelB2(true) let label = Label.commonLabelB2(true)
label.setContentCompressionResistancePriority(.required, for: .vertical) label.setContentCompressionResistancePriority(.required, for: .vertical)
label.textAlignment = .center label.textAlignment = .center
@ -23,15 +23,13 @@ open class NumericIndicatorView: View, IndicatorViewProtocol {
}() }()
let leftArrow: Arrow = { let leftArrow: Arrow = {
let arrow = Arrow() let arrow = Arrow(model: ArrowModel(), degrees: 180)
(arrow.model as? ArrowModel)?.degrees = 180
arrow.pinHeightAndWidth() arrow.pinHeightAndWidth()
arrow.setNeedsDisplay()
return arrow return arrow
}() }()
let rightArrow: Arrow = { let rightArrow: Arrow = {
let arrow = Arrow() let arrow = Arrow(model: ArrowModel())
arrow.pinHeightAndWidth() arrow.pinHeightAndWidth()
return arrow return arrow
}() }()
@ -41,19 +39,19 @@ open class NumericIndicatorView: View, IndicatorViewProtocol {
//-------------------------------------------------- //--------------------------------------------------
public var parentCarouselIndicator: CarouselIndicator? { public var parentCarouselIndicator: CarouselIndicator? {
return superview as? CarouselIndicator return superview as? CarouselIndicator
} }
open var isEnabled: Bool = true { open var isEnabled: Bool = true {
didSet { didSet {
let enabledColor = parentCarouselIndicator?.indicatorTintColor ?? .mvmBlack let enabledColor = parentCarouselIndicator?.indicatorTintColor ?? .mvmBlack
let disabledColor = parentCarouselIndicator?.disabledIndicatorColor ?? .mvmCoolGray3 let disabledColor = parentCarouselIndicator?.disabledIndicatorColor ?? .mvmCoolGray3
pageCountLabel.textColor = isEnabled ? enabledColor : disabledColor pageCount.textColor = isEnabled ? enabledColor : disabledColor
leftArrow.tintColor = isEnabled ? enabledColor : disabledColor leftArrow.tintColor = isEnabled ? enabledColor : disabledColor
rightArrow.tintColor = isEnabled ? enabledColor : disabledColor rightArrow.tintColor = isEnabled ? enabledColor : disabledColor
} }
} }
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Initializers // MARK: - Initializers
//-------------------------------------------------- //--------------------------------------------------
@ -76,7 +74,7 @@ open class NumericIndicatorView: View, IndicatorViewProtocol {
open override func updateView(_ size: CGFloat) { open override func updateView(_ size: CGFloat) {
super.updateView(size) super.updateView(size)
pageCountLabel.updateView(size) pageCount.updateView(size)
} }
//-------------------------------------------------- //--------------------------------------------------
@ -87,23 +85,21 @@ open class NumericIndicatorView: View, IndicatorViewProtocol {
super.setupView() super.setupView()
isUserInteractionEnabled = false isUserInteractionEnabled = false
backgroundColor = .black addSubview(pageCount)
addSubview(pageCountLabel)
addSubview(leftArrow) addSubview(leftArrow)
addSubview(rightArrow) addSubview(rightArrow)
pageCountLabel.centerXAnchor.constraint(equalTo: centerXAnchor).isActive = true NSLayoutConstraint.activate([
pageCountLabel.topAnchor.constraint(equalTo: topAnchor).isActive = true pageCount.centerXAnchor.constraint(equalTo: centerXAnchor),
bottomAnchor.constraint(equalTo: pageCountLabel.bottomAnchor).isActive = true pageCount.topAnchor.constraint(equalTo: topAnchor),
leftArrow.centerYAnchor.constraint(equalTo: centerYAnchor).isActive = true bottomAnchor.constraint(equalTo: pageCount.bottomAnchor),
rightArrow.centerYAnchor.constraint(equalTo: centerYAnchor).isActive = true leftArrow.centerYAnchor.constraint(equalTo: centerYAnchor),
rightArrow.centerYAnchor.constraint(equalTo: centerYAnchor),
NSLayoutConstraint.activate(NSLayoutConstraint.constraints(withVisualFormat: "H:|-[leftArrow]-(padding)-[pageCountLabel]-(padding)-[rightArrow]-|", leftArrow.leadingAnchor.constraint(equalTo: leadingAnchor),
options: .directionLeadingToTrailing, pageCount.leadingAnchor.constraint(equalTo: leftArrow.trailingAnchor, constant: PaddingOne),
metrics: ["padding": PaddingOne], rightArrow.leadingAnchor.constraint(equalTo: pageCount.trailingAnchor, constant: PaddingOne),
views: ["leftArrow": leftArrow, trailingAnchor.constraint(equalTo: rightArrow.trailingAnchor)
"pageCountLabel": pageCountLabel, ])
"rightArrow": rightArrow]))
} }
//-------------------------------------------------- //--------------------------------------------------
@ -112,7 +108,7 @@ open class NumericIndicatorView: View, IndicatorViewProtocol {
open func updateUI(previousIndex oldIndex: Int, newIndex: Int, totalCount: Int, isAnimated: Bool) { open func updateUI(previousIndex oldIndex: Int, newIndex: Int, totalCount: Int, isAnimated: Bool) {
pageCountLabel.text = "\(newIndex)/\(totalCount)" pageCount.text = "\(newIndex + 1)/\(totalCount)"
layoutIfNeeded() layoutIfNeeded()
} }
} }