vds_ios/VDS/Classes/View.swift
Matt Bruce 63543b5cf5 fixed issues with init
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
2022-10-20 13:13:28 -05:00

92 lines
2.3 KiB
Swift

//
// Control.swift
// VDS
//
// Created by Matt Bruce on 7/22/22.
//
import Foundation
import UIKit
import Combine
open class View: UIView, ModelHandlerable, ViewProtocol, Resettable {
//--------------------------------------------------
// MARK: - Combine Properties
//--------------------------------------------------
public var subject = PassthroughSubject<Void, Never>()
public var subscribers = Set<AnyCancellable>()
//--------------------------------------------------
// MARK: - Properties
//--------------------------------------------------
private var initialSetupPerformed = false
open var surface: Surface = .light { didSet { subject.send() }}
open var disabled: Bool = false { didSet { isEnabled = !disabled } }
open var isEnabled: Bool {
get { !disabled }
set {
if disabled != !newValue {
disabled = !newValue
}
isUserInteractionEnabled = isEnabled
subject.send()
}
}
//--------------------------------------------------
// MARK: - Initializers
//--------------------------------------------------
required public init() {
super.init(frame: .zero)
initialSetup()
}
public override init(frame: CGRect) {
super.init(frame: .zero)
initialSetup()
}
public required init?(coder: NSCoder) {
super.init(coder: coder)
initialSetup()
}
//--------------------------------------------------
// MARK: - Setup
//--------------------------------------------------
open func initialSetup() {
if !initialSetupPerformed {
initialSetupPerformed = true
setupUpdateView()
setup()
updateView()
}
}
//--------------------------------------------------
// MARK: - Overrides
//--------------------------------------------------
open func updateView() {
fatalError("Implement updateView")
}
open func reset() {
backgroundColor = .clear
surface = .light
disabled = false
}
// MARK: - ViewProtocol
/// Will be called only once.
open func setup() {
translatesAutoresizingMaskIntoConstraints = false
insetsLayoutMarginsFromSafeArea = false
}
}