diff --git a/MVMCoreUI/Atoms/Views/LabelWithInternalButton.swift b/MVMCoreUI/Atoms/Views/LabelWithInternalButton.swift index 7b5ba239..3810294a 100644 --- a/MVMCoreUI/Atoms/Views/LabelWithInternalButton.swift +++ b/MVMCoreUI/Atoms/Views/LabelWithInternalButton.swift @@ -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..