From 8a861077dd824a3af4a6c162ceefa56ac4f8d991 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Tue, 23 Feb 2021 14:56:23 -0500 Subject: [PATCH 1/5] styler additon. label width value --- .../Atomic/Atoms/Views/Label/Label.swift | 4 +++- MVMCoreUI/Styles/Styler.swift | 24 ++++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift b/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift index 7e902d435..8838966c 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift @@ -594,7 +594,6 @@ public typealias ActionBlock = () -> () attributedText = attributedString } - @objc public func updateView(_ size: CGFloat) { scaleSize = size as NSNumber @@ -624,6 +623,9 @@ public typealias ActionBlock = () -> () } else if !MVMCoreGetterUtility.fequal(a: Float(standardFontSize), b: 0.0), let sizeObject = sizeObject ?? MFStyler.sizeObjectGeneric(forCurrentDevice: standardFontSize) { font = font.updateSize(sizeObject.getValueBased(onSize: size)) } + + // Provide the label additional size information to help calculate its intrinsic content. + preferredMaxLayoutWidth = Styler.maxAvailableLayoutWidth(size: size) } @objc public func setFont(_ font: UIFont, scale: Bool) { diff --git a/MVMCoreUI/Styles/Styler.swift b/MVMCoreUI/Styles/Styler.swift index c0dd6792..b2614f04 100644 --- a/MVMCoreUI/Styles/Styler.swift +++ b/MVMCoreUI/Styles/Styler.swift @@ -209,7 +209,29 @@ open class Styler { } open class func sizeFontGeneric(forCurrentDevice size: CGFloat) -> CGFloat { - return sizeObjectGeneric(forCurrentDevice: size)?.getValueBasedOnApplicationWidth() ?? size + sizeObjectGeneric(forCurrentDevice: size)?.getValueBasedOnApplicationWidth() ?? size + } + + open class func defaultHorizontalPadding(for size: CGFloat) -> CGFloat { + sizeObject(withScalingStandardSize: CGFloat(Padding.Component.horizontalPaddingForApplicationWidth)).getValueBased(onSize: size) + } + + open class func defaultVerticalPadding(for size: CGFloat) -> CGFloat { + sizeObject(withScalingStandardSize: CGFloat(Padding.Component.verticalPaddingForApplicationWidth)).getValueBased(onSize: size) + } + + open class func sizeObject(withScalingStandardSize standardSize: CGFloat) -> MFSizeObject { + let object = MFSizeObject() + object.standardSize = standardSize + object.scaleStandardSize = true + return object + } + + /// Provide additional size information to help calculate its intrinsic height. + /// - Returns: The available spacing that can be used for intrinsic content width. + open class func maxAvailableLayoutWidth(size: CGFloat) -> CGFloat { + // The 2 is the product of both sides of padding. + size - (defaultHorizontalPadding(for: size) * 2) } //-------------------------------------------------- From cd94f99f6076eb3ae816e4a78e55dfe35f3df458 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Tue, 23 Feb 2021 15:33:03 -0500 Subject: [PATCH 2/5] error check. --- MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift b/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift index 8838966c..3d57d0aa 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift @@ -836,7 +836,10 @@ extension Label { fileprivate func setActionAttributes(range: NSRange) { - guard let attributedText = attributedText else { return } + guard let attributedText = attributedText, + range.length > 0, + range.length <= attributedText.length + else { return } let mutableAttributedString = NSMutableAttributedString(attributedString: attributedText) addActionAttributes(range: range, string: mutableAttributedString) From f20895627f6c8649a309b8df1595fc1c65149d7a Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Tue, 23 Feb 2021 15:34:28 -0500 Subject: [PATCH 3/5] undo --- MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift b/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift index 8838966c..7e902d435 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift @@ -594,6 +594,7 @@ public typealias ActionBlock = () -> () attributedText = attributedString } + @objc public func updateView(_ size: CGFloat) { scaleSize = size as NSNumber @@ -623,9 +624,6 @@ public typealias ActionBlock = () -> () } else if !MVMCoreGetterUtility.fequal(a: Float(standardFontSize), b: 0.0), let sizeObject = sizeObject ?? MFStyler.sizeObjectGeneric(forCurrentDevice: standardFontSize) { font = font.updateSize(sizeObject.getValueBased(onSize: size)) } - - // Provide the label additional size information to help calculate its intrinsic content. - preferredMaxLayoutWidth = Styler.maxAvailableLayoutWidth(size: size) } @objc public func setFont(_ font: UIFont, scale: Bool) { From 55217c21c3e29321f91982ccdfeed3ea0c3ee072 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Wed, 24 Feb 2021 10:14:05 -0500 Subject: [PATCH 4/5] undo --- MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift b/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift index 91521b9b..511fb4dc 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift @@ -624,6 +624,9 @@ public typealias ActionBlock = () -> () } else if !MVMCoreGetterUtility.fequal(a: Float(standardFontSize), b: 0.0), let sizeObject = sizeObject ?? MFStyler.sizeObjectGeneric(forCurrentDevice: standardFontSize) { font = font.updateSize(sizeObject.getValueBased(onSize: size)) } + + // Provide the label additional size information to help calculate its intrinsic content. + preferredMaxLayoutWidth = Styler.maxAvailableLayoutWidth(size: size) } @objc public func setFont(_ font: UIFont, scale: Bool) { @@ -834,10 +837,7 @@ extension Label { fileprivate func setActionAttributes(range: NSRange) { - guard let attributedText = attributedText, - range.length > 0, - range.length <= attributedText.length - else { return } + guard let attributedText = attributedText else { return } let mutableAttributedString = NSMutableAttributedString(attributedString: attributedText) addActionAttributes(range: range, string: mutableAttributedString) From 10a91bd1ed38e052f8e59e52d0386f391e161c1d Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Wed, 24 Feb 2021 11:19:31 -0500 Subject: [PATCH 5/5] revised --- MVMCoreUI/Styles/Padding.swift | 10 ++++------ MVMCoreUI/Styles/Styler.swift | 17 +---------------- 2 files changed, 5 insertions(+), 22 deletions(-) diff --git a/MVMCoreUI/Styles/Padding.swift b/MVMCoreUI/Styles/Padding.swift index 0dd9ff6e..480896a0 100644 --- a/MVMCoreUI/Styles/Padding.swift +++ b/MVMCoreUI/Styles/Padding.swift @@ -6,8 +6,6 @@ // Copyright © 2020 Verizon Wireless. All rights reserved. // -import Foundation - /// Padding is a multiple based on the number 4. public struct Padding { @@ -30,19 +28,19 @@ public struct Padding { public static let VerticalMarginSpacing: CGFloat = 24 public static var horizontalPaddingForApplicationWidth: CGFloat { - return MFSizeObject(scalingStandardSize: HorizontalMarginSpacing)?.getValueBasedOnApplicationWidth() ?? HorizontalMarginSpacing + MFSizeObject(scalingStandardSize: HorizontalMarginSpacing)?.getValueBasedOnApplicationWidth() ?? HorizontalMarginSpacing } public static var verticalPaddingForApplicationWidth: CGFloat { - return MFSizeObject(scalingStandardSize: VerticalMarginSpacing)?.getValueBasedOnApplicationWidth() ?? VerticalMarginSpacing + MFSizeObject(scalingStandardSize: VerticalMarginSpacing)?.getValueBasedOnApplicationWidth() ?? VerticalMarginSpacing } public static func horizontalPaddingForSize(_ size: CGFloat) -> CGFloat { - return MFSizeObject(scalingStandardSize: HorizontalMarginSpacing)?.getValueBased(onSize: size) ?? HorizontalMarginSpacing + MFSizeObject(scalingStandardSize: HorizontalMarginSpacing)?.getValueBased(onSize: size) ?? HorizontalMarginSpacing } public static func verticalPaddingForSize(_ size: CGFloat) -> CGFloat { - return MFSizeObject(scalingStandardSize: VerticalMarginSpacing)?.getValueBased(onSize: size) ?? VerticalMarginSpacing + MFSizeObject(scalingStandardSize: VerticalMarginSpacing)?.getValueBased(onSize: size) ?? VerticalMarginSpacing } } } diff --git a/MVMCoreUI/Styles/Styler.swift b/MVMCoreUI/Styles/Styler.swift index b2614f04..77402295 100644 --- a/MVMCoreUI/Styles/Styler.swift +++ b/MVMCoreUI/Styles/Styler.swift @@ -212,26 +212,11 @@ open class Styler { sizeObjectGeneric(forCurrentDevice: size)?.getValueBasedOnApplicationWidth() ?? size } - open class func defaultHorizontalPadding(for size: CGFloat) -> CGFloat { - sizeObject(withScalingStandardSize: CGFloat(Padding.Component.horizontalPaddingForApplicationWidth)).getValueBased(onSize: size) - } - - open class func defaultVerticalPadding(for size: CGFloat) -> CGFloat { - sizeObject(withScalingStandardSize: CGFloat(Padding.Component.verticalPaddingForApplicationWidth)).getValueBased(onSize: size) - } - - open class func sizeObject(withScalingStandardSize standardSize: CGFloat) -> MFSizeObject { - let object = MFSizeObject() - object.standardSize = standardSize - object.scaleStandardSize = true - return object - } - /// Provide additional size information to help calculate its intrinsic height. /// - Returns: The available spacing that can be used for intrinsic content width. open class func maxAvailableLayoutWidth(size: CGFloat) -> CGFloat { // The 2 is the product of both sides of padding. - size - (defaultHorizontalPadding(for: size) * 2) + size - (Padding.Component.horizontalPaddingForSize(size) * 2) } //--------------------------------------------------