more improvements

This commit is contained in:
Kevin G Christiano 2020-04-02 13:35:08 -04:00
parent 3210f25cd5
commit 1a8324c90b
7 changed files with 44 additions and 42 deletions

View File

@ -20,6 +20,11 @@ open class Arrow: View {
return model as? ArrowModel return model as? ArrowModel
} }
public var direction: Direction {
get { return Direction(rawValue: degrees) ?? .right}
set { degrees = newValue.rawValue }
}
open var isEnabled: Bool = true { open var isEnabled: Bool = true {
didSet { didSet {
isUserInteractionEnabled = isEnabled isUserInteractionEnabled = isEnabled
@ -47,6 +52,21 @@ open class Arrow: View {
set { arrowModel?.lineWidth = newValue } set { arrowModel?.lineWidth = newValue }
} }
//--------------------------------------------------
// MARK: - Enum
//--------------------------------------------------
public enum Direction: Float {
case right = 0
case upperRight = 45
case up = 90
case upperLeft = 135
case left = 180
case bottomLeft = 225
case down = 270
case bottomRight = 315
}
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Constraints // MARK: - Constraints
//-------------------------------------------------- //--------------------------------------------------

View File

@ -31,15 +31,15 @@ open class BarsIndicatorView: CarouselIndicator {
public static let indicatorBarWidth: CGFloat = 24 public static let indicatorBarWidth: CGFloat = 24
public static let indicatorBarHeight: (selected: CGFloat, unselected: CGFloat) = (selected: 4, unselected: 1) public static let indicatorBarHeight: (selected: CGFloat, unselected: CGFloat) = (selected: 4, unselected: 1)
//--------------------------------------------------
// MARK: - Computed Properties
//--------------------------------------------------
/// Convenience to access the model. /// Convenience to access the model.
public var barsCarouselIndicatorModel: BarsCarouselIndicatorModel? { public var barsCarouselIndicatorModel: BarsCarouselIndicatorModel? {
return model as? BarsCarouselIndicatorModel return model as? BarsCarouselIndicatorModel
} }
//--------------------------------------------------
// MARK: - Computed Properties
//--------------------------------------------------
open override var isEnabled: Bool { open override var isEnabled: Bool {
didSet { didSet {
barReferences.forEach { view, _ in barReferences.forEach { view, _ in
@ -48,13 +48,10 @@ open class BarsIndicatorView: CarouselIndicator {
} }
} }
private(set) var _currentIndicatorColor: UIColor = .black
/// Colors the currently selected index, unique from other indicators /// Colors the currently selected index, unique from other indicators
public var currentIndicatorColor: UIColor { public var currentIndicatorColor: UIColor {
get { return _currentIndicatorColor } get { return barsCarouselIndicatorModel?.currentIndicatorColor.uiColor ?? .mvmBlack }
set (newColor) { set (newColor) {
_currentIndicatorColor = newColor
barsCarouselIndicatorModel?.currentIndicatorColor = Color(uiColor: newColor) barsCarouselIndicatorModel?.currentIndicatorColor = Color(uiColor: newColor)
if !barReferences.isEmpty { if !barReferences.isEmpty {
@ -64,7 +61,7 @@ open class BarsIndicatorView: CarouselIndicator {
} }
public override var indicatorColor: UIColor { public override var indicatorColor: UIColor {
get { return _indicatorColor } get { return carouselIndicatorModel?.indicatorColor.uiColor ?? .mvmBlack }
set (newColor) { set (newColor) {
super.indicatorColor = newColor super.indicatorColor = newColor

View File

@ -41,15 +41,12 @@ open class CarouselIndicator: Control, CarouselPageControlProtocol {
//-------------------------------------------------- //--------------------------------------------------
private(set) var previousIndex = 0 private(set) var previousIndex = 0
private var _currentIndex = 0
public var currentIndex: Int { public var currentIndex: Int {
get { return _currentIndex } get { return carouselIndicatorModel?.currentIndex ?? 0 }
set (newIndex) { set (newIndex) {
previousIndex = currentIndex
carouselIndicatorModel?.currentIndex = newIndex carouselIndicatorModel?.currentIndex = newIndex
previousIndex = _currentIndex
_currentIndex = newIndex
if previousIndex != newIndex { if previousIndex != newIndex {
updateUI(previousIndex: previousIndex, updateUI(previousIndex: previousIndex,
@ -61,18 +58,16 @@ open class CarouselIndicator: Control, CarouselPageControlProtocol {
} }
} }
/// The maxmum count of pages before the indicatorView forces a Numeric Indicator in place of Bar.
private var _numberOfPages = 0
/// Holds the total number of pages displayed by the carousel. /// Holds the total number of pages displayed by the carousel.
/// Updating this property will potentially update the UI. /// Updating this property will potentially update the UI.
/// The maxmum count of pages before the indicatorView forces a Numeric Indicator in place of Bar.
public var numberOfPages: Int { public var numberOfPages: Int {
get { return _numberOfPages } get { return carouselIndicatorModel?.numberOfPages ?? 0 }
set (newTotal) { set (newTotal) {
guard _numberOfPages != newTotal else { return } guard numberOfPages != newTotal else { return }
carouselIndicatorModel?.numberOfPages = newTotal
_numberOfPages = newTotal
carouselIndicatorModel?.numberOfPages = newTotal
reset()
isHidden = (carouselIndicatorModel?.hidesForSinglePage ?? false) && newTotal <= 1 isHidden = (carouselIndicatorModel?.hidesForSinglePage ?? false) && newTotal <= 1
updateUI(previousIndex: previousIndex, updateUI(previousIndex: previousIndex,
newIndex: currentIndex, newIndex: currentIndex,
@ -81,24 +76,14 @@ open class CarouselIndicator: Control, CarouselPageControlProtocol {
} }
} }
private(set) var _disabledIndicatorColor: UIColor = .mvmCoolGray3
public var disabledIndicatorColor: UIColor { public var disabledIndicatorColor: UIColor {
get { return _disabledIndicatorColor } get { return carouselIndicatorModel?.disabledIndicatorColor.uiColor ?? .mvmCoolGray3 }
set (newDisabledColor) { set { carouselIndicatorModel?.disabledIndicatorColor = Color(uiColor: newValue) }
_disabledIndicatorColor = newDisabledColor
carouselIndicatorModel?.disabledIndicatorColor = Color(uiColor: newDisabledColor)
}
} }
private(set) var _indicatorColor: UIColor = .black
public var indicatorColor: UIColor { public var indicatorColor: UIColor {
get { return _indicatorColor } get { return carouselIndicatorModel?.indicatorColor.uiColor ?? .mvmBlack }
set (newColor) { set { carouselIndicatorModel?.indicatorColor = Color(uiColor: newValue) }
_indicatorColor = newColor
carouselIndicatorModel?.indicatorColor = Color(uiColor: newColor)
}
} }
//-------------------------------------------------- //--------------------------------------------------

View File

@ -109,8 +109,8 @@ open class CarouselIndicatorModel: CarouselPagingModelProtocol, MoleculeModelPro
try container.encode(currentIndex, forKey: .currentIndex) try container.encode(currentIndex, forKey: .currentIndex)
try container.encode(alwaysSendAction, forKey: .alwaysSendAction) try container.encode(alwaysSendAction, forKey: .alwaysSendAction)
try container.encode(isAnimated, forKey: .isAnimated) try container.encode(isAnimated, forKey: .isAnimated)
try container.encodeIfPresent(hidesForSinglePage, forKey: .hidesForSinglePage) try container.encode(hidesForSinglePage, forKey: .hidesForSinglePage)
try container.encodeIfPresent(accessibilityHasSlidesInsteadOfPage, forKey: .accessibilityHasSlidesInsteadOfPage) try container.encode(accessibilityHasSlidesInsteadOfPage, forKey: .accessibilityHasSlidesInsteadOfPage)
try container.encode(isEnabled, forKey: .isEnabled) try container.encode(isEnabled, forKey: .isEnabled)
try container.encode(disabledIndicatorColor, forKey: .disabledIndicatorColor) try container.encode(disabledIndicatorColor, forKey: .disabledIndicatorColor)
try container.encode(indicatorColor, forKey: .indicatorColor) try container.encode(indicatorColor, forKey: .indicatorColor)

View File

@ -55,7 +55,7 @@ open class NumericIndicatorView: CarouselIndicator {
/// Sets the color for pageCount text, left arrow and right arrow. /// Sets the color for pageCount text, left arrow and right arrow.
public override var indicatorColor: UIColor { public override var indicatorColor: UIColor {
get { return _indicatorColor } get { return carouselIndicatorModel?.indicatorColor.uiColor ?? .mvmBlack }
set (newColor) { set (newColor) {
super.indicatorColor = newColor super.indicatorColor = newColor

View File

@ -93,7 +93,7 @@ import UIKit
public func encode(to encoder: Encoder) throws { public func encode(to encoder: Encoder) throws {
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.encode(backgroundColor, forKey: .backgroundColor) try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
try container.encode(molecules, forKey: .molecules) try container.encode(molecules, forKey: .molecules)
try container.encode(spacing, forKey: .spacing) try container.encode(spacing, forKey: .spacing)
try container.encode(border, forKey: .border) try container.encode(border, forKey: .border)