From 1c0b8bbf459e41272020e97e7e705e9e7fab78a6 Mon Sep 17 00:00:00 2001 From: Krishna Kishore Bandaru Date: Tue, 5 Mar 2024 17:49:25 +0530 Subject: [PATCH] Addressed review comments --- VDS.xcodeproj/project.pbxproj | 8 +++ .../Icon/ButtonIcon/ButtonIcon.swift | 36 +++++------ VDS/Protocols/DropShadowable.swift | 64 ++++++------------- VDS/Utilities/DropShadowConfiguration.swift | 33 ++++++++++ VDS/Utilities/SurfaceConfigurationValue.swift | 31 +++++++++ 5 files changed, 110 insertions(+), 62 deletions(-) create mode 100644 VDS/Utilities/DropShadowConfiguration.swift create mode 100644 VDS/Utilities/SurfaceConfigurationValue.swift diff --git a/VDS.xcodeproj/project.pbxproj b/VDS.xcodeproj/project.pbxproj index 2b87c3c7..b6a3d192 100644 --- a/VDS.xcodeproj/project.pbxproj +++ b/VDS.xcodeproj/project.pbxproj @@ -18,6 +18,8 @@ 7115BD3C2B84C0C200E0A610 /* TileContainerChangeLog.txt in Resources */ = {isa = PBXBuildFile; fileRef = 7115BD3B2B84C0C200E0A610 /* TileContainerChangeLog.txt */; }; 71BFA70A2B7F70E6000DCE33 /* DropShadowable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 71BFA7092B7F70E6000DCE33 /* DropShadowable.swift */; }; 71C02B382B7BD98F00E93E66 /* NotificationChangeLog.txt in Resources */ = {isa = PBXBuildFile; fileRef = 71C02B372B7BD98F00E93E66 /* NotificationChangeLog.txt */; }; + 71FC86DE2B9738B900700965 /* SurfaceConfigurationValue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 71FC86DD2B9738B900700965 /* SurfaceConfigurationValue.swift */; }; + 71FC86E02B973AE500700965 /* DropShadowConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 71FC86DF2B973AE500700965 /* DropShadowConfiguration.swift */; }; EA0B18022A9E236900F2D0CD /* SelectorGroupBase.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA0B18012A9E236900F2D0CD /* SelectorGroupBase.swift */; }; EA0B18052A9E2D2D00F2D0CD /* SelectorBase.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA0B18032A9E2D2D00F2D0CD /* SelectorBase.swift */; }; EA0B18062A9E2D2D00F2D0CD /* SelectorItemBase.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA0B18042A9E2D2D00F2D0CD /* SelectorItemBase.swift */; }; @@ -186,6 +188,8 @@ 7115BD3B2B84C0C200E0A610 /* TileContainerChangeLog.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = TileContainerChangeLog.txt; sourceTree = ""; }; 71BFA7092B7F70E6000DCE33 /* DropShadowable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DropShadowable.swift; sourceTree = ""; }; 71C02B372B7BD98F00E93E66 /* NotificationChangeLog.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = NotificationChangeLog.txt; sourceTree = ""; }; + 71FC86DD2B9738B900700965 /* SurfaceConfigurationValue.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SurfaceConfigurationValue.swift; sourceTree = ""; }; + 71FC86DF2B973AE500700965 /* DropShadowConfiguration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DropShadowConfiguration.swift; sourceTree = ""; }; EA0B18012A9E236900F2D0CD /* SelectorGroupBase.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SelectorGroupBase.swift; sourceTree = ""; }; EA0B18032A9E2D2D00F2D0CD /* SelectorBase.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SelectorBase.swift; sourceTree = ""; }; EA0B18042A9E2D2D00F2D0CD /* SelectorItemBase.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SelectorItemBase.swift; sourceTree = ""; }; @@ -583,6 +587,8 @@ isa = PBXGroup; children = ( EA3361BC288B2C760071C351 /* TypeAlias.swift */, + 71FC86DD2B9738B900700965 /* SurfaceConfigurationValue.swift */, + 71FC86DF2B973AE500700965 /* DropShadowConfiguration.swift */, ); path = Utilities; sourceTree = ""; @@ -1031,6 +1037,7 @@ EAC846F3294B95CE00F685BA /* ButtonGroupCollectionViewCell.swift in Sources */, EAF7F0952899861000B287F5 /* CheckboxItem.swift in Sources */, EA985BE82968951C00F2FF2E /* TileletTitleModel.swift in Sources */, + 71FC86DE2B9738B900700965 /* SurfaceConfigurationValue.swift in Sources */, EA297A5529FB07760031ED56 /* TooltipLabelAttribute.swift in Sources */, EA985BEA29689B6D00F2FF2E /* TileletSubTitleModel.swift in Sources */, EA3361C9289054C50071C351 /* Surfaceable.swift in Sources */, @@ -1101,6 +1108,7 @@ EAB2376829E9992800AABE9A /* TooltipAlertViewController.swift in Sources */, EA33623E2892EE950071C351 /* UIDevice.swift in Sources */, EA985C692971B90B00F2FF2E /* IconSize.swift in Sources */, + 71FC86E02B973AE500700965 /* DropShadowConfiguration.swift in Sources */, EA985C672970C21600F2FF2E /* VDSLayout.swift in Sources */, EA3362302891EB4A0071C351 /* Font.swift in Sources */, EAF7F0AD289B142900B287F5 /* StrikeThroughLabelAttribute.swift in Sources */, diff --git a/VDS/Components/Icon/ButtonIcon/ButtonIcon.swift b/VDS/Components/Icon/ButtonIcon/ButtonIcon.swift index f998c28c..65968214 100644 --- a/VDS/Components/Icon/ButtonIcon/ButtonIcon.swift +++ b/VDS/Components/Icon/ButtonIcon/ButtonIcon.swift @@ -241,15 +241,15 @@ open class ButtonIcon: Control, Changeable, FormFieldable { }() private let dropshadow1Configuration = DropShadowConfiguration().with { $0.shadowColorConfiguration = SurfaceColorConfiguration(VDSColor.paletteBlack, VDSColor.paletteBlack).eraseToAnyColorable() - $0.shadowOpacityConfiguration = AnyConfigurationValue(CGFloat(0.12), CGFloat(0.22)) - $0.shadowOffsetConfiguration = AnyConfigurationValue(.init(width: 0, height: 1), .init(width: 0, height: 1)) - $0.shadowRadiusConfiguration = AnyConfigurationValue(CGFloat(10), CGFloat(12)) + $0.shadowOpacityConfiguration = SurfaceConfigurationValue(CGFloat(0.12), CGFloat(0.22)) + $0.shadowOffsetConfiguration = SurfaceConfigurationValue(.init(width: 0, height: 1), .init(width: 0, height: 1)) + $0.shadowRadiusConfiguration = SurfaceConfigurationValue(CGFloat(10), CGFloat(12)) } private let dropshadow2Configuration = DropShadowConfiguration().with { $0.shadowColorConfiguration = SurfaceColorConfiguration(VDSColor.paletteBlack, VDSColor.paletteBlack).eraseToAnyColorable() - $0.shadowOpacityConfiguration = AnyConfigurationValue(CGFloat(0.05), CGFloat(0.15)) - $0.shadowOffsetConfiguration = AnyConfigurationValue(.init(width: 0, height: 2), .init(width: 0, height: 2)) - $0.shadowRadiusConfiguration = AnyConfigurationValue(CGFloat(4), CGFloat(6)) + $0.shadowOpacityConfiguration = SurfaceConfigurationValue(CGFloat(0.05), CGFloat(0.15)) + $0.shadowOffsetConfiguration = SurfaceConfigurationValue(.init(width: 0, height: 2), .init(width: 0, height: 2)) + $0.shadowRadiusConfiguration = SurfaceConfigurationValue(CGFloat(4), CGFloat(6)) } var configurations: [DropShadowable] { [dropshadow1Configuration, dropshadow2Configuration] } } @@ -276,15 +276,15 @@ open class ButtonIcon: Control, Changeable, FormFieldable { }() private let dropshadow1Configuration = DropShadowConfiguration().with { $0.shadowColorConfiguration = SurfaceColorConfiguration(VDSColor.paletteBlack, VDSColor.paletteBlack).eraseToAnyColorable() - $0.shadowOpacityConfiguration = AnyConfigurationValue(CGFloat(0.12), CGFloat(0.22)) - $0.shadowOffsetConfiguration = AnyConfigurationValue(.init(width: 0, height: 1), .init(width: 0, height: 1)) - $0.shadowRadiusConfiguration = AnyConfigurationValue(CGFloat(10), CGFloat(12)) + $0.shadowOpacityConfiguration = SurfaceConfigurationValue(CGFloat(0.12), CGFloat(0.22)) + $0.shadowOffsetConfiguration = SurfaceConfigurationValue(.init(width: 0, height: 1), .init(width: 0, height: 1)) + $0.shadowRadiusConfiguration = SurfaceConfigurationValue(CGFloat(10), CGFloat(12)) } private let dropshadow2Configuration = DropShadowConfiguration().with { $0.shadowColorConfiguration = SurfaceColorConfiguration(VDSColor.paletteBlack, VDSColor.paletteBlack).eraseToAnyColorable() - $0.shadowOpacityConfiguration = AnyConfigurationValue(CGFloat(0.05), CGFloat(0.15)) - $0.shadowOffsetConfiguration = AnyConfigurationValue(.init(width: 0, height: 2), .init(width: 0, height: 2)) - $0.shadowRadiusConfiguration = AnyConfigurationValue(CGFloat(4), CGFloat(6)) + $0.shadowOpacityConfiguration = SurfaceConfigurationValue(CGFloat(0.05), CGFloat(0.15)) + $0.shadowOffsetConfiguration = SurfaceConfigurationValue(.init(width: 0, height: 2), .init(width: 0, height: 2)) + $0.shadowRadiusConfiguration = SurfaceConfigurationValue(CGFloat(4), CGFloat(6)) } var configurations: [DropShadowable] { [dropshadow1Configuration, dropshadow2Configuration] } } @@ -321,15 +321,15 @@ open class ButtonIcon: Control, Changeable, FormFieldable { }() private let dropshadow1Configuration = DropShadowConfiguration().with { $0.shadowColorConfiguration = SurfaceColorConfiguration(VDSColor.paletteBlack, VDSColor.paletteBlack).eraseToAnyColorable() - $0.shadowOpacityConfiguration = AnyConfigurationValue(CGFloat(0.22), CGFloat(0.12)) - $0.shadowOffsetConfiguration = AnyConfigurationValue(.init(width: 0, height: 1), .init(width: 0, height: 1)) - $0.shadowRadiusConfiguration = AnyConfigurationValue(CGFloat(12), CGFloat(10)) + $0.shadowOpacityConfiguration = SurfaceConfigurationValue(CGFloat(0.22), CGFloat(0.12)) + $0.shadowOffsetConfiguration = SurfaceConfigurationValue(.init(width: 0, height: 1), .init(width: 0, height: 1)) + $0.shadowRadiusConfiguration = SurfaceConfigurationValue(CGFloat(12), CGFloat(10)) } private let dropshadow2Configuration = DropShadowConfiguration().with { $0.shadowColorConfiguration = SurfaceColorConfiguration(VDSColor.paletteBlack, VDSColor.paletteBlack).eraseToAnyColorable() - $0.shadowOpacityConfiguration = AnyConfigurationValue(CGFloat(0.15), CGFloat(0.05)) - $0.shadowOffsetConfiguration = AnyConfigurationValue(.init(width: 0, height: 2), .init(width: 0, height: 2)) - $0.shadowRadiusConfiguration = AnyConfigurationValue(CGFloat(6), CGFloat(4)) + $0.shadowOpacityConfiguration = SurfaceConfigurationValue(CGFloat(0.15), CGFloat(0.05)) + $0.shadowOffsetConfiguration = SurfaceConfigurationValue(.init(width: 0, height: 2), .init(width: 0, height: 2)) + $0.shadowRadiusConfiguration = SurfaceConfigurationValue(CGFloat(6), CGFloat(4)) } var configurations: [DropShadowable] { [dropshadow1Configuration, dropshadow2Configuration] } } diff --git a/VDS/Protocols/DropShadowable.swift b/VDS/Protocols/DropShadowable.swift index 57c44036..b569ecab 100644 --- a/VDS/Protocols/DropShadowable.swift +++ b/VDS/Protocols/DropShadowable.swift @@ -8,37 +8,32 @@ import Foundation import UIKit +/** + DropShadowable protocol helps with the configuration values for adding drop shadows for light & dark surfaces. +*/ protocol DropShadowable { - + ///Shadow Color configuration for light and dark surfaces var shadowColorConfiguration: AnyColorable { get set } - var shadowOpacityConfiguration: AnyConfigurationValue { get set } - var shadowOffsetConfiguration: AnyConfigurationValue { get set } - var shadowRadiusConfiguration: AnyConfigurationValue { get set } + ///Shadow Opacity configuration for light and dark surfaces + var shadowOpacityConfiguration: SurfaceConfigurationValue { get set } + ///Shadow Offset configuration for light and dark surfaces + var shadowOffsetConfiguration: SurfaceConfigurationValue { get set } + ///Shadow Radius configuration for light and dark surfaces + var shadowRadiusConfiguration: SurfaceConfigurationValue { get set } } +/** + DropShadowableConfiguration protocol helps with multiple drop shadows configurations can be added to a view. + */ protocol DropShadowableConfiguration { + ///Configurations are the DropShadowable list, these are applied on the view var configurations: [DropShadowable] { get } } -final class DropShadowConfiguration: DropShadowable, ObjectWithable { - - typealias CGFloatConfigurationValue = AnyConfigurationValue - typealias CGSizeConfigurationValue = AnyConfigurationValue - - var shadowColorConfiguration: AnyColorable - var shadowOpacityConfiguration: CGFloatConfigurationValue - var shadowOffsetConfiguration: CGSizeConfigurationValue - var shadowRadiusConfiguration: CGFloatConfigurationValue - - init(shadowColorConfiguration: AnyColorable = SurfaceColorConfiguration().eraseToAnyColorable(), shadowOpacity: CGFloatConfigurationValue = CGFloatConfigurationValue(1.0, 1.0), shadowOffset: CGSizeConfigurationValue = CGSizeConfigurationValue(.zero, .zero), shadowRadius: CGFloatConfigurationValue = CGFloatConfigurationValue(1.0, 1.0)) { - self.shadowColorConfiguration = shadowColorConfiguration - self.shadowOpacityConfiguration = shadowOpacity - self.shadowOffsetConfiguration = shadowOffset - self.shadowRadiusConfiguration = shadowRadius - } -} - +/** + Extension on ViewProtocol for adding drop shadows & gradient layer on view. + */ extension ViewProtocol where Self: UIView { func addDropShadow(_ config: DropShadowable) { @@ -58,9 +53,9 @@ extension ViewProtocol where Self: UIView { shadowLayer.backgroundColor = backgroundColor?.cgColor shadowLayer.cornerRadius = layer.cornerRadius shadowLayer.shadowColor = config.shadowColorConfiguration.getColor(self).cgColor - shadowLayer.shadowOpacity = Float(config.shadowOpacityConfiguration.getValue(self)) - shadowLayer.shadowOffset = config.shadowOffsetConfiguration.getValue(self) - shadowLayer.shadowRadius = config.shadowRadiusConfiguration.getValue(self) + shadowLayer.shadowOpacity = Float(config.shadowOpacityConfiguration.value(for: self)) + shadowLayer.shadowOffset = config.shadowOffsetConfiguration.value(for: self) + shadowLayer.shadowRadius = config.shadowRadiusConfiguration.value(for: self) shadowLayer.name = "dropShadowLayer" shadowLayer.shouldRasterize = true shadowLayer.rasterizationScale = UIScreen.main.scale @@ -92,22 +87,3 @@ extension ViewProtocol where Self: UIView { layer.sublayers?.removeAll { $0.name == "gradientLayer" } } } - -final class AnyConfigurationValue { - - var lightValue: ValueType - var darkValue: ValueType - - public init(_ lightValue: ValueType = ValueType.self, _ darkValue: ValueType = ValueType.self) { - self.lightValue = lightValue - self.darkValue = darkValue - } - - public func getValue(_ object: Any) -> ValueType { - guard let surfaceable = object as? Surfaceable else { - assertionFailure("Self doesn't confirms to Surfaceable") - return lightValue - } - return surfaceable.surface == .light ? lightValue : darkValue - } -} diff --git a/VDS/Utilities/DropShadowConfiguration.swift b/VDS/Utilities/DropShadowConfiguration.swift new file mode 100644 index 00000000..e0cc3dd8 --- /dev/null +++ b/VDS/Utilities/DropShadowConfiguration.swift @@ -0,0 +1,33 @@ +// +// DropShadowConfiguration.swift +// VDS +// +// Created by Bandaru, Krishna Kishore on 05/03/24. +// + +import Foundation + +/** + DropShadowConfiguration confirms to DropShadowable where it has configurable properties required for drop shadow +*/ +final class DropShadowConfiguration: DropShadowable, ObjectWithable { + + typealias CGFloatConfigurationValue = SurfaceConfigurationValue + typealias CGSizeConfigurationValue = SurfaceConfigurationValue + + ///Shadow Color configuration for light and dark surfaces + var shadowColorConfiguration: AnyColorable + ///Shadow Opacity configuration for light and dark surfaces + var shadowOpacityConfiguration: CGFloatConfigurationValue + ///Shadow Offset configuration for light and dark surfaces + var shadowOffsetConfiguration: CGSizeConfigurationValue + ///Shadow Radius configuration for light and dark surfaces + var shadowRadiusConfiguration: CGFloatConfigurationValue + + init(shadowColorConfiguration: AnyColorable = SurfaceColorConfiguration().eraseToAnyColorable(), shadowOpacity: CGFloatConfigurationValue = CGFloatConfigurationValue(1.0, 1.0), shadowOffset: CGSizeConfigurationValue = CGSizeConfigurationValue(.zero, .zero), shadowRadius: CGFloatConfigurationValue = CGFloatConfigurationValue(1.0, 1.0)) { + self.shadowColorConfiguration = shadowColorConfiguration + self.shadowOpacityConfiguration = shadowOpacity + self.shadowOffsetConfiguration = shadowOffset + self.shadowRadiusConfiguration = shadowRadius + } +} diff --git a/VDS/Utilities/SurfaceConfigurationValue.swift b/VDS/Utilities/SurfaceConfigurationValue.swift new file mode 100644 index 00000000..1b304d2a --- /dev/null +++ b/VDS/Utilities/SurfaceConfigurationValue.swift @@ -0,0 +1,31 @@ +// +// SurfaceConfigurationValue.swift +// VDS +// +// Created by Bandaru, Krishna Kishore on 05/03/24. +// + +import Foundation + +/** +SurfaceConfiguration is a type that holds the generic datatype for light surface & dark surface and returns the value based on the surface. +*/ +struct SurfaceConfigurationValue { + + var lightValue: ValueType + var darkValue: ValueType + + public init(_ lightValue: ValueType, _ darkValue: ValueType) { + self.lightValue = lightValue + self.darkValue = darkValue + } + + public init(value: ValueType) { + self.lightValue = value + self.darkValue = value + } + + public func value(for object: Surfaceable) -> ValueType { + object.surface == .light ? lightValue : darkValue + } +}