updated link
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
89f65ebe3d
commit
0f85c96201
@ -8,83 +8,53 @@
|
|||||||
|
|
||||||
import UIKit
|
import UIKit
|
||||||
import VDSColorTokens
|
import VDSColorTokens
|
||||||
|
import VDS
|
||||||
|
|
||||||
|
@objcMembers open class Link: VDS.TextLink, VDSMoleculeViewProtocol {
|
||||||
|
|
||||||
@objcMembers open class Link: Button {
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Draw
|
// MARK: - Public Properties
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
open var viewModel: LinkModel!
|
||||||
|
open var delegateObject: MVMCoreUIDelegateObject?
|
||||||
|
open var additionalData: [AnyHashable : Any]?
|
||||||
|
|
||||||
open override func draw(_ rect: CGRect) {
|
//--------------------------------------------------
|
||||||
|
// MARK: - Public Functions
|
||||||
|
//--------------------------------------------------
|
||||||
|
open func viewModelDidUpdate() {
|
||||||
|
isEnabled = viewModel.enabled
|
||||||
|
size = viewModel.size
|
||||||
|
text = viewModel.title
|
||||||
|
|
||||||
guard let textRect = titleLabel?.frame,
|
onClick = { [weak self] control in
|
||||||
let context = UIGraphicsGetCurrentContext()
|
guard let self else { return }
|
||||||
else { return }
|
MVMCoreUIActionHandler.performActionUnstructured(with: self.viewModel.action,
|
||||||
|
sourceModel: self.viewModel,
|
||||||
// Set line to the same color as the text
|
additionalData: self.additionalData,
|
||||||
if let color = titleLabel?.textColor?.cgColor {
|
delegateObject: self.delegateObject)
|
||||||
context.setStrokeColor(color)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// x should be according to the text, not the button
|
|
||||||
let x = textRect.origin.x
|
|
||||||
|
|
||||||
// Line is 0 point below the text
|
|
||||||
let y = textRect.origin.y + textRect.size.height
|
|
||||||
|
|
||||||
context.move(to: CGPoint(x: x, y: y))
|
|
||||||
context.addLine(to: CGPoint(x: x + textRect.size.width, y: y))
|
|
||||||
context.strokePath()
|
|
||||||
}
|
|
||||||
|
|
||||||
open override var intrinsicContentSize: CGSize {
|
|
||||||
guard let size = titleLabel?.intrinsicContentSize else { return super.intrinsicContentSize }
|
|
||||||
return CGSize(width: size.width, height: size.height + 1)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - MoleculeViewProtocol
|
// MARK: - Overrides
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
open override func updateAccessibility() {
|
||||||
|
super.updateAccessibility()
|
||||||
|
|
||||||
public override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
|
if let viewModel, let accessibilityText = viewModel.accessibilityText {
|
||||||
super.set(with: model, delegateObject, additionalData)
|
|
||||||
|
|
||||||
guard let model = model as? LinkModel else { return }
|
|
||||||
|
|
||||||
setTitle(model.title, for: .normal)
|
|
||||||
if let accessibilityText = model.accessibilityText {
|
|
||||||
accessibilityLabel = accessibilityText
|
accessibilityLabel = accessibilityText
|
||||||
}
|
}
|
||||||
setTitleColor((model.inverted ? model.enabledColor_inverted : model.enabledColor).uiColor, for: .normal)
|
|
||||||
setTitleColor((model.inverted ? model.disabledColor_inverted : model.disabledColor).uiColor, for: .disabled)
|
|
||||||
setTitleColor((model.inverted ? model.activeColor_inverted : model.activeColor).uiColor, for: .highlighted)
|
|
||||||
isEnabled = model.enabled
|
|
||||||
titleLabel?.font = model.getFont(model.size)
|
|
||||||
set(with: model.action, delegateObject: delegateObject, additionalData: additionalData)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
open override class func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { 31 }
|
//--------------------------------------------------
|
||||||
}
|
// MARK: - MVMCoreViewProtocol
|
||||||
|
//--------------------------------------------------
|
||||||
|
open class func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { 31 }
|
||||||
|
|
||||||
// MARK: - MVMCoreViewProtocol
|
open func updateView(_ size: CGFloat) { }
|
||||||
extension Link {
|
|
||||||
|
|
||||||
open override func updateView(_ size: CGFloat) {
|
open func setupView() {}
|
||||||
super.updateView(size)
|
|
||||||
}
|
|
||||||
|
|
||||||
open override func setupView() {
|
|
||||||
super.setupView()
|
|
||||||
backgroundColor = .clear
|
|
||||||
contentMode = .redraw
|
|
||||||
setTitleColor(VDSColor.elementsPrimaryOnlight, for: .normal)
|
|
||||||
setTitleColor(VDSColor.interactiveDisabledOnlight, for: .disabled)
|
|
||||||
setTitleColor(VDSColor.interactiveActiveOnlight, for: .highlighted)
|
|
||||||
titleLabel?.numberOfLines = 1
|
|
||||||
titleLabel?.lineBreakMode = .byTruncatingTail
|
|
||||||
titleLabel?.textAlignment = .left
|
|
||||||
contentHorizontalAlignment = .left
|
|
||||||
contentVerticalAlignment = .top
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - MVMCoreUIViewConstrainingProtocol
|
// MARK: - MVMCoreUIViewConstrainingProtocol
|
||||||
|
|||||||
@ -7,7 +7,7 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
import UIKit
|
import UIKit
|
||||||
import VDSColorTokens
|
import VDS
|
||||||
|
|
||||||
open class LinkModel: ButtonModelProtocol, MoleculeModelProtocol, EnableableModelProtocol {
|
open class LinkModel: ButtonModelProtocol, MoleculeModelProtocol, EnableableModelProtocol {
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -23,15 +23,9 @@ open class LinkModel: ButtonModelProtocol, MoleculeModelProtocol, EnableableMode
|
|||||||
public var accessibilityText: String?
|
public var accessibilityText: String?
|
||||||
public var action: ActionModelProtocol
|
public var action: ActionModelProtocol
|
||||||
public var enabled = true
|
public var enabled = true
|
||||||
public var enabledColor = Color(uiColor: VDSColor.elementsPrimaryOnlight)
|
|
||||||
public var enabledColor_inverted = Color(uiColor: VDSColor.elementsPrimaryOndark)
|
|
||||||
public var disabledColor = Color(uiColor: VDSColor.interactiveDisabledOnlight)
|
|
||||||
public var disabledColor_inverted = Color(uiColor: VDSColor.interactiveDisabledOndark)
|
|
||||||
public var activeColor = Color(uiColor: VDSColor.interactiveActiveOnlight)
|
|
||||||
public var activeColor_inverted = Color(uiColor: VDSColor.interactiveActiveOndark)
|
|
||||||
|
|
||||||
public var inverted = false
|
public var inverted = false
|
||||||
public var size:linkFontSize = linkFontSize.small
|
public var size: TextLink.Size = .small
|
||||||
|
|
||||||
public var shouldMaskRecordedView: Bool? = false
|
public var shouldMaskRecordedView: Bool? = false
|
||||||
|
|
||||||
@ -57,35 +51,11 @@ open class LinkModel: ButtonModelProtocol, MoleculeModelProtocol, EnableableMode
|
|||||||
case title
|
case title
|
||||||
case action
|
case action
|
||||||
case enabled
|
case enabled
|
||||||
case enabledColor
|
|
||||||
case enabledColor_inverted
|
|
||||||
case disabledColor
|
|
||||||
case disabledColor_inverted
|
|
||||||
case activeColor
|
|
||||||
case activeColor_inverted
|
|
||||||
case inverted
|
case inverted
|
||||||
case size
|
case size
|
||||||
case shouldMaskRecordedView
|
case shouldMaskRecordedView
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum linkFontSize: String, Codable {
|
|
||||||
case small
|
|
||||||
case large
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------
|
|
||||||
// MARK: - Method
|
|
||||||
//--------------------------------------------------
|
|
||||||
|
|
||||||
func getFont(_ type: linkFontSize) -> UIFont {
|
|
||||||
switch type {
|
|
||||||
case .small:
|
|
||||||
return MFStyler.fontRegularBodySmall()
|
|
||||||
case .large:
|
|
||||||
return MFStyler.fontRegularBodyLarge()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Codec
|
// MARK: - Codec
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -108,30 +78,7 @@ open class LinkModel: ButtonModelProtocol, MoleculeModelProtocol, EnableableMode
|
|||||||
self.inverted = inverted
|
self.inverted = inverted
|
||||||
}
|
}
|
||||||
|
|
||||||
if let enabledColor = try typeContainer.decodeIfPresent(Color.self, forKey: .enabledColor) {
|
if let size = try typeContainer.decodeIfPresent(TextLink.Size.self, forKey: .size) {
|
||||||
self.enabledColor = enabledColor
|
|
||||||
}
|
|
||||||
|
|
||||||
if let enabledColor_inverted = try typeContainer.decodeIfPresent(Color.self, forKey: .enabledColor_inverted) {
|
|
||||||
self.enabledColor_inverted = enabledColor_inverted
|
|
||||||
}
|
|
||||||
|
|
||||||
if let disabledColor = try typeContainer.decodeIfPresent(Color.self, forKey: .disabledColor) {
|
|
||||||
self.disabledColor = disabledColor
|
|
||||||
}
|
|
||||||
|
|
||||||
if let disabledColor_inverted = try typeContainer.decodeIfPresent(Color.self, forKey: .disabledColor_inverted) {
|
|
||||||
self.disabledColor_inverted = disabledColor_inverted
|
|
||||||
}
|
|
||||||
|
|
||||||
if let activeColor = try typeContainer.decodeIfPresent(Color.self, forKey: .activeColor) {
|
|
||||||
self.activeColor = activeColor
|
|
||||||
}
|
|
||||||
|
|
||||||
if let activeColor_inverted = try typeContainer.decodeIfPresent(Color.self, forKey: .activeColor_inverted) {
|
|
||||||
self.activeColor_inverted = activeColor_inverted
|
|
||||||
}
|
|
||||||
if let size = try typeContainer.decodeIfPresent(linkFontSize.self, forKey: .size) {
|
|
||||||
self.size = size
|
self.size = size
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -148,13 +95,11 @@ open class LinkModel: ButtonModelProtocol, MoleculeModelProtocol, EnableableMode
|
|||||||
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)
|
||||||
try container.encode(enabledColor, forKey: .enabledColor)
|
|
||||||
try container.encode(enabledColor_inverted, forKey: .enabledColor_inverted)
|
|
||||||
try container.encode(disabledColor, forKey: .disabledColor)
|
|
||||||
try container.encode(disabledColor_inverted, forKey: .disabledColor_inverted)
|
|
||||||
try container.encode(activeColor, forKey: .activeColor)
|
|
||||||
try container.encode(activeColor_inverted, forKey: .activeColor_inverted)
|
|
||||||
try container.encodeIfPresent(size, forKey: .size)
|
try container.encodeIfPresent(size, forKey: .size)
|
||||||
try container.encode(shouldMaskRecordedView, forKey: .shouldMaskRecordedView)
|
try container.encode(shouldMaskRecordedView, forKey: .shouldMaskRecordedView)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension LinkModel {
|
||||||
|
public var surface: Surface { inverted ? .dark : .light }
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user