Revert "Make Link subclass from View instead of MFCustomButton"
This reverts commit 439261e4c4.
This commit is contained in:
parent
439261e4c4
commit
f731b56f2e
@ -8,7 +8,7 @@
|
||||
|
||||
import UIKit
|
||||
|
||||
@objcMembers open class Link: View {
|
||||
@objcMembers open class Link: MFCustomButton {
|
||||
|
||||
private lazy var sizeObject: MFSizeObject? = {
|
||||
return MFSizeObject(standardSize: 30, standardiPadPortraitSize: 36, iPadProLandscapeSize: 42)
|
||||
@ -16,7 +16,6 @@ import UIKit
|
||||
|
||||
private var additionalData: [AnyHashable: Any]?
|
||||
private var delegateObject: MVMCoreUIDelegateObject?
|
||||
public let linkButton = MFCustomButton()
|
||||
|
||||
public override init(frame: CGRect) {
|
||||
super.init(frame: frame)
|
||||
@ -29,12 +28,12 @@ import UIKit
|
||||
}
|
||||
|
||||
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()
|
||||
|
||||
//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)
|
||||
}
|
||||
|
||||
@ -50,97 +49,86 @@ import UIKit
|
||||
}
|
||||
|
||||
override open func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
open override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
|
||||
if linkButton.isEnabled {
|
||||
MVMCoreActionHandler.shared()?.handleAction(with: linkButton.actionMap, additionalData: additionalData, delegateObject: delegateObject)
|
||||
}
|
||||
MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject)
|
||||
}
|
||||
}
|
||||
|
||||
//MARK: MVMCoreViewProtocol
|
||||
extension Link {
|
||||
extension Link: MVMCoreViewProtocol {
|
||||
|
||||
public override func updateView(_ size: CGFloat) {
|
||||
public func updateView(_ size: CGFloat) {
|
||||
MVMCoreDispatchUtility.performBlock(onMainThread: { [weak self] in
|
||||
guard let self = self else { return }
|
||||
|
||||
var width = size
|
||||
if MVMCoreGetterUtility.fequal(a: Float(CGFloat.leastNormalMagnitude), b: Float(size)) {
|
||||
width = MVMCoreUISplitViewController.getApplicationViewWidth()
|
||||
}
|
||||
self.linkButton.titleLabel?.font = MFStyler.fontB2(forWidth: width)
|
||||
guard let heightConstraint = self.linkButton.heightConstraint else { return }
|
||||
self.titleLabel?.font = MFStyler.fontB2(forWidth: width)
|
||||
guard let heightConstraint = self.heightConstraint else { return }
|
||||
if !MVMCoreGetterUtility.fequal(a: 0, b: Float(heightConstraint.constant)) {
|
||||
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() {
|
||||
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)
|
||||
])
|
||||
public func setupView() {
|
||||
translatesAutoresizingMaskIntoConstraints = false
|
||||
backgroundColor = .clear
|
||||
contentMode = .redraw
|
||||
linkButton.setTitleColor(.mfTextButton(), for: .normal)
|
||||
linkButton.setTitleColor(.mfCharcoal(), for: .highlighted)
|
||||
linkButton.titleLabel?.textAlignment = .left
|
||||
linkButton.contentHorizontalAlignment = .left
|
||||
setTitleColor(.mfTextButton(), for: .normal)
|
||||
setTitleColor(.mfCharcoal(), for: .highlighted)
|
||||
// left alignment by default
|
||||
titleLabel?.textAlignment = .left
|
||||
contentHorizontalAlignment = .left
|
||||
|
||||
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)
|
||||
addConstraint(heightConstraint)
|
||||
heightConstraint.isActive = true
|
||||
self.linkButton.heightConstraint = heightConstraint
|
||||
self.heightConstraint = heightConstraint
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//MARK: MVMCoreUIMoleculeViewProtocol
|
||||
extension Link {
|
||||
extension Link: MVMCoreUIMoleculeViewProtocol {
|
||||
|
||||
public override func reset() {
|
||||
self.linkButton.setTitleColor(.mfTextButton(), for: .normal)
|
||||
self.linkButton.isEnabled = true
|
||||
public func reset() {
|
||||
self.setTitleColor(.mfTextButton(), for: .normal)
|
||||
}
|
||||
|
||||
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 {
|
||||
linkButton.actionMap = unwrappedJson
|
||||
actionMap = unwrappedJson
|
||||
self.additionalData = additionalData
|
||||
self.delegateObject = delegateObject
|
||||
linkButton.buttonDelegate = delegateObject?.buttonDelegate
|
||||
buttonDelegate = delegateObject?.buttonDelegate
|
||||
|
||||
let color = unwrappedJson.stringForkey(KeyTextColor)
|
||||
linkButton.setTitleColor(.mfGet(forHex: color), for: .normal)
|
||||
setTitleColor(.mfGet(forHex: color), for: .normal)
|
||||
|
||||
linkButton.titleLabel?.numberOfLines = 0
|
||||
linkButton.titleLabel?.lineBreakMode = .byWordWrapping;
|
||||
linkButton.setTitle(linkButton.actionMap?.stringForkey(KeyTitle), for: .normal)
|
||||
titleLabel?.numberOfLines = 0
|
||||
titleLabel?.lineBreakMode = .byWordWrapping;
|
||||
setTitle(actionMap?.stringForkey(KeyTitle), for: .normal)
|
||||
|
||||
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 {
|
||||
self.linkButton.heightConstraint?.constant = 0
|
||||
self.heightConstraint?.constant = 0
|
||||
} else {
|
||||
guard let standardSize = sizeObject?.standardSize else { return }
|
||||
linkButton.heightConstraint?.constant = standardSize
|
||||
heightConstraint?.constant = standardSize
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user