diff --git a/VDS.xcodeproj/project.pbxproj b/VDS.xcodeproj/project.pbxproj index 23e062f4..78fcf40c 100644 --- a/VDS.xcodeproj/project.pbxproj +++ b/VDS.xcodeproj/project.pbxproj @@ -22,7 +22,7 @@ EA3361B6288B2A410071C351 /* VDSControl.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA3361B5288B2A410071C351 /* VDSControl.swift */; }; EA3361B8288B2AAA0071C351 /* ViewProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA3361B7288B2AAA0071C351 /* ViewProtocol.swift */; }; EA3361BD288B2C760071C351 /* TypeAlias.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA3361BC288B2C760071C351 /* TypeAlias.swift */; }; - EA3361BF288B2EA60071C351 /* Modelable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA3361BE288B2EA60071C351 /* Modelable.swift */; }; + EA3361BF288B2EA60071C351 /* ModelHandlerable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA3361BE288B2EA60071C351 /* ModelHandlerable.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 */; }; @@ -40,10 +40,11 @@ EA3362432892EFF20071C351 /* VDSLabelModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA3362422892EFF20071C351 /* VDSLabelModel.swift */; }; EA3362452892F9130071C351 /* Labelable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA3362442892F9130071C351 /* Labelable.swift */; }; EA33624728931B050071C351 /* Initable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA33624628931B050071C351 /* Initable.swift */; }; - EA3C3B4C2894823E000CA526 /* ProxPropertyWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA3C3B4B2894823E000CA526 /* ProxPropertyWrapper.swift */; }; + EA3C3B4C2894823E000CA526 /* AnyProxy-PropertyWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA3C3B4B2894823E000CA526 /* AnyProxy-PropertyWrapper.swift */; }; EAF7F0952899861000B287F5 /* VDSCheckbox.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAF7F0932899861000B287F5 /* VDSCheckbox.swift */; }; EAF7F0962899861000B287F5 /* VDSCheckboxModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAF7F0942899861000B287F5 /* VDSCheckboxModel.swift */; }; EAF7F09A2899B17200B287F5 /* CATransaction.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAF7F0992899B17200B287F5 /* CATransaction.swift */; }; + EAF7F09E289AAEC000B287F5 /* VDSConstants.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAF7F09D289AAEC000B287F5 /* VDSConstants.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -73,7 +74,7 @@ EA3361B5288B2A410071C351 /* VDSControl.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VDSControl.swift; sourceTree = ""; }; EA3361B7288B2AAA0071C351 /* ViewProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewProtocol.swift; sourceTree = ""; }; EA3361BC288B2C760071C351 /* TypeAlias.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeAlias.swift; sourceTree = ""; }; - EA3361BE288B2EA60071C351 /* Modelable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Modelable.swift; sourceTree = ""; }; + EA3361BE288B2EA60071C351 /* ModelHandlerable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModelHandlerable.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 = ""; }; @@ -91,10 +92,11 @@ EA3362422892EFF20071C351 /* VDSLabelModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VDSLabelModel.swift; sourceTree = ""; }; 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 /* ProxPropertyWrapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProxPropertyWrapper.swift; sourceTree = ""; }; + EA3C3B4B2894823E000CA526 /* AnyProxy-PropertyWrapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AnyProxy-PropertyWrapper.swift"; sourceTree = ""; }; EAF7F0932899861000B287F5 /* VDSCheckbox.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VDSCheckbox.swift; sourceTree = ""; }; EAF7F0942899861000B287F5 /* VDSCheckboxModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VDSCheckboxModel.swift; sourceTree = ""; }; EAF7F0992899B17200B287F5 /* CATransaction.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CATransaction.swift; sourceTree = ""; }; + EAF7F09D289AAEC000B287F5 /* VDSConstants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VDSConstants.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -212,7 +214,7 @@ EA3361AE288B26310071C351 /* FormFieldable.swift */, EA33624628931B050071C351 /* Initable.swift */, EA3362442892F9130071C351 /* Labelable.swift */, - EA3361BE288B2EA60071C351 /* Modelable.swift */, + EA3361BE288B2EA60071C351 /* ModelHandlerable.swift */, EA3361C8289054C50071C351 /* Surfaceable.swift */, EA3361B7288B2AAA0071C351 /* ViewProtocol.swift */, ); @@ -223,7 +225,8 @@ isa = PBXGroup; children = ( EA3361B5288B2A410071C351 /* VDSControl.swift */, - EA3C3B4B2894823E000CA526 /* ProxPropertyWrapper.swift */, + EA3C3B4B2894823E000CA526 /* AnyProxy-PropertyWrapper.swift */, + EAF7F09D289AAEC000B287F5 /* VDSConstants.swift */, ); path = Classes; sourceTree = ""; @@ -409,8 +412,9 @@ EA33624728931B050071C351 /* Initable.swift in Sources */, EA3361BD288B2C760071C351 /* TypeAlias.swift in Sources */, EAF7F09A2899B17200B287F5 /* CATransaction.swift in Sources */, - EA3C3B4C2894823E000CA526 /* ProxPropertyWrapper.swift in Sources */, + EA3C3B4C2894823E000CA526 /* AnyProxy-PropertyWrapper.swift in Sources */, EA3361AF288B26310071C351 /* FormFieldable.swift in Sources */, + EAF7F09E289AAEC000B287F5 /* VDSConstants.swift in Sources */, EA3361B3288B265D0071C351 /* Changable.swift in Sources */, EA336171288B19200071C351 /* VDS.docc in Sources */, EAF7F0962899861000B287F5 /* VDSCheckboxModel.swift in Sources */, @@ -421,7 +425,7 @@ EA33623E2892EE950071C351 /* UIDevice.swift in Sources */, EA3362302891EB4A0071C351 /* VDSFonts.swift in Sources */, EA3361B8288B2AAA0071C351 /* ViewProtocol.swift in Sources */, - EA3361BF288B2EA60071C351 /* Modelable.swift in Sources */, + EA3361BF288B2EA60071C351 /* ModelHandlerable.swift in Sources */, EA3361A8288B23300071C351 /* UIColor.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/VDS/Classes/ProxPropertyWrapper.swift b/VDS/Classes/AnyProxy-PropertyWrapper.swift similarity index 100% rename from VDS/Classes/ProxPropertyWrapper.swift rename to VDS/Classes/AnyProxy-PropertyWrapper.swift diff --git a/VDS/Classes/VDSConstants.swift b/VDS/Classes/VDSConstants.swift new file mode 100644 index 00000000..fb496161 --- /dev/null +++ b/VDS/Classes/VDSConstants.swift @@ -0,0 +1,12 @@ +// +// VDSConstants.swift +// VDS +// +// Created by Matt Bruce on 8/3/22. +// + +import Foundation + +public struct VDSConstants { + public static let ModelStateDebounce = 0.02 +} diff --git a/VDS/Classes/VDSControl.swift b/VDS/Classes/VDSControl.swift index 3ce9dc1d..98c17788 100644 --- a/VDS/Classes/VDSControl.swift +++ b/VDS/Classes/VDSControl.swift @@ -9,7 +9,8 @@ import Foundation import UIKit import Combine -open class VDSControl: UIControl, Modelable, ViewProtocol { + +open class VDSControl: UIControl, ModelHandlerable, ViewProtocol { @Published public var model: ModelType private var cancellable: AnyCancellable? @@ -53,7 +54,7 @@ open class VDSControl: UIControl, Modelable, ViewProtocol { initialSetupPerformed = true setupView() } - cancellable = $model.debounce(for: .seconds(ModelStateDebounce), scheduler: RunLoop.main).sink { [weak self] viewModel in + cancellable = $model.debounce(for: .seconds(VDSConstants.ModelStateDebounce), scheduler: RunLoop.main).sink { [weak self] viewModel in self?.onStateChange(viewModel: viewModel) } } diff --git a/VDS/Components/Checkbox/VDSCheckbox.swift b/VDS/Components/Checkbox/VDSCheckbox.swift index 10aa4220..9f134a04 100644 --- a/VDS/Components/Checkbox/VDSCheckbox.swift +++ b/VDS/Components/Checkbox/VDSCheckbox.swift @@ -259,7 +259,6 @@ import Combine checkboxWidthConstraint = checkboxView.widthAnchor.constraint(equalToConstant: checkboxSize.width) checkboxWidthConstraint?.isActive = true - checkboxView.layer.borderWidth = 1.0 setCheckboxColor(viewModel: model) mainStackView.topAnchor.constraint(equalTo: topAnchor).isActive = true @@ -390,12 +389,9 @@ import Combine public var checkColor: UIColor = .white public var isSelected: Bool = false { didSet { - if oldValue != isSelected { - if let shapeLayer = shapeLayer, let sublayers = layer.sublayers, sublayers.contains(shapeLayer) { - shapeLayer.removeFromSuperlayer() - self.shapeLayer = nil - } - drawShapeLayer() + if let shapeLayer = shapeLayer, let sublayers = layer.sublayers, sublayers.contains(shapeLayer) { + shapeLayer.removeFromSuperlayer() + self.shapeLayer = nil } } } @@ -407,6 +403,7 @@ import Combine private func drawShapeLayer() { layer.borderColor = borderColor.cgColor layer.cornerRadius = 2.0 + layer.borderWidth = 1.0 shapeLayer?.strokeColor = checkColor.cgColor guard let path = try? checkMarkPath(), shapeLayer == nil else { return } diff --git a/VDS/Components/Label/VDSLabel.swift b/VDS/Components/Label/VDSLabel.swift index 8151bc1b..d36be140 100644 --- a/VDS/Components/Label/VDSLabel.swift +++ b/VDS/Components/Label/VDSLabel.swift @@ -10,7 +10,7 @@ import UIKit import VDSColorTokens import Combine -open class VDSLabel: UILabel, Modelable, Initable { +open class VDSLabel: UILabel, ModelHandlerable, Initable { @Published public var model: VDSLabelModel = DefaultLabelModel() private var cancellable: AnyCancellable? @@ -52,7 +52,7 @@ open class VDSLabel: UILabel, Modelable, Initable { } private func setup() { - cancellable = $model.debounce(for: .seconds(ModelStateDebounce), scheduler: RunLoop.main).sink { [weak self] viewModel in + cancellable = $model.debounce(for: .seconds(VDSConstants.ModelStateDebounce), scheduler: RunLoop.main).sink { [weak self] viewModel in self?.onStateChange(viewModel: viewModel) } } diff --git a/VDS/Protocols/Accessable.swift b/VDS/Protocols/Accessable.swift index 67905b27..469602ca 100644 --- a/VDS/Protocols/Accessable.swift +++ b/VDS/Protocols/Accessable.swift @@ -18,7 +18,7 @@ public protocol Accessable { } //Helpers to set within the UIControl -extension Modelable where Self: UIView { +extension ModelHandlerable where Self: UIView { private var accessableModel: Accessable? { guard let model = self.model as? Accessable else { return nil diff --git a/VDS/Protocols/Modelable.swift b/VDS/Protocols/ModelHandlerable.swift similarity index 77% rename from VDS/Protocols/Modelable.swift rename to VDS/Protocols/ModelHandlerable.swift index 83b0e780..1e8bd38a 100644 --- a/VDS/Protocols/Modelable.swift +++ b/VDS/Protocols/ModelHandlerable.swift @@ -7,9 +7,7 @@ import Foundation -public let ModelStateDebounce = 0.02 - -public protocol Modelable { +public protocol ModelHandlerable { associatedtype ModelType var model: ModelType { get set } init(with model: ModelType)