From 8b05b20f515870afe93142d4e69a786b5c4aa255 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Tue, 5 May 2020 09:00:47 -0400 Subject: [PATCH 1/4] latest state --- MVMCoreUI/Atomic/Atoms/Views/Arrow.swift | 10 +++---- .../NumericIndicatorView.swift | 4 +-- .../Protocols/MoleculeViewProtocol.swift | 2 +- MVMCoreUI/BaseClasses/View.swift | 26 ++++++++++++------- 4 files changed, 25 insertions(+), 17 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Views/Arrow.swift b/MVMCoreUI/Atomic/Atoms/Views/Arrow.swift index b618d43d..ae5182e5 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/Arrow.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/Arrow.swift @@ -78,11 +78,11 @@ open class Arrow: View { super.init(frame: frame) } - public convenience init(model: ArrowModel, degrees: Float = 0) { - self.init(frame: .zero) - self.model = model - arrowModel?.degrees = degrees - } +// public convenience init(degrees: Float = 0) { +// self.init(frame: .zero) +// self.model = ArrowModel() +// arrowModel?.degrees = degrees +// } public required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") diff --git a/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/NumericIndicatorView.swift b/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/NumericIndicatorView.swift index d93d7709..634038c1 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/NumericIndicatorView.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/NumericIndicatorView.swift @@ -24,14 +24,14 @@ open class NumericIndicatorView: CarouselIndicator { }() let leftArrow: Arrow = { - let arrow = Arrow(model: ArrowModel(), degrees: 180) + let arrow = Arrow(model: ArrowModel(), nil, nil) arrow.isAccessibilityElement = false arrow.pinHeightAndWidth() return arrow }() let rightArrow: Arrow = { - let arrow = Arrow(model: ArrowModel()) + let arrow = Arrow() arrow.pinHeightAndWidth() return arrow }() diff --git a/MVMCoreUI/Atomic/Protocols/MoleculeViewProtocol.swift b/MVMCoreUI/Atomic/Protocols/MoleculeViewProtocol.swift index 1654a34b..db0de647 100644 --- a/MVMCoreUI/Atomic/Protocols/MoleculeViewProtocol.swift +++ b/MVMCoreUI/Atomic/Protocols/MoleculeViewProtocol.swift @@ -45,7 +45,7 @@ extension MoleculeViewProtocol { } // Do nothing, optionals. - public func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable : Any]?) {} + public func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {} public func reset() {} public static func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { diff --git a/MVMCoreUI/BaseClasses/View.swift b/MVMCoreUI/BaseClasses/View.swift index b5fdc5e7..c0ca8ee1 100644 --- a/MVMCoreUI/BaseClasses/View.swift +++ b/MVMCoreUI/BaseClasses/View.swift @@ -8,11 +8,16 @@ import UIKit + @objcMembers open class View: UIView, MoleculeViewProtocol { + //-------------------------------------------------- + // MARK: - Properties + //-------------------------------------------------- + open var model: MoleculeModelProtocol? - + private var initialSetupPerformed = false - + //-------------------------------------------------- // MARK: - Initialization //-------------------------------------------------- @@ -21,7 +26,7 @@ import UIKit super.init(frame: .zero) initialSetup() } - + public convenience init() { self.init(frame: .zero) } @@ -38,12 +43,15 @@ import UIKit } } - // MARK:- MoleculeViewProtocol + //-------------------------------------------------- + // MARK: - MoleculeViewProtocol + //-------------------------------------------------- + open func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { - self.model = model - if let backgroundColor = model.backgroundColor { + self.model = model + if let backgroundColor = model.backgroundColor { self.backgroundColor = backgroundColor.uiColor - } + } } open class func nameForReuse(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> String? { @@ -66,8 +74,8 @@ import UIKit // MARK:- MVMCoreViewProtocol extension View: MVMCoreViewProtocol { - open func updateView(_ size: CGFloat) {} - + open func updateView(_ size: CGFloat) { } + /// Will be called only once. open func setupView() { translatesAutoresizingMaskIntoConstraints = false From 0aad6f3aa7a0b5eb12a96d88b91efdabedba2b99 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Tue, 5 May 2020 10:41:55 -0400 Subject: [PATCH 2/4] requested changes and improvements made --- MVMCoreUI/Atomic/Atoms/Views/Arrow.swift | 18 ++++------ .../CarouselIndicator/BarsIndicatorView.swift | 10 +++--- .../CarouselIndicator/CarouselIndicator.swift | 7 ++-- .../NumericIndicatorView.swift | 36 +++++++++---------- .../Atomic/Organisms/CarouselModel.swift | 2 +- 5 files changed, 35 insertions(+), 38 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Views/Arrow.swift b/MVMCoreUI/Atomic/Atoms/Views/Arrow.swift index ae5182e5..ea5023c8 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/Arrow.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/Arrow.swift @@ -54,7 +54,7 @@ open class Arrow: View { get { return arrowModel?.lineWidth ?? 1 } set { arrowModel?.lineWidth = newValue } } - + //-------------------------------------------------- // MARK: - Constraints //-------------------------------------------------- @@ -78,12 +78,6 @@ open class Arrow: View { super.init(frame: frame) } -// public convenience init(degrees: Float = 0) { -// self.init(frame: .zero) -// self.model = ArrowModel() -// arrowModel?.degrees = degrees -// } - public required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } @@ -105,9 +99,7 @@ open class Arrow: View { // MARK: - Drawing //-------------------------------------------------- - /** - Draws the arrow pointing to the right and then rotates the arrow x degrees counter-clockwise. - */ + /// Draws the arrow pointing to the right and then rotates the arrow x degrees counter-clockwise. open override func draw(_ rect: CGRect) { super.draw(rect) @@ -115,7 +107,7 @@ open class Arrow: View { drawShapeLayer() let radians = CGFloat(degrees * Float.pi / 180) - arrowLayer.transform = CATransform3DMakeRotation(-radians, 0.0, 0.0, 1.0) + arrowLayer.transform = CATransform3DMakeRotation(-radians, 0, 0, 1) } private func drawShapeLayer() { @@ -153,6 +145,10 @@ open class Arrow: View { return bezierPath.cgPath } + //-------------------------------------------------- + // MARK: - MoleculeViewProtocol + //-------------------------------------------------- + public override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { super.set(with: model, delegateObject, additionalData) diff --git a/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/BarsIndicatorView.swift b/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/BarsIndicatorView.swift index 42171934..9b4ea3bc 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/BarsIndicatorView.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/BarsIndicatorView.swift @@ -61,12 +61,12 @@ open class BarsIndicatorView: CarouselIndicator { } public override var indicatorColor: UIColor { - get { return carouselIndicatorModel?.indicatorColor.uiColor ?? .mvmBlack } + get { return super.indicatorColor } set (newColor) { super.indicatorColor = newColor - for (i, barTuple) in barReferences.enumerated() where i != currentIndex { - barTuple.view.backgroundColor = newColor + for (i, barTuple) in barReferences.enumerated() { + barTuple.view.backgroundColor = i == currentIndex ? currentIndicatorColor : newColor } } } @@ -158,8 +158,8 @@ open class BarsIndicatorView: CarouselIndicator { } let expression = { - self.barReferences[previousIndex].view.backgroundColor = self.indicatorColor - self.barReferences[newIndex].view.backgroundColor = self.currentIndicatorColor + self.barReferences[previousIndex].view.backgroundColor = self.isEnabled ? self.indicatorColor : self.disabledIndicatorColor + self.barReferences[newIndex].view.backgroundColor = self.isEnabled ? self.currentIndicatorColor : self.disabledIndicatorColor self.barReferences[previousIndex].constraint.constant = BarsIndicatorView.indicatorBarHeight.unselected self.barReferences[newIndex].constraint.constant = BarsIndicatorView.indicatorBarHeight.selected self.layoutIfNeeded() diff --git a/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/CarouselIndicator.swift b/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/CarouselIndicator.swift index ebebd047..be3b3542 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/CarouselIndicator.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/CarouselIndicator.swift @@ -140,11 +140,12 @@ open class CarouselIndicator: Control, CarouselPageControlProtocol { } func incrementCurrentIndex() { - currentIndex = min(currentIndex + 1, numberOfPages - 1) + currentIndex = (currentIndex + 1) % numberOfPages } func decrementCurrentIndex() { - currentIndex = max(0, currentIndex - 1) + let newIndex = currentIndex - 1 + currentIndex = newIndex < 0 ? numberOfPages - 1 : newIndex } /// Increments the currentIndex value. @@ -222,7 +223,7 @@ open class CarouselIndicator: Control, CarouselPageControlProtocol { let accessibleIndex = ordinalFormatter.string(from: NSNumber(value: index)) else { return } - accessibilityValue = String(format: accessibleFormat, accessibleIndex, total) + accessibilityValue = String(format: accessibleFormat, accessibleIndex, total) } func accessibilityAdjust(toPage index: Int) { diff --git a/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/NumericIndicatorView.swift b/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/NumericIndicatorView.swift index 634038c1..8660968d 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/NumericIndicatorView.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/NumericIndicatorView.swift @@ -26,12 +26,13 @@ open class NumericIndicatorView: CarouselIndicator { let leftArrow: Arrow = { let arrow = Arrow(model: ArrowModel(), nil, nil) arrow.isAccessibilityElement = false + arrow.direction = .left arrow.pinHeightAndWidth() return arrow }() let rightArrow: Arrow = { - let arrow = Arrow() + let arrow = Arrow(model: ArrowModel(), nil, nil) arrow.pinHeightAndWidth() return arrow }() @@ -41,23 +42,17 @@ open class NumericIndicatorView: CarouselIndicator { //-------------------------------------------------- open override var isEnabled: Bool { - didSet { - pageCount.textColor = isEnabled ? indicatorColor : disabledIndicatorColor - leftArrow.tintColor = isEnabled ? indicatorColor : disabledIndicatorColor - rightArrow.tintColor = isEnabled ? indicatorColor : disabledIndicatorColor - } + didSet { setViewColor(isEnabled ? indicatorColor : disabledIndicatorColor) } } /// Sets the color for pageCount text, left arrow and right arrow. public override var indicatorColor: UIColor { - get { return carouselIndicatorModel?.indicatorColor.uiColor ?? .mvmBlack } + get { return super.indicatorColor } set (newColor) { super.indicatorColor = newColor if isEnabled { - pageCount.textColor = newColor - leftArrow.arrowModel?.color = Color(uiColor: newColor) - rightArrow.arrowModel?.color = Color(uiColor: newColor) + setViewColor(newColor) } } } @@ -90,12 +85,16 @@ open class NumericIndicatorView: CarouselIndicator { leftArrow.centerYAnchor.constraint(equalTo: centerYAnchor), rightArrow.centerYAnchor.constraint(equalTo: centerYAnchor), leftArrow.leadingAnchor.constraint(equalTo: leadingAnchor), - pageCount.leadingAnchor.constraint(equalTo: leftArrow.trailingAnchor, constant: PaddingOne), - rightArrow.leadingAnchor.constraint(equalTo: pageCount.trailingAnchor, constant: PaddingOne), + pageCount.leadingAnchor.constraint(equalTo: leftArrow.trailingAnchor, constant: Padding.Two), + rightArrow.leadingAnchor.constraint(equalTo: pageCount.trailingAnchor, constant: Padding.Two), trailingAnchor.constraint(equalTo: rightArrow.trailingAnchor) ]) } + //-------------------------------------------------- + // MARK: - Methods + //-------------------------------------------------- + public override func assessTouchOf(_ touchPoint_X: CGFloat) { if touchPoint_X > bounds.width / 2 { @@ -105,14 +104,15 @@ open class NumericIndicatorView: CarouselIndicator { } } - open override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { - super.set(with: model, delegateObject, additionalData) + private func setViewColor(_ newColor: UIColor) { - guard let model = model as? CarouselIndicatorModel else { return } - - isEnabled = model.enabled + pageCount.textColor = newColor + leftArrow.color = newColor + rightArrow.color = newColor + rightArrow.setNeedsDisplay() + leftArrow.setNeedsDisplay() } - + //-------------------------------------------------- // MARK: - IndicatorViewProtocol //-------------------------------------------------- diff --git a/MVMCoreUI/Atomic/Organisms/CarouselModel.swift b/MVMCoreUI/Atomic/Organisms/CarouselModel.swift index c8406d7b..857901e8 100644 --- a/MVMCoreUI/Atomic/Organisms/CarouselModel.swift +++ b/MVMCoreUI/Atomic/Organisms/CarouselModel.swift @@ -29,7 +29,7 @@ import UIKit public var itemAlignment: UICollectionView.ScrollPosition? public var pagingMolecule: (CarouselPagingModelProtocol & MoleculeModelProtocol)? - public init(molecules: [CarouselItemModel]){ + public init(molecules: [CarouselItemModel]) { self.molecules = molecules } From 89499d59edb2ee10848de00e54de3103b0923fa3 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Tue, 5 May 2020 12:54:50 -0400 Subject: [PATCH 3/4] indicator changes --- .../Views/CarouselIndicator/BarsIndicatorView.swift | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/BarsIndicatorView.swift b/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/BarsIndicatorView.swift index 9b4ea3bc..ad65049d 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/BarsIndicatorView.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/BarsIndicatorView.swift @@ -42,19 +42,24 @@ open class BarsIndicatorView: CarouselIndicator { open override var isEnabled: Bool { didSet { - barReferences.forEach { view, _ in - view.backgroundColor = isEnabled ? indicatorColor : disabledIndicatorColor + + for (i, bar) in barReferences.enumerated() { + if i == currentIndex { + bar.view.backgroundColor = isEnabled ? currentIndicatorColor : disabledIndicatorColor + } else { + bar.view.backgroundColor = isEnabled ? indicatorColor : disabledIndicatorColor + } } } } /// Colors the currently selected index, unique from other indicators public var currentIndicatorColor: UIColor { - get { return barsCarouselIndicatorModel?.currentIndicatorColor.uiColor ?? .mvmBlack } + get { return barsCarouselIndicatorModel?.currentIndicatorColor.uiColor ?? indicatorColor } set (newColor) { barsCarouselIndicatorModel?.currentIndicatorColor = Color(uiColor: newColor) - if !barReferences.isEmpty { + if isEnabled && !barReferences.isEmpty { barReferences[currentIndex].view.backgroundColor = newColor } } From f7ba8da840ae656c12aee7e4b6392ab814c0cd6d Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Tue, 5 May 2020 13:00:26 -0400 Subject: [PATCH 4/4] enableable stuff --- .../Atoms/Views/CarouselIndicator/BarsIndicatorView.swift | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/BarsIndicatorView.swift b/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/BarsIndicatorView.swift index ad65049d..691dbfa0 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/BarsIndicatorView.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/BarsIndicatorView.swift @@ -42,7 +42,6 @@ open class BarsIndicatorView: CarouselIndicator { open override var isEnabled: Bool { didSet { - for (i, bar) in barReferences.enumerated() { if i == currentIndex { bar.view.backgroundColor = isEnabled ? currentIndicatorColor : disabledIndicatorColor @@ -70,8 +69,10 @@ open class BarsIndicatorView: CarouselIndicator { set (newColor) { super.indicatorColor = newColor - for (i, barTuple) in barReferences.enumerated() { - barTuple.view.backgroundColor = i == currentIndex ? currentIndicatorColor : newColor + if isEnabled { + for (i, barTuple) in barReferences.enumerated() { + barTuple.view.backgroundColor = i == currentIndex ? currentIndicatorColor : newColor + } } } }