general working order

This commit is contained in:
Kevin G Christiano 2020-02-17 15:31:10 -05:00
parent db74add496
commit 3fc4184349
4 changed files with 19 additions and 44 deletions

View File

@ -235,6 +235,10 @@ open class CarouselIndicator: Control, CarouselPageControlProtocol {
let leftSwipe = UISwipeGestureRecognizer(target: self, action: #selector(swipeLeft))
let rightSwipe = UISwipeGestureRecognizer(target: self, action: #selector(swipeRight))
addGestureRecognizer(tap)
addGestureRecognizer(leftSwipe)
addGestureRecognizer(rightSwipe)
uiGestures.insert(tap)
uiGestures.insert(leftSwipe)
uiGestures.insert(rightSwipe)

View File

@ -17,6 +17,7 @@ open class BarsIndicatorView: View, IndicatorViewProtocol {
let stackView: StackView = {
let stackView = StackView()
stackView.axis = .horizontal
stackView.alignment = .bottom
stackView.distribution = .equalSpacing
stackView.spacing = 6
stackView.heightAnchor.constraint(lessThanOrEqualToConstant: BarsIndicatorView.indicatorBarHeight.selected).isActive = true
@ -37,22 +38,10 @@ open class BarsIndicatorView: View, IndicatorViewProtocol {
return superview as? CarouselIndicator
}
public var enabledColor: UIColor {
return parentCarouselIndicator?.indicatorTintColor ?? .mvmBlack
}
public var currentIndexColor: UIColor {
return parentCarouselIndicator?.currentIndicatorColor ?? .mvmBlack
}
public var disabledColor: UIColor {
return parentCarouselIndicator?.disabledIndicatorColor ?? .mvmCoolGray3
}
open var isEnabled: Bool = true {
didSet {
barReferences.forEach { view, heightConstraint in
view.backgroundColor = isEnabled ? enabledColor : disabledColor
view.backgroundColor = isEnabled ? parentCarouselIndicator?.indicatorTintColor ?? .mvmBlack : parentCarouselIndicator?.disabledIndicatorColor ?? .mvmCoolGray3
}
}
}
@ -79,6 +68,8 @@ open class BarsIndicatorView: View, IndicatorViewProtocol {
addSubview(stackView)
isUserInteractionEnabled = false
heightAnchor.constraint(equalToConstant: 4).isActive = true
stackView.centerXAnchor.constraint(equalTo: centerXAnchor).isActive = true
stackView.leadingAnchor.constraint(greaterThanOrEqualTo: leadingAnchor).isActive = true
trailingAnchor.constraint(greaterThanOrEqualTo: stackView.trailingAnchor).isActive = true
@ -99,7 +90,7 @@ open class BarsIndicatorView: View, IndicatorViewProtocol {
for i in 0..<numberOfPages {
let bar = View()
bar.widthAnchor.constraint(equalToConstant: BarsIndicatorView.indicatorBarWidth).isActive = true
bar.backgroundColor = isEnabled ? enabledColor : disabledColor
bar.backgroundColor = isEnabled ? parentCarouselIndicator?.indicatorTintColor ?? .mvmBlack : parentCarouselIndicator?.disabledIndicatorColor ?? .mvmCoolGray3
let barHeight = i == currentIndex ? BarsIndicatorView.indicatorBarHeight.selected : BarsIndicatorView.indicatorBarHeight.unselected
let heightConstraint = bar.heightAnchor.constraint(equalToConstant: barHeight)
heightConstraint.isActive = true
@ -126,8 +117,8 @@ open class BarsIndicatorView: View, IndicatorViewProtocol {
guard !barReferences.isEmpty else { return }
let expression = {
self.barReferences[previousIndex].view.backgroundColor = self.enabledColor
self.barReferences[newIndex].view.backgroundColor = self.currentIndexColor
self.barReferences[previousIndex].view.backgroundColor = self.parentCarouselIndicator?.indicatorTintColor ?? .mvmBlack
self.barReferences[newIndex].view.backgroundColor = self.parentCarouselIndicator?.currentIndicatorColor ?? .mvmBlack
self.barReferences[previousIndex].constraint.constant = BarsIndicatorView.indicatorBarHeight.unselected
self.barReferences[newIndex].constraint.constant = BarsIndicatorView.indicatorBarHeight.selected
self.layoutIfNeeded()

View File

@ -44,40 +44,20 @@ open class NumericIndicatorView: View, IndicatorViewProtocol {
// MARK: - Computed Properties
//--------------------------------------------------
public var parentCarouselIndicator: 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
leftArrow.tintColor = isEnabled ? enabledColor : disabledColor
rightArrow.tintColor = isEnabled ? enabledColor : disabledColor
}
}
public var parentCarouselIndicator: CarouselIndicator? {
return superview as? CarouselIndicator
}
public var enabledColor: UIColor {
return parentCarouselIndicator?.indicatorTintColor ?? .mvmBlack
}
public var disabledColor: UIColor {
return parentCarouselIndicator?.disabledIndicatorColor ?? .mvmCoolGray3
}
/// Returns the currentIndex from its parent CarouselIndicator.
public var currentIndex: Int? {
get { return parentCarouselIndicator?.currentIndex }
set {
guard let newValue = newValue else { return }
parentCarouselIndicator?.currentIndex = newValue
}
}
/// Returns the numberOfPages count from its parent CarouselIndicator.
public var numberOfPages: Int? {
return parentCarouselIndicator?.numberOfPages
}
//--------------------------------------------------
// MARK: - Initializers
//--------------------------------------------------

View File

@ -235,7 +235,7 @@ open class Carousel: View {
addSubview(pagingView)
pagingView.centerXAnchor.constraint(equalTo: collectionView.centerXAnchor).isActive = true
collectionView.bottomAnchor.constraint(equalTo: pagingView.centerYAnchor, constant: position).isActive = true
collectionView.bottomAnchor.constraint(equalTo: pagingView.bottomAnchor, constant: position).isActive = true
bottomAnchor.constraint(greaterThanOrEqualTo: pagingView.bottomAnchor).isActive = true
bottomPin?.isActive = false
bottomPin = bottomAnchor.constraint(equalTo: collectionView.bottomAnchor)