Corrections made.

This commit is contained in:
Christiano, Kevin 2019-04-10 12:12:44 -04:00
parent 503bbc4605
commit d0bc96e3a5

View File

@ -105,7 +105,7 @@ public typealias CoreObjectActionLoadPresentDelegate = MVMCoreActionDelegateProt
public init(frontText: String?, actionText: String?, backText: String?, actionMap: [AnyHashable: Any]?, additionalData: [AnyHashable: Any]?, actionDelegate delegate: ActionObjectDelegate?, buttonDelegate: ButtonObjectDelegate?) {
super.init(frame: CGRect.zero)
setFrontText(frontText, actionText: actionText, actionMap: actionMap, backText: backText, additionalData: additionalData, delegate: delegate, buttonDelegate: buttonDelegate)
}
@ -170,10 +170,7 @@ public typealias CoreObjectActionLoadPresentDelegate = MVMCoreActionDelegateProt
let label = MFLabel(frame: CGRect.zero)
backgroundColor = .clear
label.translatesAutoresizingMaskIntoConstraints = false
label.isUserInteractionEnabled = false
label.numberOfLines = 0
label.lineBreakMode = NSLineBreakMode.byWordWrapping
label.setContentCompressionResistancePriority(.required, for: .vertical)
addSubview(label)
NSLayoutConstraint.activate(NSLayoutConstraint.constraints(withVisualFormat: "H:|-0-[label]-0-|", options: .directionLeadingToTrailing, metrics: nil, views: ["label": label]))
@ -201,11 +198,11 @@ public typealias CoreObjectActionLoadPresentDelegate = MVMCoreActionDelegateProt
var performAction = true
if let wSelf = weakSelf, let wButtonDelegate = weakButtonDelegate, wButtonDelegate.responds(to: #selector(ButtonObjectDelegate.button(_:shouldPerformActionWithMap:additionalData:))) {
performAction = wButtonDelegate.button!(wSelf, shouldPerformActionWithMap: actionMap, additionalData: additionalData)
performAction = wButtonDelegate.button?(wSelf, shouldPerformActionWithMap: actionMap, additionalData: additionalData) ?? false
}
if let wDelegate = weakDelegate as? CoreObjectActionLoadPresentDelegate, performAction {
MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegate: wDelegate )
MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegate: wDelegate)
}
}
}
@ -243,29 +240,17 @@ public typealias CoreObjectActionLoadPresentDelegate = MVMCoreActionDelegateProt
frontText = frontAttributedText.string
}
let newLineAttributed = addNewLine ? "\n" : " "
if let actions = actionMap, let actionMapCount = actionMap?.keys.count, actionMapCount > 0 {
if let b2Font = MFStyler.fontB2(),
let actions = actionMap,
actions.keys.count > 0,
let actionString = actions.optionalStringForKey(KeyTitle),
!actionString.isEmpty {
var actionString = actions.stringForkey(KeyTitle)
let actionStringOnLine = actionString + (addNewLine ? "\n" : " ")
actionText = actionStringOnLine
setActionMap(actionMap, additionalData: additionalData, actionDelegate: delegate, buttonDelegate: buttonDelegate)
mutableAttributedString.append(MFStyler.styleGetAttributedString(actionStringOnLine, font: b2Font, color: .black))
if !actionString.isEmpty {
actionString += newLineAttributed
var actionAttributedString: NSAttributedString?
if let b2Font = MFStyler.fontB2() {
actionAttributedString = MFStyler.styleGetAttributedString(actionString, font: b2Font, color: .black)
}
actionText = actionString
setActionMap(actionMap, additionalData: additionalData, actionDelegate: delegate, buttonDelegate: buttonDelegate)
if let actionAttribString = actionAttributedString {
mutableAttributedString.append(actionAttribString)
}
}
} else {
actionText = nil
actionBlock = nil
@ -276,7 +261,6 @@ public typealias CoreObjectActionLoadPresentDelegate = MVMCoreActionDelegateProt
}
attributedText = mutableAttributedString
// Added this line for underlining
setAlternateActionTextAttributes([NSAttributedString.Key.underlineStyle: NSNumber(value: NSUnderlineStyle.single.rawValue)])
}
@ -399,17 +383,17 @@ public typealias CoreObjectActionLoadPresentDelegate = MVMCoreActionDelegateProt
let actionRange: ActionIndiciesTuple = rangeOfText(text, startTag: startTag, endTag: endTag)
frontText = actionRange.revisedText
if let revisedText = actionRange.revisedText, let startBraceIndex = actionRange.startIndex, let endBraceIndex = actionRange.endIndex {
frontText = String(revisedText[revisedText.startIndex..<startBraceIndex]).trimmingCharacters(in: .whitespaces)
actionText = String(revisedText[startBraceIndex..<endBraceIndex]).trimmingCharacters(in: .whitespaces)
backText = String(revisedText[endBraceIndex...]).trimmingCharacters(in: .whitespaces)
self.text = getTextFromStringComponents()
} else {
frontText = actionRange.revisedText
self.text = actionRange.revisedText
}
self.text = actionRange.revisedText
setup()
}
@ -455,7 +439,7 @@ public typealias CoreObjectActionLoadPresentDelegate = MVMCoreActionDelegateProt
// Reset the front text, back text, action map
@objc public func setFrontAttributedText(_ frontAttributedText: NSAttributedString?, actionMap: [AnyHashable: Any]?, backAttributedText: NSAttributedString?, additionalData: [AnyHashable: Any]?, delegate: ActionObjectDelegate?) {
setFrontAttributedText(frontAttributedText, actionMap: actionMap, backAttributedText: backAttributedText, addNewLine: false, additionalData: additionalData, delegate: delegate)
}