Merge branch 'feature/new_modern_page_control' of https://gitlab.verizon.com/BPHV_MIPS/mvm_core_ui into feature/new_modern_page_control
This commit is contained in:
commit
500894c433
@ -54,7 +54,7 @@ open class Arrow: View {
|
|||||||
get { return arrowModel?.lineWidth ?? 1 }
|
get { return arrowModel?.lineWidth ?? 1 }
|
||||||
set { arrowModel?.lineWidth = newValue }
|
set { arrowModel?.lineWidth = newValue }
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Constraints
|
// MARK: - Constraints
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -78,12 +78,6 @@ open class Arrow: View {
|
|||||||
super.init(frame: frame)
|
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) {
|
public required init?(coder: NSCoder) {
|
||||||
fatalError("init(coder:) has not been implemented")
|
fatalError("init(coder:) has not been implemented")
|
||||||
}
|
}
|
||||||
@ -105,9 +99,7 @@ open class Arrow: View {
|
|||||||
// MARK: - Drawing
|
// 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) {
|
open override func draw(_ rect: CGRect) {
|
||||||
super.draw(rect)
|
super.draw(rect)
|
||||||
|
|
||||||
@ -115,7 +107,7 @@ open class Arrow: View {
|
|||||||
drawShapeLayer()
|
drawShapeLayer()
|
||||||
|
|
||||||
let radians = CGFloat(degrees * Float.pi / 180)
|
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() {
|
private func drawShapeLayer() {
|
||||||
@ -153,6 +145,10 @@ open class Arrow: View {
|
|||||||
return bezierPath.cgPath
|
return bezierPath.cgPath
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------
|
||||||
|
// MARK: - MoleculeViewProtocol
|
||||||
|
//--------------------------------------------------
|
||||||
|
|
||||||
public override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
|
public override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
|
||||||
super.set(with: model, delegateObject, additionalData)
|
super.set(with: model, delegateObject, additionalData)
|
||||||
|
|
||||||
|
|||||||
@ -42,31 +42,37 @@ open class BarsIndicatorView: CarouselIndicator {
|
|||||||
|
|
||||||
open override var isEnabled: Bool {
|
open override var isEnabled: Bool {
|
||||||
didSet {
|
didSet {
|
||||||
barReferences.forEach { view, _ in
|
for (i, bar) in barReferences.enumerated() {
|
||||||
view.backgroundColor = isEnabled ? indicatorColor : disabledIndicatorColor
|
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
|
/// Colors the currently selected index, unique from other indicators
|
||||||
public var currentIndicatorColor: UIColor {
|
public var currentIndicatorColor: UIColor {
|
||||||
get { return barsCarouselIndicatorModel?.currentIndicatorColor.uiColor ?? .mvmBlack }
|
get { return barsCarouselIndicatorModel?.currentIndicatorColor.uiColor ?? indicatorColor }
|
||||||
set (newColor) {
|
set (newColor) {
|
||||||
barsCarouselIndicatorModel?.currentIndicatorColor = Color(uiColor: newColor)
|
barsCarouselIndicatorModel?.currentIndicatorColor = Color(uiColor: newColor)
|
||||||
|
|
||||||
if !barReferences.isEmpty {
|
if isEnabled && !barReferences.isEmpty {
|
||||||
barReferences[currentIndex].view.backgroundColor = newColor
|
barReferences[currentIndex].view.backgroundColor = newColor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override var indicatorColor: UIColor {
|
public override var indicatorColor: UIColor {
|
||||||
get { return carouselIndicatorModel?.indicatorColor.uiColor ?? .mvmBlack }
|
get { return super.indicatorColor }
|
||||||
set (newColor) {
|
set (newColor) {
|
||||||
super.indicatorColor = newColor
|
super.indicatorColor = newColor
|
||||||
|
|
||||||
for (i, barTuple) in barReferences.enumerated() where i != currentIndex {
|
if isEnabled {
|
||||||
barTuple.view.backgroundColor = newColor
|
for (i, barTuple) in barReferences.enumerated() {
|
||||||
|
barTuple.view.backgroundColor = i == currentIndex ? currentIndicatorColor : newColor
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -158,8 +164,8 @@ open class BarsIndicatorView: CarouselIndicator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let expression = {
|
let expression = {
|
||||||
self.barReferences[previousIndex].view.backgroundColor = self.indicatorColor
|
self.barReferences[previousIndex].view.backgroundColor = self.isEnabled ? self.indicatorColor : self.disabledIndicatorColor
|
||||||
self.barReferences[newIndex].view.backgroundColor = self.currentIndicatorColor
|
self.barReferences[newIndex].view.backgroundColor = self.isEnabled ? self.currentIndicatorColor : self.disabledIndicatorColor
|
||||||
self.barReferences[previousIndex].constraint.constant = BarsIndicatorView.indicatorBarHeight.unselected
|
self.barReferences[previousIndex].constraint.constant = BarsIndicatorView.indicatorBarHeight.unselected
|
||||||
self.barReferences[newIndex].constraint.constant = BarsIndicatorView.indicatorBarHeight.selected
|
self.barReferences[newIndex].constraint.constant = BarsIndicatorView.indicatorBarHeight.selected
|
||||||
self.layoutIfNeeded()
|
self.layoutIfNeeded()
|
||||||
|
|||||||
@ -140,11 +140,12 @@ open class CarouselIndicator: Control, CarouselPageControlProtocol {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func incrementCurrentIndex() {
|
func incrementCurrentIndex() {
|
||||||
currentIndex = min(currentIndex + 1, numberOfPages - 1)
|
currentIndex = (currentIndex + 1) % numberOfPages
|
||||||
}
|
}
|
||||||
|
|
||||||
func decrementCurrentIndex() {
|
func decrementCurrentIndex() {
|
||||||
currentIndex = max(0, currentIndex - 1)
|
let newIndex = currentIndex - 1
|
||||||
|
currentIndex = newIndex < 0 ? numberOfPages - 1 : newIndex
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Increments the currentIndex value.
|
/// Increments the currentIndex value.
|
||||||
@ -222,7 +223,7 @@ open class CarouselIndicator: Control, CarouselPageControlProtocol {
|
|||||||
let accessibleIndex = ordinalFormatter.string(from: NSNumber(value: index))
|
let accessibleIndex = ordinalFormatter.string(from: NSNumber(value: index))
|
||||||
else { return }
|
else { return }
|
||||||
|
|
||||||
accessibilityValue = String(format: accessibleFormat, accessibleIndex, total)
|
accessibilityValue = String(format: accessibleFormat, accessibleIndex, total)
|
||||||
}
|
}
|
||||||
|
|
||||||
func accessibilityAdjust(toPage index: Int) {
|
func accessibilityAdjust(toPage index: Int) {
|
||||||
|
|||||||
@ -24,14 +24,15 @@ open class NumericIndicatorView: CarouselIndicator {
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
let leftArrow: Arrow = {
|
let leftArrow: Arrow = {
|
||||||
let arrow = Arrow(model: ArrowModel(), degrees: 180)
|
let arrow = Arrow(model: ArrowModel(), nil, nil)
|
||||||
arrow.isAccessibilityElement = false
|
arrow.isAccessibilityElement = false
|
||||||
|
arrow.direction = .left
|
||||||
arrow.pinHeightAndWidth()
|
arrow.pinHeightAndWidth()
|
||||||
return arrow
|
return arrow
|
||||||
}()
|
}()
|
||||||
|
|
||||||
let rightArrow: Arrow = {
|
let rightArrow: Arrow = {
|
||||||
let arrow = Arrow(model: ArrowModel())
|
let arrow = Arrow(model: ArrowModel(), nil, nil)
|
||||||
arrow.pinHeightAndWidth()
|
arrow.pinHeightAndWidth()
|
||||||
return arrow
|
return arrow
|
||||||
}()
|
}()
|
||||||
@ -41,23 +42,17 @@ open class NumericIndicatorView: CarouselIndicator {
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
||||||
open override var isEnabled: Bool {
|
open override var isEnabled: Bool {
|
||||||
didSet {
|
didSet { setViewColor(isEnabled ? indicatorColor : disabledIndicatorColor) }
|
||||||
pageCount.textColor = isEnabled ? indicatorColor : disabledIndicatorColor
|
|
||||||
leftArrow.tintColor = isEnabled ? indicatorColor : disabledIndicatorColor
|
|
||||||
rightArrow.tintColor = isEnabled ? indicatorColor : disabledIndicatorColor
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 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 carouselIndicatorModel?.indicatorColor.uiColor ?? .mvmBlack }
|
get { return super.indicatorColor }
|
||||||
set (newColor) {
|
set (newColor) {
|
||||||
super.indicatorColor = newColor
|
super.indicatorColor = newColor
|
||||||
|
|
||||||
if isEnabled {
|
if isEnabled {
|
||||||
pageCount.textColor = newColor
|
setViewColor(newColor)
|
||||||
leftArrow.arrowModel?.color = Color(uiColor: newColor)
|
|
||||||
rightArrow.arrowModel?.color = Color(uiColor: newColor)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -90,12 +85,16 @@ open class NumericIndicatorView: CarouselIndicator {
|
|||||||
leftArrow.centerYAnchor.constraint(equalTo: centerYAnchor),
|
leftArrow.centerYAnchor.constraint(equalTo: centerYAnchor),
|
||||||
rightArrow.centerYAnchor.constraint(equalTo: centerYAnchor),
|
rightArrow.centerYAnchor.constraint(equalTo: centerYAnchor),
|
||||||
leftArrow.leadingAnchor.constraint(equalTo: leadingAnchor),
|
leftArrow.leadingAnchor.constraint(equalTo: leadingAnchor),
|
||||||
pageCount.leadingAnchor.constraint(equalTo: leftArrow.trailingAnchor, constant: PaddingOne),
|
pageCount.leadingAnchor.constraint(equalTo: leftArrow.trailingAnchor, constant: Padding.Two),
|
||||||
rightArrow.leadingAnchor.constraint(equalTo: pageCount.trailingAnchor, constant: PaddingOne),
|
rightArrow.leadingAnchor.constraint(equalTo: pageCount.trailingAnchor, constant: Padding.Two),
|
||||||
trailingAnchor.constraint(equalTo: rightArrow.trailingAnchor)
|
trailingAnchor.constraint(equalTo: rightArrow.trailingAnchor)
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------
|
||||||
|
// MARK: - Methods
|
||||||
|
//--------------------------------------------------
|
||||||
|
|
||||||
public override func assessTouchOf(_ touchPoint_X: CGFloat) {
|
public override func assessTouchOf(_ touchPoint_X: CGFloat) {
|
||||||
|
|
||||||
if touchPoint_X > bounds.width / 2 {
|
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]?) {
|
private func setViewColor(_ newColor: UIColor) {
|
||||||
super.set(with: model, delegateObject, additionalData)
|
|
||||||
|
|
||||||
guard let model = model as? CarouselIndicatorModel else { return }
|
pageCount.textColor = newColor
|
||||||
|
leftArrow.color = newColor
|
||||||
isEnabled = model.enabled
|
rightArrow.color = newColor
|
||||||
|
rightArrow.setNeedsDisplay()
|
||||||
|
leftArrow.setNeedsDisplay()
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - IndicatorViewProtocol
|
// MARK: - IndicatorViewProtocol
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|||||||
@ -29,7 +29,7 @@ import UIKit
|
|||||||
public var itemAlignment: UICollectionView.ScrollPosition?
|
public var itemAlignment: UICollectionView.ScrollPosition?
|
||||||
public var pagingMolecule: (CarouselPagingModelProtocol & MoleculeModelProtocol)?
|
public var pagingMolecule: (CarouselPagingModelProtocol & MoleculeModelProtocol)?
|
||||||
|
|
||||||
public init(molecules: [CarouselItemModel]){
|
public init(molecules: [CarouselItemModel]) {
|
||||||
self.molecules = molecules
|
self.molecules = molecules
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -45,7 +45,7 @@ extension MoleculeViewProtocol {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Do nothing, optionals.
|
// 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 func reset() {}
|
||||||
|
|
||||||
public static func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? {
|
public static func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? {
|
||||||
|
|||||||
@ -8,11 +8,16 @@
|
|||||||
|
|
||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
|
|
||||||
@objcMembers open class View: UIView, MoleculeViewProtocol {
|
@objcMembers open class View: UIView, MoleculeViewProtocol {
|
||||||
|
//--------------------------------------------------
|
||||||
|
// MARK: - Properties
|
||||||
|
//--------------------------------------------------
|
||||||
|
|
||||||
open var model: MoleculeModelProtocol?
|
open var model: MoleculeModelProtocol?
|
||||||
|
|
||||||
private var initialSetupPerformed = false
|
private var initialSetupPerformed = false
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Initialization
|
// MARK: - Initialization
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -21,7 +26,7 @@ import UIKit
|
|||||||
super.init(frame: .zero)
|
super.init(frame: .zero)
|
||||||
initialSetup()
|
initialSetup()
|
||||||
}
|
}
|
||||||
|
|
||||||
public convenience init() {
|
public convenience init() {
|
||||||
self.init(frame: .zero)
|
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]?) {
|
open func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
|
||||||
self.model = model
|
self.model = model
|
||||||
if let backgroundColor = model.backgroundColor {
|
if let backgroundColor = model.backgroundColor {
|
||||||
self.backgroundColor = backgroundColor.uiColor
|
self.backgroundColor = backgroundColor.uiColor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
open class func nameForReuse(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> String? {
|
open class func nameForReuse(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> String? {
|
||||||
@ -66,8 +74,8 @@ import UIKit
|
|||||||
// MARK:- MVMCoreViewProtocol
|
// MARK:- MVMCoreViewProtocol
|
||||||
extension View: MVMCoreViewProtocol {
|
extension View: MVMCoreViewProtocol {
|
||||||
|
|
||||||
open func updateView(_ size: CGFloat) {}
|
open func updateView(_ size: CGFloat) { }
|
||||||
|
|
||||||
/// Will be called only once.
|
/// Will be called only once.
|
||||||
open func setupView() {
|
open func setupView() {
|
||||||
translatesAutoresizingMaskIntoConstraints = false
|
translatesAutoresizingMaskIntoConstraints = false
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user