From d61f60cc21445c91e1bcf8aeda3ef03b211c8d5e Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Tue, 26 Jul 2022 12:04:41 -0500 Subject: [PATCH] refactored more of the toggle Signed-off-by: Matt Bruce --- VDS.xcodeproj/project.pbxproj | 16 +++++---- VDS/Components/Toggle/VDSToggle.swift | 10 +++--- ...delProtocol.swift => VDSToggleModel.swift} | 4 +-- VDS/Extensions/UIColor.swift | 34 +++++++++++++++++++ VDS/Protocols/Surfaceable.swift | 16 +++++++++ 5 files changed, 67 insertions(+), 13 deletions(-) rename VDS/Components/Toggle/{ToggleModelProtocol.swift => VDSToggleModel.swift} (55%) create mode 100644 VDS/Protocols/Surfaceable.swift diff --git a/VDS.xcodeproj/project.pbxproj b/VDS.xcodeproj/project.pbxproj index d450dc75..a1c17e88 100644 --- a/VDS.xcodeproj/project.pbxproj +++ b/VDS.xcodeproj/project.pbxproj @@ -13,7 +13,7 @@ EA33617D288B19210071C351 /* VDS.h in Headers */ = {isa = PBXBuildFile; fileRef = EA33616F288B19200071C351 /* VDS.h */; settings = {ATTRIBUTES = (Public, ); }; }; EA336195288B1C420071C351 /* VDSColorTokens.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = EA33618E288B1C0C0071C351 /* VDSColorTokens.xcframework */; }; EA336197288B1C420071C351 /* VDSFormControlsTokens.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = EA33618F288B1C0C0071C351 /* VDSFormControlsTokens.xcframework */; }; - EA3361A2288B1E840071C351 /* ToggleModelProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA3361A1288B1E840071C351 /* ToggleModelProtocol.swift */; }; + EA3361A2288B1E840071C351 /* VDSToggleModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA3361A1288B1E840071C351 /* VDSToggleModel.swift */; }; EA3361A8288B23300071C351 /* UIColor.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA3361A7288B23300071C351 /* UIColor.swift */; }; EA3361AA288B25E40071C351 /* Disabling.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA3361A9288B25E40071C351 /* Disabling.swift */; }; EA3361AD288B26190071C351 /* DataTrackable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA3361AC288B26190071C351 /* DataTrackable.swift */; }; @@ -26,6 +26,7 @@ EA3361BF288B2EA60071C351 /* Modelable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA3361BE288B2EA60071C351 /* Modelable.swift */; }; EA3361C328902D960071C351 /* VDSToggle.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA3361C228902D960071C351 /* VDSToggle.swift */; }; EA3361C5289030FC0071C351 /* Accessable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA3361C4289030FC0071C351 /* Accessable.swift */; }; + EA3361C9289054C50071C351 /* Surfaceable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA3361C8289054C50071C351 /* Surfaceable.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -46,7 +47,7 @@ EA33617B288B19210071C351 /* VDSTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VDSTests.swift; sourceTree = ""; }; EA33618E288B1C0C0071C351 /* VDSColorTokens.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = VDSColorTokens.xcframework; path = "/Users/mattbruce/Documents/Projects/iPhone/Frameworks/MVA-JSONCreator/JSONCreator_iOS/../SharedFrameworks/VDSColorTokens.xcframework"; sourceTree = ""; }; EA33618F288B1C0C0071C351 /* VDSFormControlsTokens.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = VDSFormControlsTokens.xcframework; path = "/Users/mattbruce/Documents/Projects/iPhone/Frameworks/MVA-JSONCreator/JSONCreator_iOS/../SharedFrameworks/VDSFormControlsTokens.xcframework"; sourceTree = ""; }; - EA3361A1288B1E840071C351 /* ToggleModelProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ToggleModelProtocol.swift; sourceTree = ""; }; + EA3361A1288B1E840071C351 /* VDSToggleModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VDSToggleModel.swift; sourceTree = ""; }; EA3361A7288B23300071C351 /* UIColor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIColor.swift; sourceTree = ""; }; EA3361A9288B25E40071C351 /* Disabling.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Disabling.swift; sourceTree = ""; }; EA3361AC288B26190071C351 /* DataTrackable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataTrackable.swift; sourceTree = ""; }; @@ -59,6 +60,7 @@ EA3361BE288B2EA60071C351 /* Modelable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Modelable.swift; sourceTree = ""; }; EA3361C228902D960071C351 /* VDSToggle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VDSToggle.swift; sourceTree = ""; }; EA3361C4289030FC0071C351 /* Accessable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Accessable.swift; sourceTree = ""; }; + EA3361C8289054C50071C351 /* Surfaceable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Surfaceable.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -144,7 +146,7 @@ isa = PBXGroup; children = ( EA3361C228902D960071C351 /* VDSToggle.swift */, - EA3361A1288B1E840071C351 /* ToggleModelProtocol.swift */, + EA3361A1288B1E840071C351 /* VDSToggleModel.swift */, ); path = Toggle; sourceTree = ""; @@ -160,14 +162,15 @@ EA3361AB288B25EC0071C351 /* Protocols */ = { isa = PBXGroup; children = ( + EA3361C4289030FC0071C351 /* Accessable.swift */, EA3361B2288B265D0071C351 /* Changable.swift */, EA3361AC288B26190071C351 /* DataTrackable.swift */, EA3361A9288B25E40071C351 /* Disabling.swift */, EA3361AE288B26310071C351 /* FormFieldable.swift */, EA3361B0288B26490071C351 /* Invertable.swift */, - EA3361B7288B2AAA0071C351 /* ViewProtocol.swift */, EA3361BE288B2EA60071C351 /* Modelable.swift */, - EA3361C4289030FC0071C351 /* Accessable.swift */, + EA3361C8289054C50071C351 /* Surfaceable.swift */, + EA3361B7288B2AAA0071C351 /* ViewProtocol.swift */, ); path = Protocols; sourceTree = ""; @@ -299,7 +302,8 @@ files = ( EA3361C328902D960071C351 /* VDSToggle.swift in Sources */, EA3361C5289030FC0071C351 /* Accessable.swift in Sources */, - EA3361A2288B1E840071C351 /* ToggleModelProtocol.swift in Sources */, + EA3361C9289054C50071C351 /* Surfaceable.swift in Sources */, + EA3361A2288B1E840071C351 /* VDSToggleModel.swift in Sources */, EA3361BD288B2C760071C351 /* TypeAlias.swift in Sources */, EA3361AF288B26310071C351 /* FormFieldable.swift in Sources */, EA3361B3288B265D0071C351 /* Changable.swift in Sources */, diff --git a/VDS/Components/Toggle/VDSToggle.swift b/VDS/Components/Toggle/VDSToggle.swift index 67fa9231..bfb0b919 100644 --- a/VDS/Components/Toggle/VDSToggle.swift +++ b/VDS/Components/Toggle/VDSToggle.swift @@ -16,19 +16,19 @@ import VDSColorTokens Container: The background of the toggle control. Knob: The circular indicator that slides on the container. */ -@objcMembers open class VDSToggle: Control, Changable { +@objcMembers open class VDSToggle: Control, Changable { //-------------------------------------------------- // MARK: - Properties //-------------------------------------------------- /// Holds the on and off colors for the container. - public var containerTintColor: (on: UIColor, off: UIColor) = (on: .green, off: .black) + public var containerTintColor: (on: UIColor, off: UIColor) = (on: VDSColor.paletteGreen26, off: VDSColor.paletteGray44) /// Holds the on and off colors for the knob. - public var knobTintColor: (on: UIColor, off: UIColor) = (on: .white, off: .white) + public var knobTintColor: (on: UIColor, off: UIColor) = (on: VDSColor.paletteWhite, off: VDSColor.paletteWhite) /// Holds the on and off colors for the disabled state.. - public var disabledTintColor: (container: UIColor, knob: UIColor) = (container: .gray, knob: .white) + public var disabledTintColor: (container: UIColor, knob: UIColor) = (container: VDSColor.paletteGray11, knob: VDSColor.paletteWhite) /// Set this flag to false if you do not want to animate state changes. public var isAnimated = true @@ -202,7 +202,7 @@ import VDSColorTokens knobView.centerYAnchor.constraint(equalTo: centerYAnchor).isActive = true knobView.topAnchor.constraint(greaterThanOrEqualTo: topAnchor).isActive = true bottomAnchor.constraint(greaterThanOrEqualTo: knobView.bottomAnchor).isActive = true - + constrainKnobOff() } diff --git a/VDS/Components/Toggle/ToggleModelProtocol.swift b/VDS/Components/Toggle/VDSToggleModel.swift similarity index 55% rename from VDS/Components/Toggle/ToggleModelProtocol.swift rename to VDS/Components/Toggle/VDSToggleModel.swift index 11f3a25e..5385a01d 100644 --- a/VDS/Components/Toggle/ToggleModelProtocol.swift +++ b/VDS/Components/Toggle/VDSToggleModel.swift @@ -8,8 +8,8 @@ import Foundation import UIKit -public protocol ToggleModelProtocol: Invertable, FormFieldable, DataTrackable, Disabling, Accessable { +public protocol VDSToggleModel: Surfaceable, FormFieldable, DataTrackable, Disabling, Accessable { var id: String? { get set } - var hideText: Bool { get set } + var showText: Bool { get set } var on: Bool { get set } } diff --git a/VDS/Extensions/UIColor.swift b/VDS/Extensions/UIColor.swift index c967caca..66142845 100644 --- a/VDS/Extensions/UIColor.swift +++ b/VDS/Extensions/UIColor.swift @@ -109,5 +109,39 @@ extension UIColor { return nil } + + /// - parameter color: The UIColor intended to retrieve its hex value. + public var hexString: String? { + + guard let components = cgColor.components else { return nil } + + let numberOfComponents = cgColor.numberOfComponents + if numberOfComponents >= 3 { + // RGB color space + let r = Int(CGFloat(components[0]) * 255) + let g = Int(CGFloat(components[1]) * 255) + let b = Int(CGFloat(components[2]) * 255) + + // If alpha of color is less than 1.0 then alpha hex is relevant. + if cgColor.numberOfComponents == 4 && components[3] < 1.0 { + let a = Int(CGFloat(components[3]) * 255) + return String(format: "%02X%02X%02X%02X", r, g, b, a) + } + + return String(format: "%02X%02X%02X", r, g, b) + } else if numberOfComponents == 2 { + // Monochromatic color space + let value = Int(CGFloat(components[0]) * 255) + + // If alpha of color is less than 1.0 then alpha hex is relevant. + if components[1] < 1.0 { + let alpha = Int(CGFloat(components[1]) * 255) + return String(format: "%02X%02X%02X%02X", value, value, value, alpha) + } + return String(format: "%02X%02X%02X", value, value, value) + } + + return nil + } } diff --git a/VDS/Protocols/Surfaceable.swift b/VDS/Protocols/Surfaceable.swift new file mode 100644 index 00000000..4988a146 --- /dev/null +++ b/VDS/Protocols/Surfaceable.swift @@ -0,0 +1,16 @@ +// +// Surfaceable.swift +// VDS +// +// Created by Matt Bruce on 7/26/22. +// + +import Foundation + +public enum Surface: String, Codable { + case light, dark +} + +public protocol Surfaceable { + var surface: Surface { get set } +}