corrections made.
This commit is contained in:
parent
dadfc83744
commit
93f90bad47
@ -57,7 +57,6 @@ public typealias ActionBlock = () -> Void
|
|||||||
public struct ActionableClause {
|
public struct ActionableClause {
|
||||||
var location: Int?
|
var location: Int?
|
||||||
var length: Int?
|
var length: Int?
|
||||||
var actionText: String?
|
|
||||||
var actionBlock: ActionBlock?
|
var actionBlock: ActionBlock?
|
||||||
|
|
||||||
var range: NSRange {
|
var range: NSRange {
|
||||||
@ -258,30 +257,19 @@ public typealias ActionBlock = () -> Void
|
|||||||
}
|
}
|
||||||
case "actions":
|
case "actions":
|
||||||
guard let actionLabel = label as? Label,
|
guard let actionLabel = label as? Label,
|
||||||
let text = actionLabel.text,
|
|
||||||
let actions = attribute.optionalArrayForKey("actions")
|
let actions = attribute.optionalArrayForKey("actions")
|
||||||
else { continue }
|
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,
|
||||||
let actionLength = action["length"] as? Int,
|
let actionLength = action["length"] as? Int
|
||||||
let subStringRange = Range(NSRange(location: actionLocation, length: actionLength), in: text)
|
|
||||||
else { continue }
|
else { continue }
|
||||||
|
|
||||||
actionLabel.clauses.append(ActionableClause(location: actionLocation,
|
actionLabel.clauses.append(ActionableClause(location: actionLocation,
|
||||||
length: actionLength,
|
length: actionLength,
|
||||||
actionText: String(text[subStringRange]),
|
actionBlock: actionLabel.createActionBlockFrom(actionMap: json,
|
||||||
actionBlock: { [weak delegate] in
|
additionalData: additionalData,
|
||||||
var willPerform = true
|
delegate: delegate)))
|
||||||
|
|
||||||
if let buttonDelegate = (delegate as? MVMCoreUIDelegateObject)?.buttonDelegate,
|
|
||||||
buttonDelegate.responds(to: #selector(ButtonObjectDelegate.button(_:shouldPerformActionWithMap:additionalData:))) {
|
|
||||||
willPerform = buttonDelegate.button?(actionLabel, shouldPerformActionWithMap: json, additionalData: additionalData) ?? false
|
|
||||||
}
|
|
||||||
|
|
||||||
if willPerform {
|
|
||||||
MVMCoreActionHandler.shared()?.handleAction(with: json, additionalData: additionalData, delegateObject: delegate)
|
|
||||||
} }))
|
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
continue
|
continue
|
||||||
@ -291,6 +279,14 @@ public typealias ActionBlock = () -> Void
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func createActionBlockFrom(actionMap: [AnyHashable: Any]?, additionalData: [AnyHashable: Any]?, delegate: DelegateObject?) -> ActionBlock {
|
||||||
|
return { [weak delegate] in
|
||||||
|
if (delegate as? MVMCoreUIDelegateObject)?.buttonDelegate?.button?(self, shouldPerformActionWithMap: actionMap, additionalData: additionalData) ?? true {
|
||||||
|
MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegate)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//------------------------------------------------------
|
//------------------------------------------------------
|
||||||
// MARK: - Methods
|
// MARK: - Methods
|
||||||
//------------------------------------------------------
|
//------------------------------------------------------
|
||||||
@ -385,9 +381,9 @@ extension Label {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// MARK: - Multi-Action Functionality
|
// MARK: - Multi-Action Functionality
|
||||||
extension Label {
|
extension Label {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Provides an actionable range of text.
|
Provides an actionable range of text.
|
||||||
|
|
||||||
@ -398,13 +394,8 @@ extension Label {
|
|||||||
*/
|
*/
|
||||||
@objc public func addTappableLinkAttribute(range: NSRange, actionBlock: @escaping ActionBlock) {
|
@objc public func addTappableLinkAttribute(range: NSRange, actionBlock: @escaping ActionBlock) {
|
||||||
|
|
||||||
guard let text = self.text,
|
|
||||||
let subStringRange = Range(range, in: text)
|
|
||||||
else { return }
|
|
||||||
|
|
||||||
clauses.append(ActionableClause(location: range.location,
|
clauses.append(ActionableClause(location: range.location,
|
||||||
length: range.length,
|
length: range.length,
|
||||||
actionText: String(text[subStringRange]),
|
|
||||||
actionBlock: actionBlock))
|
actionBlock: actionBlock))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -418,78 +409,13 @@ extension Label {
|
|||||||
- 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]?, additionalData: [AnyHashable: Any]?, delegate: DelegateObject?) {
|
||||||
|
|
||||||
guard let text = self.text,
|
|
||||||
let subStringRange = Range(range, in: text)
|
|
||||||
else { return }
|
|
||||||
|
|
||||||
clauses.append(ActionableClause(location: range.location,
|
clauses.append(ActionableClause(location: range.location,
|
||||||
length: range.length,
|
length: range.length,
|
||||||
actionText: String(text[subStringRange]),
|
actionBlock: createActionBlockFrom(actionMap: actionMap,
|
||||||
actionBlock: { [weak self, weak delegate] in
|
additionalData: additionalData,
|
||||||
var willPerform = true
|
delegate: delegate)))
|
||||||
|
|
||||||
if let wSelf = self, let buttonDelegate = (delegate as? MVMCoreUIDelegateObject)?.buttonDelegate,
|
|
||||||
buttonDelegate.responds(to: #selector(ButtonObjectDelegate.button(_:shouldPerformActionWithMap:additionalData:))) {
|
|
||||||
willPerform = buttonDelegate.button?(wSelf, shouldPerformActionWithMap: actionMap, additionalData: additionalData) ?? false
|
|
||||||
}
|
|
||||||
|
|
||||||
if willPerform {
|
|
||||||
MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegate)
|
|
||||||
} }))
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Provides an actionable range of text.
|
|
||||||
|
|
||||||
Allows actionable range to be established by a particular substring of the containing label 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:
|
|
||||||
- actionText: The actionable text contained witin the label's text.
|
|
||||||
- actionBlock: The code triggered when tapping the range of text.
|
|
||||||
*/
|
|
||||||
@objc public func addTappableLinkAttribute(actionText: String, actionBlock: @escaping ActionBlock) {
|
|
||||||
|
|
||||||
guard let text = self.text else { return }
|
|
||||||
let string = text as NSString
|
|
||||||
let range = string.range(of: actionText)
|
|
||||||
|
|
||||||
clauses.append(ActionableClause(location: range.location,
|
|
||||||
length: range.length,
|
|
||||||
actionText: actionText,
|
|
||||||
actionBlock: actionBlock))
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Provides an actionable range of 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:
|
|
||||||
- actionText: The actionable text contained witin the label's text.
|
|
||||||
- actionMap:
|
|
||||||
- delegate:
|
|
||||||
- additionalData:
|
|
||||||
*/
|
|
||||||
@objc public func addTappableLinkAttribute(actionText: String, actionMap: [AnyHashable: Any]?, delegate: DelegateObject?, additionalData: [AnyHashable: Any]?) {
|
|
||||||
|
|
||||||
guard let text = self.text else { return }
|
|
||||||
let string = text as NSString
|
|
||||||
let range = string.range(of: actionText)
|
|
||||||
|
|
||||||
clauses.append(ActionableClause(location: range.location, length: range.length, actionText: actionText,
|
|
||||||
actionBlock: { [weak self, weak delegate] in
|
|
||||||
var willPerform = true
|
|
||||||
|
|
||||||
if let wSelf = self, let buttonDelegate = (delegate as? MVMCoreUIDelegateObject)?.buttonDelegate,
|
|
||||||
buttonDelegate.responds(to: #selector(ButtonObjectDelegate.button(_:shouldPerformActionWithMap:additionalData:))) {
|
|
||||||
willPerform = buttonDelegate.button?(wSelf, shouldPerformActionWithMap: actionMap, additionalData: additionalData) ?? false
|
|
||||||
}
|
|
||||||
|
|
||||||
if willPerform {
|
|
||||||
MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegate)
|
|
||||||
} }))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc private func textLinkTapped(_ gesture: UITapGestureRecognizer) {
|
@objc private func textLinkTapped(_ gesture: UITapGestureRecognizer) {
|
||||||
|
|||||||
@ -66,7 +66,6 @@ public typealias CoreObjectActionLoadPresentDelegate = MVMCoreActionDelegateProt
|
|||||||
} else {
|
} else {
|
||||||
label?.clauses = [Label.ActionableClause(location: actionRange.location,
|
label?.clauses = [Label.ActionableClause(location: actionRange.location,
|
||||||
length: actionRange.length,
|
length: actionRange.length,
|
||||||
actionText: actionText,
|
|
||||||
actionBlock: newActionBlock)]
|
actionBlock: newActionBlock)]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -166,19 +165,7 @@ public typealias CoreObjectActionLoadPresentDelegate = MVMCoreActionDelegateProt
|
|||||||
super.init(frame: .zero)
|
super.init(frame: .zero)
|
||||||
|
|
||||||
setText(fullText, startTag: startTag, endTag: endTag)
|
setText(fullText, startTag: startTag, endTag: endTag)
|
||||||
|
actionBlock = label?.createActionBlockFrom(actionMap: actionMap, additionalData: additionalData, delegate: delegateObject)
|
||||||
actionBlock = { [weak self, weak delegateObject] in
|
|
||||||
var performAction = true
|
|
||||||
|
|
||||||
if let wSelf = self, let wButtonDelegate = (delegateObject as? MVMCoreUIDelegateObject)?.buttonDelegate,
|
|
||||||
wButtonDelegate.responds(to: #selector(ButtonObjectDelegate.button(_:shouldPerformActionWithMap:additionalData:))) {
|
|
||||||
performAction = wButtonDelegate.button?(wSelf, shouldPerformActionWithMap: actionMap, additionalData: additionalData) ?? false
|
|
||||||
}
|
|
||||||
|
|
||||||
if performAction {
|
|
||||||
MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------
|
//------------------------------------------------------
|
||||||
@ -213,18 +200,7 @@ public typealias CoreObjectActionLoadPresentDelegate = MVMCoreActionDelegateProt
|
|||||||
|
|
||||||
@objc public func setActionMap(_ actionMap: [AnyHashable: Any]?, additionalData: [AnyHashable: Any]?, delegateObject: DelegateObject?) {
|
@objc public func setActionMap(_ actionMap: [AnyHashable: Any]?, additionalData: [AnyHashable: Any]?, delegateObject: DelegateObject?) {
|
||||||
|
|
||||||
actionBlock = { [weak self, weak delegateObject] in
|
actionBlock = label?.createActionBlockFrom(actionMap: actionMap, additionalData: additionalData, delegate: delegateObject)
|
||||||
var performAction = true
|
|
||||||
|
|
||||||
if let wSelf = self, let wButtonDelegate = (delegateObject as? MVMCoreUIDelegateObject)?.buttonDelegate,
|
|
||||||
wButtonDelegate.responds(to: #selector(ButtonObjectDelegate.button(_:shouldPerformActionWithMap:additionalData:))) {
|
|
||||||
performAction = wButtonDelegate.button?(wSelf, shouldPerformActionWithMap: actionMap, additionalData: additionalData) ?? false
|
|
||||||
}
|
|
||||||
|
|
||||||
if performAction {
|
|
||||||
MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------
|
//------------------------------------------------------
|
||||||
@ -409,18 +385,7 @@ public typealias CoreObjectActionLoadPresentDelegate = MVMCoreActionDelegateProt
|
|||||||
actionText = actionMap?.optionalStringForKey(KeyTitle)
|
actionText = actionMap?.optionalStringForKey(KeyTitle)
|
||||||
backText = actionMap?.optionalStringForKey(KeyTitlePostfix)
|
backText = actionMap?.optionalStringForKey(KeyTitlePostfix)
|
||||||
|
|
||||||
actionBlock = { [weak self, weak delegateObject] in
|
actionBlock = label?.createActionBlockFrom(actionMap: actionMap, additionalData: additionalData, delegate: delegateObject)
|
||||||
var performAction = true
|
|
||||||
|
|
||||||
if let wSelf = self, let wButtonDelegate = (delegateObject as? MVMCoreUIDelegateObject)?.buttonDelegate,
|
|
||||||
wButtonDelegate.responds(to: #selector(ButtonObjectDelegate.button(_:shouldPerformActionWithMap:additionalData:))) {
|
|
||||||
performAction = wButtonDelegate.button?(wSelf, shouldPerformActionWithMap: actionMap, additionalData: additionalData) ?? false
|
|
||||||
}
|
|
||||||
|
|
||||||
if performAction {
|
|
||||||
MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
text = getTextFromStringComponents()
|
text = getTextFromStringComponents()
|
||||||
setLabelAttributes()
|
setLabelAttributes()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user