refactored controls
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
26642e2d55
commit
c368f275cb
@ -15,10 +15,6 @@ open class Control<ModelType: Modelable>: UIControl, ModelHandlerable, ViewProto
|
||||
@Published public var model: ModelType
|
||||
private var cancellable: AnyCancellable?
|
||||
|
||||
open func set(with model: ModelType) {
|
||||
self.model = model
|
||||
}
|
||||
|
||||
open func shouldUpdateView(viewModel: ModelType) -> Bool {
|
||||
fatalError("Implement shouldUpdateView")
|
||||
}
|
||||
@ -41,12 +37,22 @@ open class Control<ModelType: Modelable>: UIControl, ModelHandlerable, ViewProto
|
||||
//--------------------------------------------------
|
||||
// MARK: - Initializers
|
||||
//--------------------------------------------------
|
||||
required public init() {
|
||||
self.model = ModelType()
|
||||
super.init(frame: .zero)
|
||||
initialSetup()
|
||||
}
|
||||
|
||||
required public init(with model: ModelType) {
|
||||
public required init(with model: ModelType) {
|
||||
self.model = model
|
||||
super.init(frame: .zero)
|
||||
initialSetup()
|
||||
set(with: model)
|
||||
}
|
||||
|
||||
public override init(frame: CGRect) {
|
||||
self.model = ModelType()
|
||||
super.init(frame: .zero)
|
||||
initialSetup()
|
||||
}
|
||||
|
||||
public required init?(coder: NSCoder) {
|
||||
|
||||
@ -15,10 +15,6 @@ open class View<ModelType: Modelable>: UIView, ModelHandlerable, ViewProtocol, R
|
||||
@Published public var model: ModelType
|
||||
private var cancellable: AnyCancellable?
|
||||
|
||||
open func set(with model: ModelType) {
|
||||
self.model = model
|
||||
}
|
||||
|
||||
open func shouldUpdateView(viewModel: ModelType) -> Bool {
|
||||
fatalError("Implement shouldUpdateView")
|
||||
}
|
||||
@ -37,15 +33,26 @@ open class View<ModelType: Modelable>: UIView, ModelHandlerable, ViewProtocol, R
|
||||
|
||||
@Proxy(\.model.disabled)
|
||||
open var disabled: Bool
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Initializers
|
||||
//--------------------------------------------------
|
||||
required public init() {
|
||||
self.model = ModelType()
|
||||
super.init(frame: .zero)
|
||||
initialSetup()
|
||||
}
|
||||
|
||||
required public init(with model: ModelType) {
|
||||
public required init(with model: ModelType) {
|
||||
self.model = model
|
||||
super.init(frame: .zero)
|
||||
initialSetup()
|
||||
set(with: model)
|
||||
}
|
||||
|
||||
public override init(frame: CGRect) {
|
||||
self.model = ModelType()
|
||||
super.init(frame: .zero)
|
||||
initialSetup()
|
||||
}
|
||||
|
||||
public required init?(coder: NSCoder) {
|
||||
|
||||
@ -58,21 +58,6 @@ open class CheckboxBase<ModelType: CheckboxModel>: SelectorBase<ModelType> {
|
||||
return config
|
||||
}()
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Initializers
|
||||
//--------------------------------------------------
|
||||
public convenience init() {
|
||||
self.init(with: ModelType())
|
||||
}
|
||||
|
||||
required public init(with model: ModelType) {
|
||||
super.init(with: model)
|
||||
}
|
||||
|
||||
required public init?(coder: NSCoder) {
|
||||
super.init(with: ModelType())
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Checkbox View
|
||||
//--------------------------------------------------
|
||||
|
||||
@ -12,7 +12,7 @@ import Combine
|
||||
|
||||
public class Label:LabelBase<DefaultLabelModel>{}
|
||||
|
||||
open class LabelBase<ModelType: LabelModel>: UILabel, ModelHandlerable, Initable, Resettable {
|
||||
open class LabelBase<ModelType: LabelModel>: UILabel, ModelHandlerable, Initable, Resettable, ViewProtocol {
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Combine Properties
|
||||
@ -62,32 +62,34 @@ open class LabelBase<ModelType: LabelModel>: UILabel, ModelHandlerable, Initable
|
||||
//--------------------------------------------------
|
||||
// MARK: - Initializers
|
||||
//--------------------------------------------------
|
||||
required public convenience init() {
|
||||
self.init(frame: .zero)
|
||||
required public init() {
|
||||
self.model = ModelType()
|
||||
super.init(frame: .zero)
|
||||
initialSetup()
|
||||
}
|
||||
|
||||
public required convenience init(with model: ModelType) {
|
||||
self.init()
|
||||
public required init(with model: ModelType) {
|
||||
self.model = model
|
||||
super.init(frame: .zero)
|
||||
initialSetup()
|
||||
}
|
||||
|
||||
|
||||
public override init(frame: CGRect) {
|
||||
self.model = ModelType()
|
||||
super.init(frame: frame)
|
||||
setup()
|
||||
super.init(frame: .zero)
|
||||
initialSetup()
|
||||
}
|
||||
|
||||
required public init?(coder: NSCoder) {
|
||||
self.model = ModelType()
|
||||
public required init?(coder: NSCoder) {
|
||||
self.model = ModelType.init()
|
||||
super.init(coder: coder)
|
||||
setup()
|
||||
initialSetup()
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Public Functions
|
||||
//--------------------------------------------------
|
||||
open func setup() {
|
||||
open func initialSetup() {
|
||||
backgroundColor = .clear
|
||||
numberOfLines = 0
|
||||
lineBreakMode = .byWordWrapping
|
||||
@ -104,9 +106,13 @@ open class LabelBase<ModelType: LabelModel>: UILabel, ModelHandlerable, Initable
|
||||
self.updateView(viewModel: viewModel)
|
||||
|
||||
}
|
||||
|
||||
setup()
|
||||
}
|
||||
|
||||
public func reset() {
|
||||
open func setup() {}
|
||||
|
||||
open func reset() {
|
||||
text = nil
|
||||
attributedText = nil
|
||||
textColor = .black
|
||||
@ -116,12 +122,7 @@ open class LabelBase<ModelType: LabelModel>: UILabel, ModelHandlerable, Initable
|
||||
accessibilityTraits = .staticText
|
||||
numberOfLines = 0
|
||||
}
|
||||
|
||||
//Modelable
|
||||
open func set(with model: ModelType) {
|
||||
self.model = model
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - State
|
||||
//--------------------------------------------------
|
||||
|
||||
@ -100,23 +100,7 @@ open class RadioButtonBase<ModelType: RadioButtonModel>: SelectorBase<ModelType>
|
||||
config.forTrue.disabled.darkColor = VDSColor.interactiveDisabledOndark
|
||||
return config
|
||||
}()
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Initializers
|
||||
//--------------------------------------------------
|
||||
public convenience init() {
|
||||
self.init(with: ModelType())
|
||||
}
|
||||
|
||||
required public init(with model: ModelType) {
|
||||
super.init(with: model)
|
||||
}
|
||||
|
||||
required public init?(coder: NSCoder) {
|
||||
super.init(with: ModelType())
|
||||
}
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - RadioButton View
|
||||
//--------------------------------------------------
|
||||
|
||||
@ -139,21 +139,6 @@ open class SelectorBase<ModelType: SelectorModel>: Control<ModelType>, Changable
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Initializers
|
||||
//--------------------------------------------------
|
||||
public convenience init() {
|
||||
self.init(with: ModelType())
|
||||
}
|
||||
|
||||
required public init(with model: ModelType) {
|
||||
super.init(with: model)
|
||||
}
|
||||
|
||||
required public init?(coder: NSCoder) {
|
||||
super.init(with: ModelType())
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Constraints
|
||||
|
||||
@ -115,19 +115,4 @@ open class SelectorGroup<SelectorType, SelectorGroupType: SelectorGroupModel<Sel
|
||||
}
|
||||
|
||||
open func didSelect(selector: SelectorHandlerType) { }
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Initializers
|
||||
//--------------------------------------------------
|
||||
public convenience init() {
|
||||
self.init(with: ModelType())
|
||||
}
|
||||
|
||||
required public init(with model: ModelType) {
|
||||
super.init(with: model)
|
||||
}
|
||||
|
||||
required public init?(coder: NSCoder) {
|
||||
super.init(with: ModelType())
|
||||
}
|
||||
}
|
||||
|
||||
@ -170,22 +170,7 @@ open class ToggleBase<ModelType: ToggleModel>: Control<ModelType>, Changable {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Initializers
|
||||
//--------------------------------------------------
|
||||
public convenience init() {
|
||||
self.init(with: ModelType())
|
||||
}
|
||||
|
||||
required public init(with model: ModelType) {
|
||||
super.init(with: model)
|
||||
}
|
||||
|
||||
required public init?(coder: NSCoder) {
|
||||
super.init(with: ModelType())
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Constraints
|
||||
//--------------------------------------------------
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
public protocol ModelHandlerable {
|
||||
public protocol ModelHandlerable: AnyObject {
|
||||
associatedtype ModelType: Modelable
|
||||
var model: ModelType { get set }
|
||||
|
||||
@ -16,3 +16,13 @@ public protocol ModelHandlerable {
|
||||
func shouldUpdateView(viewModel: ModelType) -> Bool
|
||||
func updateView(viewModel: ModelType)
|
||||
}
|
||||
|
||||
extension ModelHandlerable {
|
||||
|
||||
public func set(with model: ModelType) {
|
||||
if shouldUpdateView(viewModel: model){
|
||||
updateView(viewModel: model)
|
||||
self.model = model
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user