vds_ios/VDS/BaseClasses/Control.swift
Matt Bruce b1324444f8 refactored out speicific atomic code
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
2022-07-26 11:08:42 -05:00

65 lines
1.5 KiB
Swift

//
// Control.swift
// VDS
//
// Created by Matt Bruce on 7/22/22.
//
import Foundation
import UIKit
@objcMembers open class Control<ModelType>: UIControl, Modelable, ViewProtocol {
//--------------------------------------------------
// MARK: - Properties
//--------------------------------------------------
private var initialSetupPerformed = false
public var model: ModelType?
//--------------------------------------------------
// MARK: - Initializers
//--------------------------------------------------
public override init(frame: CGRect) {
super.init(frame: .zero)
initialSetup()
}
public init() {
super.init(frame: .zero)
initialSetup()
}
public required init?(coder: NSCoder) {
super.init(coder: coder)
fatalError("Control does not support xib.")
}
//--------------------------------------------------
// MARK: - Setup
//--------------------------------------------------
public func initialSetup() {
if !initialSetupPerformed {
initialSetupPerformed = true
setupView()
}
}
open func set(with model: ModelType) {
self.model = model
}
open func reset() {
backgroundColor = .clear
}
// MARK: - ViewProtocol
open func updateView(_ size: CGFloat) { }
/// Will be called only once.
open func setupView() {
translatesAutoresizingMaskIntoConstraints = false
insetsLayoutMarginsFromSafeArea = false
}
}