latest. not perfect.
This commit is contained in:
parent
0d6b904a7f
commit
efbb68b4cd
@ -42,6 +42,7 @@ public typealias ActionBlock = () -> ()
|
|||||||
// MARK: - Multi-Action Text
|
// MARK: - Multi-Action Text
|
||||||
//------------------------------------------------------
|
//------------------------------------------------------
|
||||||
|
|
||||||
|
/// Data store of the tappable ranges of the text.
|
||||||
public var clauses: [ActionableClause] = [] {
|
public var clauses: [ActionableClause] = [] {
|
||||||
didSet {
|
didSet {
|
||||||
isUserInteractionEnabled = !clauses.isEmpty
|
isUserInteractionEnabled = !clauses.isEmpty
|
||||||
@ -114,6 +115,29 @@ public typealias ActionBlock = () -> ()
|
|||||||
standardFontSize = size
|
standardFontSize = size
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Convenience to init Label as a TextButton. All text will behave as a link.
|
||||||
|
@objc convenience public init(text: String, actionBlock: @escaping ActionBlock) {
|
||||||
|
self.init()
|
||||||
|
self.text = text
|
||||||
|
setTextLinkState(range: getRange, actionBlock: actionBlock)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Convenience to init Label where the provided text will be marked as tappable by the given range.
|
||||||
|
@objc convenience public init(text: String, range: NSRange, actionBlock: @escaping ActionBlock) {
|
||||||
|
self.init()
|
||||||
|
self.text = text
|
||||||
|
setTextLinkState(range: range, actionBlock: actionBlock)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Convenience to init Label with the link comprised of range, actionMap and delegateObject
|
||||||
|
@objc convenience public init(text: String, range: NSRange, actionMap: [AnyHashable: Any]?, additionalData: [AnyHashable: Any]?, delegateObject: DelegateObject?) {
|
||||||
|
self.init()
|
||||||
|
self.text = text
|
||||||
|
if let actionBlock = Label.createActionBlockFor(label: self, actionMap: actionMap, additionalData: additionalData, delegateObject: delegateObject) {
|
||||||
|
setTextLinkState(range: range, actionBlock: actionBlock)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//------------------------------------------------------
|
//------------------------------------------------------
|
||||||
// MARK: - Factory Functions
|
// MARK: - Factory Functions
|
||||||
//------------------------------------------------------
|
//------------------------------------------------------
|
||||||
@ -309,8 +333,9 @@ public typealias ActionBlock = () -> ()
|
|||||||
guard let actionLabel = label as? Label else { continue }
|
guard let actionLabel = label as? Label else { continue }
|
||||||
|
|
||||||
actionLabel.addActionAttributes(range: range, string: attributedString)
|
actionLabel.addActionAttributes(range: range, string: attributedString)
|
||||||
let actionBlock = actionLabel.createActionBlockFrom(actionMap: json, additionalData: additionalData, delegateObject: delegate)
|
if let actionBlock = Label.createActionBlockFor(label: actionLabel, actionMap: json, additionalData: additionalData, delegateObject: delegate) {
|
||||||
actionLabel.appendActionableClause(range: range, actionBlock: actionBlock)
|
actionLabel.appendActionableClause(range: range, actionBlock: actionBlock)
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
continue
|
continue
|
||||||
@ -563,9 +588,10 @@ extension Label {
|
|||||||
clauses = []
|
clauses = []
|
||||||
}
|
}
|
||||||
|
|
||||||
public func createActionBlockFrom(actionMap: [AnyHashable: Any]?, additionalData: [AnyHashable: Any]?, delegateObject: DelegateObject?) -> ActionBlock {
|
public static func createActionBlockFor(label: Label?, actionMap: [AnyHashable: Any]?, additionalData: [AnyHashable: Any]?, delegateObject: DelegateObject?) -> ActionBlock? {
|
||||||
return { [weak self] in
|
guard let label = label else { return nil }
|
||||||
if let wSelf = self, (delegateObject as? MVMCoreUIDelegateObject)?.buttonDelegate?.button?(wSelf, shouldPerformActionWithMap: actionMap, additionalData: additionalData) ?? true {
|
return {
|
||||||
|
if (delegateObject as? MVMCoreUIDelegateObject)?.buttonDelegate?.button?(label, shouldPerformActionWithMap: actionMap, additionalData: additionalData) ?? true {
|
||||||
MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject)
|
MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -595,8 +621,7 @@ extension Label {
|
|||||||
*/
|
*/
|
||||||
@objc public func addTappableLinkAttribute(range: NSRange, actionBlock: @escaping ActionBlock) {
|
@objc public func addTappableLinkAttribute(range: NSRange, actionBlock: @escaping ActionBlock) {
|
||||||
|
|
||||||
setActionAttributes(range: range)
|
setTextLinkState(range: range, actionBlock: actionBlock)
|
||||||
appendActionableClause(range: range, actionBlock: actionBlock)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -610,22 +635,28 @@ extension Label {
|
|||||||
*/
|
*/
|
||||||
@objc public func addTappableLinkAttribute(range: NSRange, actionMap: [AnyHashable: Any]?, additionalData: [AnyHashable: Any]?, delegateObject: DelegateObject?) {
|
@objc public func addTappableLinkAttribute(range: NSRange, actionMap: [AnyHashable: Any]?, additionalData: [AnyHashable: Any]?, delegateObject: DelegateObject?) {
|
||||||
|
|
||||||
setActionAttributes(range: range)
|
if let actionBlock = Label.createActionBlockFor(label: self, actionMap: actionMap, additionalData: additionalData, delegateObject: delegateObject) {
|
||||||
let actionBlock = createActionBlockFrom(actionMap: actionMap, additionalData: additionalData, delegateObject: delegateObject)
|
setTextLinkState(range: range, actionBlock: actionBlock)
|
||||||
appendActionableClause(range: range, actionBlock: actionBlock)
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc public func makeAllTextLinkable(actionMap: [AnyHashable: Any]?, additionalData: [AnyHashable: Any]?, delegateObject: DelegateObject?) {
|
@objc public func makeAllTextLinkable(actionMap: [AnyHashable: Any]?, additionalData: [AnyHashable: Any]?, delegateObject: DelegateObject?) {
|
||||||
|
|
||||||
setActionAttributes(range: getRange)
|
if let actionBlock = Label.createActionBlockFor(label: self, actionMap: actionMap, additionalData: additionalData, delegateObject: delegateObject) {
|
||||||
let actionBlock = createActionBlockFrom(actionMap: actionMap, additionalData: additionalData, delegateObject: delegateObject)
|
setTextLinkState(range: getRange, actionBlock: actionBlock)
|
||||||
appendActionableClause(range: getRange, actionBlock: actionBlock)
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc public func makeAllTextLinkable(actionBlock: @escaping ActionBlock) {
|
@objc public func makeAllTextLinkable(actionBlock: @escaping ActionBlock) {
|
||||||
|
|
||||||
setActionAttributes(range: getRange)
|
setTextLinkState(range: getRange, actionBlock: actionBlock)
|
||||||
appendActionableClause(range: getRange, actionBlock: actionBlock)
|
}
|
||||||
|
|
||||||
|
/// Underlines the tappable region and stores the tap logic for interation.
|
||||||
|
private func setTextLinkState(range: NSRange, actionBlock: @escaping ActionBlock) {
|
||||||
|
|
||||||
|
setActionAttributes(range: range)
|
||||||
|
appendActionableClause(range: range, actionBlock: actionBlock)
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc private func textLinkTapped(_ gesture: UITapGestureRecognizer) {
|
@objc private func textLinkTapped(_ gesture: UITapGestureRecognizer) {
|
||||||
|
|||||||
@ -207,7 +207,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 = label?.createActionBlockFrom(actionMap: actionMap, additionalData: additionalData, delegateObject: delegateObject)
|
actionBlock = Label.createActionBlockFor(label: label, actionMap: actionMap, additionalData: additionalData, delegateObject: delegateObject)
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------
|
//------------------------------------------------------
|
||||||
@ -377,7 +377,7 @@ public typealias CoreObjectActionLoadPresentDelegate = MVMCoreActionDelegateProt
|
|||||||
actionText = actionMap?.optionalStringForKey(KeyTitle)
|
actionText = actionMap?.optionalStringForKey(KeyTitle)
|
||||||
backText = actionMap?.optionalStringForKey(KeyTitlePostfix)
|
backText = actionMap?.optionalStringForKey(KeyTitlePostfix)
|
||||||
text = getTextFromStringComponents()
|
text = getTextFromStringComponents()
|
||||||
actionBlock = label?.createActionBlockFrom(actionMap: actionMap, additionalData: additionalData, delegateObject: delegateObject)
|
actionBlock = Label.createActionBlockFor(label: label, actionMap: actionMap, additionalData: additionalData, delegateObject: delegateObject)
|
||||||
setLabelAttributes()
|
setLabelAttributes()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user