requested changes.

This commit is contained in:
Christiano, Kevin 2019-05-07 09:36:10 -04:00
parent d83cc8f8ae
commit dadfc83744

View File

@ -166,9 +166,9 @@ public typealias ActionBlock = () -> Void
- Parameters: - Parameters:
- label: The label to be set. - label: The label to be set.
- html: The url link to be applied as an attributed link. - html: any html string.
*/ */
@objc public static func setLabel(_ label: UILabel?, with html: String?) { @objc public static func setLabel(_ label: UILabel?, withHTML html: String?) {
guard let data = html?.data(using: .utf8) else { return } guard let data = html?.data(using: .utf8) else { return }
@ -195,11 +195,11 @@ public typealias ActionBlock = () -> Void
*/ */
@objc public static func setUILabel(_ label: UILabel?, withJSON json: [AnyHashable: Any]?, delegate: DelegateObject?, additionalData: [AnyHashable: Any]?) { @objc public static func setUILabel(_ label: UILabel?, withJSON json: [AnyHashable: Any]?, delegate: DelegateObject?, additionalData: [AnyHashable: Any]?) {
guard let label = label as? Label else { return } guard let label = label else { return }
label.text = json?.optionalStringForKey(KeyText) label.text = json?.optionalStringForKey(KeyText)
setLabel(label, with: json?.optionalStringForKey("html")) setLabel(label, withHTML: json?.optionalStringForKey("html"))
if let textColorHex = json?.optionalStringForKey(KeyTextColor), !textColorHex.isEmpty { if let textColorHex = json?.optionalStringForKey(KeyTextColor), !textColorHex.isEmpty {
label.textColor = UIColor.mfGet(forHex: textColorHex) label.textColor = UIColor.mfGet(forHex: textColorHex)
@ -257,8 +257,10 @@ public typealias ActionBlock = () -> Void
attributedString.addAttribute(.font, value: font, range: range) attributedString.addAttribute(.font, value: font, range: range)
} }
case "actions": case "actions":
let actions = attribute.arrayForKey("actions") guard let actionLabel = label as? Label,
guard let text = json?.optionalStringForKey(KeyText) else { continue } let text = actionLabel.text,
let actions = attribute.optionalArrayForKey("actions")
else { continue }
for case let action as [String: Any] in actions { for case let action as [String: Any] in actions {
guard let actionLocation = action["location"] as? Int, guard let actionLocation = action["location"] as? Int,
@ -266,20 +268,20 @@ public typealias ActionBlock = () -> Void
let subStringRange = Range(NSRange(location: actionLocation, length: actionLength), in: text) let subStringRange = Range(NSRange(location: actionLocation, length: actionLength), in: text)
else { continue } else { continue }
label.clauses.append(ActionableClause(location: actionLocation, actionLabel.clauses.append(ActionableClause(location: actionLocation,
length: actionLength, length: actionLength,
actionText: String(text[subStringRange]), actionText: String(text[subStringRange]),
actionBlock: { [weak delegate] in actionBlock: { [weak delegate] in
var willPerform = true var willPerform = true
if let buttonDelegate = (delegate as? MVMCoreUIDelegateObject)?.buttonDelegate, if let buttonDelegate = (delegate as? MVMCoreUIDelegateObject)?.buttonDelegate,
buttonDelegate.responds(to: #selector(ButtonObjectDelegate.button(_:shouldPerformActionWithMap:additionalData:))) { buttonDelegate.responds(to: #selector(ButtonObjectDelegate.button(_:shouldPerformActionWithMap:additionalData:))) {
willPerform = buttonDelegate.button?(label, shouldPerformActionWithMap: json, additionalData: additionalData) ?? false willPerform = buttonDelegate.button?(actionLabel, shouldPerformActionWithMap: json, additionalData: additionalData) ?? false
} }
if willPerform { if willPerform {
MVMCoreActionHandler.shared()?.handleAction(with: json, additionalData: additionalData, delegateObject: delegate) MVMCoreActionHandler.shared()?.handleAction(with: json, additionalData: additionalData, delegateObject: delegate)
} })) } }))
} }
default: default:
continue continue
@ -391,8 +393,8 @@ extension Label {
- Attention: This method expects text to be set first. Otherwise, it will do nothing. - Attention: This method expects text to be set first. Otherwise, it will do nothing.
- Parameters: - Parameters:
- range: The range of text to be tapped. - range: The range of text to be tapped.
- actionBlock: The code triggered when tapping the range of text. - actionBlock: The code triggered when tapping the range of text.
*/ */
@objc public func addTappableLinkAttribute(range: NSRange, actionBlock: @escaping ActionBlock) { @objc public func addTappableLinkAttribute(range: NSRange, actionBlock: @escaping ActionBlock) {
@ -411,10 +413,10 @@ extension Label {
- Attention: This method expects text to be set first. Otherwise, it will do nothing. - Attention: This method expects text to be set first. Otherwise, it will do nothing.
- Parameters: - Parameters:
- range: The range of text to be tapped. - range: The range of text to be tapped.
- actionMap: - actionMap:
- delegate: - delegate:
- additionalData: - additionalData:
*/ */
@objc public func addTappableLinkAttribute(range: NSRange, actionMap: [AnyHashable: Any]?, delegate: DelegateObject?, additionalData: [AnyHashable: Any]?) { @objc public func addTappableLinkAttribute(range: NSRange, actionMap: [AnyHashable: Any]?, delegate: DelegateObject?, additionalData: [AnyHashable: Any]?) {
@ -445,8 +447,8 @@ extension Label {
- Attention: This method expects text to be set first. Otherwise, it will do nothing. Do not use if actionText is not unique in the Label's text. - Attention: This method expects text to be set first. Otherwise, it will do nothing. Do not use if actionText is not unique in the Label's text.
- Parameters: - Parameters:
- actionText: The actionable text contained witin the label's text. - actionText: The actionable text contained witin the label's text.
- actionBlock: The code triggered when tapping the range of text. - actionBlock: The code triggered when tapping the range of text.
*/ */
@objc public func addTappableLinkAttribute(actionText: String, actionBlock: @escaping ActionBlock) { @objc public func addTappableLinkAttribute(actionText: String, actionBlock: @escaping ActionBlock) {
@ -465,10 +467,10 @@ extension Label {
- Attention: This method expects text to be set first. Otherwise, it will do nothing. Do not use if actionText is not unique in the Label's text. - Attention: This method expects text to be set first. Otherwise, it will do nothing. Do not use if actionText is not unique in the Label's text.
- Parameters: - Parameters:
- actionText: The actionable text contained witin the label's text. - actionText: The actionable text contained witin the label's text.
- actionMap: - actionMap:
- delegate: - delegate:
- additionalData: - additionalData:
*/ */
@objc public func addTappableLinkAttribute(actionText: String, actionMap: [AnyHashable: Any]?, delegate: DelegateObject?, additionalData: [AnyHashable: Any]?) { @objc public func addTappableLinkAttribute(actionText: String, actionMap: [AnyHashable: Any]?, delegate: DelegateObject?, additionalData: [AnyHashable: Any]?) {