From 02476e766d18eb3699dfe3570b1ee78e9f887870 Mon Sep 17 00:00:00 2001 From: Sumanth Nadigadda Date: Thu, 24 Mar 2022 00:22:38 +0530 Subject: [PATCH] Updating button VDS component for 3.0 rebranding --- .../Atomic/Atoms/Buttons/PillButton.swift | 49 ++++++++++++++++--- MVMCoreUI/Styles/Styler.swift | 8 +-- 2 files changed, 46 insertions(+), 11 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Buttons/PillButton.swift b/MVMCoreUI/Atomic/Atoms/Buttons/PillButton.swift index 5b8f75cb..edea692f 100644 --- a/MVMCoreUI/Atomic/Atoms/Buttons/PillButton.swift +++ b/MVMCoreUI/Atomic/Atoms/Buttons/PillButton.swift @@ -128,6 +128,7 @@ open class PillButton: Button, MVMCoreUIViewConstrainingProtocol { self.borderColor = borderColor } } + titleEdgeInsets = getContentEdgeInsets() } private func getInnerPadding() -> CGFloat { @@ -138,6 +139,24 @@ open class PillButton: Button, MVMCoreUIViewConstrainingProtocol { PillButton.getHeight(for: buttonSize, size: size) } + private func getContentEdgeInsets() -> UIEdgeInsets { + var verticalPadding = 0.0 + var horizontalPadding = 0.0 + switch buttonSize { + case .standard: + verticalPadding = Padding.Three + horizontalPadding = Padding.Five + break + case .small: + verticalPadding = Padding.Two + horizontalPadding = Padding.Four + break + default: + break + } + return UIEdgeInsets(top: verticalPadding, left: horizontalPadding, bottom: verticalPadding, right: horizontalPadding) + } + public static func getHeight(for buttonSize: Styler.Button.Size?, size: CGFloat) -> CGFloat { switch buttonSize { @@ -146,7 +165,11 @@ open class PillButton: Button, MVMCoreUIViewConstrainingProtocol { return MFSizeObject(standardSize: tinyHeight, standardiPadPortraitSize: 34, iPadProLandscapeSize: 38)?.getValueBased(onSize: size) ?? tinyHeight - + case .small: + let smallHeight = Styler.Button.Size.small.getHeight() + return MFSizeObject(standardSize: smallHeight, + standardiPadPortraitSize: 34, + iPadProLandscapeSize: 38)?.getValueBased(onSize: size) ?? smallHeight default: let standardHeight = Styler.Button.Size.standard.getHeight() return MFSizeObject(standardSize: standardHeight, @@ -162,8 +185,14 @@ open class PillButton: Button, MVMCoreUIViewConstrainingProtocol { return MFSizeObject(standardSize: 49, standardiPadPortraitSize: 90, iPadProLandscapeSize: 135)?.getValueBased(onSize: size) ?? 49 - - default: return 151 + case .small: + return MFSizeObject(standardSize: 1, + standardiPadPortraitSize: 2, + iPadProLandscapeSize: 3)?.getValueBased(onSize: size) ?? 1 + case .standard: + return MFSizeObject(standardSize: 76, + standardiPadPortraitSize: 90, + iPadProLandscapeSize: 135)?.getValueBased(onSize: size) ?? 76 } } @@ -172,9 +201,12 @@ open class PillButton: Button, MVMCoreUIViewConstrainingProtocol { let size = super.intrinsicContentSize let width = size.width + (2 * getInnerPadding()) return CGSize(width: max(width, getMinimumWidth()), height: getHeight()) + } else if buttonSize == .small { + let width = (2 * Padding.Four) + (titleLabel?.attributedText?.boundingRect(with: CGSize(width: 1000, height: 1000), options: [.usesLineFragmentOrigin, .usesFontLeading], context: nil).size.width ?? 0) + return CGSize(width: max(ceil(width), getMinimumWidth()), height: getHeight()) } else { - let width = Padding.Component.gutterForApplicationWidth + (2.0 * Padding.Component.columnFor(size: MVMCoreUISplitViewController.getApplicationViewWidth())) - return CGSize(width: min(292, width), height: getHeight()) + let width = (2 * Padding.Five) + (titleLabel?.attributedText?.boundingRect(with: CGSize(width: 1000, height: 1000), options: [.usesLineFragmentOrigin, .usesFontLeading], context: nil).size.width ?? 0) + return CGSize(width: max(ceil(width), getMinimumWidth()), height: getHeight()) } } @@ -218,9 +250,10 @@ open class PillButton: Button, MVMCoreUIViewConstrainingProtocol { switch buttonSize { case .tiny: titleLabel?.font = MFFonts.mfFont75Bd(11 * (intrinsicContentSize.height / Styler.Button.Size.tiny.getHeight())) - - default: - titleLabel?.font = MFFonts.mfFont75Bd(13 * (intrinsicContentSize.height / Styler.Button.Size.standard.getHeight())) + case .small: + titleLabel?.font = Styler.Font.BoldBodySmall.getFont() + case .standard: + titleLabel?.font = Styler.Font.BoldBodyLarge.getFont() } layer.cornerRadius = getInnerPadding() diff --git a/MVMCoreUI/Styles/Styler.swift b/MVMCoreUI/Styles/Styler.swift index 77402295..c8fe444e 100644 --- a/MVMCoreUI/Styles/Styler.swift +++ b/MVMCoreUI/Styles/Styler.swift @@ -178,16 +178,18 @@ open class Styler { case primary case secondary } - + ///MVA 3.0 - Button sizes are standard(default size), small, Tiny. Tiny button has been depricated as of Rebranding 3.0. public enum Size: String, Codable { case standard + case small case tiny func getHeight() -> CGFloat { switch self { case .standard: - return 42 - + return 44 + case .small: + return 32 case .tiny: return 20 }