From d38032891368ad0bd561d10b635cc95582c5406e Mon Sep 17 00:00:00 2001 From: panxi Date: Fri, 26 Apr 2019 13:41:26 -0400 Subject: [PATCH 1/2] copy from Kevin commis: https://gitlab.verizon.com/BPHV_MIPS/mvm_core_ui/commit/d373a3f7be6064b99bc48b21a7c4cc2adda9c965 --- MVMCoreUI/Atoms/Buttons/CaretButton.swift | 26 ++++++++----------- MVMCoreUI/Atoms/Views/CaretView.swift | 14 +++++----- .../Atoms/Views/LabelWithInternalButton.swift | 6 ++--- 3 files changed, 21 insertions(+), 25 deletions(-) diff --git a/MVMCoreUI/Atoms/Buttons/CaretButton.swift b/MVMCoreUI/Atoms/Buttons/CaretButton.swift index 27076a6a..dfef20ca 100644 --- a/MVMCoreUI/Atoms/Buttons/CaretButton.swift +++ b/MVMCoreUI/Atoms/Buttons/CaretButton.swift @@ -13,8 +13,9 @@ open class CaretButton: MFCustomButton { // MARK: - Constants //------------------------------------------------------ - private let CaretViewHeight: Float = 10.8 - private let CaretViewWidth: Float = 6.6 + private let CARET_VIEW_HEIGHT: Float = 10.8 + private let CARET_VIEW_WIDTH: Float = 6.6 + //------------------------------------------------------ // MARK: - Properties @@ -25,17 +26,11 @@ open class CaretButton: MFCustomButton { @objc public var rightViewWidth: NSNumber? @objc public var enabledColor: UIColor = .black { - didSet { - setTitleColor(enabledColor, for: .normal) - changeCaretColor() - } + didSet { changeCaretColor() } } @objc public var disabledColor: UIColor = .mfSilver() { - didSet { - setTitleColor(disabledColor, for: .disabled) - changeCaretColor() - } + didSet { changeCaretColor() } } private var caretSpacingConstraint: NSLayoutConstraint? @@ -61,10 +56,11 @@ open class CaretButton: MFCustomButton { //------------------------------------------------------ private func changeCaretColor() { - + setTitleColor(enabledColor, for: .normal) + setTitleColor(disabledColor, for: .disabled) + if let rightCaretView = rightView as? CaretView { - let lineColor = isEnabled ? enabledColor : disabledColor - rightCaretView.setLineColor(lineColor) + rightCaretView.setLineColor(isEnabled ? enabledColor : disabledColor) } } @@ -72,8 +68,8 @@ open class CaretButton: MFCustomButton { rightView?.removeFromSuperview() - let width = CGFloat(rightViewWidth?.floatValue ?? CaretViewWidth) - let height = CGFloat(rightViewHeight?.floatValue ?? CaretViewHeight) + let width = CGFloat(rightViewWidth?.floatValue ?? CARET_VIEW_WIDTH) + let height = CGFloat(rightViewHeight?.floatValue ?? CARET_VIEW_HEIGHT) let edgeInsets: UIEdgeInsets = contentEdgeInsets contentEdgeInsets = UIEdgeInsets(top: edgeInsets.top, left: edgeInsets.left, bottom: edgeInsets.bottom, right: 4 + width) diff --git a/MVMCoreUI/Atoms/Views/CaretView.swift b/MVMCoreUI/Atoms/Views/CaretView.swift index eb3a4c4b..51ab783a 100644 --- a/MVMCoreUI/Atoms/Views/CaretView.swift +++ b/MVMCoreUI/Atoms/Views/CaretView.swift @@ -21,7 +21,7 @@ open class CaretView: MFView { //------------------------------------------------------ @objc public init() { - super.init(frame: CGRect.zero) + super.init(frame: .zero) } @objc public override init(frame: CGRect) { @@ -98,25 +98,25 @@ open class CaretView: MFView { open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: DelegateObject?, additionalData: [AnyHashable: Any]?) { super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) // Configure class properties with JSON values - guard let jsonDictionary = json else { return } + guard let dictionary = json else { return } - if let backgroundColorHex = jsonDictionary[KeyBackgroundColor] as? String { + if let backgroundColorHex = dictionary[KeyBackgroundColor] as? String { backgroundColor = UIColor.mfGet(forHex: backgroundColorHex) } - if let strokeColorHex = jsonDictionary["strokeColor"] as? String { + if let strokeColorHex = dictionary["strokeColor"] as? String { strokeColor = UIColor.mfGet(forHex: strokeColorHex) } - if let isHiddenValue = jsonDictionary[KeyIsHidden] as? Bool { + if let isHiddenValue = dictionary[KeyIsHidden] as? Bool { isHidden = isHiddenValue } - if let isOpaqueValue = jsonDictionary[KeyIsOpaque] as? Bool { + if let isOpaqueValue = dictionary[KeyIsOpaque] as? Bool { isOpaque = isOpaqueValue } - if let lineWidthValue = jsonDictionary["lineWidth"] as? CGFloat { + if let lineWidthValue = dictionary["lineWidth"] as? CGFloat { lineWidth = lineWidthValue } } diff --git a/MVMCoreUI/Atoms/Views/LabelWithInternalButton.swift b/MVMCoreUI/Atoms/Views/LabelWithInternalButton.swift index 08dd9044..0fd48295 100644 --- a/MVMCoreUI/Atoms/Views/LabelWithInternalButton.swift +++ b/MVMCoreUI/Atoms/Views/LabelWithInternalButton.swift @@ -26,7 +26,7 @@ public typealias CoreObjectActionLoadPresentDelegate = MVMCoreActionDelegateProt public var attributedText: NSAttributedString? { willSet(newAttributedText) { - if let newAttribText = newAttributedText, !newAttribText.string.isEmpty { + if let newAttribText = newAttributedText { let mutableAttributedText = NSMutableAttributedString(attributedString: newAttribText) let paragraphStyle = NSMutableParagraphStyle() @@ -201,8 +201,8 @@ public typealias CoreObjectActionLoadPresentDelegate = MVMCoreActionDelegateProt 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) + if performAction { + MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegate: weakDelegate as? CoreObjectActionLoadPresentDelegate) } } } From 2f0a727d03c4caba948f15ff0d76667545d8f1f7 Mon Sep 17 00:00:00 2001 From: panxi Date: Fri, 26 Apr 2019 13:41:54 -0400 Subject: [PATCH 2/2] copy from Kevin's commit: https://gitlab.verizon.com/BPHV_MIPS/mvm_core_ui/commit/aac5093c37f2763c5d809701112d5d84eefe3d1c --- MVMCoreUI/Atoms/Buttons/CaretButton.swift | 4 ++-- MVMCoreUI/Atoms/Views/LabelWithInternalButton.swift | 13 ++++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/MVMCoreUI/Atoms/Buttons/CaretButton.swift b/MVMCoreUI/Atoms/Buttons/CaretButton.swift index dfef20ca..838f5d18 100644 --- a/MVMCoreUI/Atoms/Buttons/CaretButton.swift +++ b/MVMCoreUI/Atoms/Buttons/CaretButton.swift @@ -13,8 +13,8 @@ open class CaretButton: MFCustomButton { // MARK: - Constants //------------------------------------------------------ - private let CARET_VIEW_HEIGHT: Float = 10.8 - private let CARET_VIEW_WIDTH: Float = 6.6 + private let CARET_VIEW_HEIGHT: Float = 10.5 + private let CARET_VIEW_WIDTH: Float = 6.5 //------------------------------------------------------ diff --git a/MVMCoreUI/Atoms/Views/LabelWithInternalButton.swift b/MVMCoreUI/Atoms/Views/LabelWithInternalButton.swift index 0fd48295..d47594c1 100644 --- a/MVMCoreUI/Atoms/Views/LabelWithInternalButton.swift +++ b/MVMCoreUI/Atoms/Views/LabelWithInternalButton.swift @@ -74,9 +74,16 @@ public typealias CoreObjectActionLoadPresentDelegate = MVMCoreActionDelegateProt public var actionText: String? public var backText: String? - private var text: String? { - willSet(newText) { - attributedText = NSAttributedString(string: newText ?? "") + private var internalText: String = "" + + public var text: String? { + get { + return internalText + } + set { + guard let text = newValue else { return } + internalText = text + attributedText = NSAttributedString(string: text) setAlternateNormalTextAttributes([NSAttributedString.Key.font: normalTextFont as Any]) setAlternateActionTextAttributes([NSAttributedString.Key.font: actionTextFont as Any]) setAlternateNormalTextAttributes([NSAttributedString.Key.foregroundColor: normalTextColor as Any])