refactored more of the toggle

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2022-07-26 12:04:41 -05:00
parent b1324444f8
commit d61f60cc21
5 changed files with 67 additions and 13 deletions

View File

@ -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 = "<group>"; };
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 = "<absolute>"; };
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 = "<absolute>"; };
EA3361A1288B1E840071C351 /* ToggleModelProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ToggleModelProtocol.swift; sourceTree = "<group>"; };
EA3361A1288B1E840071C351 /* VDSToggleModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VDSToggleModel.swift; sourceTree = "<group>"; };
EA3361A7288B23300071C351 /* UIColor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIColor.swift; sourceTree = "<group>"; };
EA3361A9288B25E40071C351 /* Disabling.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Disabling.swift; sourceTree = "<group>"; };
EA3361AC288B26190071C351 /* DataTrackable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataTrackable.swift; sourceTree = "<group>"; };
@ -59,6 +60,7 @@
EA3361BE288B2EA60071C351 /* Modelable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Modelable.swift; sourceTree = "<group>"; };
EA3361C228902D960071C351 /* VDSToggle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VDSToggle.swift; sourceTree = "<group>"; };
EA3361C4289030FC0071C351 /* Accessable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Accessable.swift; sourceTree = "<group>"; };
EA3361C8289054C50071C351 /* Surfaceable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Surfaceable.swift; sourceTree = "<group>"; };
/* 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 = "<group>";
@ -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 = "<group>";
@ -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 */,

View File

@ -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<ToggleModelProtocol>, Changable {
@objcMembers open class VDSToggle: Control<VDSToggleModel>, 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()
}

View File

@ -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 }
}

View File

@ -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
}
}

View File

@ -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 }
}