From 16cc667b02bc6218c95e1ef32300f3df5a4efeb4 Mon Sep 17 00:00:00 2001 From: "Robinson, Blake" Date: Mon, 9 Dec 2019 14:15:55 -0500 Subject: [PATCH] Expands tappable area of Link --- MVMCoreUI/Atoms/Buttons/Link.swift | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/MVMCoreUI/Atoms/Buttons/Link.swift b/MVMCoreUI/Atoms/Buttons/Link.swift index ef4a1477..2880fcd3 100644 --- a/MVMCoreUI/Atoms/Buttons/Link.swift +++ b/MVMCoreUI/Atoms/Buttons/Link.swift @@ -14,6 +14,9 @@ import UIKit return MFSizeObject(standardSize: 30, standardiPadPortraitSize: 36, iPadProLandscapeSize: 42) }() + private var additionalData: [AnyHashable: Any]? + private var delegateObject: MVMCoreUIDelegateObject? + public override init(frame: CGRect) { super.init(frame: frame) self.setupView() @@ -50,6 +53,17 @@ import UIKit contextRef?.closePath() contextRef?.drawPath(using: .stroke) } + + 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, with event: UIEvent?) { + MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject) + } } extension Link: MVMCoreViewProtocol { @@ -100,14 +114,18 @@ extension Link: MVMCoreUIMoleculeViewProtocol { public func setWithJSON(_ json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable : Any]?) { if let unwrappedJson = json { + actionMap = unwrappedJson + self.additionalData = additionalData + self.delegateObject = delegateObject + buttonDelegate = delegateObject?.buttonDelegate + let color = unwrappedJson.stringForkey(KeyTextColor) setTitleColor(UIColor.mfGet(forHex: color), for: .normal) - setWithActionMap(json, delegateObject: delegateObject, additionalData: additionalData) + self.titleLabel?.numberOfLines = 0 + self.titleLabel?.lineBreakMode = .byWordWrapping; + self.setTitle(actionMap?.stringForkey(KeyTitle), for: .normal) - //enabling must happen after setWithActionMap is called because - //that method enables buttons when the actionMap does not contain - //disableAction = true if let enabled = unwrappedJson[KeyEnabled] as? Bool { isEnabled = enabled }