Latest changes. Now including clause changes.
This commit is contained in:
parent
a6e732afa9
commit
33754802bb
@ -56,13 +56,22 @@ public typealias ActionBlock = () -> ()
|
|||||||
public struct ActionableClause {
|
public struct ActionableClause {
|
||||||
var range: NSRange?
|
var range: NSRange?
|
||||||
var actionBlock: ActionBlock?
|
var actionBlock: ActionBlock?
|
||||||
var hash: Int = 0
|
var accessibilityID: Int = 0
|
||||||
|
|
||||||
func performAction() {
|
func performAction() {
|
||||||
actionBlock?()
|
actionBlock?()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//------------------------------------------------------
|
||||||
|
// MARK: - Convenience Setter For objective-C
|
||||||
|
//------------------------------------------------------
|
||||||
|
|
||||||
|
/// Sets the clauses array to empty.
|
||||||
|
@objc public func setEmptyClauses() {
|
||||||
|
clauses = []
|
||||||
|
}
|
||||||
|
|
||||||
//------------------------------------------------------
|
//------------------------------------------------------
|
||||||
// MARK: - Initialization
|
// MARK: - Initialization
|
||||||
//------------------------------------------------------
|
//------------------------------------------------------
|
||||||
@ -73,6 +82,7 @@ public typealias ActionBlock = () -> ()
|
|||||||
numberOfLines = 0
|
numberOfLines = 0
|
||||||
lineBreakMode = .byWordWrapping
|
lineBreakMode = .byWordWrapping
|
||||||
translatesAutoresizingMaskIntoConstraints = false
|
translatesAutoresizingMaskIntoConstraints = false
|
||||||
|
clauses = []
|
||||||
accessibilityCustomActions = []
|
accessibilityCustomActions = []
|
||||||
|
|
||||||
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(textLinkTapped(_:)))
|
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(textLinkTapped(_:)))
|
||||||
@ -295,9 +305,8 @@ 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 accessibleAction = actionLabel.customAccessibilityAction(range: range)
|
|
||||||
let actionBlock = actionLabel.createActionBlockFrom(actionMap: json, additionalData: additionalData, delegateObject: delegate)
|
let actionBlock = actionLabel.createActionBlockFrom(actionMap: json, additionalData: additionalData, delegateObject: delegate)
|
||||||
actionLabel.clauses.append(ActionableClause(range: range, actionBlock: actionBlock, hash: accessibleAction?.hash ?? -1))
|
actionLabel.appendActionableClause(range: range, actionBlock: actionBlock)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
continue
|
continue
|
||||||
@ -402,7 +411,7 @@ public typealias ActionBlock = () -> ()
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
Appends an external link image to the end of the attributed string.
|
Appends an external link image to the end of the attributed string.
|
||||||
Will provide one whitespace to the left of the icon
|
Will provide one whitespace to the left of the icon; adds 2 chars to the end of the string.
|
||||||
*/
|
*/
|
||||||
@objc public func appendExternalLinkIcon() {
|
@objc public func appendExternalLinkIcon() {
|
||||||
|
|
||||||
@ -419,7 +428,7 @@ public typealias ActionBlock = () -> ()
|
|||||||
Insert external link icon anywhere within text of Label.
|
Insert external link icon anywhere within text of Label.
|
||||||
|
|
||||||
- Note: Each icon insertion adds 1 additional characters to the overall text length.
|
- Note: Each icon insertion adds 1 additional characters to the overall text length.
|
||||||
Therefore, you MUST insert icons and links in the order they would appear.
|
Therefore, you **MUST** insert icons and links in the order they would appear.
|
||||||
- parameter index: Location within the associated text to insert an external Link Icon
|
- parameter index: Location within the associated text to insert an external Link Icon
|
||||||
*/
|
*/
|
||||||
public func insertExternalLinkIcon(at index: Int) {
|
public func insertExternalLinkIcon(at index: Int) {
|
||||||
@ -487,6 +496,12 @@ public typealias ActionBlock = () -> ()
|
|||||||
|
|
||||||
return containsAttachment
|
return containsAttachment
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func appendActionableClause(range: NSRange, actionBlock: @escaping ActionBlock) {
|
||||||
|
|
||||||
|
let accessibleAction = customAccessibilityAction(range: range)
|
||||||
|
clauses.append(ActionableClause(range: range, actionBlock: actionBlock, accessibilityID: accessibleAction?.hash ?? -1))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Atomization
|
// MARK: - Atomization
|
||||||
@ -499,6 +514,7 @@ extension Label {
|
|||||||
originalAttributedString = nil
|
originalAttributedString = nil
|
||||||
styleB2(true)
|
styleB2(true)
|
||||||
accessibilityCustomActions = []
|
accessibilityCustomActions = []
|
||||||
|
clauses = []
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc public func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) {
|
@objc public func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) {
|
||||||
@ -527,7 +543,7 @@ extension Label {
|
|||||||
// MARK: - Multi-Action Functionality
|
// MARK: - Multi-Action Functionality
|
||||||
extension Label {
|
extension Label {
|
||||||
|
|
||||||
/// Reseting to default Label values.
|
/// Applied to existing text. Removes underlines of tappable links and assoated actionable clauses.
|
||||||
@objc public func clearActionableClauses() {
|
@objc public func clearActionableClauses() {
|
||||||
|
|
||||||
guard let attributedText = attributedText else { return }
|
guard let attributedText = attributedText else { return }
|
||||||
@ -576,8 +592,7 @@ extension Label {
|
|||||||
@objc public func addTappableLinkAttribute(range: NSRange, actionBlock: @escaping ActionBlock) {
|
@objc public func addTappableLinkAttribute(range: NSRange, actionBlock: @escaping ActionBlock) {
|
||||||
|
|
||||||
setActionAttributes(range: range)
|
setActionAttributes(range: range)
|
||||||
let accessibleAction = customAccessibilityAction(range: range)
|
appendActionableClause(range: range, actionBlock: actionBlock)
|
||||||
clauses.append(ActionableClause(range: range, actionBlock: actionBlock, hash: accessibleAction?.hash ?? -1))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -592,9 +607,8 @@ 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)
|
setActionAttributes(range: range)
|
||||||
let accessibleAction = customAccessibilityAction(range: range)
|
|
||||||
let actionBlock = createActionBlockFrom(actionMap: actionMap, additionalData: additionalData, delegateObject: delegateObject)
|
let actionBlock = createActionBlockFrom(actionMap: actionMap, additionalData: additionalData, delegateObject: delegateObject)
|
||||||
clauses.append(ActionableClause(range: range, actionBlock: actionBlock, hash: accessibleAction?.hash ?? -1))
|
appendActionableClause(range: range, actionBlock: actionBlock)
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc private func textLinkTapped(_ gesture: UITapGestureRecognizer) {
|
@objc private func textLinkTapped(_ gesture: UITapGestureRecognizer) {
|
||||||
@ -668,7 +682,7 @@ extension Label {
|
|||||||
@objc public func accessibilityCustomAction(_ action: UIAccessibilityCustomAction) {
|
@objc public func accessibilityCustomAction(_ action: UIAccessibilityCustomAction) {
|
||||||
|
|
||||||
for clause in clauses {
|
for clause in clauses {
|
||||||
if action.hash == clause.hash {
|
if action.hash == clause.accessibilityID {
|
||||||
clause.performAction()
|
clause.performAction()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@ -67,11 +67,11 @@ public typealias CoreObjectActionLoadPresentDelegate = MVMCoreActionDelegateProt
|
|||||||
guard let label = label else { return }
|
guard let label = label else { return }
|
||||||
|
|
||||||
let accessibleAction = UIAccessibilityCustomAction(name: actionText ?? "", target: label, selector: #selector(label.accessibilityCustomAction(_:)))
|
let accessibleAction = UIAccessibilityCustomAction(name: actionText ?? "", target: label, selector: #selector(label.accessibilityCustomAction(_:)))
|
||||||
label.clauses = [Label.ActionableClause(range: actionRange, actionBlock: newActionBlock, hash: accessibleAction.hash)]
|
label.clauses = [Label.ActionableClause(range: actionRange, actionBlock: newActionBlock, accessibilityID: accessibleAction.hash)]
|
||||||
label.accessibilityCustomActions = [accessibleAction]
|
label.accessibilityCustomActions = [accessibleAction]
|
||||||
|
|
||||||
if label.accessibilityHint == nil {
|
if label.accessibilityHint == nil {
|
||||||
label.accessibilityHint = MVMCoreUIUtility.hardcodedString(withKey: "plan_selector_int_swipe_action_hint")
|
label.accessibilityHint = MVMCoreUIUtility.hardcodedString(withKey: "swipe_to_select_with_action_hint")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user