From 963e31acd3e98759c0b815b6e5507ecb6bff0fe5 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 1 Mar 2024 14:28:17 -0600 Subject: [PATCH] Adding the padding fix between TileContainer/Tilelet Signed-off-by: Matt Bruce --- VDS.xcodeproj/project.pbxproj | 8 +++ .../TileContainer/TileContainer.swift | 70 ++++++++++--------- VDS/Components/Tilelet/Tilelet.swift | 54 ++++++++------ VDS/Extensions/VDSLayout.swift | 4 +- VDS/Protocols/EnumSubset.swift | 2 +- VDS/Protocols/EnumValuing.swift | 12 ++++ VDS/Protocols/Valuing.swift | 13 ++++ 7 files changed, 107 insertions(+), 56 deletions(-) create mode 100644 VDS/Protocols/EnumValuing.swift create mode 100644 VDS/Protocols/Valuing.swift diff --git a/VDS.xcodeproj/project.pbxproj b/VDS.xcodeproj/project.pbxproj index 5d78557f..4b863360 100644 --- a/VDS.xcodeproj/project.pbxproj +++ b/VDS.xcodeproj/project.pbxproj @@ -99,6 +99,8 @@ EAA5EEF128F5C909003B3210 /* VDSColorTokens.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = EAA5EEED28F5C908003B3210 /* VDSColorTokens.xcframework */; }; EAA5EEF328F5C909003B3210 /* VDSFormControlsTokens.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = EAA5EEEE28F5C908003B3210 /* VDSFormControlsTokens.xcframework */; }; EAA7456C2AB23E2000C1841F /* TooltipModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAA7456B2AB23E2000C1841F /* TooltipModel.swift */; }; + EAACB8982B92706F006A3869 /* EnumValuing.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAACB8972B92706F006A3869 /* EnumValuing.swift */; }; + EAACB89A2B927108006A3869 /* Valuing.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAACB8992B927108006A3869 /* Valuing.swift */; }; EAB1D29C28A5618900DAE764 /* RadioButtonGroup.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAB1D29B28A5618900DAE764 /* RadioButtonGroup.swift */; }; EAB1D2CD28ABE76100DAE764 /* Withable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAB1D2CC28ABE76000DAE764 /* Withable.swift */; }; EAB1D2CF28ABEF2B00DAE764 /* Typography+Base.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAB1D2CE28ABEF2B00DAE764 /* Typography+Base.swift */; }; @@ -268,6 +270,8 @@ EAA5EEED28F5C908003B3210 /* VDSColorTokens.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = VDSColorTokens.xcframework; path = ../SharedFrameworks/VDSColorTokens.xcframework; sourceTree = ""; }; EAA5EEEE28F5C908003B3210 /* VDSFormControlsTokens.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = VDSFormControlsTokens.xcframework; path = ../SharedFrameworks/VDSFormControlsTokens.xcframework; sourceTree = ""; }; EAA7456B2AB23E2000C1841F /* TooltipModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TooltipModel.swift; sourceTree = ""; }; + EAACB8972B92706F006A3869 /* EnumValuing.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EnumValuing.swift; sourceTree = ""; }; + EAACB8992B927108006A3869 /* Valuing.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Valuing.swift; sourceTree = ""; }; EAB1D29B28A5618900DAE764 /* RadioButtonGroup.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RadioButtonGroup.swift; sourceTree = ""; }; EAB1D2CC28ABE76000DAE764 /* Withable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Withable.swift; sourceTree = ""; }; EAB1D2CE28ABEF2B00DAE764 /* Typography+Base.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Typography+Base.swift"; sourceTree = ""; }; @@ -552,6 +556,7 @@ EA3361A9288B25E40071C351 /* Disabling.swift */, EAF978202A99035B00C2FEA9 /* Enabling.swift */, EA5E305929510F8B0082B959 /* EnumSubset.swift */, + EAACB8972B92706F006A3869 /* EnumValuing.swift */, EAF7F0A1289AFB3900B287F5 /* Errorable.swift */, EA3361AE288B26310071C351 /* FormFieldable.swift */, EA33624628931B050071C351 /* Initable.swift */, @@ -562,6 +567,7 @@ EA3361B7288B2AAA0071C351 /* ViewProtocol.swift */, EAB1D2CC28ABE76000DAE764 /* Withable.swift */, 5F21D7BE28DCEB3D003E7CD6 /* Useable.swift */, + EAACB8992B927108006A3869 /* Valuing.swift */, 71BFA7092B7F70E6000DCE33 /* Dropshadowable.swift */, ); path = Protocols; @@ -1001,6 +1007,7 @@ EAC9258C2911C9DE00091998 /* InputField.swift in Sources */, EA3362402892EF6C0071C351 /* Label.swift in Sources */, EAB2376229E9880400AABE9A /* TrailingTooltipLabel.swift in Sources */, + EAACB8982B92706F006A3869 /* EnumValuing.swift in Sources */, EAB2376A29E9E59100AABE9A /* TooltipLaunchable.swift in Sources */, EAB2375D29E8789100AABE9A /* Tooltip.swift in Sources */, 71BFA70A2B7F70E6000DCE33 /* Dropshadowable.swift in Sources */, @@ -1016,6 +1023,7 @@ EAF7F0AF289B144C00B287F5 /* UnderlineLabelAttribute.swift in Sources */, EA0D1C412A6AD61C00E5C127 /* Typography+Additional.swift in Sources */, EAC925842911C63100091998 /* Colorable.swift in Sources */, + EAACB89A2B927108006A3869 /* Valuing.swift in Sources */, EAB5FEF5292D371F00998C17 /* ButtonBase.swift in Sources */, EA978EC5291D6AFE00ACC883 /* AnyLabelAttribute.swift in Sources */, EAC71A1F2A2E173D00E47A9F /* RadioButton.swift in Sources */, diff --git a/VDS/Components/TileContainer/TileContainer.swift b/VDS/Components/TileContainer/TileContainer.swift index 98090ae4..27cfa1f4 100644 --- a/VDS/Components/TileContainer/TileContainer.swift +++ b/VDS/Components/TileContainer/TileContainer.swift @@ -11,7 +11,39 @@ import VDSFormControlsTokens import UIKit @objc(VDSTileContainer) -open class TileContainer: Control { +open class TileContainer: TileContainerBase { + + /// Enum used to describe the padding choices used for this component. + public enum Padding: EnumValuing { + case padding2X + case padding4X + case padding6X + case padding8X + case padding12X + case custom(CGFloat) + + public static var defaultValue: Self { .padding4X } + + public var value: CGFloat { + switch self { + case .padding2X: + return VDSLayout.Spacing.space2X.value + case .padding4X: + return VDSLayout.Spacing.space4X.value + case .padding6X: + return VDSLayout.Spacing.space6X.value + case .padding8X: + return VDSLayout.Spacing.space8X.value + case .padding12X: + return VDSLayout.Spacing.space12X.value + case .custom(let padding): + return padding + } + } + } +} + +open class TileContainerBase: Control where PaddingType.ValueType == CGFloat { //-------------------------------------------------- // MARK: - Initializers @@ -53,33 +85,6 @@ open class TileContainer: Control { case gradient(String, String) case none } - - /// Enum used to describe the padding choices used for this component. - public enum Padding { - case padding2X - case padding4X - case padding6X - case padding8X - case padding12X - case custom(CGFloat) - - public var value: CGFloat { - switch self { - case .padding2X: - return VDSLayout.Spacing.space2X.value - case .padding4X: - return VDSLayout.Spacing.space4X.value - case .padding6X: - return VDSLayout.Spacing.space6X.value - case .padding8X: - return VDSLayout.Spacing.space8X.value - case .padding12X: - return VDSLayout.Spacing.space12X.value - case .custom(let padding): - return padding - } - } - } /// Enum used to describe the aspect ratios used for this component. public enum AspectRatio: String, CaseIterable { @@ -130,7 +135,7 @@ open class TileContainer: Control { open var backgroundEffect: BackgroundEffect = .none { didSet { setNeedsUpdate() } } /// Sets the inside padding for the component - open var padding: Padding = .padding4X { didSet { setNeedsUpdate() } } + open var padding: PaddingType = PaddingType.defaultValue { didSet { setNeedsUpdate() } } /// Applies a background color if backgroundImage prop fails or has trouble loading. open var imageFallbackColor: Surface = .light { didSet { setNeedsUpdate() } } @@ -253,7 +258,6 @@ open class TileContainer: Control { super.reset() shouldUpdateView = false color = .white - padding = .padding4X aspectRatio = .ratio1x1 imageFallbackColor = .light width = nil @@ -395,7 +399,7 @@ open class TileContainer: Control { } -extension TileContainer { +extension TileContainerBase { struct DropshadowConfiguration: Dropshadowable { var shadowColorConfiguration: AnyColorable = SurfaceColorConfiguration().with { @@ -408,7 +412,7 @@ extension TileContainer { final class BackgroundColorConfiguration: ObjectColorable { - typealias ObjectType = TileContainer + typealias ObjectType = TileContainerBase let primaryColorConfig = SurfaceColorConfiguration(VDSColor.backgroundPrimaryLight, VDSColor.backgroundPrimaryDark) let secondaryColorConfig = SurfaceColorConfiguration(VDSColor.backgroundSecondaryLight, VDSColor.backgroundSecondaryDark) @@ -418,7 +422,7 @@ extension TileContainer { required init() { } - func getColor(_ object: TileContainer) -> UIColor { + func getColor(_ object: ObjectType) -> UIColor { switch object.color { case .primary: primaryColorConfig.getColor(object.surface) diff --git a/VDS/Components/Tilelet/Tilelet.swift b/VDS/Components/Tilelet/Tilelet.swift index e562ff0a..77d6c70e 100644 --- a/VDS/Components/Tilelet/Tilelet.swift +++ b/VDS/Components/Tilelet/Tilelet.swift @@ -16,7 +16,38 @@ import Combine /// while it can include an arrow CTA, it does not require one in order to /// function. @objc(VDSTilelet) -open class Tilelet: TileContainer { +open class Tilelet: TileContainerBase { + + /// Enum used to describe the padding choices used for this component. + public enum Padding: String, EnumValuing, CaseIterable { + case small + case large + + public static var defaultValue: Self { .large } + + public var value: CGFloat { + switch self { + case .small: + return UIDevice.isIPad ? VDSLayout.Spacing.space3X.value : VDSLayout.Spacing.space4X.value + case .large: + return UIDevice.isIPad ? VDSLayout.Spacing.space4X.value : VDSLayout.Spacing.space6X.value + } + } + + fileprivate var titleLockupBottomSpacing: CGFloat { + switch self.value { + case VDSLayout.Spacing.space3X.value: + return VDSLayout.Spacing.space4X.value + case VDSLayout.Spacing.space4X.value: + return VDSLayout.Spacing.space6X.value + case VDSLayout.Spacing.space4X.value: + return VDSLayout.Spacing.space8X.value + default: + return VDSLayout.Spacing.space4X.value + } + } + } + //-------------------------------------------------- // MARK: - Initializers @@ -303,7 +334,6 @@ open class Tilelet: TileContainer { .pinTop() .pinBottom() - padding = .custom( UIDevice.isIPad ? VDSLayout.Spacing.space6X.value : VDSLayout.Spacing.space4X.value) //If a Tilelet has Badge, Title and Subtitle, then Subtitle will be truncated first and Badge will be truncated second. Title will be truncated last (lowest priority). var labelPriority = UILayoutPriority.defaultHigh.rawValue titleLockup.titleLabel.setContentCompressionResistancePriority(UILayoutPriority(labelPriority), for: .vertical) @@ -456,7 +486,7 @@ open class Tilelet: TileContainer { view = titleLockupContainerView } if let view { - stackView.setCustomSpacing(padding.tiletSpacing, after: view) + stackView.setCustomSpacing(padding.titleLockupBottomSpacing, after: view) } if iconContainerView.superview == nil { stackView.addArrangedSubview(iconContainerView) @@ -505,21 +535,3 @@ extension TitleLockup { return nil } } - -extension TileContainer.Padding { - - fileprivate var tiletSpacing: CGFloat { - switch self { - case .padding4X: - return 24 - case .padding6X: - return 32 - case .custom(let padding): - if padding == VDSLayout.Spacing.space3X.value { - return 16 - } else { fallthrough } - default: - return 16 - } - } -} diff --git a/VDS/Extensions/VDSLayout.swift b/VDS/Extensions/VDSLayout.swift index f30a0635..30df201b 100644 --- a/VDS/Extensions/VDSLayout.swift +++ b/VDS/Extensions/VDSLayout.swift @@ -10,7 +10,9 @@ import Foundation /// Represents constants used that deal with layout. public struct VDSLayout { /// Enum used to describe the spacing constants. - public enum Spacing: String, CaseIterable { + public enum Spacing: String, CaseIterable, EnumValuing { + public static var defaultValue: VDSLayout.Spacing = .space2X + case space1X case space2X case space3X diff --git a/VDS/Protocols/EnumSubset.swift b/VDS/Protocols/EnumSubset.swift index a690fca3..831ce1fb 100644 --- a/VDS/Protocols/EnumSubset.swift +++ b/VDS/Protocols/EnumSubset.swift @@ -7,7 +7,7 @@ import Foundation -public protocol EnumSubset: RawRepresentable, CaseIterable { +public protocol EnumSubset: RawRepresentable, CaseIterable, Valuing { associatedtype T:RawRepresentable var defaultValue: T { get } } diff --git a/VDS/Protocols/EnumValuing.swift b/VDS/Protocols/EnumValuing.swift new file mode 100644 index 00000000..b8f27824 --- /dev/null +++ b/VDS/Protocols/EnumValuing.swift @@ -0,0 +1,12 @@ +// +// EnumValuing.swift +// VDS +// +// Created by Matt Bruce on 3/1/24. +// + +import Foundation + +public protocol EnumValuing: Valuing { + static var defaultValue: Self { get } +} diff --git a/VDS/Protocols/Valuing.swift b/VDS/Protocols/Valuing.swift new file mode 100644 index 00000000..61cea9e8 --- /dev/null +++ b/VDS/Protocols/Valuing.swift @@ -0,0 +1,13 @@ +// +// Valuing.swift +// VDS +// +// Created by Matt Bruce on 3/1/24. +// + +import Foundation + +public protocol Valuing { + associatedtype ValueType + var value: ValueType { get } +}