Updating Link class. adding identifier to molecule mapping.
This commit is contained in:
parent
9882528b9e
commit
5ce8446be2
@ -14,6 +14,11 @@ import UIKit
|
||||
//--------------------------------------------------
|
||||
|
||||
private var additionalData: [AnyHashable: Any]?
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Delegate
|
||||
//--------------------------------------------------
|
||||
|
||||
private var delegateObject: MVMCoreUIDelegateObject?
|
||||
|
||||
//--------------------------------------------------
|
||||
@ -25,6 +30,10 @@ import UIKit
|
||||
setupView()
|
||||
}
|
||||
|
||||
public convenience init() {
|
||||
self.init(frame: .zero)
|
||||
}
|
||||
|
||||
public required init?(coder: NSCoder) {
|
||||
super.init(coder: coder)
|
||||
setupView()
|
||||
@ -35,69 +44,77 @@ import UIKit
|
||||
//--------------------------------------------------
|
||||
|
||||
open override func draw(_ rect: CGRect) {
|
||||
|
||||
guard let textRect = titleLabel?.frame else { return }
|
||||
|
||||
let contextRef = UIGraphicsGetCurrentContext()
|
||||
let context = UIGraphicsGetCurrentContext()
|
||||
|
||||
//set to the same color as the text
|
||||
// Set to the same color as the text
|
||||
if let color = titleLabel?.textColor?.cgColor {
|
||||
contextRef?.setStrokeColor(color)
|
||||
context?.setStrokeColor(color)
|
||||
}
|
||||
|
||||
//x should be according to the text, not the button
|
||||
// x should be according to the text, not the button
|
||||
let x = textRect.origin.x
|
||||
// line is 1 point below the text
|
||||
|
||||
// Line is 1 point below the text
|
||||
let y = textRect.origin.y + textRect.size.height + 1
|
||||
|
||||
contextRef?.move(to: CGPoint(x: x, y: y))
|
||||
contextRef?.addLine(to: CGPoint(x: x + textRect.size.width, y: y))
|
||||
contextRef?.closePath()
|
||||
contextRef?.drawPath(using: .stroke)
|
||||
context?.move(to: CGPoint(x: x, y: y))
|
||||
context?.addLine(to: CGPoint(x: x + textRect.size.width, y: y))
|
||||
context?.closePath()
|
||||
context?.drawPath(using: .stroke)
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - UITouch
|
||||
//--------------------------------------------------
|
||||
|
||||
override open func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
|
||||
|
||||
let faultTolerance: CGFloat = 20.0
|
||||
let area = bounds.insetBy(dx: -faultTolerance, dy: -faultTolerance)
|
||||
return area.contains(point)
|
||||
}
|
||||
|
||||
open override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
|
||||
MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - AppleGuidelinesProtocol
|
||||
extension Link: AppleGuidelinesProtocol {
|
||||
|
||||
override open func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
|
||||
|
||||
return Self.acceptablyOutsideBounds(point: point, bounds: bounds)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - MVMCoreViewProtocol
|
||||
extension Link: MVMCoreViewProtocol {
|
||||
|
||||
public func updateView(_ size: CGFloat) {
|
||||
MVMCoreDispatchUtility.performBlock(onMainThread: { [weak self] in
|
||||
|
||||
DispatchQueue.main.async { [weak self] in
|
||||
guard let self = self else { return }
|
||||
|
||||
var width = size
|
||||
if MVMCoreGetterUtility.fequal(a: Float(CGFloat.leastNormalMagnitude), b: Float(size)) {
|
||||
width = MVMCoreUIUtility.getWidth()
|
||||
}
|
||||
|
||||
self.titleLabel?.font = MFStyler.fontB2(forWidth: width)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
public func setupView() {
|
||||
|
||||
translatesAutoresizingMaskIntoConstraints = false
|
||||
backgroundColor = .clear
|
||||
contentMode = .redraw
|
||||
setTitleColor(.mfTextButton(), for: .normal)
|
||||
setTitleColor(.mfCharcoal(), for: .highlighted)
|
||||
// left alignment by default
|
||||
titleLabel?.textAlignment = .left
|
||||
contentHorizontalAlignment = .left
|
||||
titleLabel?.numberOfLines = 1
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - MVMCoreUIMoleculeViewProtocol
|
||||
extension Link: MVMCoreUIMoleculeViewProtocol {
|
||||
|
||||
public func reset() {
|
||||
@ -105,17 +122,18 @@ extension Link: MVMCoreUIMoleculeViewProtocol {
|
||||
}
|
||||
|
||||
public func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) {
|
||||
guard let unwrappedJson = json else { return }
|
||||
actionMap = unwrappedJson
|
||||
self.additionalData = additionalData
|
||||
self.delegateObject = delegateObject
|
||||
|
||||
guard let unwrappedJson = json else { return }
|
||||
actionMap = unwrappedJson
|
||||
|
||||
buttonDelegate = delegateObject?.buttonDelegate
|
||||
|
||||
let color = unwrappedJson.stringForkey(KeyTextColor)
|
||||
setTitleColor(.mfGet(forHex: color), for: .normal)
|
||||
|
||||
titleLabel?.numberOfLines = 0
|
||||
titleLabel?.lineBreakMode = .byWordWrapping;
|
||||
|
||||
if let title = unwrappedJson.optionalStringForKey(KeyTitle) {
|
||||
setTitle(title, for: .normal)
|
||||
}
|
||||
@ -130,6 +148,7 @@ extension Link: MVMCoreUIMoleculeViewProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
// MARK:- MVMCoreUIViewConstrainingProtocol
|
||||
extension Link: MVMCoreUIViewConstrainingProtocol {
|
||||
|
||||
public func needsToBeConstrained() -> Bool {
|
||||
|
||||
@ -27,6 +27,7 @@
|
||||
mapping = [@{
|
||||
@"label": Label.class,
|
||||
@"line": Line.class,
|
||||
@"link": Link.class,
|
||||
@"button": PrimaryButton.class,
|
||||
@"textButton": MFTextButton.class,
|
||||
@"header": StandardHeaderView.class,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user