From d6a2ebaf95f5f955bfdc5a49ebebafa9ffbf7677 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 26 Aug 2022 14:20:07 -0500 Subject: [PATCH 1/6] refactored into extension Signed-off-by: Matt Bruce --- VDS/Classes/ColorConfiguration.swift | 4 ++++ VDS/Components/Checkbox/CheckboxModel.swift | 1 - VDS/Components/RadioBox/RadioBoxModel.swift | 1 - VDS/Components/RadioButton/RadioButtonModel.swift | 1 - 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/VDS/Classes/ColorConfiguration.swift b/VDS/Classes/ColorConfiguration.swift index 43777b4c..65d84f41 100644 --- a/VDS/Classes/ColorConfiguration.swift +++ b/VDS/Classes/ColorConfiguration.swift @@ -17,6 +17,10 @@ public protocol BinaryColorable{ var userTrueColor: Bool { get } } +extension BinaryColorable where Self: Selectable { + public var userTrueColor: Bool { return selected } +} + /// Meant to be used in a Object that implements the following interfaces for 2 possible color combinations /// - Surfaceable (var surface: Surface) /// diff --git a/VDS/Components/Checkbox/CheckboxModel.swift b/VDS/Components/Checkbox/CheckboxModel.swift index f6d76d30..d9720d26 100644 --- a/VDS/Components/Checkbox/CheckboxModel.swift +++ b/VDS/Components/Checkbox/CheckboxModel.swift @@ -16,7 +16,6 @@ public protocol CheckboxModel: Modelable, FormFieldable, Errorable, DataTrackabl } extension CheckboxModel { - public var userTrueColor: Bool { return selected } public var shouldShowError: Bool { guard hasError && !disabled && errorText?.isEmpty == false else { return false } diff --git a/VDS/Components/RadioBox/RadioBoxModel.swift b/VDS/Components/RadioBox/RadioBoxModel.swift index d8f634f5..de8359f7 100644 --- a/VDS/Components/RadioBox/RadioBoxModel.swift +++ b/VDS/Components/RadioBox/RadioBoxModel.swift @@ -19,7 +19,6 @@ public protocol RadioBoxModel: Modelable, FormFieldable, Errorable, DataTrackabl } extension RadioBoxModel { - public var userTrueColor: Bool { return selected } public var shouldShowError: Bool { guard hasError && !disabled && errorText?.isEmpty == false else { return false } diff --git a/VDS/Components/RadioButton/RadioButtonModel.swift b/VDS/Components/RadioButton/RadioButtonModel.swift index 9d1f2d82..6a7567eb 100644 --- a/VDS/Components/RadioButton/RadioButtonModel.swift +++ b/VDS/Components/RadioButton/RadioButtonModel.swift @@ -16,7 +16,6 @@ public protocol RadioButtonModel: Modelable, FormFieldable, Errorable, DataTrack } extension RadioButtonModel { - public var userTrueColor: Bool { return selected } public var shouldShowError: Bool { guard hasError && !disabled && errorText?.isEmpty == false else { return false } From 3b3ea3bece8c24cd31f73ef5c568b468d8bbec79 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Tue, 30 Aug 2022 14:32:06 -0500 Subject: [PATCH 2/6] removed id Signed-off-by: Matt Bruce --- VDS/Components/Checkbox/Checkbox.swift | 3 --- VDS/Components/Checkbox/CheckboxGroup.swift | 2 +- VDS/Components/Checkbox/CheckboxGroupModel.swift | 3 +-- VDS/Components/Checkbox/CheckboxModel.swift | 1 - VDS/Components/RadioBox/RadioBox.swift | 3 --- VDS/Components/RadioBox/RadioBoxGroup.swift | 2 +- VDS/Components/RadioBox/RadioBoxModel.swift | 1 - VDS/Components/RadioButton/RadioButton.swift | 3 --- VDS/Components/RadioButton/RadioButtonGroup.swift | 4 ++-- VDS/Components/RadioButton/RadioButtonModel.swift | 1 - VDS/Components/Toggle/ToggleModel.swift | 1 - VDS/Protocols/FormFieldable.swift | 1 - VDS/Protocols/SelectorGroupModelHandlerable.swift | 8 ++++---- 13 files changed, 9 insertions(+), 24 deletions(-) diff --git a/VDS/Components/Checkbox/Checkbox.swift b/VDS/Components/Checkbox/Checkbox.swift index 803b001d..0ab14b6d 100644 --- a/VDS/Components/Checkbox/Checkbox.swift +++ b/VDS/Components/Checkbox/Checkbox.swift @@ -58,9 +58,6 @@ open class CheckboxBase: Control, Changable public var onChange: Blocks.ActionBlock? - @Proxy(\.model.id) - open var id: UUID - //can't bind to @Proxy open override var isSelected: Bool { get { model.selected } diff --git a/VDS/Components/Checkbox/CheckboxGroup.swift b/VDS/Components/Checkbox/CheckboxGroup.swift index 37a498b9..ded709e2 100644 --- a/VDS/Components/Checkbox/CheckboxGroup.swift +++ b/VDS/Components/Checkbox/CheckboxGroup.swift @@ -82,7 +82,7 @@ public class CheckboxGroup: Control, SelectorGroupMod open override func updateView(viewModel: ModelType) { for selectorModel in viewModel.selectors { //see if view is there for the model - if let foundSelectorView = findSelectorView(id: selectorModel.id) { + if let foundSelectorView = findSelectorView(inputId: selectorModel.inputId) { foundSelectorView.set(with: selectorModel) } else { diff --git a/VDS/Components/Checkbox/CheckboxGroupModel.swift b/VDS/Components/Checkbox/CheckboxGroupModel.swift index 41d4f3f9..75a91dad 100644 --- a/VDS/Components/Checkbox/CheckboxGroupModel.swift +++ b/VDS/Components/Checkbox/CheckboxGroupModel.swift @@ -7,13 +7,12 @@ import Foundation -public protocol CheckboxGroupModel: SelectorGroupModelable where SelectorModelType: CheckboxModel { +public protocol CheckboxGroupModel: SelectorGroupModelable, Errorable where SelectorModelType: CheckboxModel { } public struct DefaultCheckboxGroupModel: CheckboxGroupModel { public typealias SelectorModelType = DefaultCheckboxModel - public var id: UUID = UUID() public var inputId: String? public var value: AnyHashable? public var surface: Surface = .light diff --git a/VDS/Components/Checkbox/CheckboxModel.swift b/VDS/Components/Checkbox/CheckboxModel.swift index d9720d26..b6e3c335 100644 --- a/VDS/Components/Checkbox/CheckboxModel.swift +++ b/VDS/Components/Checkbox/CheckboxModel.swift @@ -64,7 +64,6 @@ extension CheckboxModel { } public struct DefaultCheckboxModel: CheckboxModel { - public var id: UUID = UUID() public var selected: Bool = false public var labelText: String? diff --git a/VDS/Components/RadioBox/RadioBox.swift b/VDS/Components/RadioBox/RadioBox.swift index a649fc41..9134d947 100644 --- a/VDS/Components/RadioBox/RadioBox.swift +++ b/VDS/Components/RadioBox/RadioBox.swift @@ -60,9 +60,6 @@ open class RadioBoxBase: Control, Changable public var onChange: Blocks.ActionBlock? - @Proxy(\.model.id) - open var id: UUID - //can't bind to @Proxy open override var isSelected: Bool { get { model.selected } diff --git a/VDS/Components/RadioBox/RadioBoxGroup.swift b/VDS/Components/RadioBox/RadioBoxGroup.swift index 14f36179..06a79fa5 100644 --- a/VDS/Components/RadioBox/RadioBoxGroup.swift +++ b/VDS/Components/RadioBox/RadioBoxGroup.swift @@ -117,7 +117,7 @@ public class RadioBoxGroup: Control, SelectorGroupSel open override func updateView(viewModel: ModelType) { for selectorModel in viewModel.selectors { //see if view is there for the model - if let foundSelectorView = findSelectorView(id: selectorModel.id) { + if let foundSelectorView = findSelectorView(inputId: selectorModel.inputId) { foundSelectorView.set(with: selectorModel) } else { diff --git a/VDS/Components/RadioBox/RadioBoxModel.swift b/VDS/Components/RadioBox/RadioBoxModel.swift index de8359f7..d09cace9 100644 --- a/VDS/Components/RadioBox/RadioBoxModel.swift +++ b/VDS/Components/RadioBox/RadioBoxModel.swift @@ -74,7 +74,6 @@ extension RadioBoxModel { public struct DefaultRadioBoxModel: RadioBoxModel { - public var id: UUID = UUID() public var selected: Bool = false public var text: String = "Default Text" diff --git a/VDS/Components/RadioButton/RadioButton.swift b/VDS/Components/RadioButton/RadioButton.swift index da887cdb..ac811fdb 100644 --- a/VDS/Components/RadioButton/RadioButton.swift +++ b/VDS/Components/RadioButton/RadioButton.swift @@ -57,9 +57,6 @@ open class RadioButtonBase: Control, Cha public var onChange: Blocks.ActionBlock? - @Proxy(\.model.id) - open var id: UUID - //can't bind to @Proxy open override var isSelected: Bool { get { model.selected } diff --git a/VDS/Components/RadioButton/RadioButtonGroup.swift b/VDS/Components/RadioButton/RadioButtonGroup.swift index 4aef4d8a..64d7341c 100644 --- a/VDS/Components/RadioButton/RadioButtonGroup.swift +++ b/VDS/Components/RadioButton/RadioButtonGroup.swift @@ -86,7 +86,7 @@ public class RadioButtonGroup: Control, SelectorGr } open override func shouldUpdateView(viewModel: ModelType) -> Bool { - let update = viewModel.selectedModel?.id != model.selectedModel?.id + let update = viewModel.selectedModel?.inputId != model.selectedModel?.inputId || viewModel.selectors.count != model.selectors.count || viewModel.hasError != model.hasError || viewModel.surface != model.surface @@ -97,7 +97,7 @@ public class RadioButtonGroup: Control, SelectorGr open override func updateView(viewModel: ModelType) { for selectorModel in viewModel.selectors { //see if view is there for the model - if let foundSelectorView = findSelectorView(id: selectorModel.id) { + if let foundSelectorView = findSelectorView(inputId: selectorModel.inputId) { foundSelectorView.set(with: selectorModel) } else { diff --git a/VDS/Components/RadioButton/RadioButtonModel.swift b/VDS/Components/RadioButton/RadioButtonModel.swift index 6a7567eb..ebaf6e8c 100644 --- a/VDS/Components/RadioButton/RadioButtonModel.swift +++ b/VDS/Components/RadioButton/RadioButtonModel.swift @@ -64,7 +64,6 @@ extension RadioButtonModel { } public struct DefaultRadioButtonModel: RadioButtonModel { - public var id: UUID = UUID() public var selected: Bool = false public var labelText: String? diff --git a/VDS/Components/Toggle/ToggleModel.swift b/VDS/Components/Toggle/ToggleModel.swift index 500c0e84..f851d2c0 100644 --- a/VDS/Components/Toggle/ToggleModel.swift +++ b/VDS/Components/Toggle/ToggleModel.swift @@ -30,7 +30,6 @@ extension ToggleModel { } public struct DefaultToggleModel: ToggleModel { - public var id: UUID = UUID() public var on: Bool = false public var showText: Bool = false public var offText: String = "Off" diff --git a/VDS/Protocols/FormFieldable.swift b/VDS/Protocols/FormFieldable.swift index 356f6e35..41017204 100644 --- a/VDS/Protocols/FormFieldable.swift +++ b/VDS/Protocols/FormFieldable.swift @@ -8,7 +8,6 @@ import Foundation public protocol FormFieldable { - var id: UUID { get set } var inputId: String? { get set } var value: AnyHashable? { get set } } diff --git a/VDS/Protocols/SelectorGroupModelHandlerable.swift b/VDS/Protocols/SelectorGroupModelHandlerable.swift index 02fd2fae..72307e3d 100644 --- a/VDS/Protocols/SelectorGroupModelHandlerable.swift +++ b/VDS/Protocols/SelectorGroupModelHandlerable.swift @@ -17,9 +17,9 @@ public protocol SelectorGroupModelHandlerable: ModelHandlerable, Disabling, Surf extension SelectorGroupModelHandlerable { - public func findSelectorView(id: UUID) -> ModelHandlerType? { + public func findSelectorView(inputId: String?) -> ModelHandlerType? { return selectorViews.first(where: { existingSelectorView in - return existingSelectorView.model.id == id + return existingSelectorView.model.inputId == inputId }) } @@ -51,7 +51,7 @@ extension SelectorGroupModelHandlerable { public func getCachedSelector(viewModel: ModelHandlerType.ModelType) -> ModelHandlerType.ModelType? { if let index = model.selectors.firstIndex(where: { element in - return element.id == viewModel.id + return element.inputId == viewModel.inputId }) { return model.selectors[index] } else { @@ -61,7 +61,7 @@ extension SelectorGroupModelHandlerable { public func replace(viewModel: ModelHandlerType.ModelType){ if let index = model.selectors.firstIndex(where: { element in - return element.id == viewModel.id + return element.inputId == viewModel.inputId }) { model.selectors[index] = viewModel } From 298a170be98ff5188493199258f29359da284ae7 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Tue, 30 Aug 2022 14:34:22 -0500 Subject: [PATCH 3/6] removed id Signed-off-by: Matt Bruce --- VDS/Components/RadioBox/RadioBoxGroupModel.swift | 1 - VDS/Components/RadioButton/RadioButtonGroupModel.swift | 1 - 2 files changed, 2 deletions(-) diff --git a/VDS/Components/RadioBox/RadioBoxGroupModel.swift b/VDS/Components/RadioBox/RadioBoxGroupModel.swift index bb784de7..8919944c 100644 --- a/VDS/Components/RadioBox/RadioBoxGroupModel.swift +++ b/VDS/Components/RadioBox/RadioBoxGroupModel.swift @@ -11,7 +11,6 @@ public protocol RadioBoxGroupModel: SelectorGroupSelectedModelable where Selecto public struct DefaultRadioBoxGroupModel: RadioBoxGroupModel { public typealias SelectorModelType = DefaultRadioBoxModel - public var id: UUID = UUID() public var inputId: String? public var value: AnyHashable? public var surface: Surface = .light diff --git a/VDS/Components/RadioButton/RadioButtonGroupModel.swift b/VDS/Components/RadioButton/RadioButtonGroupModel.swift index 086e1b42..277b47c0 100644 --- a/VDS/Components/RadioButton/RadioButtonGroupModel.swift +++ b/VDS/Components/RadioButton/RadioButtonGroupModel.swift @@ -15,7 +15,6 @@ extension RadioButtonGroupModel { public struct DefaultRadioButtonGroupModel: RadioButtonGroupModel { public typealias SelectorModelType = DefaultRadioButtonModel - public var id: UUID = UUID() public var inputId: String? public var value: AnyHashable? public var surface: Surface = .light From 146829463708d7f927de8e4d6e81c71e191741c1 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 26 Aug 2022 14:19:48 -0500 Subject: [PATCH 4/6] added colorcodable Signed-off-by: Matt Bruce --- VDS.xcodeproj/project.pbxproj | 6 ++- VDS/PropertyWrappers/CodableColor.swift | 57 +++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 VDS/PropertyWrappers/CodableColor.swift diff --git a/VDS.xcodeproj/project.pbxproj b/VDS.xcodeproj/project.pbxproj index cebd999c..05bb03d6 100644 --- a/VDS.xcodeproj/project.pbxproj +++ b/VDS.xcodeproj/project.pbxproj @@ -37,6 +37,7 @@ EA3362452892F9130071C351 /* Labelable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA3362442892F9130071C351 /* Labelable.swift */; }; EA33624728931B050071C351 /* Initable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA33624628931B050071C351 /* Initable.swift */; }; EA3C3B4C2894823E000CA526 /* AnyProxy.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA3C3B4B2894823E000CA526 /* AnyProxy.swift */; }; + EA84F6B128B94A2500D67ABC /* CodableColor.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA84F6B028B94A2500D67ABC /* CodableColor.swift */; }; EA89200228AECF2A006B9984 /* UIButton+Publisher.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA89200128AECF2A006B9984 /* UIButton+Publisher.swift */; }; EA89200428AECF4B006B9984 /* UITextField+Publisher.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA89200328AECF4B006B9984 /* UITextField+Publisher.swift */; }; EA89200628B526D6006B9984 /* CheckboxGroup.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA89200528B526D6006B9984 /* CheckboxGroup.swift */; }; @@ -127,6 +128,7 @@ EA3362442892F9130071C351 /* Labelable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Labelable.swift; sourceTree = ""; }; EA33624628931B050071C351 /* Initable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Initable.swift; sourceTree = ""; }; EA3C3B4B2894823E000CA526 /* AnyProxy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnyProxy.swift; sourceTree = ""; }; + EA84F6B028B94A2500D67ABC /* CodableColor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CodableColor.swift; sourceTree = ""; }; EA89200128AECF2A006B9984 /* UIButton+Publisher.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIButton+Publisher.swift"; sourceTree = ""; }; EA89200328AECF4B006B9984 /* UITextField+Publisher.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UITextField+Publisher.swift"; sourceTree = ""; }; EA89200528B526D6006B9984 /* CheckboxGroup.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CheckboxGroup.swift; sourceTree = ""; }; @@ -385,8 +387,9 @@ isa = PBXGroup; children = ( EA3C3B4B2894823E000CA526 /* AnyProxy.swift */, - EAB1D2A028A598FE00DAE764 /* UsesAutoLayout.swift */, + EA84F6B028B94A2500D67ABC /* CodableColor.swift */, EAB1D2A228A5994800DAE764 /* Debuggable.swift */, + EAB1D2A028A598FE00DAE764 /* UsesAutoLayout.swift */, ); path = PropertyWrappers; sourceTree = ""; @@ -569,6 +572,7 @@ EAF7F11828A1475A00B287F5 /* RadioButtonModel.swift in Sources */, EA89200D28B530FD006B9984 /* RadioBoxModel.swift in Sources */, EA89201328B568D8006B9984 /* RadioBox.swift in Sources */, + EA84F6B128B94A2500D67ABC /* CodableColor.swift in Sources */, EA3362402892EF6C0071C351 /* Label.swift in Sources */, EAF7F0B3289B1ADC00B287F5 /* LabelAttributeAction.swift in Sources */, EA33622E2891EA3C0071C351 /* DispatchQueue+Once.swift in Sources */, diff --git a/VDS/PropertyWrappers/CodableColor.swift b/VDS/PropertyWrappers/CodableColor.swift new file mode 100644 index 00000000..3b046acc --- /dev/null +++ b/VDS/PropertyWrappers/CodableColor.swift @@ -0,0 +1,57 @@ +// +// CodableColor.swift +// VDS +// +// Created by Matt Bruce on 8/26/22. +// + +import Foundation +import UIKit + +@propertyWrapper +public struct CodableColor { + public var wrappedValue: UIColor + + public init(wrappedValue: UIColor) { + self.wrappedValue = wrappedValue + } +} + +extension CodableColor: Codable { + public init(from decoder: Decoder) throws { + let container = try decoder.singleValueContainer() + let colorString = try container.decode(String.self) + wrappedValue = UIColor(hexString: colorString) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.singleValueContainer() + try container.encode(wrappedValue.hexString) + } +} + +@propertyWrapper +public struct OptionalCodableColor { + public var wrappedValue: UIColor? + + public init(wrappedValue: UIColor?) { + self.wrappedValue = wrappedValue + } +} + +extension OptionalCodableColor: Codable { + public init(from decoder: Decoder) throws { + let container = try decoder.singleValueContainer() + if container.decodeNil() { + wrappedValue = nil + } else { + let colorString = try container.decode(String.self) + wrappedValue = UIColor(hexString: colorString) + } + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.singleValueContainer() + try container.encode(wrappedValue?.hexString) + } +} From 2247e529c0874f7960f58310bf4643a62cc26029 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 26 Aug 2022 14:20:24 -0500 Subject: [PATCH 5/6] coverted to colors Signed-off-by: Matt Bruce --- VDS/Components/Label/Attributes/LabelAttributeColor.swift | 6 +++--- VDS/Components/Label/Attributes/LabelAttributeFont.swift | 6 +++--- .../Label/Attributes/LabelAttributeUnderline.swift | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/VDS/Components/Label/Attributes/LabelAttributeColor.swift b/VDS/Components/Label/Attributes/LabelAttributeColor.swift index 59f9727f..977d3c6e 100644 --- a/VDS/Components/Label/Attributes/LabelAttributeColor.swift +++ b/VDS/Components/Label/Attributes/LabelAttributeColor.swift @@ -14,11 +14,11 @@ public struct LabelAttributeColor: LabelAttributeModel { //-------------------------------------------------- public var location: Int public var length: Int - public var color: String + @CodableColor public var color: UIColor //-------------------------------------------------- // MARK: - Initializer //-------------------------------------------------- - public init(location: Int, length: Int, color: String = "#000000") { + public init(location: Int, length: Int, color: UIColor = .black) { self.location = location self.length = length self.color = color @@ -26,6 +26,6 @@ public struct LabelAttributeColor: LabelAttributeModel { public func setAttribute(on attributedString: NSMutableAttributedString) { attributedString.removeAttribute(.foregroundColor, range: range) - attributedString.addAttribute(.foregroundColor, value: UIColor(hexString: color), range: range) + attributedString.addAttribute(.foregroundColor, value: color, range: range) } } diff --git a/VDS/Components/Label/Attributes/LabelAttributeFont.swift b/VDS/Components/Label/Attributes/LabelAttributeFont.swift index 80e773ad..c1dccc53 100644 --- a/VDS/Components/Label/Attributes/LabelAttributeFont.swift +++ b/VDS/Components/Label/Attributes/LabelAttributeFont.swift @@ -15,11 +15,11 @@ public struct LabelAttributeFont: LabelAttributeModel { public var location: Int public var length: Int public var style: TypographicalStyle - public var color: String + @CodableColor public var color: UIColor //-------------------------------------------------- // MARK: - Initializer //-------------------------------------------------- - public init(location: Int, length: Int, style: TypographicalStyle, color: String = "#000000") { + public init(location: Int, length: Int, style: TypographicalStyle, color: UIColor = .black) { self.location = location self.length = length self.style = style @@ -31,6 +31,6 @@ public struct LabelAttributeFont: LabelAttributeModel { attributedString.removeAttribute(.font, range: range) attributedString.removeAttribute(.foregroundColor, range: range) attributedString.addAttribute(.font, value: style.font, range: range) - attributedString.addAttribute(.foregroundColor, value: UIColor(hexString: color), range: range) + attributedString.addAttribute(.foregroundColor, value: color, range: range) } } diff --git a/VDS/Components/Label/Attributes/LabelAttributeUnderline.swift b/VDS/Components/Label/Attributes/LabelAttributeUnderline.swift index f904d52b..83a19a37 100644 --- a/VDS/Components/Label/Attributes/LabelAttributeUnderline.swift +++ b/VDS/Components/Label/Attributes/LabelAttributeUnderline.swift @@ -11,7 +11,7 @@ import UIKit public struct LabelAttributeUnderline: LabelAttributeModel { public var location: Int public var length: Int - public var color: String? + @OptionalCodableColor public var color: UIColor? public var style: UnderlineStyle = .single public var pattern: UnderlineStyle.Pattern? @@ -23,7 +23,7 @@ public struct LabelAttributeUnderline: LabelAttributeModel { } } - public init(location: Int, length: Int, style: UnderlineStyle = .single, color: String? = nil, pattern: UnderlineStyle.Pattern? = nil) { + public init(location: Int, length: Int, style: UnderlineStyle = .single, color: UIColor = .black, pattern: UnderlineStyle.Pattern? = nil) { self.location = location self.length = length self.color = color @@ -34,7 +34,7 @@ public struct LabelAttributeUnderline: LabelAttributeModel { public func setAttribute(on attributedString: NSMutableAttributedString) { attributedString.addAttribute(.underlineStyle, value: underlineValue.rawValue, range: range) if let color = color { - attributedString.addAttribute(.underlineColor, value: UIColor(hexString: color), range: range) + attributedString.addAttribute(.underlineColor, value: color, range: range) } } } From d87adf477c2ef82e263ddd939b84a21e540f4245 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Tue, 30 Aug 2022 14:46:15 -0500 Subject: [PATCH 6/6] updated to remove codable Signed-off-by: Matt Bruce --- VDS/Components/Label/Attributes/LabelAttributeColor.swift | 2 +- VDS/Components/Label/Attributes/LabelAttributeFont.swift | 2 +- VDS/Components/Label/Attributes/LabelAttributeModel.swift | 2 +- VDS/Components/Label/Attributes/LabelAttributeUnderline.swift | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/VDS/Components/Label/Attributes/LabelAttributeColor.swift b/VDS/Components/Label/Attributes/LabelAttributeColor.swift index 977d3c6e..b04a0e5a 100644 --- a/VDS/Components/Label/Attributes/LabelAttributeColor.swift +++ b/VDS/Components/Label/Attributes/LabelAttributeColor.swift @@ -14,7 +14,7 @@ public struct LabelAttributeColor: LabelAttributeModel { //-------------------------------------------------- public var location: Int public var length: Int - @CodableColor public var color: UIColor + public var color: UIColor //-------------------------------------------------- // MARK: - Initializer //-------------------------------------------------- diff --git a/VDS/Components/Label/Attributes/LabelAttributeFont.swift b/VDS/Components/Label/Attributes/LabelAttributeFont.swift index c1dccc53..767f5270 100644 --- a/VDS/Components/Label/Attributes/LabelAttributeFont.swift +++ b/VDS/Components/Label/Attributes/LabelAttributeFont.swift @@ -15,7 +15,7 @@ public struct LabelAttributeFont: LabelAttributeModel { public var location: Int public var length: Int public var style: TypographicalStyle - @CodableColor public var color: UIColor + public var color: UIColor //-------------------------------------------------- // MARK: - Initializer //-------------------------------------------------- diff --git a/VDS/Components/Label/Attributes/LabelAttributeModel.swift b/VDS/Components/Label/Attributes/LabelAttributeModel.swift index 0341b477..75e14f69 100644 --- a/VDS/Components/Label/Attributes/LabelAttributeModel.swift +++ b/VDS/Components/Label/Attributes/LabelAttributeModel.swift @@ -8,7 +8,7 @@ import Foundation import UIKit -public protocol LabelAttributeModel: Codable { +public protocol LabelAttributeModel { var location: Int { get set } var length: Int { get set } func setAttribute(on attributedString: NSMutableAttributedString) diff --git a/VDS/Components/Label/Attributes/LabelAttributeUnderline.swift b/VDS/Components/Label/Attributes/LabelAttributeUnderline.swift index 83a19a37..f7784711 100644 --- a/VDS/Components/Label/Attributes/LabelAttributeUnderline.swift +++ b/VDS/Components/Label/Attributes/LabelAttributeUnderline.swift @@ -11,7 +11,7 @@ import UIKit public struct LabelAttributeUnderline: LabelAttributeModel { public var location: Int public var length: Int - @OptionalCodableColor public var color: UIColor? + public var color: UIColor? public var style: UnderlineStyle = .single public var pattern: UnderlineStyle.Pattern?