From 2a1f3c9e331be27b5ac4df14662955b29c9cae96 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 26 Aug 2022 13:15:29 -0500 Subject: [PATCH] initial commit Signed-off-by: Matt Bruce --- VDS.xcodeproj/project.pbxproj | 36 +++++- VDS/Classes/CollectionView.swift | 114 ++++++++++++++++++ VDS/Classes/CollectionViewCell.swift | 108 +++++++++++++++++ VDS/Components/RadioSwatch/RadioSwatch.swift | 8 ++ .../RadioSwatch/RadioSwatchGroup.swift | 8 ++ .../RadioSwatch/RadioSwatchGroupModel.swift | 8 ++ .../RadioSwatch/RadioSwatchModel.swift | 8 ++ 7 files changed, 288 insertions(+), 2 deletions(-) create mode 100644 VDS/Classes/CollectionView.swift create mode 100644 VDS/Classes/CollectionViewCell.swift create mode 100644 VDS/Components/RadioSwatch/RadioSwatch.swift create mode 100644 VDS/Components/RadioSwatch/RadioSwatchGroup.swift create mode 100644 VDS/Components/RadioSwatch/RadioSwatchGroupModel.swift create mode 100644 VDS/Components/RadioSwatch/RadioSwatchModel.swift diff --git a/VDS.xcodeproj/project.pbxproj b/VDS.xcodeproj/project.pbxproj index cebd999c..84e18c9d 100644 --- a/VDS.xcodeproj/project.pbxproj +++ b/VDS.xcodeproj/project.pbxproj @@ -7,6 +7,12 @@ objects = { /* Begin PBXBuildFile section */ + EA1F265D28B944F00033E859 /* CollectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA1F265B28B944F00033E859 /* CollectionView.swift */; }; + EA1F265E28B944F00033E859 /* CollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA1F265C28B944F00033E859 /* CollectionViewCell.swift */; }; + EA1F266428B945070033E859 /* RadioSwatchGroupModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA1F266028B945070033E859 /* RadioSwatchGroupModel.swift */; }; + EA1F266528B945070033E859 /* RadioSwatch.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA1F266128B945070033E859 /* RadioSwatch.swift */; }; + EA1F266628B945070033E859 /* RadioSwatchGroup.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA1F266228B945070033E859 /* RadioSwatchGroup.swift */; }; + EA1F266728B945070033E859 /* RadioSwatchModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA1F266328B945070033E859 /* RadioSwatchModel.swift */; }; EA336171288B19200071C351 /* VDS.docc in Sources */ = {isa = PBXBuildFile; fileRef = EA336170288B19200071C351 /* VDS.docc */; }; EA336177288B19210071C351 /* VDS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EA33616C288B19200071C351 /* VDS.framework */; }; EA33617C288B19210071C351 /* VDSTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA33617B288B19210071C351 /* VDSTests.swift */; }; @@ -93,6 +99,12 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + EA1F265B28B944F00033E859 /* CollectionView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CollectionView.swift; sourceTree = ""; }; + EA1F265C28B944F00033E859 /* CollectionViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CollectionViewCell.swift; sourceTree = ""; }; + EA1F266028B945070033E859 /* RadioSwatchGroupModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RadioSwatchGroupModel.swift; sourceTree = ""; }; + EA1F266128B945070033E859 /* RadioSwatch.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RadioSwatch.swift; sourceTree = ""; }; + EA1F266228B945070033E859 /* RadioSwatchGroup.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RadioSwatchGroup.swift; sourceTree = ""; }; + EA1F266328B945070033E859 /* RadioSwatchModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RadioSwatchModel.swift; sourceTree = ""; }; EA33616C288B19200071C351 /* VDS.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = VDS.framework; sourceTree = BUILT_PRODUCTS_DIR; }; EA33616F288B19200071C351 /* VDS.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = VDS.h; sourceTree = ""; }; EA336170288B19200071C351 /* VDS.docc */ = {isa = PBXFileReference; lastKnownFileType = folder.documentationcatalog; path = VDS.docc; sourceTree = ""; }; @@ -195,6 +207,17 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + EA1F265F28B945070033E859 /* RadioSwatch */ = { + isa = PBXGroup; + children = ( + EA1F266128B945070033E859 /* RadioSwatch.swift */, + EA1F266328B945070033E859 /* RadioSwatchModel.swift */, + EA1F266228B945070033E859 /* RadioSwatchGroup.swift */, + EA1F266028B945070033E859 /* RadioSwatchGroupModel.swift */, + ); + path = RadioSwatch; + sourceTree = ""; + }; EA336162288B19200071C351 = { isa = PBXGroup; children = ( @@ -258,11 +281,12 @@ EA33619D288B1E330071C351 /* Components */ = { isa = PBXGroup; children = ( + EAF7F092289985E200B287F5 /* Checkbox */, + EA3362412892EF700071C351 /* Label */, EA89200B28B530F0006B9984 /* RadioBox */, EAF7F11428A1470D00B287F5 /* RadioButton */, - EAF7F092289985E200B287F5 /* Checkbox */, + EA1F265F28B945070033E859 /* RadioSwatch */, EA3361A0288B1E6F0071C351 /* Toggle */, - EA3362412892EF700071C351 /* Label */, ); path = Components; sourceTree = ""; @@ -316,6 +340,8 @@ EA3361B4288B2A360071C351 /* Classes */ = { isa = PBXGroup; children = ( + EA1F265B28B944F00033E859 /* CollectionView.swift */, + EA1F265C28B944F00033E859 /* CollectionViewCell.swift */, EAF7F0B8289C139800B287F5 /* ColorConfiguration.swift */, EAF7F09D289AAEC000B287F5 /* Constants.swift */, EA3361B5288B2A410071C351 /* Control.swift */, @@ -568,6 +594,7 @@ EAF7F0A0289AB7EC00B287F5 /* View.swift in Sources */, EAF7F11828A1475A00B287F5 /* RadioButtonModel.swift in Sources */, EA89200D28B530FD006B9984 /* RadioBoxModel.swift in Sources */, + EA1F266728B945070033E859 /* RadioSwatchModel.swift in Sources */, EA89201328B568D8006B9984 /* RadioBox.swift in Sources */, EA3362402892EF6C0071C351 /* Label.swift in Sources */, EAF7F0B3289B1ADC00B287F5 /* LabelAttributeAction.swift in Sources */, @@ -582,6 +609,7 @@ EA89201728B56CFF006B9984 /* RadioBoxGroupModel.swift in Sources */, EA3361C9289054C50071C351 /* Surfaceable.swift in Sources */, EA3361A2288B1E840071C351 /* ToggleModel.swift in Sources */, + EA1F265D28B944F00033E859 /* CollectionView.swift in Sources */, EA3362432892EFF20071C351 /* LabelModel.swift in Sources */, EA33624728931B050071C351 /* Initable.swift in Sources */, EAF7F0A4289B017C00B287F5 /* LabelAttributeModel.swift in Sources */, @@ -602,6 +630,7 @@ EAF7F0BB289D80ED00B287F5 /* Modelable.swift in Sources */, EA89201528B56CF4006B9984 /* RadioBoxGroup.swift in Sources */, EAF7F09E289AAEC000B287F5 /* Constants.swift in Sources */, + EA1F266528B945070033E859 /* RadioSwatch.swift in Sources */, EA3361B3288B265D0071C351 /* Changable.swift in Sources */, EA89200228AECF2A006B9984 /* UIButton+Publisher.swift in Sources */, EAF7F0AB289B13FD00B287F5 /* LabelAttributeFont.swift in Sources */, @@ -619,10 +648,13 @@ EA3361AD288B26190071C351 /* DataTrackable.swift in Sources */, EA33623E2892EE950071C351 /* UIDevice.swift in Sources */, EA3362302891EB4A0071C351 /* Fonts.swift in Sources */, + EA1F265E28B944F00033E859 /* CollectionViewCell.swift in Sources */, EAF7F0AD289B142900B287F5 /* LabelAttributeStrikeThrough.swift in Sources */, EA3361B8288B2AAA0071C351 /* ViewProtocol.swift in Sources */, EA3361BF288B2EA60071C351 /* ModelHandlerable.swift in Sources */, EA3361A8288B23300071C351 /* UIColor.swift in Sources */, + EA1F266428B945070033E859 /* RadioSwatchGroupModel.swift in Sources */, + EA1F266628B945070033E859 /* RadioSwatchGroup.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/VDS/Classes/CollectionView.swift b/VDS/Classes/CollectionView.swift new file mode 100644 index 00000000..eca2ddf4 --- /dev/null +++ b/VDS/Classes/CollectionView.swift @@ -0,0 +1,114 @@ +// +// CollectionView.swift +// VDS +// +// Created by Matt Bruce on 8/25/22. +// + +import Foundation +import UIKit +import Combine + +open class CollectionView: UICollectionView, ModelHandlerable, ViewProtocol, Resettable { + + //-------------------------------------------------- + // MARK: - Combine Properties + //-------------------------------------------------- + @Published public var model: ModelType = ModelType() + public var modelPublisher: Published.Publisher { $model } + public var subscribers = Set() + + //-------------------------------------------------- + // MARK: - Properties + //-------------------------------------------------- + private var initialSetupPerformed = false + + @Proxy(\.model.surface) + open var surface: Surface + + @Proxy(\.model.disabled) + open var disabled: Bool { + didSet { + self.isEnabled = !disabled + } + } + + open var isEnabled: Bool { + get { !model.disabled } + set { + //create local vars for clear coding + let disabled = !newValue + if model.disabled != disabled { + model.disabled = disabled + } + } + } + + //-------------------------------------------------- + // MARK: - Initializers + //-------------------------------------------------- + required public init() { + super.init(frame: .zero, collectionViewLayout: UICollectionViewFlowLayout()) + initialSetup() + } + + public required init(with model: ModelType) { + super.init(frame: .zero, collectionViewLayout: UICollectionViewFlowLayout()) + initialSetup() + set(with: model) + } + + public required init(with model: ModelType, collectionViewLayout layout: UICollectionViewLayout) { + super.init(frame: .zero, collectionViewLayout: layout) + initialSetup() + set(with: model) + } + + public override init(frame: CGRect, collectionViewLayout layout: UICollectionViewLayout) { + super.init(frame: frame, collectionViewLayout: layout) + initialSetup() + set(with: model) + } + + public required init?(coder: NSCoder) { + super.init(coder: coder) + initialSetup() + } + + //-------------------------------------------------- + // MARK: - Setup + //-------------------------------------------------- + + public func initialSetup() { + if !initialSetupPerformed { + initialSetupPerformed = true + setupUpdateView() + setup() + } + } + + //-------------------------------------------------- + // MARK: - Overrides + //-------------------------------------------------- + open func shouldUpdateView(viewModel: ModelType) -> Bool { + fatalError("Implement shouldUpdateView") + } + + open func updateView(viewModel: ModelType) { + fatalError("Implement updateView") + } + + open func reset() { + backgroundColor = .clear + if let model = model as? Resettable { + model.reset() + } + } + + // MARK: - ViewProtocol + /// Will be called only once. + open func setup() { + translatesAutoresizingMaskIntoConstraints = false + insetsLayoutMarginsFromSafeArea = false + } +} diff --git a/VDS/Classes/CollectionViewCell.swift b/VDS/Classes/CollectionViewCell.swift new file mode 100644 index 00000000..4f2eca85 --- /dev/null +++ b/VDS/Classes/CollectionViewCell.swift @@ -0,0 +1,108 @@ +// +// CollectionViewCell.swift +// VDS +// +// Created by Matt Bruce on 8/25/22. +// + +import Foundation +import UIKit +import Combine + +open class CollectionViewCell: UICollectionViewCell, ModelHandlerable, ViewProtocol, Resettable { + + //-------------------------------------------------- + // MARK: - Combine Properties + //-------------------------------------------------- + @Published public var model: ModelType = ModelType() + public var modelPublisher: Published.Publisher { $model } + public var subscribers = Set() + + //-------------------------------------------------- + // MARK: - Properties + //-------------------------------------------------- + private var initialSetupPerformed = false + + @Proxy(\.model.surface) + open var surface: Surface + + @Proxy(\.model.disabled) + open var disabled: Bool { + didSet { + self.isEnabled = !disabled + } + } + + open var isEnabled: Bool { + get { !model.disabled } + set { + //create local vars for clear coding + let disabled = !newValue + if model.disabled != disabled { + model.disabled = disabled + } + } + } + + //-------------------------------------------------- + // MARK: - Initializers + //-------------------------------------------------- + required public init() { + super.init(frame: .zero) + initialSetup() + } + + public required init(with model: ModelType) { + super.init(frame: .zero) + initialSetup() + set(with: model) + } + + public override init(frame: CGRect) { + super.init(frame: frame) + initialSetup() + set(with: model) + } + + public required init?(coder: NSCoder) { + super.init(coder: coder) + initialSetup() + } + + //-------------------------------------------------- + // MARK: - Setup + //-------------------------------------------------- + + public func initialSetup() { + if !initialSetupPerformed { + initialSetupPerformed = true + setupUpdateView() + setup() + } + } + + //-------------------------------------------------- + // MARK: - Overrides + //-------------------------------------------------- + open func shouldUpdateView(viewModel: ModelType) -> Bool { + fatalError("Implement shouldUpdateView") + } + + open func updateView(viewModel: ModelType) { + fatalError("Implement updateView") + } + + open func reset() { + backgroundColor = .clear + if let model = model as? Resettable { + model.reset() + } + } + + // MARK: - ViewProtocol + /// Will be called only once. + open func setup() { + translatesAutoresizingMaskIntoConstraints = false + insetsLayoutMarginsFromSafeArea = false + } +} diff --git a/VDS/Components/RadioSwatch/RadioSwatch.swift b/VDS/Components/RadioSwatch/RadioSwatch.swift new file mode 100644 index 00000000..22be4f21 --- /dev/null +++ b/VDS/Components/RadioSwatch/RadioSwatch.swift @@ -0,0 +1,8 @@ +// +// RadioSwatch.swift +// VDS +// +// Created by Matt Bruce on 8/25/22. +// + +import Foundation diff --git a/VDS/Components/RadioSwatch/RadioSwatchGroup.swift b/VDS/Components/RadioSwatch/RadioSwatchGroup.swift new file mode 100644 index 00000000..608d9723 --- /dev/null +++ b/VDS/Components/RadioSwatch/RadioSwatchGroup.swift @@ -0,0 +1,8 @@ +// +// RadioSwatchGroup.swift +// VDS +// +// Created by Matt Bruce on 8/25/22. +// + +import Foundation diff --git a/VDS/Components/RadioSwatch/RadioSwatchGroupModel.swift b/VDS/Components/RadioSwatch/RadioSwatchGroupModel.swift new file mode 100644 index 00000000..18109458 --- /dev/null +++ b/VDS/Components/RadioSwatch/RadioSwatchGroupModel.swift @@ -0,0 +1,8 @@ +// +// RadioSwatchGroupModel.swift +// VDS +// +// Created by Matt Bruce on 8/25/22. +// + +import Foundation diff --git a/VDS/Components/RadioSwatch/RadioSwatchModel.swift b/VDS/Components/RadioSwatch/RadioSwatchModel.swift new file mode 100644 index 00000000..d672e9f7 --- /dev/null +++ b/VDS/Components/RadioSwatch/RadioSwatchModel.swift @@ -0,0 +1,8 @@ +// +// RadioSwatchModel.swift +// VDS +// +// Created by Matt Bruce on 8/25/22. +// + +import Foundation