Revert "Make Link subclass from View instead of MFCustomButton"

This reverts commit 439261e4c4.
This commit is contained in:
Robinson, Blake 2019-12-17 10:23:56 -05:00
parent 439261e4c4
commit f731b56f2e

View File

@ -8,7 +8,7 @@
import UIKit import UIKit
@objcMembers open class Link: View { @objcMembers open class Link: MFCustomButton {
private lazy var sizeObject: MFSizeObject? = { private lazy var sizeObject: MFSizeObject? = {
return MFSizeObject(standardSize: 30, standardiPadPortraitSize: 36, iPadProLandscapeSize: 42) return MFSizeObject(standardSize: 30, standardiPadPortraitSize: 36, iPadProLandscapeSize: 42)
@ -16,7 +16,6 @@ import UIKit
private var additionalData: [AnyHashable: Any]? private var additionalData: [AnyHashable: Any]?
private var delegateObject: MVMCoreUIDelegateObject? private var delegateObject: MVMCoreUIDelegateObject?
public let linkButton = MFCustomButton()
public override init(frame: CGRect) { public override init(frame: CGRect) {
super.init(frame: frame) super.init(frame: frame)
@ -29,12 +28,12 @@ import UIKit
} }
open override func draw(_ rect: CGRect) { open override func draw(_ rect: CGRect) {
guard let textRect = self.linkButton.titleLabel?.frame else { return } guard let textRect = self.titleLabel?.frame else { return }
let contextRef = UIGraphicsGetCurrentContext() let contextRef = UIGraphicsGetCurrentContext()
//set to the same color as the text //set to the same color as the text
if let color = self.linkButton.titleLabel?.textColor?.cgColor { if let color = self.titleLabel?.textColor?.cgColor {
contextRef?.setStrokeColor(color) contextRef?.setStrokeColor(color)
} }
@ -50,97 +49,86 @@ import UIKit
} }
override open func point(inside point: CGPoint, with event: UIEvent?) -> Bool { override open func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
let faultTolerance: CGFloat = 20.0 let faultTolerance: CGFloat = 20.0
let area = linkButton.bounds.insetBy(dx: -faultTolerance, dy: -faultTolerance) let area = bounds.insetBy(dx: -faultTolerance, dy: -faultTolerance)
return area.contains(point) return area.contains(point)
} }
open override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) { open override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
if linkButton.isEnabled { MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject)
MVMCoreActionHandler.shared()?.handleAction(with: linkButton.actionMap, additionalData: additionalData, delegateObject: delegateObject)
}
} }
} }
//MARK: MVMCoreViewProtocol extension Link: MVMCoreViewProtocol {
extension Link {
public override func updateView(_ size: CGFloat) { public func updateView(_ size: CGFloat) {
MVMCoreDispatchUtility.performBlock(onMainThread: { [weak self] in MVMCoreDispatchUtility.performBlock(onMainThread: { [weak self] in
guard let self = self else { return } guard let self = self else { return }
var width = size var width = size
if MVMCoreGetterUtility.fequal(a: Float(CGFloat.leastNormalMagnitude), b: Float(size)) { if MVMCoreGetterUtility.fequal(a: Float(CGFloat.leastNormalMagnitude), b: Float(size)) {
width = MVMCoreUISplitViewController.getApplicationViewWidth() width = MVMCoreUISplitViewController.getApplicationViewWidth()
} }
self.linkButton.titleLabel?.font = MFStyler.fontB2(forWidth: width) self.titleLabel?.font = MFStyler.fontB2(forWidth: width)
guard let heightConstraint = self.linkButton.heightConstraint else { return } guard let heightConstraint = self.heightConstraint else { return }
if !MVMCoreGetterUtility.fequal(a: 0, b: Float(heightConstraint.constant)) { if !MVMCoreGetterUtility.fequal(a: 0, b: Float(heightConstraint.constant)) {
guard let sizeObject = self.sizeObject else { return } guard let sizeObject = self.sizeObject else { return }
self.linkButton.heightConstraint?.constant = sizeObject.getValueBased(onSize: width) self.heightConstraint?.constant = sizeObject.getValueBased(onSize: width)
} }
}) })
} }
public override func setupView() { public func setupView() {
linkButton.isUserInteractionEnabled = false
linkButton.translatesAutoresizingMaskIntoConstraints = false
addSubview(linkButton)
NSLayoutConstraint.activate([
linkButton.leadingAnchor.constraint(equalTo: leadingAnchor),
linkButton.topAnchor.constraint(equalTo: topAnchor),
trailingAnchor.constraint(greaterThanOrEqualTo: linkButton.trailingAnchor),
bottomAnchor.constraint(equalTo: linkButton.bottomAnchor)
])
translatesAutoresizingMaskIntoConstraints = false translatesAutoresizingMaskIntoConstraints = false
backgroundColor = .clear backgroundColor = .clear
contentMode = .redraw contentMode = .redraw
linkButton.setTitleColor(.mfTextButton(), for: .normal) setTitleColor(.mfTextButton(), for: .normal)
linkButton.setTitleColor(.mfCharcoal(), for: .highlighted) setTitleColor(.mfCharcoal(), for: .highlighted)
linkButton.titleLabel?.textAlignment = .left // left alignment by default
linkButton.contentHorizontalAlignment = .left titleLabel?.textAlignment = .left
contentHorizontalAlignment = .left
if let constant = self.sizeObject?.standardSize { if let constant = self.sizeObject?.standardSize {
let heightConstraint = NSLayoutConstraint(item: self as Any, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1.0, constant: constant) let heightConstraint = NSLayoutConstraint(item: self as Any, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1.0, constant: constant)
addConstraint(heightConstraint) addConstraint(heightConstraint)
heightConstraint.isActive = true heightConstraint.isActive = true
self.linkButton.heightConstraint = heightConstraint self.heightConstraint = heightConstraint
} }
} }
} }
//MARK: MVMCoreUIMoleculeViewProtocol extension Link: MVMCoreUIMoleculeViewProtocol {
extension Link {
public override func reset() { public func reset() {
self.linkButton.setTitleColor(.mfTextButton(), for: .normal) self.setTitleColor(.mfTextButton(), for: .normal)
self.linkButton.isEnabled = true
} }
public override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { public func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) {
if let unwrappedJson = json { if let unwrappedJson = json {
linkButton.actionMap = unwrappedJson actionMap = unwrappedJson
self.additionalData = additionalData self.additionalData = additionalData
self.delegateObject = delegateObject self.delegateObject = delegateObject
linkButton.buttonDelegate = delegateObject?.buttonDelegate buttonDelegate = delegateObject?.buttonDelegate
let color = unwrappedJson.stringForkey(KeyTextColor) let color = unwrappedJson.stringForkey(KeyTextColor)
linkButton.setTitleColor(.mfGet(forHex: color), for: .normal) setTitleColor(.mfGet(forHex: color), for: .normal)
linkButton.titleLabel?.numberOfLines = 0 titleLabel?.numberOfLines = 0
linkButton.titleLabel?.lineBreakMode = .byWordWrapping; titleLabel?.lineBreakMode = .byWordWrapping;
linkButton.setTitle(linkButton.actionMap?.stringForkey(KeyTitle), for: .normal) setTitle(actionMap?.stringForkey(KeyTitle), for: .normal)
if let enabled = unwrappedJson[KeyEnabled] as? Bool { if let enabled = unwrappedJson[KeyEnabled] as? Bool {
linkButton.isEnabled = enabled isEnabled = enabled
} }
} }
if let title = self.linkButton.title(for: .normal), if let title = self.title(for: .normal),
title.isEmpty { title.isEmpty {
self.linkButton.heightConstraint?.constant = 0 self.heightConstraint?.constant = 0
} else { } else {
guard let standardSize = sizeObject?.standardSize else { return } guard let standardSize = sizeObject?.standardSize else { return }
linkButton.heightConstraint?.constant = standardSize heightConstraint?.constant = standardSize
} }
} }