Merge branch 'feature/atomic_vds_textLinkCaret' into feature/vds_batch_two
# Conflicts: # MVMCoreUI/Atomic/Extensions/VDS-Enums+Codable.swift Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
commit
d2af968892
@ -6,152 +6,61 @@
|
|||||||
// Created by Christiano, Kevin on 3/18/19.
|
// Created by Christiano, Kevin on 3/18/19.
|
||||||
// Copyright © 2019 Verizon Wireless. All rights reserved.
|
// Copyright © 2019 Verizon Wireless. All rights reserved.
|
||||||
//
|
//
|
||||||
|
import VDS
|
||||||
|
|
||||||
|
open class CaretLink: VDS.TextLinkCaret, VDSMoleculeViewProtocol {
|
||||||
|
|
||||||
open class CaretLink: Button, MVMCoreUIViewConstrainingProtocol {
|
//--------------------------------------------------
|
||||||
//------------------------------------------------------
|
// MARK: - Public Properties
|
||||||
// MARK: - Constants
|
//--------------------------------------------------
|
||||||
//------------------------------------------------------
|
open var viewModel: CaretLinkModel!
|
||||||
|
open var delegateObject: MVMCoreUIDelegateObject?
|
||||||
|
open var additionalData: [AnyHashable : Any]?
|
||||||
|
|
||||||
private let CARET_VIEW_HEIGHT: Float = 10.5
|
//--------------------------------------------------
|
||||||
private let CARET_VIEW_WIDTH: Float = 6.5
|
// MARK: - Public Functions
|
||||||
|
//--------------------------------------------------
|
||||||
//------------------------------------------------------
|
open func viewModelDidUpdate() {
|
||||||
// MARK: - Properties
|
isEnabled = viewModel.enabled
|
||||||
//------------------------------------------------------
|
iconPosition = viewModel.iconPosition
|
||||||
|
text = viewModel.title
|
||||||
@objc public var rightView: UIView?
|
surface = viewModel.surface
|
||||||
@objc public var rightViewHeight: NSNumber?
|
onClick = { [weak self] control in
|
||||||
@objc public var rightViewWidth: NSNumber?
|
guard let self else { return }
|
||||||
|
MVMCoreUIActionHandler.performActionUnstructured(with: self.viewModel.action,
|
||||||
@objc public var enabledColor: UIColor = .mvmBlack {
|
sourceModel: self.viewModel,
|
||||||
didSet { changeCaretColor() }
|
additionalData: self.additionalData,
|
||||||
}
|
delegateObject: self.delegateObject)
|
||||||
|
|
||||||
@objc public var disabledColor: UIColor = .mvmCoolGray3 {
|
|
||||||
didSet { changeCaretColor() }
|
|
||||||
}
|
|
||||||
|
|
||||||
private var caretSpacingConstraint: NSLayoutConstraint?
|
|
||||||
|
|
||||||
//------------------------------------------------------
|
|
||||||
// MARK: - Inits
|
|
||||||
//------------------------------------------------------
|
|
||||||
|
|
||||||
// Default values for view.
|
|
||||||
public required init(model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
|
|
||||||
super.init(frame: .zero)
|
|
||||||
backgroundColor = .clear
|
|
||||||
translatesAutoresizingMaskIntoConstraints = false
|
|
||||||
setTitleColor(enabledColor, for: .normal)
|
|
||||||
setTitleColor(disabledColor, for: .disabled)
|
|
||||||
}
|
|
||||||
|
|
||||||
public override init(frame: CGRect) {
|
|
||||||
super.init(frame: frame)
|
|
||||||
}
|
|
||||||
|
|
||||||
public required init?(coder: NSCoder) {
|
|
||||||
super.init(coder: coder)
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------
|
|
||||||
// MARK: - Lifecycle
|
|
||||||
//------------------------------------------------------
|
|
||||||
|
|
||||||
override public var isEnabled: Bool {
|
|
||||||
didSet { changeCaretColor() }
|
|
||||||
}
|
|
||||||
|
|
||||||
public override func updateView(_ size: CGFloat) {
|
|
||||||
titleLabel?.font = MFStyler.fontBoldBodySmall()
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------
|
|
||||||
// MARK: - Methods
|
|
||||||
//------------------------------------------------------
|
|
||||||
|
|
||||||
private func changeCaretColor() {
|
|
||||||
|
|
||||||
setTitleColor(enabledColor, for: .normal)
|
|
||||||
setTitleColor(disabledColor, for: .disabled)
|
|
||||||
|
|
||||||
if let rightCaretView = rightView as? CaretView {
|
|
||||||
rightCaretView.enabledColor = enabledColor
|
|
||||||
rightCaretView.disabledColor = disabledColor
|
|
||||||
rightCaretView.isEnabled = isEnabled
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func createCaretView() -> CaretView {
|
//--------------------------------------------------
|
||||||
let caret = CaretView()
|
// MARK: - Overrides
|
||||||
caret.lineWidth = 1.5
|
//--------------------------------------------------
|
||||||
return caret
|
open override func updateAccessibility() {
|
||||||
}
|
super.updateAccessibility()
|
||||||
|
|
||||||
private func addCaretImageView() {
|
guard let viewModel = viewModel else { return }
|
||||||
|
if let accessibilityText = viewModel.accessibilityText {
|
||||||
rightView?.removeFromSuperview()
|
self.accessibilityLabel = accessibilityText
|
||||||
|
|
||||||
let width = CGFloat(rightViewWidth?.floatValue ?? CARET_VIEW_WIDTH)
|
|
||||||
let height = CGFloat(rightViewHeight?.floatValue ?? CARET_VIEW_HEIGHT)
|
|
||||||
|
|
||||||
contentEdgeInsets.right = 4 + width
|
|
||||||
|
|
||||||
let caretView: UIView = rightView ?? createCaretView()
|
|
||||||
rightView = caretView
|
|
||||||
rightView?.translatesAutoresizingMaskIntoConstraints = false
|
|
||||||
addSubview(caretView)
|
|
||||||
|
|
||||||
caretView.widthAnchor.constraint(equalToConstant: width).isActive = true
|
|
||||||
caretView.heightAnchor.constraint(equalToConstant: height).isActive = true
|
|
||||||
|
|
||||||
let caretLabelSpacing = NSLayoutConstraint(item: caretView, attribute: .left, relatedBy: .equal, toItem: titleLabel, attribute: .right, multiplier: 1.0, constant: 7)
|
|
||||||
caretLabelSpacing.isActive = true
|
|
||||||
caretSpacingConstraint = caretLabelSpacing
|
|
||||||
|
|
||||||
caretView.centerYAnchor.constraint(equalTo: centerYAnchor).isActive = true
|
|
||||||
trailingAnchor.constraint(greaterThanOrEqualTo: caretView.trailingAnchor).isActive = true
|
|
||||||
caretView.topAnchor.constraint(greaterThanOrEqualTo: topAnchor).isActive = true
|
|
||||||
bottomAnchor.constraint(greaterThanOrEqualTo: caretView.bottomAnchor).isActive = true
|
|
||||||
contentHorizontalAlignment = .left
|
|
||||||
|
|
||||||
// Set correct color after layout
|
|
||||||
changeCaretColor()
|
|
||||||
}
|
|
||||||
|
|
||||||
public func updateCaretSpacing(_ spacing: CGFloat) {
|
|
||||||
caretSpacingConstraint?.constant = spacing
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------
|
|
||||||
// MARK: - Atomization
|
|
||||||
//------------------------------------------------------
|
|
||||||
|
|
||||||
public override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
|
|
||||||
addCaretImageView()
|
|
||||||
guard let model = model as? CaretLinkModel else { return }
|
|
||||||
|
|
||||||
if let color = model.backgroundColor {
|
|
||||||
backgroundColor = color.uiColor
|
|
||||||
}
|
}
|
||||||
|
|
||||||
enabledColor = (model.inverted ? model.enabledColor_inverted : model.enabledColor).uiColor
|
if let accessibilityIdentifier = viewModel.accessibilityIdentifier {
|
||||||
disabledColor = (model.inverted ? model.disabledColor_inverted : model.disabledColor).uiColor
|
self.accessibilityIdentifier = accessibilityIdentifier
|
||||||
|
}
|
||||||
isEnabled = model.enabled
|
|
||||||
set(with: model.action, delegateObject: delegateObject, additionalData: additionalData)
|
|
||||||
setTitle(model.title, for: .normal)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
open override func reset() {
|
//--------------------------------------------------
|
||||||
super.reset()
|
// MARK: - MVMCoreViewProtocol
|
||||||
rightView?.removeFromSuperview()
|
//--------------------------------------------------
|
||||||
}
|
public func updateView(_ size: CGFloat) {}
|
||||||
|
|
||||||
|
open class func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { 10.5 }
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - MVMCoreUIViewConstrainingProtocol
|
||||||
|
extension CaretLink: MVMCoreUIViewConstrainingProtocol {
|
||||||
public func needsToBeConstrained() -> Bool { true }
|
public func needsToBeConstrained() -> Bool { true }
|
||||||
|
|
||||||
open func horizontalAlignment() -> UIStackView.Alignment { .leading }
|
open func horizontalAlignment() -> UIStackView.Alignment { .leading }
|
||||||
|
|
||||||
open override class func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { 10.5 }
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
import MVMCore
|
import MVMCore
|
||||||
|
import VDS
|
||||||
|
|
||||||
public class CaretLinkModel: ButtonModelProtocol, MoleculeModelProtocol, EnableableModelProtocol {
|
public class CaretLinkModel: ButtonModelProtocol, MoleculeModelProtocol, EnableableModelProtocol {
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -20,13 +20,11 @@ public class CaretLinkModel: ButtonModelProtocol, MoleculeModelProtocol, Enablea
|
|||||||
public var backgroundColor: Color?
|
public var backgroundColor: Color?
|
||||||
public var accessibilityIdentifier: String?
|
public var accessibilityIdentifier: String?
|
||||||
public var title: String
|
public var title: String
|
||||||
|
public var accessibilityText: String?
|
||||||
public var action: ActionModelProtocol
|
public var action: ActionModelProtocol
|
||||||
public var enabledColor: Color = Color(uiColor: .mvmBlack)
|
|
||||||
public var disabledColor: Color = Color(uiColor: .mvmCoolGray6)
|
|
||||||
public var enabledColor_inverted: Color = Color(uiColor: .mvmWhite)
|
|
||||||
public var disabledColor_inverted: Color = Color(uiColor: .mvmCoolGray10)
|
|
||||||
public var enabled = true
|
public var enabled = true
|
||||||
public var inverted = false
|
public var inverted = false
|
||||||
|
public var iconPosition: TextLinkCaret.IconPosition = .right
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Initializer
|
// MARK: - Initializer
|
||||||
@ -45,12 +43,10 @@ public class CaretLinkModel: ButtonModelProtocol, MoleculeModelProtocol, Enablea
|
|||||||
case id
|
case id
|
||||||
case backgroundColor
|
case backgroundColor
|
||||||
case accessibilityIdentifier
|
case accessibilityIdentifier
|
||||||
|
case accessibilityText
|
||||||
|
case iconPosition
|
||||||
case title
|
case title
|
||||||
case action
|
case action
|
||||||
case enabledColor_inverted
|
|
||||||
case disabledColor_inverted
|
|
||||||
case enabledColor
|
|
||||||
case disabledColor
|
|
||||||
case enabled
|
case enabled
|
||||||
case inverted
|
case inverted
|
||||||
case moleculeName
|
case moleculeName
|
||||||
@ -66,22 +62,11 @@ public class CaretLinkModel: ButtonModelProtocol, MoleculeModelProtocol, Enablea
|
|||||||
id = try typeContainer.decodeIfPresent(String.self, forKey: .id) ?? UUID().uuidString
|
id = try typeContainer.decodeIfPresent(String.self, forKey: .id) ?? UUID().uuidString
|
||||||
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
|
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
|
||||||
accessibilityIdentifier = try typeContainer.decodeIfPresent(String.self, forKey: .accessibilityIdentifier)
|
accessibilityIdentifier = try typeContainer.decodeIfPresent(String.self, forKey: .accessibilityIdentifier)
|
||||||
|
accessibilityText = try typeContainer.decodeIfPresent(String.self, forKey: .accessibilityText)
|
||||||
title = try typeContainer.decode(String.self, forKey: .title)
|
title = try typeContainer.decode(String.self, forKey: .title)
|
||||||
|
|
||||||
if let enabledColor_inverted = try typeContainer.decodeIfPresent(Color.self, forKey: .enabledColor_inverted) {
|
if let iconPosition = try typeContainer.decodeIfPresent(TextLinkCaret.IconPosition.self, forKey: .iconPosition) {
|
||||||
self.enabledColor_inverted = enabledColor_inverted
|
self.iconPosition = iconPosition
|
||||||
}
|
|
||||||
|
|
||||||
if let disabledColor_inverted = try typeContainer.decodeIfPresent(Color.self, forKey: .disabledColor_inverted) {
|
|
||||||
self.disabledColor_inverted = disabledColor_inverted
|
|
||||||
}
|
|
||||||
|
|
||||||
if let color = try typeContainer.decodeIfPresent(Color.self, forKey: .enabledColor) {
|
|
||||||
enabledColor = color
|
|
||||||
}
|
|
||||||
|
|
||||||
if let color = try typeContainer.decodeIfPresent(Color.self, forKey: .disabledColor) {
|
|
||||||
disabledColor = color
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if let enabled = try typeContainer.decodeIfPresent(Bool.self, forKey: .enabled) {
|
if let enabled = try typeContainer.decodeIfPresent(Bool.self, forKey: .enabled) {
|
||||||
@ -99,15 +84,17 @@ public class CaretLinkModel: ButtonModelProtocol, MoleculeModelProtocol, Enablea
|
|||||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||||
try container.encode(id, forKey: .id)
|
try container.encode(id, forKey: .id)
|
||||||
try container.encode(moleculeName, forKey: .moleculeName)
|
try container.encode(moleculeName, forKey: .moleculeName)
|
||||||
|
try container.encode(iconPosition, forKey: .iconPosition)
|
||||||
try container.encode(title, forKey: .title)
|
try container.encode(title, forKey: .title)
|
||||||
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
||||||
try container.encodeIfPresent(accessibilityIdentifier, forKey: .accessibilityIdentifier)
|
try container.encodeIfPresent(accessibilityIdentifier, forKey: .accessibilityIdentifier)
|
||||||
|
try container.encodeIfPresent(accessibilityText, forKey: .accessibilityText)
|
||||||
try container.encodeModel(action, forKey: .action)
|
try container.encodeModel(action, forKey: .action)
|
||||||
try container.encode(enabledColor, forKey: .enabledColor)
|
|
||||||
try container.encodeIfPresent(disabledColor, forKey: .disabledColor)
|
|
||||||
try container.encode(enabled, forKey: .enabled)
|
try container.encode(enabled, forKey: .enabled)
|
||||||
try container.encode(enabledColor_inverted, forKey: .enabledColor_inverted)
|
|
||||||
try container.encode(disabledColor_inverted, forKey: .disabledColor_inverted)
|
|
||||||
try container.encode(inverted, forKey: .inverted)
|
try container.encode(inverted, forKey: .inverted)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension CaretLinkModel {
|
||||||
|
public var surface: Surface { inverted ? .dark : .light }
|
||||||
|
}
|
||||||
|
|||||||
@ -60,7 +60,6 @@ open class Link: VDS.TextLink, VDSMoleculeViewProtocol {
|
|||||||
|
|
||||||
open func updateView(_ size: CGFloat) { }
|
open func updateView(_ size: CGFloat) { }
|
||||||
|
|
||||||
open func setupView() {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - MVMCoreUIViewConstrainingProtocol
|
// MARK: - MVMCoreUIViewConstrainingProtocol
|
||||||
|
|||||||
@ -92,6 +92,7 @@ open class LinkModel: ButtonModelProtocol, MoleculeModelProtocol, EnableableMode
|
|||||||
try container.encode(moleculeName, forKey: .moleculeName)
|
try container.encode(moleculeName, forKey: .moleculeName)
|
||||||
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
||||||
try container.encodeIfPresent(accessibilityIdentifier, forKey: .accessibilityIdentifier)
|
try container.encodeIfPresent(accessibilityIdentifier, forKey: .accessibilityIdentifier)
|
||||||
|
try container.encodeIfPresent(accessibilityText, forKey: .accessibilityText)
|
||||||
try container.encodeModel(action, forKey: .action)
|
try container.encodeModel(action, forKey: .action)
|
||||||
try container.encode(inverted, forKey: .inverted)
|
try container.encode(inverted, forKey: .inverted)
|
||||||
try container.encode(enabled, forKey: .enabled)
|
try container.encode(enabled, forKey: .enabled)
|
||||||
|
|||||||
@ -19,10 +19,11 @@ extension VDS.Badge.FillColor: Codable {}
|
|||||||
extension VDS.ButtonGroup.Alignment: Codable {}
|
extension VDS.ButtonGroup.Alignment: Codable {}
|
||||||
extension VDS.Icon.Name: Codable {}
|
extension VDS.Icon.Name: Codable {}
|
||||||
extension VDS.Icon.Size: Codable {}
|
extension VDS.Icon.Size: Codable {}
|
||||||
|
extension VDS.TextLink.Size: Codable {}
|
||||||
|
extension VDS.TextLinkCaret.IconPosition: Codable {}
|
||||||
extension VDS.TileContainer.BackgroundColor: Codable {}
|
extension VDS.TileContainer.BackgroundColor: Codable {}
|
||||||
extension VDS.TileContainer.Padding: Codable {}
|
extension VDS.TileContainer.Padding: Codable {}
|
||||||
extension VDS.TileContainer.AspectRatio: Codable {}
|
extension VDS.TileContainer.AspectRatio: Codable {}
|
||||||
extension VDS.TextLink.Size: Codable {}
|
|
||||||
extension VDS.Line.Style: Codable {}
|
extension VDS.Line.Style: Codable {}
|
||||||
extension VDS.Line.Orientation: Codable {}
|
extension VDS.Line.Orientation: Codable {}
|
||||||
extension VDS.Use: Codable {}
|
extension VDS.Use: Codable {}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user